![](/media/cache/profiles/94aef38441efa3380a3bed3faf1f9d5d.50x50_q85.jpg)
This program is porting rosserial_arduino for mbed http://www.ros.org/wiki/rosserial_arduino This program supported the revision of 169 of rosserial. This program contains an example.
Dependencies: rosserial_mbed_lib mbed Servo
examples/ServiceClient.cpp@3:dff241b66f84, 2011-11-12 (annotated)
- Committer:
- nucho
- Date:
- Sat Nov 12 23:53:04 2011 +0000
- Revision:
- 3:dff241b66f84
This program supported the revision of 167 of rosserial.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
nucho | 3:dff241b66f84 | 1 | //#define COMPILE_SERVICECLIENT_CODE_ROSSERIAL |
nucho | 3:dff241b66f84 | 2 | #ifdef COMPILE_SERVICECLIENT_CODE_ROSSERIAL |
nucho | 3:dff241b66f84 | 3 | |
nucho | 3:dff241b66f84 | 4 | /* |
nucho | 3:dff241b66f84 | 5 | * rosserial Service Client |
nucho | 3:dff241b66f84 | 6 | */ |
nucho | 3:dff241b66f84 | 7 | |
nucho | 3:dff241b66f84 | 8 | #include <ros.h> |
nucho | 3:dff241b66f84 | 9 | #include <std_msgs/String.h> |
nucho | 3:dff241b66f84 | 10 | |
nucho | 3:dff241b66f84 | 11 | #include <rosserial_arduino/Test.h> |
nucho | 3:dff241b66f84 | 12 | |
nucho | 3:dff241b66f84 | 13 | ros::NodeHandle nh; |
nucho | 3:dff241b66f84 | 14 | using rosserial_arduino::Test; |
nucho | 3:dff241b66f84 | 15 | |
nucho | 3:dff241b66f84 | 16 | ros::ServiceClient<Test::Request, Test::Response> client("test_srv"); |
nucho | 3:dff241b66f84 | 17 | |
nucho | 3:dff241b66f84 | 18 | std_msgs::String str_msg; |
nucho | 3:dff241b66f84 | 19 | ros::Publisher chatter("chatter", &str_msg); |
nucho | 3:dff241b66f84 | 20 | |
nucho | 3:dff241b66f84 | 21 | char hello[13] = "hello world!"; |
nucho | 3:dff241b66f84 | 22 | |
nucho | 3:dff241b66f84 | 23 | int main() { |
nucho | 3:dff241b66f84 | 24 | nh.initNode(); |
nucho | 3:dff241b66f84 | 25 | nh.serviceClient(client); |
nucho | 3:dff241b66f84 | 26 | nh.advertise(chatter); |
nucho | 3:dff241b66f84 | 27 | while (!nh.connected()) nh.spinOnce(); |
nucho | 3:dff241b66f84 | 28 | nh.loginfo("Startup complete"); |
nucho | 3:dff241b66f84 | 29 | while (1) { |
nucho | 3:dff241b66f84 | 30 | Test::Request req; |
nucho | 3:dff241b66f84 | 31 | Test::Response res; |
nucho | 3:dff241b66f84 | 32 | req.input = hello; |
nucho | 3:dff241b66f84 | 33 | client.call(req, res); |
nucho | 3:dff241b66f84 | 34 | str_msg.data = res.output; |
nucho | 3:dff241b66f84 | 35 | chatter.publish( &str_msg ); |
nucho | 3:dff241b66f84 | 36 | nh.spinOnce(); |
nucho | 3:dff241b66f84 | 37 | wait_ms(100); |
nucho | 3:dff241b66f84 | 38 | } |
nucho | 3:dff241b66f84 | 39 | } |
nucho | 3:dff241b66f84 | 40 | #endif |