create.h
Go to the documentation of this file.
1 
32 #ifndef CREATE_H
33 #define CREATE_H
34 
35 #include <boost/shared_ptr.hpp>
36 #include <boost/numeric/ublas/matrix.hpp>
37 #include <chrono>
38 #include <string>
39 #include <unistd.h>
40 
41 #include "create/serial_stream.h"
42 #include "create/serial_query.h"
43 #include "create/data.h"
44 #include "create/types.h"
45 #include "create/util.h"
46 
47 namespace create {
48  class Create {
49  private:
50  typedef boost::numeric::ublas::matrix<float> Matrix;
51 
52  enum CreateLED {
54  LED_SPOT = 2,
55  LED_DOCK = 4,
57  };
58 
60 
61  uint8_t mainMotorPower;
62  uint8_t sideMotorPower;
64 
65  // LEDs
66  uint8_t debrisLED;
67  uint8_t spotLED;
68  uint8_t dockLED;
69  uint8_t checkLED;
70  uint8_t powerLED;
72 
74 
77 
78  uint32_t prevTicksLeft;
79  uint32_t prevTicksRight;
83  std::chrono::time_point<std::chrono::system_clock> prevOnDataTime;
84 
85  Matrix poseCovar;
86 
91 
92  void init();
93  // Add two matrices and handle overflow case
94  Matrix addMatrices(const Matrix &A, const Matrix &B) const;
95  void onData();
96  bool updateLEDs();
97 
98  protected:
99  boost::shared_ptr<create::Data> data;
100  boost::shared_ptr<create::Serial> serial;
101 
102  public:
111 
120  Create(const std::string& port, const int& baud, RobotModel model = RobotModel::CREATE_2);
121 
125  ~Create();
126 
134  bool connect(const std::string& port, const int& baud);
135 
141  inline bool connected() const { return serial->connected(); };
142 
146  void disconnect();
147 
153  bool setMode(const create::CreateMode& mode);
154 
160  bool clean(const create::CleanMode& mode = CLEAN_DEFAULT);
161 
167  bool dock() const;
168 
176  bool setDate(const create::DayOfWeek& day, const uint8_t& hour, const uint8_t& min) const;
177 
187  bool driveRadius(const float& velocity, const float& radius);
188 
195  bool driveWheels(const float& leftWheel, const float& rightWheel);
196 
203  bool driveWheelsPwm(const float& leftWheel, const float& rightWheel);
204 
211  bool drive(const float& xVel, const float& angularVel);
212 
218  bool setSideMotor(const float& power);
219 
225  bool setMainMotor(const float& power);
226 
232  bool setVacuumMotor(const float& power);
233 
241  bool setAllMotors(const float& mainPower, const float& sidePower, const float& vacuumPower);
242 
248  bool enableDebrisLED(const bool& enable);
249 
255  bool enableSpotLED(const bool& enable);
256 
262  bool enableDockLED(const bool& enable);
263 
269  bool enableCheckRobotLED(const bool& enable);
270 
277  bool setPowerLED(const uint8_t& power, const uint8_t& intensity = 255);
278 
298  bool setDigits(const std::vector<bool>& segments) const;
299 
309  bool setDigitsASCII(const uint8_t& digit1, const uint8_t& digit2,
310  const uint8_t& digit3, const uint8_t& digit4) const;
311 
322  bool defineSong(const uint8_t& songNumber,
323  const uint8_t& songLength,
324  const uint8_t* notes,
325  const float* durations) const;
326 
333  bool playSong(const uint8_t& songNumber) const;
334 
338  bool isWheeldrop() const;
339 
343  bool isLeftWheeldrop() const;
344 
348  bool isRightWheeldrop() const;
349 
353  bool isLeftBumper() const;
354 
358  bool isRightBumper() const;
359 
363  bool isWall() const;
364 
368  bool isCliff() const;
369 
373  bool isCliffLeft() const;
374 
378  bool isCliffFrontLeft() const;
379 
383  bool isCliffRight() const;
384 
388  bool isCliffFrontRight() const;
389 
393  bool isVirtualWall() const;
394 
399  bool isWheelOvercurrent() const;
400 
405  bool isMainBrushOvercurrent() const;
406 
411  bool isSideBrushOvercurrent() const;
412 
417  uint8_t getDirtDetect() const;
418 
423  uint8_t getIROmni() const;
424 
430  uint8_t getIRLeft() const;
431 
436  uint8_t getIRRight() const;
437 
442  bool isCleanButtonPressed() const;
443 
447  bool isClockButtonPressed() const;
448 
452  bool isScheduleButtonPressed() const;
453 
458  bool isDayButtonPressed() const;
459 
464  bool isHourButtonPressed() const;
465 
470  bool isMinButtonPressed() const;
471 
476  bool isDockButtonPressed() const;
477 
482  bool isSpotButtonPressed() const;
483 
488  float getVoltage() const;
489 
495  float getCurrent() const;
496 
501  int8_t getTemperature() const;
502 
507  float getBatteryCharge() const;
508 
513  float getBatteryCapacity() const;
514 
518  bool isLightBumperLeft() const;
519 
523  bool isLightBumperFrontLeft() const;
524 
528  bool isLightBumperCenterLeft() const;
529 
533  bool isLightBumperRight() const;
534 
538  bool isLightBumperFrontRight() const;
539 
543  bool isLightBumperCenterRight() const;
544 
549  uint16_t getLightSignalLeft() const;
550 
555  uint16_t getLightSignalFrontLeft() const;
556 
561  uint16_t getLightSignalCenterLeft() const;
562 
567  uint16_t getLightSignalRight() const;
568 
573  uint16_t getLightSignalFrontRight() const;
574 
579  uint16_t getLightSignalCenterRight() const;
580 
584  bool isMovingForward() const;
585 
590  float getLeftWheelDistance() const;
591 
596  float getRightWheelDistance() const;
597 
602  float getMeasuredLeftWheelVel() const;
603 
608  float getMeasuredRightWheelVel() const;
609 
615  float getRequestedLeftWheelVel() const;
616 
622  float getRequestedRightWheelVel() const;
623 
629 
635 
640  create::Pose getPose() const;
641 
646  create::Vel getVel() const;
647 
654  uint64_t getNumCorruptPackets() const;
655 
660  uint64_t getTotalPackets() const;
661  }; // end Create class
662 
663 } // namespace create
664 #endif // CREATE_DRIVER_H
uint64_t getTotalPackets() const
Get the total number of serial packets received (including corrupt packets) since first connecting to...
Definition: create.cpp:1082
ChargingState
Definition: types.h:216
bool setSideMotor(const float &power)
Set the power to the side brush motor.
Definition: create.cpp:488
void init()
Definition: create.cpp:18
uint8_t getIROmni() const
Get value of 8-bit IR character currently being received by omnidirectional sensor.
Definition: create.cpp:733
float totalLeftDist
Definition: create.h:80
create::Vel vel
Definition: create.h:76
uint8_t dockLED
Definition: create.h:68
uint8_t powerLEDIntensity
Definition: create.h:71
bool isLeftWheeldrop() const
Definition: create.cpp:607
float totalRightDist
Definition: create.h:81
float getMeasuredRightWheelVel() const
Get the measured velocity of the right wheel.
Definition: create.cpp:1051
bool setVacuumMotor(const float &power)
Set the power to the vacuum motor.
Definition: create.cpp:492
bool isWheeldrop() const
Definition: create.cpp:597
bool isWheelOvercurrent() const
bool firstOnData
Definition: create.h:82
bool isLightBumperFrontLeft() const
Definition: create.cpp:919
bool setDigitsASCII(const uint8_t &digit1, const uint8_t &digit2, const uint8_t &digit3, const uint8_t &digit4) const
Set the four 7-segment display digits from left to right with ASCII codes. Any code out side the acce...
Definition: create.cpp:549
float requestedRightVel
Definition: create.h:90
bool isCliffRight() const
Definition: create.cpp:693
bool isLeftBumper() const
Definition: create.cpp:627
create::ChargingState getChargingState() const
Get the current charging state.
Definition: create.cpp:763
bool driveWheels(const float &leftWheel, const float &rightWheel)
Set the velocities for the left and right wheels.
Definition: create.cpp:380
bool dock() const
Starts the docking behaviour. Changes mode to MODE_PASSIVE.
Definition: create.cpp:342
uint32_t prevTicksRight
Definition: create.h:79
create::Pose pose
Definition: create.h:75
int8_t getTemperature() const
Get the temperature of battery.
Definition: create.cpp:879
bool isHourButtonPressed() const
Get state of &#39;hour&#39; button.
Definition: create.cpp:819
bool isClockButtonPressed() const
Not supported by any firmware!
Definition: create.cpp:786
uint16_t getLightSignalFrontLeft() const
Get the signal strength from the front-left light sensor.
Definition: create.cpp:979
bool isLightBumperCenterRight() const
Definition: create.cpp:939
float getRequestedLeftWheelVel() const
Get the requested velocity of the left wheel. This value is bounded at the maximum velocity of the ro...
Definition: create.cpp:1055
uint8_t spotLED
Definition: create.h:67
bool setDate(const create::DayOfWeek &day, const uint8_t &hour, const uint8_t &min) const
Sets the internal clock of Create.
Definition: create.cpp:346
float getRightWheelDistance() const
Get the total distance the right wheel has moved.
Definition: create.cpp:1043
create::Pose getPose() const
Get the estimated pose of Create based on wheel encoders.
Definition: create.cpp:1070
boost::shared_ptr< create::Serial > serial
Definition: create.h:100
Definition: create.h:47
uint8_t getDirtDetect() const
Get level of the dirt detect sensor.
Definition: create.cpp:723
uint8_t powerLED
Definition: create.h:70
float getRequestedRightWheelVel() const
Get the requested velocity of the right wheel. This value is bounded at the maximum velocity of the r...
Definition: create.cpp:1059
bool enableDockLED(const bool &enable)
Set the green "dock" LED on/off.
Definition: create.cpp:523
bool setPowerLED(const uint8_t &power, const uint8_t &intensity=255)
Set the center power LED.
Definition: create.cpp:539
bool isLightBumperFrontRight() const
Definition: create.cpp:949
float getBatteryCharge() const
Get battery&#39;s remaining charge.
Definition: create.cpp:889
uint8_t getIRRight() const
Get value of 8-bit IR character currently being received by right sensor.
Definition: create.cpp:753
float getCurrent() const
Get current flowing in/out of battery. A positive current implies Create is charging.
Definition: create.cpp:869
bool driveWheelsPwm(const float &leftWheel, const float &rightWheel)
Set the direct for the left and right wheels.
Definition: create.cpp:428
CreateMode mode
Definition: create.h:73
Represents a robot pose.
Definition: types.h:275
bool isVirtualWall() const
Definition: create.cpp:713
bool isCliffFrontRight() const
Definition: create.cpp:703
bool setDigits(const std::vector< bool > &segments) const
Set the four 7-segment display digits from left to right.
bool playSong(const uint8_t &songNumber) const
Play a previously created song. This command will not work if a song was not already defined with the...
Definition: create.cpp:590
bool connected() const
Check if serial connection is active.
Definition: create.h:141
bool isMovingForward() const
Definition: create.cpp:1029
Matrix addMatrices(const Matrix &A, const Matrix &B) const
Definition: create.cpp:66
float measuredRightVel
Definition: create.h:88
create::Vel getVel() const
Get the estimated velocity of Create based on wheel encoders.
Definition: create.cpp:1074
uint64_t getNumCorruptPackets() const
Get the number of corrupt serial packets since first connecting to Create. This value is ideally zero...
Definition: create.cpp:1078
uint16_t getLightSignalCenterLeft() const
Get the signal strength from the center-left light sensor.
Definition: create.cpp:989
uint8_t sideMotorPower
Definition: create.h:62
bool isLightBumperLeft() const
Definition: create.cpp:909
bool clean(const create::CleanMode &mode=CLEAN_DEFAULT)
Starts a cleaning mode. Changes mode to MODE_PASSIVE.
Definition: create.cpp:338
uint8_t checkLED
Definition: create.h:69
bool isScheduleButtonPressed() const
Not supported by any firmware!
Definition: create.cpp:798
bool enableCheckRobotLED(const bool &enable)
Set the orange "check Create" LED on/off.
Definition: create.cpp:531
bool driveRadius(const float &velocity, const float &radius)
Set the average wheel velocity and turning radius of Create.
Definition: create.cpp:356
bool enableSpotLED(const bool &enable)
Set the green "spot" LED on/off.
Definition: create.cpp:515
bool setMainMotor(const float &power)
Set the power to the main brush motor.
Definition: create.cpp:484
bool isMinButtonPressed() const
Get state of &#39;min&#39; button.
Definition: create.cpp:829
bool isCleanButtonPressed() const
Get state of &#39;clean&#39; button (&#39;play&#39; button on Create 1).
Definition: create.cpp:775
bool drive(const float &xVel, const float &angularVel)
Set the forward and angular velocity of Create.
Definition: create.cpp:449
bool isDockButtonPressed() const
Get state of &#39;dock&#39; button (&#39;advance&#39; button on Create 1).
Definition: create.cpp:839
boost::shared_ptr< create::Data > data
Definition: create.h:99
float getMeasuredLeftWheelVel() const
Get the measured velocity of the left wheel.
Definition: create.cpp:1047
boost::numeric::ublas::matrix< float > Matrix
Definition: create.h:50
bool enableDebrisLED(const bool &enable)
Set the blue "debris" LED on/off.
Definition: create.cpp:507
float getVoltage() const
Get battery voltage.
Definition: create.cpp:859
uint16_t getLightSignalLeft() const
Get the signal strength from the left light sensor.
Definition: create.cpp:969
uint8_t vacuumMotorPower
Definition: create.h:63
bool isMainBrushOvercurrent() const
bool updateLEDs()
Definition: create.cpp:496
bool isRightWheeldrop() const
Definition: create.cpp:617
bool isRightBumper() const
Definition: create.cpp:637
bool isDayButtonPressed() const
Get state of &#39;day&#39; button.
Definition: create.cpp:809
bool isWall() const
Definition: create.cpp:647
RobotModel model
Definition: create.h:59
uint16_t getLightSignalCenterRight() const
Get the signal strength from the center-right light sensor.
Definition: create.cpp:1019
bool isSpotButtonPressed() const
Get state of &#39;spot&#39; button.
Definition: create.cpp:849
uint32_t prevTicksLeft
Definition: create.h:78
CleanMode
Definition: types.h:210
uint8_t debrisLED
Definition: create.h:66
bool isCliffFrontLeft() const
Definition: create.cpp:683
float measuredLeftVel
Definition: create.h:87
Create(RobotModel model=RobotModel::CREATE_2)
Default constructor.
Definition: create.cpp:53
uint16_t getLightSignalRight() const
Get the signal strength from the right light sensor.
Definition: create.cpp:999
bool isSideBrushOvercurrent() const
float getBatteryCapacity() const
Get estimated battery charge capacity.
Definition: create.cpp:899
bool isCliffLeft() const
Definition: create.cpp:673
float requestedLeftVel
Definition: create.h:89
bool connect(const std::string &port, const int &baud)
Make a serial connection to Create.
Definition: create.cpp:270
uint8_t mainMotorPower
Definition: create.h:61
static RobotModel CREATE_2
Compatible with Create 2 or Roomba 600 series and greater.
Definition: types.h:73
uint8_t getIRLeft() const
Get value of 8-bit IR character currently being received by left sensor.
Definition: create.cpp:743
bool isCliff() const
Definition: create.cpp:657
std::chrono::time_point< std::chrono::system_clock > prevOnDataTime
Definition: create.h:83
bool setAllMotors(const float &mainPower, const float &sidePower, const float &vacuumPower)
Set the power of all motors.
Definition: create.cpp:456
Matrix poseCovar
Definition: create.h:85
void disconnect()
Disconnect from serial.
Definition: create.cpp:291
void onData()
Definition: create.cpp:90
CreateMode
Definition: types.h:202
DayOfWeek
Definition: types.h:225
float getLeftWheelDistance() const
Get the total distance the left wheel has moved.
Definition: create.cpp:1039
bool setMode(const create::CreateMode &mode)
Change Create mode.
Definition: create.cpp:302
create::CreateMode getMode()
Get the current mode reported by Create.
Definition: create.cpp:1063
~Create()
Attempts to disconnect from serial.
Definition: create.cpp:62
bool isLightBumperRight() const
Definition: create.cpp:959
bool isLightBumperCenterLeft() const
Definition: create.cpp:929
uint16_t getLightSignalFrontRight() const
Get the signal strength from the front-right light sensor.
Definition: create.cpp:1009
bool defineSong(const uint8_t &songNumber, const uint8_t &songLength, const uint8_t *notes, const float *durations) const
Defines a song from the provided notes and labels it with a song number.
Definition: create.cpp:567


libcreate
Author(s): Jacob Perron
autogenerated on Thu Dec 5 2019 04:03:13