57#ifndef WEBOTS_NXT_bridge_DEFINED
58#define WEBOTS_NXT_bridge_DEFINED
59#define WEBOTS_NXT_encoders_DEFINED
60#define WEBOTS_NXT_bumper_DEFINED
61#define WEBOTS_NXT_camera_DEFINED
62#define WEBOTS_NXT_deadReakoning_walk_DEFINED
63#define WEBOTS_NXT_walk_isRunning_DEFINED
64#define WEBOTS_NXT_colorLine_walk_DEFINED
65#define WEBOTS_NXT_gridMotions_DEFINED
66#define WEBOTS_NXT_vector_bridge_DEFINED
68#pragma clang diagnostic push
69#pragma clang diagnostic ignored "-Wpadded"
91 static const char* MotorStrings[] = {
106 static const char* SoundStrings[] = {
176static const char* Commands[] = {
"MOVE_MOTORS",
"ONE_MOTOR_SETTING",
"PLAY_SOUND",
"LIGHTUP_LED",
177 "START_DISTANCE",
"START_INTENSITY_LIGHT",
"START_ROTATION_ENCODER",
178 "START_CAMERA",
"START_TOUCH",
"Undefined"};
217 _theRobotID(other._theRobotID),
218 _speedLeftMotor(other._speedLeftMotor),
219 _speedRightMotor(other._speedRightMotor),
220 _soundFrequency(other._soundFrequency),
221 _soundDuration(other._soundDuration) {}
225 _theRobotID = other._theRobotID;
226 _speedLeftMotor = other._speedLeftMotor;
227 _speedRightMotor = other._speedRightMotor;
228 _soundFrequency = other._soundFrequency;
229 _soundDuration = other._soundDuration;
235 std::ostringstream ss;
249 set_speedLeftMotor(0);
250 set_speedRightMotor(0);
251 set_soundFrequency(0);
252 set_soundDuration(0);
253 std::istringstream iss(strWithID);
256 int16_t numberForID = int16_t ( atoi(token.c_str())) ;
257 if (numberForID <0) set_theRobotID(-numberForID);
else set_theRobotID(numberForID);
259 std::size_t found = strWithID.find(comaDel);
260 if (std::string::npos!=found ) {
261 std::string str=strWithID.substr (found+comaDel.size());
263 std::istringstream second_iss(str);
266 std::size_t postionEQUALS= token.find(
EQUALS);
269 && (std::string::npos!=postionEQUALS) )
270 { std::string theValue = token.substr (postionEQUALS+1,token.size() );
271 set_speedLeftMotor(
static_cast<int16_t
>(atoi (theValue.c_str()) ));
275 && (std::string::npos!=postionEQUALS) )
276 { std::string theValue = token.substr (postionEQUALS+1,token.size() );
277 set_speedRightMotor(
static_cast<int16_t
>(atoi (theValue.c_str()) ));
281 && (std::string::npos!=postionEQUALS) )
282 { std::string theValue = token.substr (postionEQUALS+1,token.size() );
283 set_soundFrequency(
static_cast<int16_t
>( atoi (theValue.c_str()) ));
286 if ( (std::string::npos!=token.find(SoundStrings[
SOUND_DURATION]) )
287 && (std::string::npos!=postionEQUALS) )
288 { std::string theValue = token.substr (postionEQUALS+1,token.size() );
289 set_soundDuration(
static_cast<int16_t
>( atoi (theValue.c_str()) ));
293 found = str.find(comaDel);
294 if (std::string::npos!=found ) {
295 std::string newstr=str.substr (found+comaDel.size());
296 second_iss.str(newstr);
298 str=str.substr (found+comaDel.size());
315 switch (theActuator) {
321 switch (theInstructionModality) {
354 PROPERTY(int16_t, theRobotID)
358 PROPERTY(int16_t, firstParameter)
360 PROPERTY(int16_t, secondParameter)
362 PROPERTY(
bool, isSensorData)
367 WEBOTS_NXT_bridge(int16_t theRobotID =0 ,
DifferentialInstructions theInstruction =
MOVE_MOTORS, int16_t firstParameter = 0, int16_t secondParameter=0,
bool isSensorData =
false): _theRobotID(theRobotID), _theInstruction(theInstruction), _firstParameter(firstParameter), _secondParameter(secondParameter), _isSensorData(isSensorData) { }
373 WEBOTS_NXT_bridge(
const WEBOTS_NXT_bridge &other): _theRobotID(other._theRobotID), _theInstruction(other._theInstruction), _firstParameter(other._firstParameter), _secondParameter(other._secondParameter), _isSensorData(other._isSensorData) {}
376 WEBOTS_NXT_bridge &operator=(
const WEBOTS_NXT_bridge &other) { _theRobotID = other._theRobotID; _theInstruction = other._theInstruction; _firstParameter = other._firstParameter; _secondParameter = other._secondParameter;_isSensorData = other._isSensorData;
return *
this; }
379 std::string description()
const {
380 std::ostringstream ss;
383 switch(_theInstruction) {
385 ss <<
"SENSOR"<<
"ROTATION_ENCODER" <<
"," << _firstParameter <<
"," << _secondParameter <<
OBJECT_SEPARATOR ;
388 ss <<
"SENSOR"<<
"INTENSITY_LIGHT" <<
"," << _firstParameter <<
"," << _secondParameter <<
OBJECT_SEPARATOR ;
391 ss <<
"SENSOR"<<
"DISTANCE" <<
"," << _firstParameter <<
"," << _secondParameter <<
OBJECT_SEPARATOR ;
395 ss <<
"SENSOR"<<
"CAMERA" <<
"," << _firstParameter <<
"," << _secondParameter <<
OBJECT_SEPARATOR ;
398 ss <<
"SENSOR"<<
"TOUCH" <<
"," << _firstParameter <<
"," << _secondParameter <<
OBJECT_SEPARATOR ;
408 switch(_theInstruction) {
414 ss <<
"MOVE_MOTORS" <<
"," << _firstParameter <<
"," << _secondParameter <<
OBJECT_SEPARATOR ;
421 ss <<
"ONE_MOTOR_SETTING" <<
"," << _firstParameter <<
"," << _secondParameter <<
OBJECT_SEPARATOR;
427 ss <<
"PLAY_SOUND" <<
"," << _firstParameter <<
"," << _secondParameter <<
OBJECT_SEPARATOR;
433 ss <<
"LIGHTUP_LED" <<
"," << ((0!=_firstParameter)? 1: 0) <<
OBJECT_SEPARATOR;
440 ss <<
"DISTANCE" <<
"," << _firstParameter <<
"," << _secondParameter <<
OBJECT_SEPARATOR ;
447 ss <<
"INTENSITY_LIGHT" <<
"," << _firstParameter <<
"," << _secondParameter <<
OBJECT_SEPARATOR ;
454 ss <<
"ROTATION_ENCODER" <<
"," << _firstParameter <<
"," << _secondParameter <<
OBJECT_SEPARATOR ;
462 ss <<
"CAMERA" <<
"," << _firstParameter <<
"," << _secondParameter <<
OBJECT_SEPARATOR ;
469 ss <<
"TOUCH" <<
"," << _firstParameter <<
"," << _secondParameter <<
OBJECT_SEPARATOR ;
479 void from_string(
const std::string &strWithID) {
480 std::istringstream iss(strWithID);
483 int16_t numberForID = int16_t ( atoi(token.c_str())) ;
485 if (numberForID <0) set_theRobotID(-numberForID);
else set_theRobotID(numberForID);
486 std::string comaDel (
",");
487 std::size_t found = strWithID.find(comaDel);
488 if (std::string::npos!=found ) {
489 std::string str=strWithID.substr (found+comaDel.size());
491 std::istringstream second_iss(str);
493 set_firstParameter(0);
494 set_secondParameter(0);
495 set_isSensorData(
false);
496 std::string sensorStr (
"SENSOR");
516 instruction_from_string ( str );
521 set_isSensorData(
true);
523 found = str.find(sensorStr);
524 if (std::string::npos!=found ) {
525 std::string strWithoutPrefix =str.substr (found+sensorStr.size());
526 measurement_from_string ( strWithoutPrefix );
540 void set_parameters2ndBinary (
const std::string &str ) {
541 std::istringstream iss(str);
546 int16_t value = int16_t ( atoi(token.c_str())) ;
548 set_firstParameter(value);
553 set_secondParameter(int16_t( (0== atoi(token.c_str())? 0 :1 ) ));
557 void set_parameters2ndNum (
const std::string &str ) {
558 std::istringstream iss(str);
563 int16_t value = int16_t ( atoi(token.c_str())) ;
565 set_firstParameter(value);
570 set_secondParameter(int16_t( atoi(token.c_str()) ));
574 void set_parametersCamera (
const std::string &str ) {
575 std::istringstream iss(str);
580 int16_t value = int16_t ( atoi(token.c_str())) ;
581 set_firstParameter(value);
584 set_secondParameter(int16_t(atoi(token.c_str()) ));
591 void instruction_from_string (
const std::string &str ) {
592 std::istringstream iss(str);
600 set_firstParameter(int16_t(atoi(token.c_str())));
603 set_secondParameter(int16_t(atoi(token.c_str())));
611 set_firstParameter(motorID);
614 set_secondParameter(int16_t(atoi(token.c_str())));
620 set_firstParameter(0);
621 set_secondParameter(0);
624 int16_t value= int16_t ( atoi(token.c_str()) );
625 value = value >=0 ? value : -1*value;
626 set_firstParameter(value);
629 int16_t frequency_value= int16_t ( atoi(token.c_str()) );
630 frequency_value = frequency_value >=0 ? frequency_value : -1*frequency_value;
631 set_secondParameter(frequency_value);
639 set_firstParameter(int16_t((0== atoi(token.c_str())? 0 :1 ) ));
645 set_parameters2ndBinary(str);
649 set_theInstruction(
TOUCH);
650 set_parameters2ndBinary(str);
655 set_parameters2ndBinary(str);
660 set_parameters2ndBinary(str);
664 set_theInstruction(
CAMERA);
665 set_parameters2ndBinary(str);
673 void measurement_from_string (
const std::string &str ) {
674 std::istringstream iss(str);
681 set_parameters2ndNum(str);
686 set_parameters2ndNum(str);
691 set_parameters2ndNum(str);
695 set_theInstruction(
CAMERA);
696 set_parametersCamera(str);
711 PROPERTY(int16_t, robotID)
715 PROPERTY(int16_t, power)
727 PROPERTY(int16_t, colorIntensityThreshold)
731 PROPERTY(int16_t, visibilityCountThreshold)
735 PROPERTY(int16_t, limit)
738 WEBOTS_NXT_colorLine_walk(int16_t robotID = 0 , int16_t power = 0,
ColorLineInstructions theInstruction =
FOLLOW_COLOR,
CAMERA_E_PUCK_CHANNELS color =
BLUE_CHANNEL, int16_t colorIntensityThreshold = 100, int16_t visibilityCountThreshold = 10, int16_t limit=90): _robotID(robotID), _power(power), _theInstruction(theInstruction), _color(color), _colorIntensityThreshold(colorIntensityThreshold), _visibilityCountThreshold(visibilityCountThreshold), _limit(limit) { }
744 WEBOTS_NXT_colorLine_walk(
const WEBOTS_NXT_colorLine_walk &other): _robotID(other._robotID), _power(other._power), _theInstruction(other._theInstruction), _color(other._color), _colorIntensityThreshold(other._colorIntensityThreshold), _visibilityCountThreshold(other._visibilityCountThreshold), _limit(other._limit) {}
747 WEBOTS_NXT_colorLine_walk &operator=(
const WEBOTS_NXT_colorLine_walk &other) { _robotID = other._robotID; _power = other._power; _theInstruction = other._theInstruction; _color = other._color; _colorIntensityThreshold = other._colorIntensityThreshold; _visibilityCountThreshold = other._visibilityCountThreshold; _limit = other._limit;
return *
this; }
750 std::string description()
const {
751 std::ostringstream ss;
754 switch(_theInstruction) {
779 void from_string(
const std::string &str) {
780 std::istringstream iss(str);
783 _robotID = int16_t ( atoi(token.c_str())) ;
785 _power = int16_t ( atoi(token.c_str())) ;
788 std::size_t found = token.find(
"RIGHT");
791 found = token.find(
"LEFT");
796 found = token.find(
"RED");
797 if (std::string::npos!=found) _color =
RED_CHANNEL;
799 found = token.find(
"GREEN");
802 found = token.find(
"GREY");
808 _colorIntensityThreshold = int16_t ( atoi(token.c_str())) ;
810 _visibilityCountThreshold = int16_t ( atoi(token.c_str())) ;
811 if (getline(iss, token,
FIELD_SERPARATOR)) _limit = int16_t ( atoi(token.c_str()));
829 PROPERTY(int16_t, robotID)
833 PROPERTY(
bool, runningFlag)
837 PROPERTY(
bool, successLastMove)
840 WEBOTS_NXT_walk_isRunning(int16_t robotID =0 ,
bool runningFlag =
false,
bool successLastMove=
false ): _robotID(robotID), _runningFlag(runningFlag), _successLastMove(successLastMove) { }
852 std::string description()
const {
853 std::ostringstream ss;
861 void from_string(
const std::string &str) {
862 std::istringstream iss(str);
865 _robotID = int16_t ( atoi(token.c_str())) ;
867 _runningFlag = 0 != atoi(token.c_str());
869 _successLastMove = 0 != atoi(token.c_str());
886 PROPERTY(int16_t, robotID)
890 PROPERTY(int16_t, power)
895 PROPERTY(int16_t, spin)
899 PROPERTY(int16_t, forward)
902 WEBOTS_NXT_deadReakoning_walk(int16_t robotID =0 , int16_t power = 0, int16_t spin=0, int16_t forward =0): _robotID(robotID), _power(power), _spin(spin), _forward(forward) { }
914 std::string description()
const {
915 std::ostringstream ss;
924 void from_string(
const std::string &str) {
925 std::istringstream iss(str);
928 _robotID = int16_t ( atoi(token.c_str())) ;
930 _power = int16_t ( atoi(token.c_str())) ;
932 _spin = int16_t ( atoi(token.c_str())) ;
933 if (getline(iss, token,
FIELD_SERPARATOR)) _forward = int16_t ( atoi(token.c_str())) ;
963 _touchSensors[sensorID]=obj;
974 memcpy(
this, &other,
sizeof(other));
983 memcpy(_touchSensors, objects,
sizeof(_touchSensors));
988 _touchSensors[sensorID]=obj;
993 return _touchSensors[sensorID];
998 return _touchSensors[sensorID];
1003 std::ostringstream ss;
1006 ss << _touchSensors[sensorID].description();
1013 std::istringstream iss(str);
1018 _touchSensors[object].from_string( token );
1034 PROPERTY(int16_t, maxSpeed)
1053 _encoders[encoderID]=obj;
1065 memcpy(
this, &other,
sizeof(other));
1086 std::ostringstream ss;
1089 ss << _encoders[encoderID].description();
1097 std::istringstream iss(str);
1102 _encoders[object].from_string( token );
1106 _maxSpeed = int16_t ( atoi(token.c_str())) ;
1121 PROPERTY(int16_t, width)
1144 _channels[channelID]=obj;
1156 memcpy(
this, &other,
sizeof(other));
1168 _channels[channelID]=obj;
1180 std::ostringstream ss;
1183 ss << _channels[channelID].description();
1191 std::istringstream iss(str);
1196 _channels[object].from_string( token );
1199 if (getline(iss, token,
FIELD_SERPARATOR)) _width = int16_t ( atoi(token.c_str())) ;
1225 PROPERTY(int16_t, theRobotID)
1233 PROPERTY(int16_t, howMany)
1250 std::string description()
const {
1251 std::ostringstream ss;
1253 switch(_theInstruction) {
1279 void from_string(
const std::string &strWithID) {
1283 std::istringstream iss(strWithID);
1286 int16_t numberForID = int16_t ( atoi(token.c_str())) ;
1288 if (numberForID <0) set_theRobotID(-numberForID);
else set_theRobotID(numberForID);
1293 std::size_t found = token.find(
"RIGHT");
1296 found = token.find(
"LEFT");
1299 found = token.find(
"YELLOW");
1302 found = token.find(
"MAGENTA");
1305 found = token.find(
"COMPLETED");
1306 if (std::string::npos!=found) _theInstruction =
COMPLETED;
1313 int16_t numberofTimes = int16_t ( atoi(token.c_str())) ;
1314 if (numberofTimes <0) set_howMany(-numberofTimes);
else set_howMany(numberofTimes >0 ? numberofTimes : 1);
1331#pragma clang diagnostic pop
const char OBJECT_SEPARATOR
const char FIELD_SERPARATOR
This is the base class for the WEBOTS_NXT_bridge library.
This class reports the status of the Bumper behaviour.
WEBOTS_NXT_bumper(const WEBOTS_NXT_bumper &other)
copy constructor
void set_a_sensor(const class WEBOTS_NXT_bridge &obj, enum TouchSensorID sensorID=LEFT_TOUCH_SENSOR)
single sensor object setter
WEBOTS_NXT_bumper & operator=(const WEBOTS_NXT_bumper &other)
copy assignment operator
std::string description() const
convert to a string
void from_string(const std::string &str)
convert from a string
WEBOTS_NXT_bumper(const class WEBOTS_NXT_bridge &obj, enum TouchSensorID sensorID=LEFT_TOUCH_SENSOR)
single touch sensor constructor LEFT_TOUCH_SENDOR is used because it is the first enumerator
void set_touchSensors(const class WEBOTS_NXT_bridge *objects)
property setter
WEBOTS_NXT_bridge & get_object(enum TouchSensorID sensorID=LEFT_TOUCH_SENSOR)
single sensor object getter
const WEBOTS_NXT_bridge & get_object(enum TouchSensorID sensorID=LEFT_TOUCH_SENSOR) const
single sensor object getter
class WEBOTS_NXT_bridge * touchSensors()
property getter
WEBOTS_NXT_bumper(const std::string &names)
string constructor
This class reports the status of the Camera.
const WEBOTS_NXT_bridge & get_object(enum CAMERA_E_PUCK_CHANNELS channelID=GREY_CHANNEL) const
single channel object getter
WEBOTS_NXT_camera & operator=(const WEBOTS_NXT_camera &other)
copy assignment operator
void from_string(const std::string &str)
convert from a string
WEBOTS_NXT_camera(const WEBOTS_NXT_camera &other)
copy constructor
WEBOTS_NXT_camera(const std::string &names)
string constructor
void set_channels(const class WEBOTS_NXT_bridge *objects)
property setter
WEBOTS_NXT_bridge & get_channel(enum CAMERA_E_PUCK_CHANNELS channelID=GREY_CHANNEL)
single channel object getter
void set_encoder(const class WEBOTS_NXT_bridge &obj, int16_t a_width, enum CAMERA_E_PUCK_CHANNELS channelID=GREY_CHANNEL)
single channel with width setter
WEBOTS_NXT_camera(const class WEBOTS_NXT_bridge &obj, int16_t a_width, enum CAMERA_E_PUCK_CHANNELS channelID=GREY_CHANNEL)
single channel with width constructor
std::string description() const
convert to a string
class WEBOTS_NXT_bridge * channels()
property getter
This class reports the status of the ColorLine_Walk behaviour.
This class reports the status of the Dead Reakoning Walk behaviour.
This class reports the status of the Encoder Status.
WEBOTS_NXT_encoders(const class WEBOTS_NXT_bridge &obj, enum DifferentialMotor encoderID=NXT_MOTOR3)
single encoder constructor
WEBOTS_NXT_encoders & operator=(const WEBOTS_NXT_encoders &other)
copy assignment operator
void set_encoders(const class WEBOTS_NXT_bridge *objects)
property setter
const WEBOTS_NXT_bridge & get_object(enum DifferentialMotor encoderID=NXT_MOTOR3) const
single encoder object getter
void set_encoder(const class WEBOTS_NXT_bridge &obj, enum DifferentialMotor encoderID=NXT_MOTOR3)
single encoder object setter
WEBOTS_NXT_encoders(const std::string &names)
string constructor
WEBOTS_NXT_encoders(const WEBOTS_NXT_encoders &other)
copy constructor
void from_string(const std::string &str)
convert from a string
class WEBOTS_NXT_bridge * encoders()
property getter
WEBOTS_NXT_bridge & get_object(enum DifferentialMotor encoderID=NXT_MOTOR3)
single encoder object getter
std::string description() const
convert to a string
This class of messages are for the motion module for the miPal demo grid world.
WEBOTS_NXT_vector_bridge & operator=(const WEBOTS_NXT_vector_bridge &other)
copy assignment operator
WEBOTS_NXT_vector_bridge(const WEBOTS_NXT_vector_bridge &other)
copy constructor
WEBOTS_NXT_vector_bridge(const std::string &names)
string constructor
std::string description() const
convert to a string
void from_string(const std::string &strWithID)
convert from a string
PROPERTY(int16_t, theRobotID) PROPERTY(int16_t
The robot this status is for.
void set_actuator(DifferentialInstructions theActuator, int16_t firstParameter, int16_t secondParameter)
Sets the WEBOTS_NXT_vector_bridge instance properties that represent actuator states based on the spe...
This class reports the status of the Walk is running behaviour.
CAMERA_E_PUCK_CHANNELS
Enumeration of the Colour Channels available in camera of the E-Puck differential robot.
SoundDiscriminators
Enumeration of the Sound parameter settings.
TouchSensorID
Enumeration of the Touch Sensors in the NXT and E-Puck differential robots.
@ NXT_NUM_SENSORS_IN_BUMBER
GridStep
Enumeration of ID's for motions of the differential robot.
@ YELLOW_LINE_STRAIGHT_STEP
@ MAGENTA_LINE_STRAIGHT_STEP
@ PLAIN_LINE_STRAIGHT_STEP
NXT_Sensor_Ports
Enumeration of the Sensor ports available in the NXT differential robot.
DifferentialMotor
Enumerations of motor's in the NXT and E-Puck differential robots.
@ RIGHT_MOTOR_DIFFERENTIAL
@ LEFT_MOTOR_DIFFERENTIAL
SonarSensorID
Enumeration of the Sonar Sensors in the NXT and E-Puck differential robots.
DifferentialInstructions
Enumeration of the defined general instructions.
@ NUMBER_WEBOTS_NXT_bridge_MESSAGES
LightSensorID
Enumeration of the Light Sensors in the NXT differential robot.
ColorLineInstructions
Enumeration of the available strategies when following lines.
@ TURN_LEFT_UNTIL_COLOR_FOUND
@ TURN_RIGHT_UNTIL_COLOR_FOUND