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(); } }
dynamic_reconfigure/Config.h@0:fd24f7ca9688, 2016-03-31 (annotated)
- Committer:
- garyservin
- Date:
- Thu Mar 31 14:22:59 2016 +0000
- Revision:
- 0:fd24f7ca9688
Initial commit, generated based on a clean indigo-desktop-full
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
garyservin | 0:fd24f7ca9688 | 1 | #ifndef _ROS_dynamic_reconfigure_Config_h |
garyservin | 0:fd24f7ca9688 | 2 | #define _ROS_dynamic_reconfigure_Config_h |
garyservin | 0:fd24f7ca9688 | 3 | |
garyservin | 0:fd24f7ca9688 | 4 | #include <stdint.h> |
garyservin | 0:fd24f7ca9688 | 5 | #include <string.h> |
garyservin | 0:fd24f7ca9688 | 6 | #include <stdlib.h> |
garyservin | 0:fd24f7ca9688 | 7 | #include "ros/msg.h" |
garyservin | 0:fd24f7ca9688 | 8 | #include "dynamic_reconfigure/BoolParameter.h" |
garyservin | 0:fd24f7ca9688 | 9 | #include "dynamic_reconfigure/IntParameter.h" |
garyservin | 0:fd24f7ca9688 | 10 | #include "dynamic_reconfigure/StrParameter.h" |
garyservin | 0:fd24f7ca9688 | 11 | #include "dynamic_reconfigure/DoubleParameter.h" |
garyservin | 0:fd24f7ca9688 | 12 | #include "dynamic_reconfigure/GroupState.h" |
garyservin | 0:fd24f7ca9688 | 13 | |
garyservin | 0:fd24f7ca9688 | 14 | namespace dynamic_reconfigure |
garyservin | 0:fd24f7ca9688 | 15 | { |
garyservin | 0:fd24f7ca9688 | 16 | |
garyservin | 0:fd24f7ca9688 | 17 | class Config : public ros::Msg |
garyservin | 0:fd24f7ca9688 | 18 | { |
garyservin | 0:fd24f7ca9688 | 19 | public: |
garyservin | 0:fd24f7ca9688 | 20 | uint8_t bools_length; |
garyservin | 0:fd24f7ca9688 | 21 | dynamic_reconfigure::BoolParameter st_bools; |
garyservin | 0:fd24f7ca9688 | 22 | dynamic_reconfigure::BoolParameter * bools; |
garyservin | 0:fd24f7ca9688 | 23 | uint8_t ints_length; |
garyservin | 0:fd24f7ca9688 | 24 | dynamic_reconfigure::IntParameter st_ints; |
garyservin | 0:fd24f7ca9688 | 25 | dynamic_reconfigure::IntParameter * ints; |
garyservin | 0:fd24f7ca9688 | 26 | uint8_t strs_length; |
garyservin | 0:fd24f7ca9688 | 27 | dynamic_reconfigure::StrParameter st_strs; |
garyservin | 0:fd24f7ca9688 | 28 | dynamic_reconfigure::StrParameter * strs; |
garyservin | 0:fd24f7ca9688 | 29 | uint8_t doubles_length; |
garyservin | 0:fd24f7ca9688 | 30 | dynamic_reconfigure::DoubleParameter st_doubles; |
garyservin | 0:fd24f7ca9688 | 31 | dynamic_reconfigure::DoubleParameter * doubles; |
garyservin | 0:fd24f7ca9688 | 32 | uint8_t groups_length; |
garyservin | 0:fd24f7ca9688 | 33 | dynamic_reconfigure::GroupState st_groups; |
garyservin | 0:fd24f7ca9688 | 34 | dynamic_reconfigure::GroupState * groups; |
garyservin | 0:fd24f7ca9688 | 35 | |
garyservin | 0:fd24f7ca9688 | 36 | Config(): |
garyservin | 0:fd24f7ca9688 | 37 | bools_length(0), bools(NULL), |
garyservin | 0:fd24f7ca9688 | 38 | ints_length(0), ints(NULL), |
garyservin | 0:fd24f7ca9688 | 39 | strs_length(0), strs(NULL), |
garyservin | 0:fd24f7ca9688 | 40 | doubles_length(0), doubles(NULL), |
garyservin | 0:fd24f7ca9688 | 41 | groups_length(0), groups(NULL) |
garyservin | 0:fd24f7ca9688 | 42 | { |
garyservin | 0:fd24f7ca9688 | 43 | } |
garyservin | 0:fd24f7ca9688 | 44 | |
garyservin | 0:fd24f7ca9688 | 45 | virtual int serialize(unsigned char *outbuffer) const |
garyservin | 0:fd24f7ca9688 | 46 | { |
garyservin | 0:fd24f7ca9688 | 47 | int offset = 0; |
garyservin | 0:fd24f7ca9688 | 48 | *(outbuffer + offset++) = bools_length; |
garyservin | 0:fd24f7ca9688 | 49 | *(outbuffer + offset++) = 0; |
garyservin | 0:fd24f7ca9688 | 50 | *(outbuffer + offset++) = 0; |
garyservin | 0:fd24f7ca9688 | 51 | *(outbuffer + offset++) = 0; |
garyservin | 0:fd24f7ca9688 | 52 | for( uint8_t i = 0; i < bools_length; i++){ |
garyservin | 0:fd24f7ca9688 | 53 | offset += this->bools[i].serialize(outbuffer + offset); |
garyservin | 0:fd24f7ca9688 | 54 | } |
garyservin | 0:fd24f7ca9688 | 55 | *(outbuffer + offset++) = ints_length; |
garyservin | 0:fd24f7ca9688 | 56 | *(outbuffer + offset++) = 0; |
garyservin | 0:fd24f7ca9688 | 57 | *(outbuffer + offset++) = 0; |
garyservin | 0:fd24f7ca9688 | 58 | *(outbuffer + offset++) = 0; |
garyservin | 0:fd24f7ca9688 | 59 | for( uint8_t i = 0; i < ints_length; i++){ |
garyservin | 0:fd24f7ca9688 | 60 | offset += this->ints[i].serialize(outbuffer + offset); |
garyservin | 0:fd24f7ca9688 | 61 | } |
garyservin | 0:fd24f7ca9688 | 62 | *(outbuffer + offset++) = strs_length; |
garyservin | 0:fd24f7ca9688 | 63 | *(outbuffer + offset++) = 0; |
garyservin | 0:fd24f7ca9688 | 64 | *(outbuffer + offset++) = 0; |
garyservin | 0:fd24f7ca9688 | 65 | *(outbuffer + offset++) = 0; |
garyservin | 0:fd24f7ca9688 | 66 | for( uint8_t i = 0; i < strs_length; i++){ |
garyservin | 0:fd24f7ca9688 | 67 | offset += this->strs[i].serialize(outbuffer + offset); |
garyservin | 0:fd24f7ca9688 | 68 | } |
garyservin | 0:fd24f7ca9688 | 69 | *(outbuffer + offset++) = doubles_length; |
garyservin | 0:fd24f7ca9688 | 70 | *(outbuffer + offset++) = 0; |
garyservin | 0:fd24f7ca9688 | 71 | *(outbuffer + offset++) = 0; |
garyservin | 0:fd24f7ca9688 | 72 | *(outbuffer + offset++) = 0; |
garyservin | 0:fd24f7ca9688 | 73 | for( uint8_t i = 0; i < doubles_length; i++){ |
garyservin | 0:fd24f7ca9688 | 74 | offset += this->doubles[i].serialize(outbuffer + offset); |
garyservin | 0:fd24f7ca9688 | 75 | } |
garyservin | 0:fd24f7ca9688 | 76 | *(outbuffer + offset++) = groups_length; |
garyservin | 0:fd24f7ca9688 | 77 | *(outbuffer + offset++) = 0; |
garyservin | 0:fd24f7ca9688 | 78 | *(outbuffer + offset++) = 0; |
garyservin | 0:fd24f7ca9688 | 79 | *(outbuffer + offset++) = 0; |
garyservin | 0:fd24f7ca9688 | 80 | for( uint8_t i = 0; i < groups_length; i++){ |
garyservin | 0:fd24f7ca9688 | 81 | offset += this->groups[i].serialize(outbuffer + offset); |
garyservin | 0:fd24f7ca9688 | 82 | } |
garyservin | 0:fd24f7ca9688 | 83 | return offset; |
garyservin | 0:fd24f7ca9688 | 84 | } |
garyservin | 0:fd24f7ca9688 | 85 | |
garyservin | 0:fd24f7ca9688 | 86 | virtual int deserialize(unsigned char *inbuffer) |
garyservin | 0:fd24f7ca9688 | 87 | { |
garyservin | 0:fd24f7ca9688 | 88 | int offset = 0; |
garyservin | 0:fd24f7ca9688 | 89 | uint8_t bools_lengthT = *(inbuffer + offset++); |
garyservin | 0:fd24f7ca9688 | 90 | if(bools_lengthT > bools_length) |
garyservin | 0:fd24f7ca9688 | 91 | this->bools = (dynamic_reconfigure::BoolParameter*)realloc(this->bools, bools_lengthT * sizeof(dynamic_reconfigure::BoolParameter)); |
garyservin | 0:fd24f7ca9688 | 92 | offset += 3; |
garyservin | 0:fd24f7ca9688 | 93 | bools_length = bools_lengthT; |
garyservin | 0:fd24f7ca9688 | 94 | for( uint8_t i = 0; i < bools_length; i++){ |
garyservin | 0:fd24f7ca9688 | 95 | offset += this->st_bools.deserialize(inbuffer + offset); |
garyservin | 0:fd24f7ca9688 | 96 | memcpy( &(this->bools[i]), &(this->st_bools), sizeof(dynamic_reconfigure::BoolParameter)); |
garyservin | 0:fd24f7ca9688 | 97 | } |
garyservin | 0:fd24f7ca9688 | 98 | uint8_t ints_lengthT = *(inbuffer + offset++); |
garyservin | 0:fd24f7ca9688 | 99 | if(ints_lengthT > ints_length) |
garyservin | 0:fd24f7ca9688 | 100 | this->ints = (dynamic_reconfigure::IntParameter*)realloc(this->ints, ints_lengthT * sizeof(dynamic_reconfigure::IntParameter)); |
garyservin | 0:fd24f7ca9688 | 101 | offset += 3; |
garyservin | 0:fd24f7ca9688 | 102 | ints_length = ints_lengthT; |
garyservin | 0:fd24f7ca9688 | 103 | for( uint8_t i = 0; i < ints_length; i++){ |
garyservin | 0:fd24f7ca9688 | 104 | offset += this->st_ints.deserialize(inbuffer + offset); |
garyservin | 0:fd24f7ca9688 | 105 | memcpy( &(this->ints[i]), &(this->st_ints), sizeof(dynamic_reconfigure::IntParameter)); |
garyservin | 0:fd24f7ca9688 | 106 | } |
garyservin | 0:fd24f7ca9688 | 107 | uint8_t strs_lengthT = *(inbuffer + offset++); |
garyservin | 0:fd24f7ca9688 | 108 | if(strs_lengthT > strs_length) |
garyservin | 0:fd24f7ca9688 | 109 | this->strs = (dynamic_reconfigure::StrParameter*)realloc(this->strs, strs_lengthT * sizeof(dynamic_reconfigure::StrParameter)); |
garyservin | 0:fd24f7ca9688 | 110 | offset += 3; |
garyservin | 0:fd24f7ca9688 | 111 | strs_length = strs_lengthT; |
garyservin | 0:fd24f7ca9688 | 112 | for( uint8_t i = 0; i < strs_length; i++){ |
garyservin | 0:fd24f7ca9688 | 113 | offset += this->st_strs.deserialize(inbuffer + offset); |
garyservin | 0:fd24f7ca9688 | 114 | memcpy( &(this->strs[i]), &(this->st_strs), sizeof(dynamic_reconfigure::StrParameter)); |
garyservin | 0:fd24f7ca9688 | 115 | } |
garyservin | 0:fd24f7ca9688 | 116 | uint8_t doubles_lengthT = *(inbuffer + offset++); |
garyservin | 0:fd24f7ca9688 | 117 | if(doubles_lengthT > doubles_length) |
garyservin | 0:fd24f7ca9688 | 118 | this->doubles = (dynamic_reconfigure::DoubleParameter*)realloc(this->doubles, doubles_lengthT * sizeof(dynamic_reconfigure::DoubleParameter)); |
garyservin | 0:fd24f7ca9688 | 119 | offset += 3; |
garyservin | 0:fd24f7ca9688 | 120 | doubles_length = doubles_lengthT; |
garyservin | 0:fd24f7ca9688 | 121 | for( uint8_t i = 0; i < doubles_length; i++){ |
garyservin | 0:fd24f7ca9688 | 122 | offset += this->st_doubles.deserialize(inbuffer + offset); |
garyservin | 0:fd24f7ca9688 | 123 | memcpy( &(this->doubles[i]), &(this->st_doubles), sizeof(dynamic_reconfigure::DoubleParameter)); |
garyservin | 0:fd24f7ca9688 | 124 | } |
garyservin | 0:fd24f7ca9688 | 125 | uint8_t groups_lengthT = *(inbuffer + offset++); |
garyservin | 0:fd24f7ca9688 | 126 | if(groups_lengthT > groups_length) |
garyservin | 0:fd24f7ca9688 | 127 | this->groups = (dynamic_reconfigure::GroupState*)realloc(this->groups, groups_lengthT * sizeof(dynamic_reconfigure::GroupState)); |
garyservin | 0:fd24f7ca9688 | 128 | offset += 3; |
garyservin | 0:fd24f7ca9688 | 129 | groups_length = groups_lengthT; |
garyservin | 0:fd24f7ca9688 | 130 | for( uint8_t i = 0; i < groups_length; i++){ |
garyservin | 0:fd24f7ca9688 | 131 | offset += this->st_groups.deserialize(inbuffer + offset); |
garyservin | 0:fd24f7ca9688 | 132 | memcpy( &(this->groups[i]), &(this->st_groups), sizeof(dynamic_reconfigure::GroupState)); |
garyservin | 0:fd24f7ca9688 | 133 | } |
garyservin | 0:fd24f7ca9688 | 134 | return offset; |
garyservin | 0:fd24f7ca9688 | 135 | } |
garyservin | 0:fd24f7ca9688 | 136 | |
garyservin | 0:fd24f7ca9688 | 137 | const char * getType(){ return "dynamic_reconfigure/Config"; }; |
garyservin | 0:fd24f7ca9688 | 138 | const char * getMD5(){ return "958f16a05573709014982821e6822580"; }; |
garyservin | 0:fd24f7ca9688 | 139 | |
garyservin | 0:fd24f7ca9688 | 140 | }; |
garyservin | 0:fd24f7ca9688 | 141 | |
garyservin | 0:fd24f7ca9688 | 142 | } |
garyservin | 0:fd24f7ca9688 | 143 | #endif |