create.h
Go to the documentation of this file.
1 
32 #ifndef CREATE_H
33 #define CREATE_H
34 
35 #include <boost/numeric/ublas/matrix.hpp>
36 #include <chrono>
37 #include <memory>
38 #include <string>
39 #include <unistd.h>
40 #include <deque>
41 
42 #include "create/serial_stream.h"
43 #include "create/serial_query.h"
44 #include "create/data.h"
45 #include "create/types.h"
46 #include "create/util.h"
47 
48 namespace create {
49  class Create {
50  private:
51  typedef boost::numeric::ublas::matrix<float> Matrix;
52 
53  enum CreateLED {
55  LED_SPOT = 2,
56  LED_DOCK = 4,
58  };
59 
61 
62  uint8_t mainMotorPower;
63  uint8_t sideMotorPower;
65 
66  // LEDs
67  uint8_t debrisLED;
68  uint8_t spotLED;
69  uint8_t dockLED;
70  uint8_t checkLED;
71  uint8_t powerLED;
73 
75 
78 
79  uint32_t prevTicksLeft;
80  uint32_t prevTicksRight;
84  std::chrono::time_point<std::chrono::steady_clock> prevOnDataTime;
85  std::deque<float> dtHistory;
86  uint8_t dtHistoryLength;
87 
88  Matrix poseCovar;
89 
94 
95  void init(bool install_signal_handler);
96  // Add two matrices and handle overflow case
97  Matrix addMatrices(const Matrix &A, const Matrix &B) const;
98  void onData();
99  bool updateLEDs();
100 
101  // Flag to enable/disable the workaround for some 6xx incorrectly reporting OI mode
102  // https://github.com/AutonomyLab/create_robot/issues/64
104 
105  protected:
106  std::shared_ptr<create::Data> data;
107  std::shared_ptr<create::Serial> serial;
108 
109  public:
119  Create(RobotModel model = RobotModel::CREATE_2, bool install_signal_handler = true);
120 
131  Create(const std::string& port, const int& baud, RobotModel model = RobotModel::CREATE_2, bool install_signal_handler = true);
132 
136  ~Create();
137 
145  bool connect(const std::string& port, const int& baud);
146 
152  inline bool connected() const { return serial->connected(); };
153 
157  void disconnect();
158 
164  bool setMode(const create::CreateMode& mode);
165 
171  bool clean(const create::CleanMode& mode = CLEAN_DEFAULT);
172 
178  bool dock() const;
179 
187  bool setDate(const create::DayOfWeek& day, const uint8_t& hour, const uint8_t& min) const;
188 
198  bool driveRadius(const float& velocity, const float& radius);
199 
206  bool driveWheels(const float& leftWheel, const float& rightWheel);
207 
214  bool driveWheelsPwm(const float& leftWheel, const float& rightWheel);
215 
222  bool drive(const float& xVel, const float& angularVel);
223 
229  bool setSideMotor(const float& power);
230 
236  bool setMainMotor(const float& power);
237 
243  bool setVacuumMotor(const float& power);
244 
252  bool setAllMotors(const float& mainPower, const float& sidePower, const float& vacuumPower);
253 
259  bool enableDebrisLED(const bool& enable);
260 
266  bool enableSpotLED(const bool& enable);
267 
273  bool enableDockLED(const bool& enable);
274 
280  bool enableCheckRobotLED(const bool& enable);
281 
288  bool setPowerLED(const uint8_t& power, const uint8_t& intensity = 255);
289 
309  bool setDigits(const std::vector<bool>& segments) const;
310 
320  bool setDigitsASCII(const uint8_t& digit1, const uint8_t& digit2,
321  const uint8_t& digit3, const uint8_t& digit4) const;
322 
333  bool defineSong(const uint8_t& songNumber,
334  const uint8_t& songLength,
335  const uint8_t* notes,
336  const float* durations) const;
337 
344  bool playSong(const uint8_t& songNumber) const;
345 
352  void setDtHistoryLength(const uint8_t& dtHistoryLength);
353 
357  bool isWheeldrop() const;
358 
362  bool isLeftWheeldrop() const;
363 
367  bool isRightWheeldrop() const;
368 
372  bool isLeftBumper() const;
373 
377  bool isRightBumper() const;
378 
382  bool isWall() const;
383 
387  bool isCliff() const;
388 
392  bool isCliffLeft() const;
393 
397  bool isCliffFrontLeft() const;
398 
402  bool isCliffRight() const;
403 
407  bool isCliffFrontRight() const;
408 
412  bool isVirtualWall() const;
413 
418  bool isWheelOvercurrent() const;
419 
424  bool isMainBrushOvercurrent() const;
425 
430  bool isSideBrushOvercurrent() const;
431 
436  uint8_t getDirtDetect() const;
437 
442  uint8_t getIROmni() const;
443 
449  uint8_t getIRLeft() const;
450 
455  uint8_t getIRRight() const;
456 
461  bool isCleanButtonPressed() const;
462 
466  bool isClockButtonPressed() const;
467 
471  bool isScheduleButtonPressed() const;
472 
477  bool isDayButtonPressed() const;
478 
483  bool isHourButtonPressed() const;
484 
489  bool isMinButtonPressed() const;
490 
495  bool isDockButtonPressed() const;
496 
501  bool isSpotButtonPressed() const;
502 
507  float getVoltage() const;
508 
514  float getCurrent() const;
515 
520  int8_t getTemperature() const;
521 
526  float getBatteryCharge() const;
527 
532  float getBatteryCapacity() const;
533 
537  bool isLightBumperLeft() const;
538 
542  bool isLightBumperFrontLeft() const;
543 
547  bool isLightBumperCenterLeft() const;
548 
552  bool isLightBumperRight() const;
553 
557  bool isLightBumperFrontRight() const;
558 
562  bool isLightBumperCenterRight() const;
563 
568  uint16_t getLightSignalLeft() const;
569 
574  uint16_t getLightSignalFrontLeft() const;
575 
580  uint16_t getLightSignalCenterLeft() const;
581 
586  uint16_t getLightSignalRight() const;
587 
592  uint16_t getLightSignalFrontRight() const;
593 
598  uint16_t getLightSignalCenterRight() const;
599 
603  bool isMovingForward() const;
604 
609  float getLeftWheelDistance() const;
610 
615  float getRightWheelDistance() const;
616 
621  float getMeasuredLeftWheelVel() const;
622 
627  float getMeasuredRightWheelVel() const;
628 
634  float getRequestedLeftWheelVel() const;
635 
641  float getRequestedRightWheelVel() const;
642 
648 
654 
659  create::Pose getPose() const;
660 
665  create::Vel getVel() const;
666 
673  uint64_t getNumCorruptPackets() const;
674 
679  uint64_t getTotalPackets() const;
680 
687  void setModeReportWorkaround(const bool& enable);
688 
692  bool getModeReportWorkaround() const;
693 
694  }; // end Create class
695 
696 } // namespace create
697 #endif // CREATE_DRIVER_H
bool isDockButtonPressed() const
Get state of &#39;dock&#39; button (&#39;advance&#39; button on Create 1).
Definition: create.cpp:867
ChargingState
Definition: types.h:216
bool setSideMotor(const float &power)
Set the power to the side brush motor.
Definition: create.cpp:512
float totalLeftDist
Definition: create.h:81
bool isLightBumperLeft() const
Definition: create.cpp:937
bool isSpotButtonPressed() const
Get state of &#39;spot&#39; button.
Definition: create.cpp:877
uint16_t getLightSignalLeft() const
Get the signal strength from the left light sensor.
Definition: create.cpp:997
create::Vel vel
Definition: create.h:77
uint16_t getLightSignalCenterRight() const
Get the signal strength from the center-right light sensor.
Definition: create.cpp:1047
bool modeReportWorkaround
Definition: create.h:103
uint8_t dockLED
Definition: create.h:69
uint8_t powerLEDIntensity
Definition: create.h:72
bool isCliffFrontLeft() const
Definition: create.cpp:711
float totalRightDist
Definition: create.h:82
bool setVacuumMotor(const float &power)
Set the power to the vacuum motor.
Definition: create.cpp:516
bool isSideBrushOvercurrent() const
Definition: create.cpp:1067
bool firstOnData
Definition: create.h:83
float requestedRightVel
Definition: create.h:93
uint16_t getLightSignalRight() const
Get the signal strength from the right light sensor.
Definition: create.cpp:1027
bool isHourButtonPressed() const
Get state of &#39;hour&#39; button.
Definition: create.cpp:847
bool isScheduleButtonPressed() const
Not supported by any firmware!
Definition: create.cpp:826
bool isVirtualWall() const
Definition: create.cpp:741
float getVoltage() const
Get battery voltage.
Definition: create.cpp:887
bool setDate(const create::DayOfWeek &day, const uint8_t &hour, const uint8_t &min) const
Sets the internal clock of Create.
Definition: create.cpp:370
bool driveWheels(const float &leftWheel, const float &rightWheel)
Set the velocities for the left and right wheels.
Definition: create.cpp:404
bool dock() const
Starts the docking behaviour. Changes mode to MODE_PASSIVE.
Definition: create.cpp:366
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:573
float getBatteryCapacity() const
Get estimated battery charge capacity.
Definition: create.cpp:927
uint32_t prevTicksRight
Definition: create.h:80
create::Pose pose
Definition: create.h:76
bool isRightWheeldrop() const
Definition: create.cpp:645
uint8_t dtHistoryLength
Definition: create.h:86
bool isCliffLeft() const
Definition: create.cpp:701
uint8_t spotLED
Definition: create.h:68
void setDtHistoryLength(const uint8_t &dtHistoryLength)
Set dtHistoryLength parameter. Used to configure the size of the buffer for calculating average time ...
Definition: create.cpp:621
bool isMovingForward() const
Definition: create.cpp:1057
bool isCleanButtonPressed() const
Get state of &#39;clean&#39; button (&#39;play&#39; button on Create 1).
Definition: create.cpp:803
bool isLightBumperCenterRight() const
Definition: create.cpp:967
bool getModeReportWorkaround() const
Definition: create.cpp:1125
bool isLeftBumper() const
Definition: create.cpp:655
Definition: create.h:48
uint8_t powerLED
Definition: create.h:71
bool enableDockLED(const bool &enable)
Set the green "dock" LED on/off.
Definition: create.cpp:547
bool setPowerLED(const uint8_t &power, const uint8_t &intensity=255)
Set the center power LED.
Definition: create.cpp:563
void init(bool install_signal_handler)
Definition: create.cpp:17
bool driveWheelsPwm(const float &leftWheel, const float &rightWheel)
Set the direct for the left and right wheels.
Definition: create.cpp:452
CreateMode mode
Definition: create.h:74
std::shared_ptr< create::Data > data
Definition: create.h:106
Represents a robot pose.
Definition: types.h:275
uint16_t getLightSignalFrontRight() const
Get the signal strength from the front-right light sensor.
Definition: create.cpp:1037
float measuredRightVel
Definition: create.h:91
uint8_t sideMotorPower
Definition: create.h:63
std::shared_ptr< create::Serial > serial
Definition: create.h:107
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:1117
bool clean(const create::CleanMode &mode=CLEAN_DEFAULT)
Starts a cleaning mode. Changes mode to MODE_PASSIVE.
Definition: create.cpp:362
uint16_t getLightSignalCenterLeft() const
Get the signal strength from the center-left light sensor.
Definition: create.cpp:1017
uint8_t checkLED
Definition: create.h:70
float getLeftWheelDistance() const
Get the total distance the left wheel has moved.
Definition: create.cpp:1097
Create(RobotModel model=RobotModel::CREATE_2, bool install_signal_handler=true)
Default constructor.
Definition: create.cpp:55
bool connected() const
Check if serial connection is active.
Definition: create.h:152
bool enableCheckRobotLED(const bool &enable)
Set the orange "check Create" LED on/off.
Definition: create.cpp:555
bool driveRadius(const float &velocity, const float &radius)
Set the average wheel velocity and turning radius of Create.
Definition: create.cpp:380
bool enableSpotLED(const bool &enable)
Set the green "spot" LED on/off.
Definition: create.cpp:539
bool setMainMotor(const float &power)
Set the power to the main brush motor.
Definition: create.cpp:508
uint64_t getNumCorruptPackets() const
Get the number of corrupt serial packets since first connecting to Create. This value is ideally zero...
Definition: create.cpp:1149
float getCurrent() const
Get current flowing in/out of battery. A positive current implies Create is charging.
Definition: create.cpp:897
bool isMainBrushOvercurrent() const
Definition: create.cpp:1077
bool drive(const float &xVel, const float &angularVel)
Set the forward and angular velocity of Create.
Definition: create.cpp:473
bool isLeftWheeldrop() const
Definition: create.cpp:635
uint8_t getIROmni() const
Get value of 8-bit IR character currently being received by omnidirectional sensor.
Definition: create.cpp:761
bool isLightBumperFrontRight() const
Definition: create.cpp:977
boost::numeric::ublas::matrix< float > Matrix
Definition: create.h:51
bool enableDebrisLED(const bool &enable)
Set the blue "debris" LED on/off.
Definition: create.cpp:531
uint8_t vacuumMotorPower
Definition: create.h:64
uint64_t getTotalPackets() const
Get the total number of serial packets received (including corrupt packets) since first connecting to...
Definition: create.cpp:1153
bool updateLEDs()
Definition: create.cpp:520
bool isWheelOvercurrent() const
Definition: create.cpp:1087
bool isCliff() const
Definition: create.cpp:685
bool isClockButtonPressed() const
Not supported by any firmware!
Definition: create.cpp:814
float getMeasuredLeftWheelVel() const
Get the measured velocity of the left wheel.
Definition: create.cpp:1105
create::ChargingState getChargingState() const
Get the current charging state.
Definition: create.cpp:791
bool setDigits(const std::vector< bool > &segments) const
Set the four 7-segment display digits from left to right.
bool isRightBumper() const
Definition: create.cpp:665
RobotModel model
Definition: create.h:60
float getRightWheelDistance() const
Get the total distance the right wheel has moved.
Definition: create.cpp:1101
std::chrono::time_point< std::chrono::steady_clock > prevOnDataTime
Definition: create.h:84
bool isLightBumperRight() const
Definition: create.cpp:987
void setModeReportWorkaround(const bool &enable)
Enable or disable the mode reporting workaround. Some Roomba 6xx robots incorrectly report the OI mod...
Definition: create.cpp:1121
bool isMinButtonPressed() const
Get state of &#39;min&#39; button.
Definition: create.cpp:857
uint32_t prevTicksLeft
Definition: create.h:79
CleanMode
Definition: types.h:210
int8_t getTemperature() const
Get the temperature of battery.
Definition: create.cpp:907
uint8_t debrisLED
Definition: create.h:67
bool isCliffRight() const
Definition: create.cpp:721
float measuredLeftVel
Definition: create.h:90
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:591
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:614
float requestedLeftVel
Definition: create.h:92
bool connect(const std::string &port, const int &baud)
Make a serial connection to Create.
Definition: create.cpp:294
uint8_t mainMotorPower
Definition: create.h:62
static RobotModel CREATE_2
Compatible with Create 2 or Roomba 600 series and greater.
Definition: types.h:73
bool isLightBumperFrontLeft() const
Definition: create.cpp:947
bool setAllMotors(const float &mainPower, const float &sidePower, const float &vacuumPower)
Set the power of all motors.
Definition: create.cpp:480
Matrix poseCovar
Definition: create.h:88
float getMeasuredRightWheelVel() const
Get the measured velocity of the right wheel.
Definition: create.cpp:1109
bool isLightBumperCenterLeft() const
Definition: create.cpp:957
void disconnect()
Disconnect from serial.
Definition: create.cpp:315
void onData()
Definition: create.cpp:94
bool isCliffFrontRight() const
Definition: create.cpp:731
CreateMode
Definition: types.h:202
DayOfWeek
Definition: types.h:225
uint8_t getIRRight() const
Get value of 8-bit IR character currently being received by right sensor.
Definition: create.cpp:781
uint16_t getLightSignalFrontLeft() const
Get the signal strength from the front-left light sensor.
Definition: create.cpp:1007
create::Vel getVel() const
Get the estimated velocity of Create based on wheel encoders.
Definition: create.cpp:1145
create::Pose getPose() const
Get the estimated pose of Create based on wheel encoders.
Definition: create.cpp:1141
bool setMode(const create::CreateMode &mode)
Change Create mode.
Definition: create.cpp:326
create::CreateMode getMode()
Get the current mode reported by Create.
Definition: create.cpp:1129
~Create()
Attempts to disconnect from serial.
Definition: create.cpp:66
uint8_t getDirtDetect() const
Get level of the dirt detect sensor.
Definition: create.cpp:751
std::deque< float > dtHistory
Definition: create.h:85
float getBatteryCharge() const
Get battery&#39;s remaining charge.
Definition: create.cpp:917
uint8_t getIRLeft() const
Get value of 8-bit IR character currently being received by left sensor.
Definition: create.cpp:771
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:1113
bool isWheeldrop() const
Definition: create.cpp:625
bool isDayButtonPressed() const
Get state of &#39;day&#39; button.
Definition: create.cpp:837
Matrix addMatrices(const Matrix &A, const Matrix &B) const
Definition: create.cpp:70
bool isWall() const
Definition: create.cpp:675


libcreate
Author(s): Jacob Perron
autogenerated on Wed May 24 2023 02:50:13