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 
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
create::Create::measuredLeftVel
float measuredLeftVel
Definition: create.h:90
create::Create::getLeftWheelDistance
float getLeftWheelDistance() const
Get the total distance the left wheel has moved.
Definition: create.cpp:1097
create::Create::isSpotButtonPressed
bool isSpotButtonPressed() const
Get state of 'spot' button.
Definition: create.cpp:877
create::Create::updateLEDs
bool updateLEDs()
Definition: create.cpp:520
create::Create::~Create
~Create()
Attempts to disconnect from serial.
Definition: create.cpp:66
create::Create::isHourButtonPressed
bool isHourButtonPressed() const
Get state of 'hour' button.
Definition: create.cpp:847
create::Create::isDockButtonPressed
bool isDockButtonPressed() const
Get state of 'dock' button ('advance' button on Create 1).
Definition: create.cpp:867
create::Create::setAllMotors
bool setAllMotors(const float &mainPower, const float &sidePower, const float &vacuumPower)
Set the power of all motors.
Definition: create.cpp:480
create::Create::setMode
bool setMode(const create::CreateMode &mode)
Change Create mode.
Definition: create.cpp:326
create::Create::requestedRightVel
float requestedRightVel
Definition: create.h:93
create::Create::checkLED
uint8_t checkLED
Definition: create.h:70
serial_stream.h
create::Create::mainMotorPower
uint8_t mainMotorPower
Definition: create.h:62
create::Create::isCliffFrontLeft
bool isCliffFrontLeft() const
Definition: create.cpp:711
types.h
create::Create::powerLED
uint8_t powerLED
Definition: create.h:71
create::Create::getRequestedLeftWheelVel
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
create::Create
Definition: create.h:49
create::Create::isMainBrushOvercurrent
bool isMainBrushOvercurrent() const
Definition: create.cpp:1077
create::RobotModel::CREATE_2
static RobotModel CREATE_2
Compatible with Create 2 or Roomba 600 series and greater.
Definition: types.h:73
create::Create::vel
create::Vel vel
Definition: create.h:77
create::Create::data
std::shared_ptr< create::Data > data
Definition: create.h:106
create::Create::driveWheelsPwm
bool driveWheelsPwm(const float &leftWheel, const float &rightWheel)
Set the direct for the left and right wheels.
Definition: create.cpp:452
create::Create::getLightSignalFrontLeft
uint16_t getLightSignalFrontLeft() const
Get the signal strength from the front-left light sensor.
Definition: create.cpp:1007
create::Create::dtHistory
std::deque< float > dtHistory
Definition: create.h:85
create::Create::isLightBumperRight
bool isLightBumperRight() const
Definition: create.cpp:987
create::Create::getIROmni
uint8_t getIROmni() const
Get value of 8-bit IR character currently being received by omnidirectional sensor.
Definition: create.cpp:761
create::Create::connected
bool connected() const
Check if serial connection is active.
Definition: create.h:152
create::Create::setModeReportWorkaround
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
create::Create::Create
Create(RobotModel model=RobotModel::CREATE_2, bool install_signal_handler=true)
Default constructor.
Definition: create.cpp:55
create::Create::setDtHistoryLength
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
create::Create::measuredRightVel
float measuredRightVel
Definition: create.h:91
create::CleanMode
CleanMode
Definition: types.h:210
create::Create::modeReportWorkaround
bool modeReportWorkaround
Definition: create.h:103
create::Create::isCliff
bool isCliff() const
Definition: create.cpp:685
create::Create::addMatrices
Matrix addMatrices(const Matrix &A, const Matrix &B) const
Definition: create.cpp:70
create::Create::Matrix
boost::numeric::ublas::matrix< float > Matrix
Definition: create.h:51
create::Create::pose
create::Pose pose
Definition: create.h:76
create::Create::LED_DEBRIS
@ LED_DEBRIS
Definition: create.h:54
create::Create::firstOnData
bool firstOnData
Definition: create.h:83
create::Create::powerLEDIntensity
uint8_t powerLEDIntensity
Definition: create.h:72
create::Create::setMainMotor
bool setMainMotor(const float &power)
Set the power to the main brush motor.
Definition: create.cpp:508
create::Create::isClockButtonPressed
bool isClockButtonPressed() const
Not supported by any firmware!
Definition: create.cpp:814
create::Create::isDayButtonPressed
bool isDayButtonPressed() const
Get state of 'day' button.
Definition: create.cpp:837
create::Create::isRightWheeldrop
bool isRightWheeldrop() const
Definition: create.cpp:645
create::Create::isWall
bool isWall() const
Definition: create.cpp:675
create::Create::isCliffLeft
bool isCliffLeft() const
Definition: create.cpp:701
create::CreateMode
CreateMode
Definition: types.h:202
create::Create::setDate
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
create::Create::clean
bool clean(const create::CleanMode &mode=CLEAN_DEFAULT)
Starts a cleaning mode. Changes mode to MODE_PASSIVE.
Definition: create.cpp:362
create::Create::totalLeftDist
float totalLeftDist
Definition: create.h:81
create::Create::getLightSignalCenterLeft
uint16_t getLightSignalCenterLeft() const
Get the signal strength from the center-left light sensor.
Definition: create.cpp:1017
create::Create::enableDockLED
bool enableDockLED(const bool &enable)
Set the green "dock" LED on/off.
Definition: create.cpp:547
create::Create::serial
std::shared_ptr< create::Serial > serial
Definition: create.h:107
create::Create::LED_CHECK
@ LED_CHECK
Definition: create.h:57
create::Create::isSideBrushOvercurrent
bool isSideBrushOvercurrent() const
Definition: create.cpp:1067
create::Pose
Represents a robot pose.
Definition: types.h:275
create::Create::prevTicksRight
uint32_t prevTicksRight
Definition: create.h:80
create::Create::enableSpotLED
bool enableSpotLED(const bool &enable)
Set the green "spot" LED on/off.
Definition: create.cpp:539
create::Create::getPose
create::Pose getPose() const
Get the estimated pose of Create based on wheel encoders.
Definition: create.cpp:1141
create::Create::spotLED
uint8_t spotLED
Definition: create.h:68
create::Create::LED_SPOT
@ LED_SPOT
Definition: create.h:55
create::Create::driveWheels
bool driveWheels(const float &leftWheel, const float &rightWheel)
Set the velocities for the left and right wheels.
Definition: create.cpp:404
create::Create::prevTicksLeft
uint32_t prevTicksLeft
Definition: create.h:79
create::Create::getTemperature
int8_t getTemperature() const
Get the temperature of battery.
Definition: create.cpp:907
create::Create::getLightSignalRight
uint16_t getLightSignalRight() const
Get the signal strength from the right light sensor.
Definition: create.cpp:1027
create::Create::getMeasuredRightWheelVel
float getMeasuredRightWheelVel() const
Get the measured velocity of the right wheel.
Definition: create.cpp:1109
create::Create::isLightBumperCenterLeft
bool isLightBumperCenterLeft() const
Definition: create.cpp:957
create::Create::setVacuumMotor
bool setVacuumMotor(const float &power)
Set the power to the vacuum motor.
Definition: create.cpp:516
create::DayOfWeek
DayOfWeek
Definition: types.h:225
create::Create::getLightSignalFrontRight
uint16_t getLightSignalFrontRight() const
Get the signal strength from the front-right light sensor.
Definition: create.cpp:1037
create::Create::drive
bool drive(const float &xVel, const float &angularVel)
Set the forward and angular velocity of Create.
Definition: create.cpp:473
create::Create::dock
bool dock() const
Starts the docking behaviour. Changes mode to MODE_PASSIVE.
Definition: create.cpp:366
create::Create::enableCheckRobotLED
bool enableCheckRobotLED(const bool &enable)
Set the orange "check Create" LED on/off.
Definition: create.cpp:555
create::CLEAN_DEFAULT
@ CLEAN_DEFAULT
Definition: types.h:211
create::Create::isLightBumperFrontRight
bool isLightBumperFrontRight() const
Definition: create.cpp:977
create::Create::isCliffRight
bool isCliffRight() const
Definition: create.cpp:721
create::Create::getLightSignalCenterRight
uint16_t getLightSignalCenterRight() const
Get the signal strength from the center-right light sensor.
Definition: create.cpp:1047
create::Create::getTotalPackets
uint64_t getTotalPackets() const
Get the total number of serial packets received (including corrupt packets) since first connecting to...
Definition: create.cpp:1153
create::Create::getModeReportWorkaround
bool getModeReportWorkaround() const
Definition: create.cpp:1125
create::Create::isMinButtonPressed
bool isMinButtonPressed() const
Get state of 'min' button.
Definition: create.cpp:857
create::Create::isWheelOvercurrent
bool isWheelOvercurrent() const
Definition: create.cpp:1087
create::Create::onData
void onData()
Definition: create.cpp:94
create::Create::dtHistoryLength
uint8_t dtHistoryLength
Definition: create.h:86
create::Create::debrisLED
uint8_t debrisLED
Definition: create.h:67
create::ChargingState
ChargingState
Definition: types.h:216
create::Create::getNumCorruptPackets
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
create::Create::setPowerLED
bool setPowerLED(const uint8_t &power, const uint8_t &intensity=255)
Set the center power LED.
Definition: create.cpp:563
create::Create::getRequestedRightWheelVel
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
create::Create::getVoltage
float getVoltage() const
Get battery voltage.
Definition: create.cpp:887
create::Create::enableDebrisLED
bool enableDebrisLED(const bool &enable)
Set the blue "debris" LED on/off.
Definition: create.cpp:531
create::Create::getCurrent
float getCurrent() const
Get current flowing in/out of battery. A positive current implies Create is charging.
Definition: create.cpp:897
create::Create::isLeftBumper
bool isLeftBumper() const
Definition: create.cpp:655
create::Create::isRightBumper
bool isRightBumper() const
Definition: create.cpp:665
create::Create::model
RobotModel model
Definition: create.h:60
create::Create::isLightBumperLeft
bool isLightBumperLeft() const
Definition: create.cpp:937
create::Create::getRightWheelDistance
float getRightWheelDistance() const
Get the total distance the right wheel has moved.
Definition: create.cpp:1101
create::Create::isMovingForward
bool isMovingForward() const
Definition: create.cpp:1057
create::Create::mode
CreateMode mode
Definition: create.h:74
create::Create::setDigitsASCII
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
create::Create::getBatteryCharge
float getBatteryCharge() const
Get battery's remaining charge.
Definition: create.cpp:917
create::Create::isCleanButtonPressed
bool isCleanButtonPressed() const
Get state of 'clean' button ('play' button on Create 1).
Definition: create.cpp:803
create::Create::isLightBumperCenterRight
bool isLightBumperCenterRight() const
Definition: create.cpp:967
create::Create::isLightBumperFrontLeft
bool isLightBumperFrontLeft() const
Definition: create.cpp:947
create::Create::LED_DOCK
@ LED_DOCK
Definition: create.h:56
create::Create::poseCovar
Matrix poseCovar
Definition: create.h:88
create::Create::getVel
create::Vel getVel() const
Get the estimated velocity of Create based on wheel encoders.
Definition: create.cpp:1145
data.h
create::Create::getIRRight
uint8_t getIRRight() const
Get value of 8-bit IR character currently being received by right sensor.
Definition: create.cpp:781
create::Create::disconnect
void disconnect()
Disconnect from serial.
Definition: create.cpp:315
create::Create::driveRadius
bool driveRadius(const float &velocity, const float &radius)
Set the average wheel velocity and turning radius of Create.
Definition: create.cpp:380
serial_query.h
create::Create::getDirtDetect
uint8_t getDirtDetect() const
Get level of the dirt detect sensor.
Definition: create.cpp:751
create::Create::prevOnDataTime
std::chrono::time_point< std::chrono::steady_clock > prevOnDataTime
Definition: create.h:84
create::Create::defineSong
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
create::Create::getMode
create::CreateMode getMode()
Get the current mode reported by Create.
Definition: create.cpp:1129
create::Create::totalRightDist
float totalRightDist
Definition: create.h:82
create::Create::connect
bool connect(const std::string &port, const int &baud)
Make a serial connection to Create.
Definition: create.cpp:294
create::Create::getMeasuredLeftWheelVel
float getMeasuredLeftWheelVel() const
Get the measured velocity of the left wheel.
Definition: create.cpp:1105
create::Create::isLeftWheeldrop
bool isLeftWheeldrop() const
Definition: create.cpp:635
create::Create::setDigits
bool setDigits(const std::vector< bool > &segments) const
Set the four 7-segment display digits from left to right.
create::Create::isCliffFrontRight
bool isCliffFrontRight() const
Definition: create.cpp:731
create::Create::sideMotorPower
uint8_t sideMotorPower
Definition: create.h:63
create::Create::vacuumMotorPower
uint8_t vacuumMotorPower
Definition: create.h:64
util.h
create::Create::getChargingState
create::ChargingState getChargingState() const
Get the current charging state.
Definition: create.cpp:791
create::Create::getIRLeft
uint8_t getIRLeft() const
Get value of 8-bit IR character currently being received by left sensor.
Definition: create.cpp:771
create::Create::isScheduleButtonPressed
bool isScheduleButtonPressed() const
Not supported by any firmware!
Definition: create.cpp:826
create::Create::requestedLeftVel
float requestedLeftVel
Definition: create.h:92
create
Definition: create.h:48
create::Create::isWheeldrop
bool isWheeldrop() const
Definition: create.cpp:625
create::Create::playSong
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
create::Create::init
void init(bool install_signal_handler)
Definition: create.cpp:17
create::RobotModel
Definition: types.h:48
create::Create::setSideMotor
bool setSideMotor(const float &power)
Set the power to the side brush motor.
Definition: create.cpp:512
create::Create::isVirtualWall
bool isVirtualWall() const
Definition: create.cpp:741
create::Create::CreateLED
CreateLED
Definition: create.h:53
create::Create::dockLED
uint8_t dockLED
Definition: create.h:69
create::Create::getBatteryCapacity
float getBatteryCapacity() const
Get estimated battery charge capacity.
Definition: create.cpp:927
create::Create::getLightSignalLeft
uint16_t getLightSignalLeft() const
Get the signal strength from the left light sensor.
Definition: create.cpp:997


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