
Example of a Publisher Subscriber ROSSerial node for Mbed enabled boards using String messages.
Dependencies: mbed ros_lib_kinetic
Dependents: roscar_ver_20190501_anglechange_copy
Revision 4:26006d815db0, committed 2018-08-24
- Comitter:
- FernandoLG
- Date:
- Fri Aug 24 21:21:46 2018 +0000
- Parent:
- 3:6690a73cf982
- Commit message:
- ROS-Mbed Publisher Subscriber example with String Messages - Working
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
diff -r 6690a73cf982 -r 26006d815db0 main.cpp --- a/main.cpp Fri Aug 24 20:30:13 2018 +0000 +++ b/main.cpp Fri Aug 24 21:21:46 2018 +0000 @@ -4,28 +4,29 @@ */ #include "mbed.h" #include <ros.h> -#include <std_msgs/Char.h> +#include <std_msgs/String.h> ros::NodeHandle nh; DigitalOut myled(LED1); -std_msgs::Char commandRead; +std_msgs::String commandRead; ros::Publisher chatter("chatter", &commandRead); // /* -void handlerFunction(const std_msgs::Char& commandSend){ +void handlerFunction(const std_msgs::String& commandSend){ commandRead = commandSend; } // */ -ros::Subscriber<std_msgs::Char> sub("cmd_vel", &handlerFunction); +ros::Subscriber<std_msgs::String> sub("cmd_vel", &handlerFunction); int main() { nh.initNode(); nh.subscribe(sub); nh.advertise(chatter); - commandRead.data= 'X'; + char initialValue[2] = "X"; + commandRead.data= initialValue; while (1) { chatter.publish( &commandRead);