root / quad2 / arduino / src / ros_lib / tests / float64_test / float64_test.pde @ c1426757
History | View | Annotate | Download (629 Bytes)
1 | c1426757 | Tom Mullins | /* |
---|---|---|---|
2 | * rosserial::std_msgs::Float64 Test |
||
3 | * Receives a Float64 input, subtracts 1.0, and publishes it |
||
4 | */ |
||
5 | |||
6 | #include <ros.h> |
||
7 | #include <std_msgs/Float64.h> |
||
8 | |||
9 | |||
10 | ros::NodeHandle nh; |
||
11 | |||
12 | float x; |
||
13 | |||
14 | void messageCb( const std_msgs::Float64& msg){ |
||
15 | x = msg.data - 1.0; |
||
16 | digitalWrite(13, HIGH-digitalRead(13)); // blink the led |
||
17 | } |
||
18 | |||
19 | std_msgs::Float64 test; |
||
20 | ros::Subscriber<std_msgs::Float64> s("your_topic", &messageCb); |
||
21 | ros::Publisher p("my_topic", &test); |
||
22 | |||
23 | void setup() |
||
24 | { |
||
25 | pinMode(13, OUTPUT); |
||
26 | nh.initNode(); |
||
27 | nh.advertise(p); |
||
28 | nh.subscribe(s); |
||
29 | } |
||
30 | |||
31 | void loop() |
||
32 | { |
||
33 | test.data = x; |
||
34 | p.publish( &test ); |
||
35 | nh.spinOnce(); |
||
36 | delay(10); |
||
37 | } |