9 int main(
int argc,
char** argv)
12 ros::init(argc, argv,
"uc_bridge", ros::init_options::NoSigintHandler);
15 bool regSensorGrps, motorCtrlOn, steeringCtrlOn, kinectOn, usOn, daqOn,
17 std::string configPath;
19 nh.getParam(
"/uc_bridge/register_sensor_groups", regSensorGrps);
20 nh.getParam(
"/uc_bridge/activate_motor_controller", motorCtrlOn);
21 nh.getParam(
"/uc_bridge/activate_steering_controller", steeringCtrlOn);
22 nh.getParam(
"/uc_bridge/activate_kinect", kinectOn);
23 nh.getParam(
"/uc_bridge/activate_us_sensors", usOn);
24 nh.getParam(
"/uc_bridge/activate_daq", daqOn);
25 nh.getParam(
"/uc_bridge/config_path", configPath);
26 nh.getParam(
"/uc_bridge/enable_debug_messages", debugMsgOn);
27 nh.getParam(
"/uc_bridge/enable_raw_communication", rawComOn);
30 regSensorGrps =
false;
32 steeringCtrlOn =
false;
42 ros::Publisher grp11 = nh.advertise<sensor_msgs::Range>(
"/uc_bridge/usl", 10);
43 ros::Publisher grp12 = nh.advertise<sensor_msgs::Range>(
"/uc_bridge/usf", 10);
44 ros::Publisher grp13 = nh.advertise<sensor_msgs::Range>(
"/uc_bridge/usr", 10);
45 ros::Publisher grp2 = nh.advertise<sensor_msgs::Imu>(
"/uc_bridge/imu", 10);
46 ros::Publisher grp31 =
47 nh.advertise<std_msgs::UInt8>(
"/uc_bridge/hall_cnt", 10);
48 ros::Publisher grp32 =
49 nh.advertise<std_msgs::Float64>(
"/uc_bridge/hall_dt", 10);
51 nh.advertise<std_msgs::Float64>(
"/uc_bridge/hall_dt8", 10);
53 nh.advertise<sensor_msgs::MagneticField>(
"/uc_bridge/mag", 10);
54 ros::Publisher grp51 =
55 nh.advertise<sensor_msgs::BatteryState>(
"/uc_bridge/vdbat", 10);
56 ros::Publisher grp52 =
57 nh.advertise<sensor_msgs::BatteryState>(
"/uc_bridge/vsbat", 10);
60 debug = nh.advertise<std_msgs::String>(
"DEBUG", 10);
62 std::unordered_map<std::string, ros::Publisher*> usGrp;
63 std::unordered_map<std::string, ros::Publisher*> imuGrp;
64 std::unordered_map<std::string, ros::Publisher*> hallcntDtGrp;
65 std::unordered_map<std::string, ros::Publisher*> hallDt8Grp;
66 std::unordered_map<std::string, ros::Publisher*> magGrp;
67 std::unordered_map<std::string, ros::Publisher*> batGrp;
68 usGrp.insert(std::make_pair(
"USL", &grp11));
69 usGrp.insert(std::make_pair(
"USF", &grp12));
70 usGrp.insert(std::make_pair(
"USR", &grp13));
71 imuGrp.insert(std::make_pair(
"IMU", &grp2));
72 hallcntDtGrp.insert(std::make_pair(
"HALL_CNT", &grp31));
73 hallcntDtGrp.insert(std::make_pair(
"HALL_DT", &grp32));
74 hallDt8Grp.insert(std::make_pair(
"HALL_DT8", &grp6));
75 magGrp.insert(std::make_pair(
"MAG", &grp4));
76 batGrp.insert(std::make_pair(
"VDBAT", &grp51));
77 batGrp.insert(std::make_pair(
"VSBAT", &grp52));
112 catch (std::exception& e)
114 ROS_WARN_STREAM(
"An error occured while trying to set up the connection.\n " 152 ros::ServiceServer deleteGroupService =
153 nh.advertiseService<pses_ucbridge::DeleteGroup::Request,
154 pses_ucbridge::DeleteGroup::Response>(
155 "/uc_bridge/delete_group",
157 std::placeholders::_2, &com));
159 ros::ServiceServer getControllerIDService =
160 nh.advertiseService<pses_ucbridge::GetControllerID::Request,
161 pses_ucbridge::GetControllerID::Response>(
162 "/uc_bridge/get_controller_id",
164 std::placeholders::_2, &com));
166 ros::ServiceServer getDAQStatusService =
167 nh.advertiseService<pses_ucbridge::GetDAQStatus::Request,
168 pses_ucbridge::GetDAQStatus::Response>(
169 "/uc_bridge/get_daq_status",
171 std::placeholders::_2, &com));
173 ros::ServiceServer getFirmwareVersionService =
174 nh.advertiseService<pses_ucbridge::GetFirmwareVersion::Request,
175 pses_ucbridge::GetFirmwareVersion::Response>(
176 "/uc_bridge/get_firmware_version",
178 std::placeholders::_2, &com));
180 ros::ServiceServer getIMUInfoService =
181 nh.advertiseService<pses_ucbridge::GetIMUInfo::Request,
182 pses_ucbridge::GetIMUInfo::Response>(
183 "/uc_bridge/get_imu_info",
185 std::placeholders::_2, &com));
187 ros::ServiceServer getInfoAllGroupsService =
188 nh.advertiseService<pses_ucbridge::GetInfoAllGroups::Request,
189 pses_ucbridge::GetInfoAllGroups::Response>(
190 "/uc_bridge/get_info_all_groups",
192 std::placeholders::_2, &com));
194 ros::ServiceServer getInfoGroupService =
195 nh.advertiseService<pses_ucbridge::GetInfoGroup::Request,
196 pses_ucbridge::GetInfoGroup::Response>(
197 "/uc_bridge/get_info_group",
199 std::placeholders::_2, &com));
201 ros::ServiceServer getKinectStatusService =
202 nh.advertiseService<pses_ucbridge::GetKinectStatus::Request,
203 pses_ucbridge::GetKinectStatus::Response>(
204 "/uc_bridge/get_kinect_status",
206 std::placeholders::_2, &com));
208 ros::ServiceServer getMagASAService =
209 nh.advertiseService<pses_ucbridge::GetMagASA::Request,
210 pses_ucbridge::GetMagASA::Response>(
211 "/uc_bridge/get_mag_asa",
213 std::placeholders::_2, &com));
215 ros::ServiceServer getMagInfoService =
216 nh.advertiseService<pses_ucbridge::GetMagInfo::Request,
217 pses_ucbridge::GetMagInfo::Response>(
218 "/uc_bridge/get_mag_info",
220 std::placeholders::_2, &com));
222 ros::ServiceServer getMotorLevelService =
223 nh.advertiseService<pses_ucbridge::GetMotorLevel::Request,
224 pses_ucbridge::GetMotorLevel::Response>(
225 "/uc_bridge/get_motor_level",
227 std::placeholders::_2, &com));
229 ros::ServiceServer getSessionIDService =
230 nh.advertiseService<pses_ucbridge::GetSessionID::Request,
231 pses_ucbridge::GetSessionID::Response>(
232 "/uc_bridge/get_session_id",
234 std::placeholders::_2, &com));
236 ros::ServiceServer getSteeringLevelService =
237 nh.advertiseService<pses_ucbridge::GetSteeringLevel::Request,
238 pses_ucbridge::GetSteeringLevel::Response>(
239 "/uc_bridge/get_steering_level",
241 std::placeholders::_2, &com));
243 ros::ServiceServer getUSInfoService =
244 nh.advertiseService<pses_ucbridge::GetUSInfo::Request,
245 pses_ucbridge::GetUSInfo::Response>(
246 "/uc_bridge/get_us_info",
248 std::placeholders::_2, &com));
250 ros::ServiceServer resetControllerService =
251 nh.advertiseService<pses_ucbridge::ResetController::Request,
252 pses_ucbridge::ResetController::Response>(
253 "/uc_bridge/reset_controller",
255 std::placeholders::_2, &com));
257 ros::ServiceServer resetDMSService =
258 nh.advertiseService<pses_ucbridge::ResetDMS::Request,
259 pses_ucbridge::ResetDMS::Response>(
260 "/uc_bridge/reset_dms",
262 std::placeholders::_2, &com));
264 ros::ServiceServer setIMUService =
265 nh.advertiseService<pses_ucbridge::SetIMU::Request,
266 pses_ucbridge::SetIMU::Response>(
267 "/uc_bridge/set_imu",
269 std::placeholders::_2, &com));
271 ros::ServiceServer setMagService =
272 nh.advertiseService<pses_ucbridge::SetMag::Request,
273 pses_ucbridge::SetMag::Response>(
274 "/uc_bridge/set_mag",
276 std::placeholders::_2, &com));
278 ros::ServiceServer setMotorLevelService =
279 nh.advertiseService<pses_ucbridge::SetMotorLevel::Request,
280 pses_ucbridge::SetMotorLevel::Response>(
281 "/uc_bridge/set_motor_level",
283 std::placeholders::_2, &com));
285 ros::ServiceServer setSessionIDService =
286 nh.advertiseService<pses_ucbridge::SetSessionID::Request,
287 pses_ucbridge::SetSessionID::Response>(
288 "/uc_bridge/set_session_id",
290 std::placeholders::_2, &com));
292 ros::ServiceServer setSteeringLevelService =
293 nh.advertiseService<pses_ucbridge::SetSteering::Request,
294 pses_ucbridge::SetSteering::Response>(
295 "/uc_bridge/set_steering_level",
297 std::placeholders::_2, &com));
299 ros::ServiceServer setUSService =
300 nh.advertiseService<pses_ucbridge::SetUS::Request,
301 pses_ucbridge::SetUS::Response>(
304 std::placeholders::_2, &com));
306 ros::ServiceServer toggleBrakesService =
307 nh.advertiseService<pses_ucbridge::ToggleBrakes::Request,
308 pses_ucbridge::ToggleBrakes::Response>(
309 "/uc_bridge/toggle_brakes",
311 std::placeholders::_2, &com));
313 ros::ServiceServer toggleDAQService =
314 nh.advertiseService<pses_ucbridge::ToggleDAQ::Request,
315 pses_ucbridge::ToggleDAQ::Response>(
316 "/uc_bridge/toggle_daq",
318 std::placeholders::_2, &com));
320 ros::ServiceServer toggleDMSService =
321 nh.advertiseService<pses_ucbridge::ToggleDMS::Request,
322 pses_ucbridge::ToggleDMS::Response>(
323 "/uc_bridge/toggle_dms",
325 std::placeholders::_2, &com));
327 ros::ServiceServer toggleGroupService =
328 nh.advertiseService<pses_ucbridge::ToggleGroup::Request,
329 pses_ucbridge::ToggleGroup::Response>(
330 "/uc_bridge/toggle_group",
332 std::placeholders::_2, &com));
334 ros::ServiceServer toggleKinectService =
335 nh.advertiseService<pses_ucbridge::ToggleKinect::Request,
336 pses_ucbridge::ToggleKinect::Response>(
337 "/uc_bridge/toggle_kinect",
339 std::placeholders::_2, &com));
341 ros::ServiceServer toggleMotorService =
342 nh.advertiseService<pses_ucbridge::ToggleMotor::Request,
343 pses_ucbridge::ToggleMotor::Response>(
344 "/uc_bridge/toggle_motor",
346 std::placeholders::_2, &com));
347 ros::ServiceServer toggleUSService =
348 nh.advertiseService<pses_ucbridge::ToggleUS::Request,
349 pses_ucbridge::ToggleUS::Response>(
350 "/uc_bridge/toggle_us",
352 std::placeholders::_2, &com));
355 ros::Subscriber motorLevelSubscriber = nh.subscribe<std_msgs::Int16>(
356 "/uc_bridge/set_motor_level_msg", 1,
358 ros::Subscriber steeringLevelSubscriber = nh.subscribe<std_msgs::Int16>(
359 "/uc_bridge/set_steering_level_msg", 1,
362 ros::Subscriber ucBoardMsgSubscriber;
364 ucBoardMsgSubscriber = nh.subscribe<std_msgs::String>(
365 "/uc_bridge/send_uc_board_msg", 10,
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...
bool getMagInfo(pses_ucbridge::GetMagInfo::Request &req, pses_ucbridge::GetMagInfo::Response &res, Communication *com)
A call to this Service will send a command to the serial device to transmit info about its magnetic f...
bool getUSInfo(pses_ucbridge::GetUSInfo::Request &req, pses_ucbridge::GetUSInfo::Response &res, Communication *com)
A call to this Service will send a command to the serial device to transmit the calibration of its ul...
bool toggleKinect(pses_ucbridge::ToggleKinect::Request &req, pses_ucbridge::ToggleKinect::Response &res, Communication *com)
A call to this Service will send a command to the serial device to activate/deactivate the kinect pow...
void startCommunication()
Start reading the serial input buffer and start parsing threads.
void registerSensorGroups(Communication *com)
This function will trigger the registration of all predefined sensor groups on the serial device...
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 enableRawCommunication()
Enables the transmission of raw messages to the serial device.
bool getIMUInfo(pses_ucbridge::GetIMUInfo::Request &req, pses_ucbridge::GetIMUInfo::Response &res, Communication *com)
A call to this Service will send a command to the serial device to transmit the calibration of its IM...
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 connect()
Tries to setup a connection to a serial devive with a certain device-tag and specified baudrate...
bool toggleGroup(pses_ucbridge::ToggleGroup::Request &req, pses_ucbridge::ToggleGroup::Response &res, Communication *com)
A call to this Service will send a command to the serial device to activate/deactivate a particular g...
bool setSessionID(pses_ucbridge::SetSessionID::Request &req, pses_ucbridge::SetSessionID::Response &res, Communication *com)
A call to this Service will send a command to the serial device to set the current session id...
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...
bool setUS(pses_ucbridge::SetUS::Request &req, pses_ucbridge::SetUS::Response &res, Communication *com)
A call to this Service will send a command to the serial device to change the calibration of its ultr...
bool deleteGroup(pses_ucbridge::DeleteGroup::Request &req, pses_ucbridge::DeleteGroup::Response &res, Communication *com)
A call to this Service will send a command to the serial device to delete a certain group...
bool getFirmwareVersion(pses_ucbridge::GetFirmwareVersion::Request &req, pses_ucbridge::GetFirmwareVersion::Response &res, Communication *com)
A call to this Service will send a command to the serial device to transmit its firmware version...
bool getInfoGroup(pses_ucbridge::GetInfoGroup::Request &req, pses_ucbridge::GetInfoGroup::Response &res, Communication *com)
A call to this Service will send a command to the serial device to transmit the info about a particul...
bool getKinectStatus(pses_ucbridge::GetKinectStatus::Request &req, pses_ucbridge::GetKinectStatus::Response &res, Communication *com)
A call to this Service will send a command to the serial device to transmit the power supply status o...
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 registerErrorCallback(debugCallbackPtr error)
Register a callback to handle transmission/communication errors.
bool getInfoAllGroups(pses_ucbridge::GetInfoAllGroups::Request &req, pses_ucbridge::GetInfoAllGroups::Response &res, Communication *com)
A call to this Service will send a command to the serial device to transmit info about all registered...
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...
bool setIMU(pses_ucbridge::SetIMU::Request &req, pses_ucbridge::SetIMU::Response &res, Communication *com)
A call to this Service will send a command to the serial device to change the calibration of its IMU...
bool getDAQStatus(pses_ucbridge::GetDAQStatus::Request &req, pses_ucbridge::GetDAQStatus::Response &res, Communication *com)
A call to this Service will send a command to the serial device to transmit the daq status...
bool getControllerID(pses_ucbridge::GetControllerID::Request &req, pses_ucbridge::GetControllerID::Response &res, Communication *com)
A call to this Service will send a command to the serial device to transmit its id.
void enableDebugMessages(debugCallbackPtr debug)
Enable pass through of every line in the input buffer.
void registerTextCallback(debugCallbackPtr text)
Register a callback to handle plain text messages from the serial device.
void registerSensorGroupCallback(const unsigned char &grpNumber, responseCallback cbPtr)
Register a callback to handle sensor group messages from the serial device.
void activateUS(Communication *com)
This function will activate the ultra sonic range sensors of the serial device.
int main(int argc, char **argv)
Header file for the uc_bridge node.
The Communication class provides access to microcontroller communication.
bool toggleDMS(pses_ucbridge::ToggleDMS::Request &req, pses_ucbridge::ToggleDMS::Response &res, Communication *com)
A call to this Service will send a command to the serial device to activate/deactivate the dead man's...
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.
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...
bool getMotorLevel(pses_ucbridge::GetMotorLevel::Request &req, pses_ucbridge::GetMotorLevel::Response &res, Communication *com)
A call to this Service will send a command to the serial device to transmit the current motor level...
bool setMag(pses_ucbridge::SetMag::Request &req, pses_ucbridge::SetMag::Response &res, Communication *com)
A call to this Service will send a command to the serial device whether to use the magnetic field sen...
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...
bool resetController(pses_ucbridge::ResetController::Request &req, pses_ucbridge::ResetController::Response &res, Communication *com)
A call to this Service will send a command to the serial device to do perform a soft reset...
bool resetDMS(pses_ucbridge::ResetDMS::Request &req, pses_ucbridge::ResetDMS::Response &res, Communication *com)
A call to this Service will send a command to the serial device to reset the counter on the dead man'...
bool toggleBrakes(pses_ucbridge::ToggleBrakes::Request &req, pses_ucbridge::ToggleBrakes::Response &res, Communication *com)
A call to this Service will send a command to the serial device to activate/deactivate its motor brak...
bool getSteeringLevel(pses_ucbridge::GetSteeringLevel::Request &req, pses_ucbridge::GetSteeringLevel::Response &res, Communication *com)
A call to this Service will send a command to the serial device to transmit the current steering leve...
void activateMotorController(Communication *com)
This function will activate the motor controller of the serial device.
bool toggleDAQ(pses_ucbridge::ToggleDAQ::Request &req, pses_ucbridge::ToggleDAQ::Response &res, Communication *com)
A call to this Service will send a command to the serial device to activate/deactivate the daq...
bool setSteeringLevel(pses_ucbridge::SetSteering::Request &req, pses_ucbridge::SetSteering::Response &res, Communication *com)
A call to this Service will send a command to the serial device to change the current steering level...
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...
bool getMagASA(pses_ucbridge::GetMagASA::Request &req, pses_ucbridge::GetMagASA::Response &res, Communication *com)
A call to this Service will send a command to the serial device to transmit the calibration of its ma...
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...
bool setMotorLevel(pses_ucbridge::SetMotorLevel::Request &req, pses_ucbridge::SetMotorLevel::Response &res, Communication *com)
A call to this Service will send a command to the serial device to change the current motor level...
bool getSessionID(pses_ucbridge::GetSessionID::Request &req, pses_ucbridge::GetSessionID::Response &res, Communication *com)
A call to this Service will send a command to the serial device to transmit its current session id...
bool toggleMotor(pses_ucbridge::ToggleMotor::Request &req, pses_ucbridge::ToggleMotor::Response &res, Communication *com)
A call to this Service will send a command to the serial device to activate/deactivate the motor cont...
bool toggleUS(pses_ucbridge::ToggleUS::Request &req, pses_ucbridge::ToggleUS::Response &res, Communication *com)
A call to this Service will send a command to the serial device to activate/deactivate the ultra soni...
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...