ROS Serial library for Mbed platforms for ROS Indigo Igloo. Check http://wiki.ros.org/rosserial_mbed/ for more information
Dependents: rosserial_mbed_hello_world_publisher rtos_base_control rosserial_mbed_F64MA ROS-RTOS ... more
ROSSerial_mbed for Indigo Distribution
The Robot Operating System (ROS) is a flexible framework for writing robot software. It is a collection of tools, libraries, and conventions that aim to simplify the task of creating complex and robust robot behavior across a wide variety of robotic platforms.
The rosserial_mbed package allows to write ROS nodes on any mbed enabled devices and have them connected to a running ROS system on your computer using the serial port.
Hello World (example publisher)
Import programrosserial_mbed_hello_world_publisher
rosserial_mbed Hello World
Running the Code
Now, launch the roscore in a new terminal window:
Quote:
$ roscore
Next, run the rosserial client application that forwards your MBED messages to the rest of ROS. Make sure to use the correct serial port:
Quote:
$ rosrun rosserial_python serial_node.py /dev/ttyACM0
Finally, watch the greetings come in from your MBED by launching a new terminal window and entering :
Quote:
$ rostopic echo chatter
See Also
More examples
Blink
/* * rosserial Subscriber Example * Blinks an LED on callback */ #include "mbed.h" #include <ros.h> #include <std_msgs/Empty.h> ros::NodeHandle nh; DigitalOut myled(LED1); void messageCb(const std_msgs::Empty& toggle_msg){ myled = !myled; // blink the led } ros::Subscriber<std_msgs::Empty> sub("toggle_led", &messageCb); int main() { nh.initNode(); nh.subscribe(sub); while (1) { nh.spinOnce(); wait_ms(1); } }
Push
/* * Button Example for Rosserial */ #include "mbed.h" #include <ros.h> #include <std_msgs/Bool.h> PinName button = p20; ros::NodeHandle nh; std_msgs::Bool pushed_msg; ros::Publisher pub_button("pushed", &pushed_msg); DigitalIn button_pin(button); DigitalOut led_pin(LED1); bool last_reading; long last_debounce_time=0; long debounce_delay=50; bool published = true; Timer t; int main() { t.start(); nh.initNode(); nh.advertise(pub_button); //Enable the pullup resistor on the button button_pin.mode(PullUp); //The button is a normally button last_reading = ! button_pin; while (1) { bool reading = ! button_pin; if (last_reading!= reading) { last_debounce_time = t.read_ms(); published = false; } //if the button value has not changed for the debounce delay, we know its stable if ( !published && (t.read_ms() - last_debounce_time) > debounce_delay) { led_pin = reading; pushed_msg.data = reading; pub_button.publish(&pushed_msg); published = true; } last_reading = reading; nh.spinOnce(); } }
rosgraph_msgs/TopicStatistics.h
- Committer:
- garyservin
- Date:
- 2016-03-31
- Revision:
- 0:fd24f7ca9688
File content as of revision 0:fd24f7ca9688:
#ifndef _ROS_rosgraph_msgs_TopicStatistics_h #define _ROS_rosgraph_msgs_TopicStatistics_h #include <stdint.h> #include <string.h> #include <stdlib.h> #include "ros/msg.h" #include "ros/time.h" #include "ros/duration.h" namespace rosgraph_msgs { class TopicStatistics : public ros::Msg { public: const char* topic; const char* node_pub; const char* node_sub; ros::Time window_start; ros::Time window_stop; int32_t delivered_msgs; int32_t dropped_msgs; int32_t traffic; ros::Duration period_mean; ros::Duration period_stddev; ros::Duration period_max; ros::Duration stamp_age_mean; ros::Duration stamp_age_stddev; ros::Duration stamp_age_max; TopicStatistics(): topic(""), node_pub(""), node_sub(""), window_start(), window_stop(), delivered_msgs(0), dropped_msgs(0), traffic(0), period_mean(), period_stddev(), period_max(), stamp_age_mean(), stamp_age_stddev(), stamp_age_max() { } virtual int serialize(unsigned char *outbuffer) const { int offset = 0; uint32_t length_topic = strlen(this->topic); memcpy(outbuffer + offset, &length_topic, sizeof(uint32_t)); offset += 4; memcpy(outbuffer + offset, this->topic, length_topic); offset += length_topic; uint32_t length_node_pub = strlen(this->node_pub); memcpy(outbuffer + offset, &length_node_pub, sizeof(uint32_t)); offset += 4; memcpy(outbuffer + offset, this->node_pub, length_node_pub); offset += length_node_pub; uint32_t length_node_sub = strlen(this->node_sub); memcpy(outbuffer + offset, &length_node_sub, sizeof(uint32_t)); offset += 4; memcpy(outbuffer + offset, this->node_sub, length_node_sub); offset += length_node_sub; *(outbuffer + offset + 0) = (this->window_start.sec >> (8 * 0)) & 0xFF; *(outbuffer + offset + 1) = (this->window_start.sec >> (8 * 1)) & 0xFF; *(outbuffer + offset + 2) = (this->window_start.sec >> (8 * 2)) & 0xFF; *(outbuffer + offset + 3) = (this->window_start.sec >> (8 * 3)) & 0xFF; offset += sizeof(this->window_start.sec); *(outbuffer + offset + 0) = (this->window_start.nsec >> (8 * 0)) & 0xFF; *(outbuffer + offset + 1) = (this->window_start.nsec >> (8 * 1)) & 0xFF; *(outbuffer + offset + 2) = (this->window_start.nsec >> (8 * 2)) & 0xFF; *(outbuffer + offset + 3) = (this->window_start.nsec >> (8 * 3)) & 0xFF; offset += sizeof(this->window_start.nsec); *(outbuffer + offset + 0) = (this->window_stop.sec >> (8 * 0)) & 0xFF; *(outbuffer + offset + 1) = (this->window_stop.sec >> (8 * 1)) & 0xFF; *(outbuffer + offset + 2) = (this->window_stop.sec >> (8 * 2)) & 0xFF; *(outbuffer + offset + 3) = (this->window_stop.sec >> (8 * 3)) & 0xFF; offset += sizeof(this->window_stop.sec); *(outbuffer + offset + 0) = (this->window_stop.nsec >> (8 * 0)) & 0xFF; *(outbuffer + offset + 1) = (this->window_stop.nsec >> (8 * 1)) & 0xFF; *(outbuffer + offset + 2) = (this->window_stop.nsec >> (8 * 2)) & 0xFF; *(outbuffer + offset + 3) = (this->window_stop.nsec >> (8 * 3)) & 0xFF; offset += sizeof(this->window_stop.nsec); union { int32_t real; uint32_t base; } u_delivered_msgs; u_delivered_msgs.real = this->delivered_msgs; *(outbuffer + offset + 0) = (u_delivered_msgs.base >> (8 * 0)) & 0xFF; *(outbuffer + offset + 1) = (u_delivered_msgs.base >> (8 * 1)) & 0xFF; *(outbuffer + offset + 2) = (u_delivered_msgs.base >> (8 * 2)) & 0xFF; *(outbuffer + offset + 3) = (u_delivered_msgs.base >> (8 * 3)) & 0xFF; offset += sizeof(this->delivered_msgs); union { int32_t real; uint32_t base; } u_dropped_msgs; u_dropped_msgs.real = this->dropped_msgs; *(outbuffer + offset + 0) = (u_dropped_msgs.base >> (8 * 0)) & 0xFF; *(outbuffer + offset + 1) = (u_dropped_msgs.base >> (8 * 1)) & 0xFF; *(outbuffer + offset + 2) = (u_dropped_msgs.base >> (8 * 2)) & 0xFF; *(outbuffer + offset + 3) = (u_dropped_msgs.base >> (8 * 3)) & 0xFF; offset += sizeof(this->dropped_msgs); union { int32_t real; uint32_t base; } u_traffic; u_traffic.real = this->traffic; *(outbuffer + offset + 0) = (u_traffic.base >> (8 * 0)) & 0xFF; *(outbuffer + offset + 1) = (u_traffic.base >> (8 * 1)) & 0xFF; *(outbuffer + offset + 2) = (u_traffic.base >> (8 * 2)) & 0xFF; *(outbuffer + offset + 3) = (u_traffic.base >> (8 * 3)) & 0xFF; offset += sizeof(this->traffic); *(outbuffer + offset + 0) = (this->period_mean.sec >> (8 * 0)) & 0xFF; *(outbuffer + offset + 1) = (this->period_mean.sec >> (8 * 1)) & 0xFF; *(outbuffer + offset + 2) = (this->period_mean.sec >> (8 * 2)) & 0xFF; *(outbuffer + offset + 3) = (this->period_mean.sec >> (8 * 3)) & 0xFF; offset += sizeof(this->period_mean.sec); *(outbuffer + offset + 0) = (this->period_mean.nsec >> (8 * 0)) & 0xFF; *(outbuffer + offset + 1) = (this->period_mean.nsec >> (8 * 1)) & 0xFF; *(outbuffer + offset + 2) = (this->period_mean.nsec >> (8 * 2)) & 0xFF; *(outbuffer + offset + 3) = (this->period_mean.nsec >> (8 * 3)) & 0xFF; offset += sizeof(this->period_mean.nsec); *(outbuffer + offset + 0) = (this->period_stddev.sec >> (8 * 0)) & 0xFF; *(outbuffer + offset + 1) = (this->period_stddev.sec >> (8 * 1)) & 0xFF; *(outbuffer + offset + 2) = (this->period_stddev.sec >> (8 * 2)) & 0xFF; *(outbuffer + offset + 3) = (this->period_stddev.sec >> (8 * 3)) & 0xFF; offset += sizeof(this->period_stddev.sec); *(outbuffer + offset + 0) = (this->period_stddev.nsec >> (8 * 0)) & 0xFF; *(outbuffer + offset + 1) = (this->period_stddev.nsec >> (8 * 1)) & 0xFF; *(outbuffer + offset + 2) = (this->period_stddev.nsec >> (8 * 2)) & 0xFF; *(outbuffer + offset + 3) = (this->period_stddev.nsec >> (8 * 3)) & 0xFF; offset += sizeof(this->period_stddev.nsec); *(outbuffer + offset + 0) = (this->period_max.sec >> (8 * 0)) & 0xFF; *(outbuffer + offset + 1) = (this->period_max.sec >> (8 * 1)) & 0xFF; *(outbuffer + offset + 2) = (this->period_max.sec >> (8 * 2)) & 0xFF; *(outbuffer + offset + 3) = (this->period_max.sec >> (8 * 3)) & 0xFF; offset += sizeof(this->period_max.sec); *(outbuffer + offset + 0) = (this->period_max.nsec >> (8 * 0)) & 0xFF; *(outbuffer + offset + 1) = (this->period_max.nsec >> (8 * 1)) & 0xFF; *(outbuffer + offset + 2) = (this->period_max.nsec >> (8 * 2)) & 0xFF; *(outbuffer + offset + 3) = (this->period_max.nsec >> (8 * 3)) & 0xFF; offset += sizeof(this->period_max.nsec); *(outbuffer + offset + 0) = (this->stamp_age_mean.sec >> (8 * 0)) & 0xFF; *(outbuffer + offset + 1) = (this->stamp_age_mean.sec >> (8 * 1)) & 0xFF; *(outbuffer + offset + 2) = (this->stamp_age_mean.sec >> (8 * 2)) & 0xFF; *(outbuffer + offset + 3) = (this->stamp_age_mean.sec >> (8 * 3)) & 0xFF; offset += sizeof(this->stamp_age_mean.sec); *(outbuffer + offset + 0) = (this->stamp_age_mean.nsec >> (8 * 0)) & 0xFF; *(outbuffer + offset + 1) = (this->stamp_age_mean.nsec >> (8 * 1)) & 0xFF; *(outbuffer + offset + 2) = (this->stamp_age_mean.nsec >> (8 * 2)) & 0xFF; *(outbuffer + offset + 3) = (this->stamp_age_mean.nsec >> (8 * 3)) & 0xFF; offset += sizeof(this->stamp_age_mean.nsec); *(outbuffer + offset + 0) = (this->stamp_age_stddev.sec >> (8 * 0)) & 0xFF; *(outbuffer + offset + 1) = (this->stamp_age_stddev.sec >> (8 * 1)) & 0xFF; *(outbuffer + offset + 2) = (this->stamp_age_stddev.sec >> (8 * 2)) & 0xFF; *(outbuffer + offset + 3) = (this->stamp_age_stddev.sec >> (8 * 3)) & 0xFF; offset += sizeof(this->stamp_age_stddev.sec); *(outbuffer + offset + 0) = (this->stamp_age_stddev.nsec >> (8 * 0)) & 0xFF; *(outbuffer + offset + 1) = (this->stamp_age_stddev.nsec >> (8 * 1)) & 0xFF; *(outbuffer + offset + 2) = (this->stamp_age_stddev.nsec >> (8 * 2)) & 0xFF; *(outbuffer + offset + 3) = (this->stamp_age_stddev.nsec >> (8 * 3)) & 0xFF; offset += sizeof(this->stamp_age_stddev.nsec); *(outbuffer + offset + 0) = (this->stamp_age_max.sec >> (8 * 0)) & 0xFF; *(outbuffer + offset + 1) = (this->stamp_age_max.sec >> (8 * 1)) & 0xFF; *(outbuffer + offset + 2) = (this->stamp_age_max.sec >> (8 * 2)) & 0xFF; *(outbuffer + offset + 3) = (this->stamp_age_max.sec >> (8 * 3)) & 0xFF; offset += sizeof(this->stamp_age_max.sec); *(outbuffer + offset + 0) = (this->stamp_age_max.nsec >> (8 * 0)) & 0xFF; *(outbuffer + offset + 1) = (this->stamp_age_max.nsec >> (8 * 1)) & 0xFF; *(outbuffer + offset + 2) = (this->stamp_age_max.nsec >> (8 * 2)) & 0xFF; *(outbuffer + offset + 3) = (this->stamp_age_max.nsec >> (8 * 3)) & 0xFF; offset += sizeof(this->stamp_age_max.nsec); return offset; } virtual int deserialize(unsigned char *inbuffer) { int offset = 0; uint32_t length_topic; memcpy(&length_topic, (inbuffer + offset), sizeof(uint32_t)); offset += 4; for(unsigned int k= offset; k< offset+length_topic; ++k){ inbuffer[k-1]=inbuffer[k]; } inbuffer[offset+length_topic-1]=0; this->topic = (char *)(inbuffer + offset-1); offset += length_topic; uint32_t length_node_pub; memcpy(&length_node_pub, (inbuffer + offset), sizeof(uint32_t)); offset += 4; for(unsigned int k= offset; k< offset+length_node_pub; ++k){ inbuffer[k-1]=inbuffer[k]; } inbuffer[offset+length_node_pub-1]=0; this->node_pub = (char *)(inbuffer + offset-1); offset += length_node_pub; uint32_t length_node_sub; memcpy(&length_node_sub, (inbuffer + offset), sizeof(uint32_t)); offset += 4; for(unsigned int k= offset; k< offset+length_node_sub; ++k){ inbuffer[k-1]=inbuffer[k]; } inbuffer[offset+length_node_sub-1]=0; this->node_sub = (char *)(inbuffer + offset-1); offset += length_node_sub; this->window_start.sec = ((uint32_t) (*(inbuffer + offset))); this->window_start.sec |= ((uint32_t) (*(inbuffer + offset + 1))) << (8 * 1); this->window_start.sec |= ((uint32_t) (*(inbuffer + offset + 2))) << (8 * 2); this->window_start.sec |= ((uint32_t) (*(inbuffer + offset + 3))) << (8 * 3); offset += sizeof(this->window_start.sec); this->window_start.nsec = ((uint32_t) (*(inbuffer + offset))); this->window_start.nsec |= ((uint32_t) (*(inbuffer + offset + 1))) << (8 * 1); this->window_start.nsec |= ((uint32_t) (*(inbuffer + offset + 2))) << (8 * 2); this->window_start.nsec |= ((uint32_t) (*(inbuffer + offset + 3))) << (8 * 3); offset += sizeof(this->window_start.nsec); this->window_stop.sec = ((uint32_t) (*(inbuffer + offset))); this->window_stop.sec |= ((uint32_t) (*(inbuffer + offset + 1))) << (8 * 1); this->window_stop.sec |= ((uint32_t) (*(inbuffer + offset + 2))) << (8 * 2); this->window_stop.sec |= ((uint32_t) (*(inbuffer + offset + 3))) << (8 * 3); offset += sizeof(this->window_stop.sec); this->window_stop.nsec = ((uint32_t) (*(inbuffer + offset))); this->window_stop.nsec |= ((uint32_t) (*(inbuffer + offset + 1))) << (8 * 1); this->window_stop.nsec |= ((uint32_t) (*(inbuffer + offset + 2))) << (8 * 2); this->window_stop.nsec |= ((uint32_t) (*(inbuffer + offset + 3))) << (8 * 3); offset += sizeof(this->window_stop.nsec); union { int32_t real; uint32_t base; } u_delivered_msgs; u_delivered_msgs.base = 0; u_delivered_msgs.base |= ((uint32_t) (*(inbuffer + offset + 0))) << (8 * 0); u_delivered_msgs.base |= ((uint32_t) (*(inbuffer + offset + 1))) << (8 * 1); u_delivered_msgs.base |= ((uint32_t) (*(inbuffer + offset + 2))) << (8 * 2); u_delivered_msgs.base |= ((uint32_t) (*(inbuffer + offset + 3))) << (8 * 3); this->delivered_msgs = u_delivered_msgs.real; offset += sizeof(this->delivered_msgs); union { int32_t real; uint32_t base; } u_dropped_msgs; u_dropped_msgs.base = 0; u_dropped_msgs.base |= ((uint32_t) (*(inbuffer + offset + 0))) << (8 * 0); u_dropped_msgs.base |= ((uint32_t) (*(inbuffer + offset + 1))) << (8 * 1); u_dropped_msgs.base |= ((uint32_t) (*(inbuffer + offset + 2))) << (8 * 2); u_dropped_msgs.base |= ((uint32_t) (*(inbuffer + offset + 3))) << (8 * 3); this->dropped_msgs = u_dropped_msgs.real; offset += sizeof(this->dropped_msgs); union { int32_t real; uint32_t base; } u_traffic; u_traffic.base = 0; u_traffic.base |= ((uint32_t) (*(inbuffer + offset + 0))) << (8 * 0); u_traffic.base |= ((uint32_t) (*(inbuffer + offset + 1))) << (8 * 1); u_traffic.base |= ((uint32_t) (*(inbuffer + offset + 2))) << (8 * 2); u_traffic.base |= ((uint32_t) (*(inbuffer + offset + 3))) << (8 * 3); this->traffic = u_traffic.real; offset += sizeof(this->traffic); this->period_mean.sec = ((uint32_t) (*(inbuffer + offset))); this->period_mean.sec |= ((uint32_t) (*(inbuffer + offset + 1))) << (8 * 1); this->period_mean.sec |= ((uint32_t) (*(inbuffer + offset + 2))) << (8 * 2); this->period_mean.sec |= ((uint32_t) (*(inbuffer + offset + 3))) << (8 * 3); offset += sizeof(this->period_mean.sec); this->period_mean.nsec = ((uint32_t) (*(inbuffer + offset))); this->period_mean.nsec |= ((uint32_t) (*(inbuffer + offset + 1))) << (8 * 1); this->period_mean.nsec |= ((uint32_t) (*(inbuffer + offset + 2))) << (8 * 2); this->period_mean.nsec |= ((uint32_t) (*(inbuffer + offset + 3))) << (8 * 3); offset += sizeof(this->period_mean.nsec); this->period_stddev.sec = ((uint32_t) (*(inbuffer + offset))); this->period_stddev.sec |= ((uint32_t) (*(inbuffer + offset + 1))) << (8 * 1); this->period_stddev.sec |= ((uint32_t) (*(inbuffer + offset + 2))) << (8 * 2); this->period_stddev.sec |= ((uint32_t) (*(inbuffer + offset + 3))) << (8 * 3); offset += sizeof(this->period_stddev.sec); this->period_stddev.nsec = ((uint32_t) (*(inbuffer + offset))); this->period_stddev.nsec |= ((uint32_t) (*(inbuffer + offset + 1))) << (8 * 1); this->period_stddev.nsec |= ((uint32_t) (*(inbuffer + offset + 2))) << (8 * 2); this->period_stddev.nsec |= ((uint32_t) (*(inbuffer + offset + 3))) << (8 * 3); offset += sizeof(this->period_stddev.nsec); this->period_max.sec = ((uint32_t) (*(inbuffer + offset))); this->period_max.sec |= ((uint32_t) (*(inbuffer + offset + 1))) << (8 * 1); this->period_max.sec |= ((uint32_t) (*(inbuffer + offset + 2))) << (8 * 2); this->period_max.sec |= ((uint32_t) (*(inbuffer + offset + 3))) << (8 * 3); offset += sizeof(this->period_max.sec); this->period_max.nsec = ((uint32_t) (*(inbuffer + offset))); this->period_max.nsec |= ((uint32_t) (*(inbuffer + offset + 1))) << (8 * 1); this->period_max.nsec |= ((uint32_t) (*(inbuffer + offset + 2))) << (8 * 2); this->period_max.nsec |= ((uint32_t) (*(inbuffer + offset + 3))) << (8 * 3); offset += sizeof(this->period_max.nsec); this->stamp_age_mean.sec = ((uint32_t) (*(inbuffer + offset))); this->stamp_age_mean.sec |= ((uint32_t) (*(inbuffer + offset + 1))) << (8 * 1); this->stamp_age_mean.sec |= ((uint32_t) (*(inbuffer + offset + 2))) << (8 * 2); this->stamp_age_mean.sec |= ((uint32_t) (*(inbuffer + offset + 3))) << (8 * 3); offset += sizeof(this->stamp_age_mean.sec); this->stamp_age_mean.nsec = ((uint32_t) (*(inbuffer + offset))); this->stamp_age_mean.nsec |= ((uint32_t) (*(inbuffer + offset + 1))) << (8 * 1); this->stamp_age_mean.nsec |= ((uint32_t) (*(inbuffer + offset + 2))) << (8 * 2); this->stamp_age_mean.nsec |= ((uint32_t) (*(inbuffer + offset + 3))) << (8 * 3); offset += sizeof(this->stamp_age_mean.nsec); this->stamp_age_stddev.sec = ((uint32_t) (*(inbuffer + offset))); this->stamp_age_stddev.sec |= ((uint32_t) (*(inbuffer + offset + 1))) << (8 * 1); this->stamp_age_stddev.sec |= ((uint32_t) (*(inbuffer + offset + 2))) << (8 * 2); this->stamp_age_stddev.sec |= ((uint32_t) (*(inbuffer + offset + 3))) << (8 * 3); offset += sizeof(this->stamp_age_stddev.sec); this->stamp_age_stddev.nsec = ((uint32_t) (*(inbuffer + offset))); this->stamp_age_stddev.nsec |= ((uint32_t) (*(inbuffer + offset + 1))) << (8 * 1); this->stamp_age_stddev.nsec |= ((uint32_t) (*(inbuffer + offset + 2))) << (8 * 2); this->stamp_age_stddev.nsec |= ((uint32_t) (*(inbuffer + offset + 3))) << (8 * 3); offset += sizeof(this->stamp_age_stddev.nsec); this->stamp_age_max.sec = ((uint32_t) (*(inbuffer + offset))); this->stamp_age_max.sec |= ((uint32_t) (*(inbuffer + offset + 1))) << (8 * 1); this->stamp_age_max.sec |= ((uint32_t) (*(inbuffer + offset + 2))) << (8 * 2); this->stamp_age_max.sec |= ((uint32_t) (*(inbuffer + offset + 3))) << (8 * 3); offset += sizeof(this->stamp_age_max.sec); this->stamp_age_max.nsec = ((uint32_t) (*(inbuffer + offset))); this->stamp_age_max.nsec |= ((uint32_t) (*(inbuffer + offset + 1))) << (8 * 1); this->stamp_age_max.nsec |= ((uint32_t) (*(inbuffer + offset + 2))) << (8 * 2); this->stamp_age_max.nsec |= ((uint32_t) (*(inbuffer + offset + 3))) << (8 * 3); offset += sizeof(this->stamp_age_max.nsec); return offset; } const char * getType(){ return "rosgraph_msgs/TopicStatistics"; }; const char * getMD5(){ return "10152ed868c5097a5e2e4a89d7daa710"; }; }; } #endif