15 #include <ros/package.h> 16 #include <std_msgs/Float64.h> 17 #include <std_msgs/UInt8.h> 18 #include <std_msgs/Int16.h> 19 #include <std_msgs/String.h> 20 #include <sensor_msgs/Range.h> 21 #include <sensor_msgs/Imu.h> 22 #include <sensor_msgs/MagneticField.h> 23 #include <sensor_msgs/BatteryState.h> 44 std::string cmd =
"Reset Controller";
51 catch (std::exception& e)
54 "An error occured during initial Reset!\n Description: " << e.what());
69 ros::Duration(0.1).sleep();
76 catch (std::exception& e)
78 ROS_WARN_STREAM(
"An error occured while trying to shut down the " 79 "connection.\n Description: " 95 ROS_WARN_STREAM(
"Registering all sensor groups failed!");
97 catch (std::exception& e)
99 ROS_WARN_STREAM(
"An error occured while trying to register sensor " 100 "groups!\n Description: " 110 bool was_set =
false;
113 std::string cmd =
"Drive Forward";
120 ROS_WARN_STREAM(
"Activating motor controller failed!");
122 catch (std::exception& e)
124 ROS_WARN_STREAM(
"An error occured while trying to activate the motor " 125 "controller!\n Description: " 136 bool was_set =
false;
139 std::string cmd =
"Set Steering Level";
146 ROS_WARN_STREAM(
"Activating steering controller failed!");
148 catch (std::exception& e)
150 ROS_WARN_STREAM(
"An error occured while trying to activate the steering " 151 "controller!\n Description: " 162 bool was_set =
false;
165 std::string cmd =
"Toggle Kinect On";
170 ROS_WARN_STREAM(
"Activating kinect failed!");
172 catch (std::exception& e)
175 "An error occured while trying to activate kinect!\n Description: " 186 bool was_set =
false;
189 std::string cmd =
"Toggle US On";
194 ROS_WARN_STREAM(
"Activating us-sensors failed!");
196 catch (std::exception& e)
199 "An error occured while trying to activate us-sensors!\n Description: " 209 bool was_set =
false;
212 std::string cmd =
"Start DAQ";
217 ROS_WARN_STREAM(
"Activating daq failed!");
219 catch (std::exception& e)
222 "An error occured while trying to activate daq!\n Description: " 237 SensorGroup* grp, std::unordered_map<std::string, ros::Publisher*>& pub)
239 sensor_msgs::Range usl, usr, usf;
241 ros::Time t = ros::Time::now();
252 usl.min_range = 0.06;
253 usl.field_of_view = 0.76;
254 usl.radiation_type = 0;
255 usl.header.frame_id =
"left_sensor";
256 usl.header.stamp = t;
259 usf.min_range = 0.06;
260 usf.field_of_view = 0.76;
261 usf.radiation_type = 0;
262 usf.header.frame_id =
"front_sensor";
263 usf.header.stamp = t;
266 usr.min_range = 0.06;
267 usr.field_of_view = 0.76;
268 usr.radiation_type = 0;
269 usr.header.frame_id =
"right_sensor";
270 usr.header.stamp = t;
272 pub[
"USL"]->publish(usl);
273 pub[
"USF"]->publish(usf);
274 pub[
"USR"]->publish(usr);
276 catch (std::exception& e)
278 ROS_WARN_STREAM(
"An error in Message 'Sensor grp1' occured!\n Description: " 291 SensorGroup* grp, std::unordered_map<std::string, ros::Publisher*>& pub)
293 sensor_msgs::Imu imu;
294 ros::Time t = ros::Time::now();
303 imu.header.stamp = t;
304 imu.header.frame_id =
"robot_imu";
306 pub[
"IMU"]->publish(imu);
308 catch (std::exception& e)
310 ROS_WARN_STREAM(
"An error in Message 'Sensor grp2' occured!\n Description: " 323 SensorGroup* grp, std::unordered_map<std::string, ros::Publisher*>& pub)
325 std_msgs::UInt8 hallcnt;
326 std_msgs::Float64 halldt, halldt8;
331 pub[
"HALL_CNT"]->publish(hallcnt);
332 pub[
"HALL_DT"]->publish(halldt);
334 catch (std::exception& e)
336 ROS_WARN_STREAM(
"An error in Message 'Sensor grp3' occured!\n Description: " 349 SensorGroup* grp, std::unordered_map<std::string, ros::Publisher*>& pub)
351 sensor_msgs::MagneticField mag;
353 ros::Time t = ros::Time::now();
359 mag.header.stamp = t;
360 mag.header.frame_id =
"robot_magnetometer";
361 pub[
"MAG"]->publish(mag);
363 catch (std::exception& e)
365 ROS_WARN_STREAM(
"An error in Message 'Sensor grp4' occured!\n Description: " 378 SensorGroup* grp, std::unordered_map<std::string, ros::Publisher*>& pub)
380 sensor_msgs::BatteryState batVD, batVS;
382 ros::Time t = ros::Time::now();
387 batVD.voltage = vdbat;
388 batVS.voltage = vsbat;
389 batVD.header.stamp = t;
390 batVS.header.stamp = t;
392 pub[
"VDBAT"]->publish(batVD);
393 pub[
"VSBAT"]->publish(batVS);
395 catch (std::exception& e)
397 ROS_WARN_STREAM(
"An error in Message 'Sensor grp5' occured!\n Description: " 410 SensorGroup* grp, std::unordered_map<std::string, ros::Publisher*>& pub)
412 std_msgs::UInt8 hallcnt;
413 std_msgs::Float64 halldt, halldt8;
417 pub[
"HALL_DT8"]->publish(halldt8);
419 catch (std::exception& e)
421 ROS_WARN_STREAM(
"An error in Message 'Sensor grp6' occured!\n Description: " 434 ROS_WARN_STREAM(
"A communication Error occured!\n" << msg);
443 ROS_INFO_STREAM(
"UC board sent the following info:\n" << msg);
455 std_msgs::String debug;
473 bool was_set =
false;
474 std::string cmd =
"Drive Forward";
475 short level = motorLevel->data;
478 cmd =
"Drive Backward";
488 catch (std::exception& e)
491 "An error in Message 'set_motor_level_msg' occured!\n Description: " 496 ROS_WARN_STREAM(
"Motor level set to: " << motorLevel->data <<
" failed!");
510 bool was_set =
false;
511 std::string cmd =
"Set Steering Level";
519 catch (std::exception& e)
522 "An error in Message 'set_steering_level_msg' occured!\n Description: " 527 ROS_WARN_STREAM(
"Steering level set to: " << steeringLevel->data
547 catch (std::exception& e)
550 "An error in Message 'send_uc_board_msg' occured!\n Description: " 556 #endif // UC_BRIDGE_H Header file for the CommunicationConfig class.
void motorLevelCallback(std_msgs::Int16::ConstPtr motorLevel, Communication *com)
This function will be called whenever a ros node published a message on the motor level topic...
Header file for the Communication class.
bool registerSensorGroups(const std::string &cmdName, unsigned int timeout=100000)
Register all predefined sensor groups on the serial device.
void registerSensorGroups(Communication *com)
This function will trigger the registration of all predefined sensor groups on the serial device...
const bool getChannelValue(const std::string &name, T &value) const
Get a received value from a certain channel.
void textCallback(const std::string &msg)
This function will be called whenever the communication received a plain text message which will be p...
void shutdownSignalHandler(int sig)
This function is the callback for the shutdown system signal.
void sendRawMessage(const std::string &msg)
Method to send a string directly to the serial device.
void stopCommunication()
Stop reading the serial input buffer and shutdown parsing threads.
void ucBoardMessageCallback(std_msgs::String::ConstPtr msg, Communication *com)
This function will be called whenever a ros node published a message on the raw communication topic...
void activateSteeringController(Communication *com)
This function will activate the steering controller of the serial device.
void publishSensorGroupMessage2(SensorGroup *grp, std::unordered_map< std::string, ros::Publisher * > &pub)
This function will be called whenever a message from sensor group 2 has been received and publish the...
The Parameter::ParameterMap class provides a map functionality for Parameter::Parameter objects conta...
bool sendCommand(const std::string &command, const Parameter::ParameterMap &inputParams, Parameter::ParameterMap &outputParams, unsigned int timeout=100000)
Send a command to the servial device.
void publishSensorGroupMessage3(SensorGroup *grp, std::unordered_map< std::string, ros::Publisher * > &pub)
This function will be called whenever a message from sensor group 3 has been received and publish the...
void publishSensorGroupMessage1(SensorGroup *grp, std::unordered_map< std::string, ros::Publisher * > &pub)
This function will be called whenever a message from sensor group 1 has been received and publish the...
void disconnect()
Terminates a connection to a serial devive with a certain device-tag.
The SensorGroup class builds the syntactic template for its specific command that results from the se...
void activateUS(Communication *com)
This function will activate the ultra sonic range sensors of the serial device.
The Communication class provides access to microcontroller communication.
void errorCallback(const std::string &msg)
This function will be called whenever a communication error occured and post its content as a ROS War...
void activateKinect(Communication *com)
This function will activate the kinect power supply of the serial device.
const bool getChannelValueConverted(const std::string &name, double &value) const
Get a received converted value from a certain channel.
void insertParameter(const std::string &name, const std::string &type, const T &value, const bool isValid=true)
Insert a new parameter in this map, with the given name, type and value.
void activateDAQ(Communication *com)
This function will activate the daq of the serial device.
void steeringLevelCallback(std_msgs::Int16::ConstPtr steeringLevel, Communication *com)
This function will be called whenever a ros node published a message on the steering level topic...
void publishSensorGroupMessage5(SensorGroup *grp, std::unordered_map< std::string, ros::Publisher * > &pub)
This function will be called whenever a message from sensor group 5 has been received and publish the...
Contains all service functions and their respective implementations.
void resetController(Communication *com)
This function send a soft reset command to the serial device.
This namespace contains functions used in the uc_bridge node.
void activateMotorController(Communication *com)
This function will activate the motor controller of the serial device.
void publishSensorGroupMessage6(SensorGroup *grp, std::unordered_map< std::string, ros::Publisher * > &pub)
This function will be called whenever a message from sensor group 6 has been received and publish the...
void publishSensorGroupMessage4(SensorGroup *grp, std::unordered_map< std::string, ros::Publisher * > &pub)
This function will be called whenever a message from sensor group 4 has been received and publish the...
void publishDebugMessage(const std::string &msg, ros::Publisher *pub)
This function will be called whenever the communication received any message if the debug mode is ena...