8 #ifndef _KIPR_CREATE_CREATE_HPP_
9 #define _KIPR_CREATE_CREATE_HPP_
22 typedef unsigned int speed_t;
45 void append(
const unsigned char &
byte);
46 void append(
const unsigned char *data,
const size_t &size);
49 void remove(
const size_t &i,
const size_t &len = 1);
51 const unsigned char *
data()
const;
54 unsigned char byte(
const size_t &i);
59 std::vector<unsigned char> m_script;
79 namespace CreatePackets
181 class CliffFrontLeft;
182 class CliffFrontRight;
186 class CliffLeftSignal;
187 class CliffFrontLeftSignal;
188 class CliffFrontRightSignal;
189 class CliffRightSignal;
190 class CargoBayAnalogSignal;
191 class CargoBayDigitalInputs;
194 class BatteryTemperature;
196 class BatteryCapacity;
201 class WheelDropRight;
203 class WheelDropCaster;
206 class LightBumpFrontLeft;
207 class LightBumpFrontRight;
208 class LightBumpRight;
209 class LightBumpCenterLeft;
210 class LightBumpCenterRight;
212 class LightBumpLeftSignal;
213 class LightBumpFrontLeftSignal;
214 class LightBumpFrontRightSignal;
215 class LightBumpRightSignal;
216 class LightBumpCenterLeftSignal;
217 class LightBumpCenterRightSignal;
300 bool write(
const unsigned char *data,
const size_t &len);
317 int read(
unsigned char *data,
const size_t &len);
326 bool blockingRead(
unsigned char *data,
const size_t &size,
unsigned timeout = 25);
328 template <
typename T>
331 return blockingRead(
reinterpret_cast<unsigned char *
>(&data),
sizeof(T),
332 timeout ? timeout :
sizeof(T) * 7);
335 void setLeds(
const bool &advance,
const bool &play,
const unsigned char &color,
const unsigned char &brightness);
337 void drive(
const short &velocity,
const short &radius);
348 void turn(
const short &angle,
const unsigned short &speed);
356 void move(
const short &millimeters,
const unsigned short &speed);
452 bool loadSong(
const unsigned char *song,
const unsigned char length,
const unsigned char songNum);
481 pthread_mutex_lock(&m_mutex);
488 pthread_mutex_unlock(&m_mutex);
500 void setLocalBaudRate(
const speed_t &baudRate);
507 template <
typename T>
508 inline void lazyDelete(T *&ptr)
514 inline timeval timeOfDay()
const
518 GetSystemTimeAsFileTime(&ft);
519 unsigned long t = (ULONGLONG)ft.dwLowDateTime + ((ULONGLONG)(ft.dwHighDateTime) << 32);
522 tv.tv_usec = t % 1000L;
523 tv.tv_sec = (t - tv.tv_usec) / 1000L;
527 gettimeofday(&ret, NULL);
532 inline bool hasRequiredTimePassed(
const timeval ×tamp)
const
535 timeval current = timeOfDay();
537 timersub(¤t, ×tamp, &result);
538 const long msecs = result.tv_sec * 1000 + result.tv_usec / 1000;
539 return msecs > m_refreshRate;
545 inline double timevalToFloat(
const timeval &tv)
547 return ((
double)tv.tv_sec) + ((double)tv.tv_usec / 1000000.0);
550 inline float deg2rad(
const float °)
552 return deg / 180.0 *
PI;
557 void updateSensorPacket1();
558 void updateSensorPacket2(
bool forceUpdate =
false);
559 void updateSensorPacket3();
560 void updateSensorPacket4();
561 void updateSensorPacket5();
562 void updateSensorPacket101();
566 unsigned short m_refreshRate;
568 CreatePackets::_1 m_1;
569 CreatePackets::_2 m_2;
570 CreatePackets::_3 m_3;
571 CreatePackets::_4 m_4;
572 CreatePackets::_5 m_5;
573 CreatePackets::_101 m_101;
574 timeval timestamps[6];
579 mutable sensors::PlayButton *m_playButton;
580 mutable sensors::AdvanceButton *m_advanceButton;
582 mutable sensors::Wall *m_wall;
583 mutable sensors::CliffLeft *m_cliffLeft;
584 mutable sensors::CliffFrontLeft *m_cliffFrontLeft;
585 mutable sensors::CliffFrontRight *m_cliffFrontRight;
586 mutable sensors::CliffRight *m_cliffRight;
587 mutable sensors::VirtualWall *m_virtualWall;
589 mutable sensors::WallSignal *m_wallSignal;
590 mutable sensors::CliffLeftSignal *m_cliffLeftSignal;
591 mutable sensors::CliffFrontLeftSignal *m_cliffFrontLeftSignal;
592 mutable sensors::CliffFrontRightSignal *m_cliffFrontRightSignal;
593 mutable sensors::CliffRightSignal *m_cliffRightSignal;
594 mutable sensors::CargoBayAnalogSignal *m_cargoBayAnalogSignal;
595 mutable sensors::CargoBayDigitalInputs *m_cargoBayDigitalInputs;
597 mutable sensors::LightBumpLeft *m_lightBumpLeft;
598 mutable sensors::LightBumpFrontLeft *m_lightBumpFrontLeft;
599 mutable sensors::LightBumpCenterLeft *m_lightBumpCenterLeft;
600 mutable sensors::LightBumpCenterRight *m_lightBumpCenterRight;
601 mutable sensors::LightBumpFrontRight *m_lightBumpFrontRight;
602 mutable sensors::LightBumpRight *m_lightBumpRight;
604 mutable sensors::LightBumpLeftSignal *m_lightBumpLeftSignal;
605 mutable sensors::LightBumpFrontLeftSignal *m_lightBumpFrontLeftSignal;
606 mutable sensors::LightBumpCenterLeftSignal *m_lightBumpCenterLeftSignal;
607 mutable sensors::LightBumpCenterRightSignal *m_lightBumpCenterRightSignal;
608 mutable sensors::LightBumpFrontRightSignal *m_lightBumpFrontRightSignal;
609 mutable sensors::LightBumpRightSignal *m_lightBumpRightSignal;
611 mutable sensors::IR *m_ir;
613 mutable sensors::ChargingState *m_chargingState;
614 mutable sensors::BatteryTemperature *m_batteryTemperature;
615 mutable sensors::BatteryCharge *m_batteryCharge;
616 mutable sensors::BatteryCapacity *m_batteryCapacity;
618 mutable sensors::Angle *m_angle;
619 mutable sensors::Distance *m_distance;
621 mutable sensors::BumpLeft *m_bumpLeft;
622 mutable sensors::BumpRight *m_bumpRight;
624 mutable sensors::WheelDropLeft *m_wheelDropLeft;
625 mutable sensors::WheelDropRight *m_wheelDropRight;
626 mutable sensors::WheelDropCaster *m_wheelDropCaster;
628 mutable sensors::SongPlaying *m_songPlaying;
629 mutable sensors::SongNumber *m_songNumber;
632 CreateScript m_script;
635 pthread_mutex_t m_mutex;
Definition: create.hpp:40
const unsigned char * data() const
void append(const unsigned char &byte)
void append(const CreateScript &script)
void remove(const size_t &i, const size_t &len=1)
CreateScript(const CreateScript &rhs)
CreateScript & operator=(const CreateScript &rhs)
void append(const unsigned char *data, const size_t &size)
unsigned char byte(const size_t &i)
Facilitates communication with the iRobot (R) Create (TM)
Definition: create.hpp:231
sensor::Sensor< bool > * cliffFrontRight() const
sensor::Sensor< bool > * wall() const
void send(const CreateScript &script)
sensor::Sensor< bool > * cliffRight() const
sensor::Sensor< unsigned short > * cliffRightSignal() const
sensor::Sensor< bool > * bumpLeft() const
void setLeds(const bool &advance, const bool &play, const unsigned char &color, const unsigned char &brightness)
void spinCounterClockwise(const short &speed)
bool write(const unsigned char *data, const size_t &len)
void move(const short &millimeters, const unsigned short &speed)
void turn(const short &angle, const unsigned short &speed)
void setDistance(const int distance)
sensor::Sensor< unsigned char > * songNumber() const
sensor::Sensor< bool > * lightBumpRight() const
sensor::Sensor< bool > * lightBumpCenterLeft() const
sensor::Sensor< unsigned char > * cargoBayDigitalInputs() const
sensor::Sensor< unsigned short > * lightBumpCenterRightSignal() const
BaudRate
Definition: create.hpp:258
sensor::Sensor< bool > * lightBumpCenterRight() const
bool setBaudRate(const unsigned char &baudCode)
void beginAtomicOperation()
Definition: create.hpp:478
BaudRate defaultBaudRate() const
Definition: create.hpp:493
int read(unsigned char *data, const size_t &len)
void endAtomicOperation()
Definition: create.hpp:485
sensor::Sensor< unsigned char > * songPlaying() const
sensor::Sensor< bool > * cliffFrontLeft() const
sensor::Sensor< unsigned short > * cargoBayAnalogSignal() const
bool connect(const BaudRate baudRate)
const CreatePackets::_4 * sensorPacket4()
sensor::Sensor< int > * distance() const
bool blockingRead(T &data, unsigned timeout=0)
Definition: create.hpp:329
button::AbstractButton * playButton() const
const unsigned short & refreshRate() const
sensor::Sensor< char > * batteryTemperature() const
sensor::Sensor< unsigned short > * batteryCapacity() const
void drive(const short &velocity, const short &radius)
void spinClockwise(const short &speed)
short angularVelocity() const
const CreatePackets::_2 * sensorPacket2()
sensor::Sensor< unsigned short > * lightBumpRightSignal() const
sensor::Sensor< unsigned short > * lightBumpCenterLeftSignal() const
sensor::Sensor< unsigned short > * wallSignal() const
sensor::Sensor< bool > * lightBumpLeft() const
button::AbstractButton * advanceButton() const
void driveDirect(const short &left, const short &right)
const CreatePackets::_101 * sensorPacket101()
const CreateState * state()
sensor::Sensor< unsigned char > * chargingState() const
sensor::Sensor< unsigned short > * lightBumpFrontRightSignal() const
void setRefreshRate(const unsigned short &refreshRate)
void setMode(const Create::Mode &mode)
void spin(const short &speed)
sensor::Sensor< bool > * wheelDropLeft() const
sensor::Sensor< bool > * lightBumpFrontLeft() const
Mode
Definition: create.hpp:240
@ OffMode
Definition: create.hpp:241
@ SafeMode
Definition: create.hpp:243
@ PassiveMode
Definition: create.hpp:242
sensor::Sensor< unsigned short > * cliffFrontRightSignal() const
sensor::Sensor< unsigned short > * cliffLeftSignal() const
bool write(const unsigned char &c)
sensor::Sensor< bool > * virtualWall() const
const CreatePackets::_5 * sensorPacket5()
sensor::Sensor< int > * angle() const
sensor::Sensor< bool > * wheelDropCaster() const
sensor::Sensor< unsigned short > * batteryCharge() const
sensor::Sensor< unsigned short > * lightBumpLeftSignal() const
const CreatePackets::_3 * sensorPacket3()
bool blockingRead(unsigned char *data, const size_t &size, unsigned timeout=25)
void setDefaultBaudRate(const BaudRate defaultBaudRate)
Definition: create.hpp:492
sensor::Sensor< unsigned short > * cliffFrontLeftSignal() const
sensor::Sensor< bool > * cliffLeft() const
sensor::Sensor< bool > * wheelDropRight() const
sensor::Sensor< unsigned char > * ir() const
void driveStraight(const short &speed)
void setAngle(const int angle)
static Create * instance()
sensor::Sensor< bool > * bumpRight() const
const CreatePackets::_1 * sensorPacket1()
sensor::Sensor< unsigned short > * lightBumpFrontLeftSignal() const
sensor::Sensor< bool > * lightBumpFrontRight() const
BaudRate
The baudrate to use with the create.
Definition: create.h:659
@ Baud115200
Baudrate of 115200 times per second.
Definition: create.h:661
@ Baud57600
Baudrate of 57600 times per second.
Definition: create.h:660
#define PI
Definition: create.hpp:29
#define EXPORT_SYM
Definition: export.h:7
bool loadSong(const unsigned char *song, const unsigned char length, const unsigned char songNum)
bool playSong(const unsigned char songNum)
Definition: create.hpp:155
unsigned char lightBumpRightSignal[2]
Definition: create.hpp:165
unsigned char rightEncoderCounts[2]
Definition: create.hpp:157
unsigned char lightBumpCenterRightSignal[2]
Definition: create.hpp:163
char mainBrushMotorCurrent[2]
Definition: create.hpp:169
char rightMotorCurrent[2]
Definition: create.hpp:168
unsigned char lightBumpFrontLeftSignal[2]
Definition: create.hpp:161
char sideBrushMotorCurrent[2]
Definition: create.hpp:170
unsigned char lightBumpLeftSignal[2]
Definition: create.hpp:160
char stasis
Definition: create.hpp:171
unsigned char leftEncoderCounts[2]
Definition: create.hpp:156
unsigned char lightBumpBits
Definition: create.hpp:159
unsigned char lightBumpFrontRightSignal[2]
Definition: create.hpp:164
char leftMotorCurrent[2]
Definition: create.hpp:167
unsigned char lightBumpCenterLeftSignal[2]
Definition: create.hpp:162
Definition: create.hpp:85
unsigned char wall
Definition: create.hpp:87
unsigned char virtualWall
Definition: create.hpp:92
unsigned char bumpsAndWheelDrops
Definition: create.hpp:86
unsigned char cliffLeft
Definition: create.hpp:88
unsigned char cliffFrontRight
Definition: create.hpp:90
unsigned char cliffRight
Definition: create.hpp:91
unsigned char cargoBayDigitalInputs
Definition: create.hpp:93
unsigned char lowSideDriverAndWheelOvercurrents
Definition: create.hpp:94
unsigned char cliffFrontLeft
Definition: create.hpp:89
Definition: create.hpp:101
unsigned char ir
Definition: create.hpp:102
unsigned char buttons
Definition: create.hpp:103
unsigned char angle[2]
Definition: create.hpp:105
unsigned char distance[2]
Definition: create.hpp:104
Definition: create.hpp:112
char batteryTemperature
Definition: create.hpp:116
unsigned char chargingState
Definition: create.hpp:113
unsigned char batteryCharge[2]
Definition: create.hpp:117
unsigned char batteryCapacity[2]
Definition: create.hpp:118
char current[2]
Definition: create.hpp:115
unsigned char voltage[2]
Definition: create.hpp:114
Definition: create.hpp:125
unsigned char cliffLeftSignal[2]
Definition: create.hpp:127
unsigned char wallSignal[2]
Definition: create.hpp:126
unsigned char chargingSourcesAvailable
Definition: create.hpp:133
unsigned char cliffRightSignal[2]
Definition: create.hpp:130
unsigned char cliffFrontLeftSignal[2]
Definition: create.hpp:128
unsigned char cliffFrontRightSignal[2]
Definition: create.hpp:129
unsigned char userAnalogInput[2]
Definition: create.hpp:132
unsigned char userDigitalInputs
Definition: create.hpp:131
Definition: create.hpp:140
char radius[2]
Definition: create.hpp:146
char leftVelocity[2]
Definition: create.hpp:148
unsigned char numberOfStreamPackets
Definition: create.hpp:144
unsigned char songNumber
Definition: create.hpp:142
char velocity[2]
Definition: create.hpp:145
unsigned char mode
Definition: create.hpp:141
char rightVelocity[2]
Definition: create.hpp:147
unsigned char songPlaying
Definition: create.hpp:143
Definition: create.hpp:66
short rightVelocity
Definition: create.hpp:72
int angle
Definition: create.hpp:70
int distance
Definition: create.hpp:69
short leftVelocity
Definition: create.hpp:73
short radius
Definition: create.hpp:71
timeval timestamp
Definition: create.hpp:67