Personal fork
Fork of rosserial_mbed_lib by
Embed:
(wiki syntax)
Show/hide line numbers
float64_test.cpp
00001 //#define COMPLIE_FLOAT64_CODE_ROSSERIAL 00002 #ifdef COMPILE_FLOAT64_CODE_ROSSERIAL 00003 00004 /* 00005 * rosserial::std_msgs::Float64 Test 00006 * Receives a Float64 input, subtracts 1.0, and publishes it 00007 */ 00008 00009 #include "mbed.h" 00010 #include <ros.h> 00011 #include <std_msgs/Float64.h> 00012 00013 00014 ros::NodeHandle nh; 00015 00016 float x; 00017 DigitalOut myled(LED1); 00018 00019 void messageCb( const std_msgs::Float64& msg) { 00020 x = msg.data - 1.0; 00021 myled = !myled; // blink the led 00022 } 00023 00024 std_msgs::Float64 test; 00025 ros::Subscriber<std_msgs::Float64> s("your_topic", &messageCb); 00026 ros::Publisher p("my_topic", &test); 00027 00028 int main() { 00029 nh.initNode(); 00030 nh.advertise(p); 00031 nh.subscribe(s); 00032 while (1) { 00033 test.data = x; 00034 p.publish( &test ); 00035 nh.spinOnce(); 00036 wait_ms(10); 00037 } 00038 } 00039 #endif
Generated on Tue Jul 12 2022 19:53:57 by 1.7.2