13 #include "../../include/xbot_driver/xbot.hpp"    15 #include <ecl/converters.hpp>    16 #include <ecl/geometry/angle.hpp>    17 #include <ecl/geometry/angle.hpp>    18 #include <ecl/math.hpp>    19 #include <ecl/sigslots.hpp>    20 #include <ecl/time/sleep.hpp>    21 #include <ecl/time/timestamp.hpp>    24 #include "../../include/xbot_driver/packet_handler/payload_headers.hpp"    39   for (
unsigned int i = 0; i < packet_size; i++) {
    42   return cs ? 
false : 
true;
    50     : shutdown_requested(false),
    52       base_is_connected(false),
    53       sensor_is_connected(false),
    55       sensor_is_alive(false),
    56       heading_offset(0.0 / 0.0),
    65     for (
int i = 0; i < 10; ++i) {
    80                                  "Xbot's parameter settings did not validate.");
    87                                std::string(
"/base_stream_data"));
    89                                     std::string(
"/base_raw_data_command"));
    91                                    std::string(
"/base_raw_data_stream"));
    95                                  std::string(
"/sensor_stream_data"));
    97                                       std::string(
"/sensor_raw_data_command"));
    99                                      std::string(
"/sensor_raw_data_stream"));
   116           "base device does not (yet) available, is the usb connected?.");  
   130           "sensor device does not (yet) available, is the usb connected?");
   191   ecl::TimeStamp last_signal_time;
   193   unsigned char buf[256];
   218               "base device does not (yet) available on this port, waiting...");
   220           sig_info.
emit(
"base device failed to open, waiting... [" +
   221                         std::string(e.
what()) + 
"]");
   241       if (
base_is_alive && ((ecl::TimeStamp() - last_signal_time) > timeout)) {
   243         sig_debug.
emit(
"Timed out while waiting for incoming bytes.");
   247       std::ostringstream ostream;
   248       ostream << 
"xbot_node : serial_read(" << n << 
")"   249               << 
", packet_finder.numberOfDataToRead("   292       last_signal_time.stamp();
   297       if (
base_is_alive && ((ecl::TimeStamp() - last_signal_time) > timeout)) {
   308   if (byteStream.
size() <
   312     std::stringstream ostream;
   313     unsigned int header_id = 
static_cast<unsigned int>(byteStream.
pop_front());
   314     unsigned int length = 
static_cast<unsigned int>(byteStream.
pop_front());
   315     unsigned int remains = byteStream.
size();
   318     ostream << 
"[" << header_id << 
"]";
   319     ostream << 
"[" << length << 
"]";
   322     ostream << std::setfill(
'0') << std::uppercase;
   323     ostream << std::hex << std::setw(2) << header_id << 
" " << std::dec;
   324     ostream << std::hex << std::setw(2) << length << 
" " << std::dec;
   326     if (remains < length)
   331     for (
unsigned int i = 0; i < to_pop; i++) {
   332       unsigned int byte = 
static_cast<unsigned int>(byteStream.
pop_front());
   333       ostream << std::hex << std::setw(2) << byte << 
" " << std::dec;
   340   ecl::TimeStamp last_signal_time;
   342   unsigned char buf[256];
   367               "sensor device does not (yet) available on this port, "   370           sig_info.
emit(
"sensor device failed to open, waiting... [" +
   371                         std::string(e.
what()) + 
"]");
   392           ((ecl::TimeStamp() - last_signal_time) > timeout)) {
   394         sig_debug.
emit(
"Timed out while waiting for incoming bytes.");
   398       std::ostringstream ostream;
   399       ostream << 
"xbot_node : serial_read(" << n << 
")"   400               << 
", packet_finder.numberOfDataToRead("   442       last_signal_time.stamp();
   446           ((ecl::TimeStamp() - last_signal_time) > timeout)) {
   457   if (byteStream.
size() <
   461     std::stringstream ostream;
   462     unsigned int header_id = 
static_cast<unsigned int>(byteStream.
pop_front());
   463     unsigned int length = 
static_cast<unsigned int>(byteStream.
pop_front());
   464     unsigned int remains = byteStream.
size();
   467     ostream << 
"[" << header_id << 
"]";
   468     ostream << 
"[" << length << 
"]";
   471     ostream << std::setfill(
'0') << std::uppercase;
   472     ostream << std::hex << std::setw(2) << header_id << 
" " << std::dec;
   473     ostream << std::hex << std::setw(2) << length << 
" " << std::dec;
   475     if (remains < length)
   480     for (
unsigned int i = 0; i < to_pop; i++) {
   481       unsigned int byte = 
static_cast<unsigned int>(byteStream.
pop_front());
   482       ostream << std::hex << std::setw(2) << byte << 
" " << std::dec;
   530                                float &wheel_left_angle_rate,
   531                                float &wheel_right_angle,
   532                                float &wheel_right_angle_rate) {
   534                                  wheel_right_angle, wheel_right_angle_rate);
   553                           ecl::linear_algebra::Vector3d &pose_update_rates) {
   564                           const float &angular_velocity) {
   602   std::vector<float> velocity_commands_received;
   604     velocity_commands_received =
   611   std::cout << 
"linear_velocity: " << velocity_commands[0]
   612             << 
", angular_velocity: " << velocity_commands[1] << 
std::endl;
   613   if ((velocity_commands[0] != 0) || (velocity_commands[1] != 0)) {
   615                                             velocity_commands[1]));
   656     unsigned char checksum = 0;
   692     unsigned char checksum = 0;
 bool serialise(ecl::PushAndPop< unsigned char > &byteStream)
int getDebugSensors() const 
void sensor_lockDataAccess()
void velocityCommands(const float &vx, const float &wz)
std::string base_port
The serial device port name [/dev/xbot]. 
ecl::Serial sensor_serial
static Command SetPowerControl(const bool &power_state)
const char * what() const 
void sensor_fixPayload(ecl::PushAndPop< unsigned char > &byteStream)
ecl::Signal< PacketFinder::BufferType & > base_sig_raw_data_stream
unsigned int size() const 
void resetBuffer(Buffer &buffer)
void update(const unsigned int &time_stamp, const uint16_t &left_encoder, const uint16_t &right_encoder, ecl::Pose2D< double > &pose_update, ecl::linear_algebra::Vector3d &pose_update_rates)
Updates the odometry from firmware stamps and encoders. 
Parameter list and validator for the xbot. 
double getAngularVelocity() const 
static Command SetYawPlatformControl(const int &yaw_platform_degree)
std::vector< float > pointVelocity() const 
static Command SetLedControl(const unsigned char &led)
#define LOC
Stringify the line of code you are at. 
bool validate()
A validator to ensure the user has supplied correct/sensible parameter values. 
AccelerationLimiter acceleration_limiter
void getWheelJointStates(float &wheel_left_angle, float &wheel_left_angle_rate, float &wheel_right_angle, float &wheel_right_angle_rate)
void getWheelJointStates(float &wheel_left_angle, float &wheel_left_angle_rate, float &wheel_right_angle, float &wheel_right_angle_rate)
std::string sigslots_namespace
The first part of a sigslot connection namespace ["/xbot"]. 
void sensor_unlockDataAccess()
std::vector< float > limit(const std::vector< float > &command)
Limits the input velocity commands if gatekeeper is enabled. 
void setPitchPlatformControl(const int &pitch_degree)
void base_unlockDataAccess()
ecl::Mutex sensor_command_mutex
static Command SetSoundControl(const bool &sound_state)
void setLedControl(const char &led)
void setBaseControl(const float &linear_velocity, const float &angular_velocity)
void push_back(const Type &datum)
void configure(const std::string &sigslots_namespace, const BufferType &putStx, const BufferType &putEtx, unsigned int sizeLengthField, unsigned int sizeMaxPayload, unsigned int sizeChecksumField, bool variableSizePayload)
Standard exception type, provides code location and error string. 
static Command SetPitchPlatformControl(const int &pitch_platform_degree)
void setVelocityCommands(const float &vx, const float &wz)
unsigned char HeightPercent
ecl::Signal< PacketFinder::BufferType & > sensor_sig_raw_data_stream
ecl::Signal sensor_sig_stream_data
ecl::PushAndPop< unsigned char > BufferType
struct xbot::CoreSensors::Data data
void setLiftControl(const unsigned char &height_percent)
void base_fixPayload(ecl::PushAndPop< unsigned char > &byteStream)
Command::Buffer command_buffer
virtual bool update(const unsigned char *incoming, unsigned int numberOfIncoming)
PacketFinder::BufferType base_data_buffer
ecl::Thread sensor_thread
ecl::Signal< const std::string & > sig_warn
PacketFinder::BufferType sensor_data_buffer
void setYawPlatformControl(const int &yaw_degree)
ecl_geometry_PUBLIC const float & wrap_angle(float &angle)
Wrap the angle on -pi,pi (float types). 
ecl::Mutex sensor_data_mutex
void setPowerControl(const bool &power)
ecl::Signal base_sig_stream_data
struct xbot::Sensors::Data data
bool deserialise(ecl::PushAndPop< unsigned char > &byteStream)
Parent template definition for angles. 
ecl::Signal< const std::string & > sig_error
ecl::Mutex base_data_mutex
void sendCommand(Command command)
Send the prepared command to the serial port. 
void getBuffer(BufferType &bufferRef)
bool deserialise(ecl::PushAndPop< unsigned char > &byteStream)
ecl::Signal< Command::Buffer & > sensor_sig_raw_data_command
double getHeading() const 
ecl::Signal< const std::string & > sig_debug
void updateOdometry(ecl::Pose2D< double > &pose_update, ecl::linear_algebra::Vector3d &pose_update_rates)
Use the current sensor data (encoders and gyro) to calculate an update for the odometry. 
ecl::Signal< const std::string & > sig_info
void f(int i) ecl_debug_throw_decl(StandardException)
ecl::Mutex base_command_mutex
void connect(const std::string &topic)
void base_spin()
Performs a scan looking for incoming data packets. 
PacketFinder base_packet_finder
static Command SetVelocityControl(DiffDrive &diff_drive)
void base_lockDataAccess()
bool enable_acceleration_limiter
Enable or disable the acceleration limiter [true]. 
void init(Parameters ¶meters)
void init(bool enable_acceleration_limiter, float linear_acceleration_max_=0.5, float angular_acceleration_max_=3.5, float linear_deceleration_max_=-0.5 *1.2, float angular_deceleration_max_=-3.5 *1.2)
void setSoundEnableControl(const bool &sound)
void getPayload(BufferType &bufferRef)
unsigned int numberOfDataToRead()
PacketFinder sensor_packet_finder
ecl::Signal< Command::Buffer & > base_sig_raw_data_command
static Command SetLiftControl(const unsigned char &lift_height)
const ErrorFlag & flag() const 
void sendBaseControlCommand()