ROS Serial library for Mbed platforms for ROS Melodic Morenia. Check http://wiki.ros.org/rosserial_mbed/ for more information.
Dependents: rosserial_mbed_hello_world_publisher_melodic Motortest Nucleo_vr_servo_project NucleoFM ... more
ROSSerial_mbed for Melodic 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_melodic
rosserial_mbed Hello World example for Melodic Morenia distribution
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(); } }
controller_manager_msgs/ListControllerTypes.h@1:da82487f547e, 2019-11-08 (annotated)
- Committer:
- Gary Servin
- Date:
- Fri Nov 08 14:55:04 2019 -0300
- Revision:
- 1:da82487f547e
- Parent:
- 0:04ac6be8229a
Add missing round() method
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Gary Servin |
0:04ac6be8229a | 1 | #ifndef _ROS_SERVICE_ListControllerTypes_h |
Gary Servin |
0:04ac6be8229a | 2 | #define _ROS_SERVICE_ListControllerTypes_h |
Gary Servin |
0:04ac6be8229a | 3 | #include <stdint.h> |
Gary Servin |
0:04ac6be8229a | 4 | #include <string.h> |
Gary Servin |
0:04ac6be8229a | 5 | #include <stdlib.h> |
Gary Servin |
0:04ac6be8229a | 6 | #include "ros/msg.h" |
Gary Servin |
0:04ac6be8229a | 7 | |
Gary Servin |
0:04ac6be8229a | 8 | namespace controller_manager_msgs |
Gary Servin |
0:04ac6be8229a | 9 | { |
Gary Servin |
0:04ac6be8229a | 10 | |
Gary Servin |
0:04ac6be8229a | 11 | static const char LISTCONTROLLERTYPES[] = "controller_manager_msgs/ListControllerTypes"; |
Gary Servin |
0:04ac6be8229a | 12 | |
Gary Servin |
0:04ac6be8229a | 13 | class ListControllerTypesRequest : public ros::Msg |
Gary Servin |
0:04ac6be8229a | 14 | { |
Gary Servin |
0:04ac6be8229a | 15 | public: |
Gary Servin |
0:04ac6be8229a | 16 | |
Gary Servin |
0:04ac6be8229a | 17 | ListControllerTypesRequest() |
Gary Servin |
0:04ac6be8229a | 18 | { |
Gary Servin |
0:04ac6be8229a | 19 | } |
Gary Servin |
0:04ac6be8229a | 20 | |
Gary Servin |
0:04ac6be8229a | 21 | virtual int serialize(unsigned char *outbuffer) const |
Gary Servin |
0:04ac6be8229a | 22 | { |
Gary Servin |
0:04ac6be8229a | 23 | int offset = 0; |
Gary Servin |
0:04ac6be8229a | 24 | return offset; |
Gary Servin |
0:04ac6be8229a | 25 | } |
Gary Servin |
0:04ac6be8229a | 26 | |
Gary Servin |
0:04ac6be8229a | 27 | virtual int deserialize(unsigned char *inbuffer) |
Gary Servin |
0:04ac6be8229a | 28 | { |
Gary Servin |
0:04ac6be8229a | 29 | int offset = 0; |
Gary Servin |
0:04ac6be8229a | 30 | return offset; |
Gary Servin |
0:04ac6be8229a | 31 | } |
Gary Servin |
0:04ac6be8229a | 32 | |
Gary Servin |
0:04ac6be8229a | 33 | const char * getType(){ return LISTCONTROLLERTYPES; }; |
Gary Servin |
0:04ac6be8229a | 34 | const char * getMD5(){ return "d41d8cd98f00b204e9800998ecf8427e"; }; |
Gary Servin |
0:04ac6be8229a | 35 | |
Gary Servin |
0:04ac6be8229a | 36 | }; |
Gary Servin |
0:04ac6be8229a | 37 | |
Gary Servin |
0:04ac6be8229a | 38 | class ListControllerTypesResponse : public ros::Msg |
Gary Servin |
0:04ac6be8229a | 39 | { |
Gary Servin |
0:04ac6be8229a | 40 | public: |
Gary Servin |
0:04ac6be8229a | 41 | uint32_t types_length; |
Gary Servin |
0:04ac6be8229a | 42 | typedef char* _types_type; |
Gary Servin |
0:04ac6be8229a | 43 | _types_type st_types; |
Gary Servin |
0:04ac6be8229a | 44 | _types_type * types; |
Gary Servin |
0:04ac6be8229a | 45 | uint32_t base_classes_length; |
Gary Servin |
0:04ac6be8229a | 46 | typedef char* _base_classes_type; |
Gary Servin |
0:04ac6be8229a | 47 | _base_classes_type st_base_classes; |
Gary Servin |
0:04ac6be8229a | 48 | _base_classes_type * base_classes; |
Gary Servin |
0:04ac6be8229a | 49 | |
Gary Servin |
0:04ac6be8229a | 50 | ListControllerTypesResponse(): |
Gary Servin |
0:04ac6be8229a | 51 | types_length(0), types(NULL), |
Gary Servin |
0:04ac6be8229a | 52 | base_classes_length(0), base_classes(NULL) |
Gary Servin |
0:04ac6be8229a | 53 | { |
Gary Servin |
0:04ac6be8229a | 54 | } |
Gary Servin |
0:04ac6be8229a | 55 | |
Gary Servin |
0:04ac6be8229a | 56 | virtual int serialize(unsigned char *outbuffer) const |
Gary Servin |
0:04ac6be8229a | 57 | { |
Gary Servin |
0:04ac6be8229a | 58 | int offset = 0; |
Gary Servin |
0:04ac6be8229a | 59 | *(outbuffer + offset + 0) = (this->types_length >> (8 * 0)) & 0xFF; |
Gary Servin |
0:04ac6be8229a | 60 | *(outbuffer + offset + 1) = (this->types_length >> (8 * 1)) & 0xFF; |
Gary Servin |
0:04ac6be8229a | 61 | *(outbuffer + offset + 2) = (this->types_length >> (8 * 2)) & 0xFF; |
Gary Servin |
0:04ac6be8229a | 62 | *(outbuffer + offset + 3) = (this->types_length >> (8 * 3)) & 0xFF; |
Gary Servin |
0:04ac6be8229a | 63 | offset += sizeof(this->types_length); |
Gary Servin |
0:04ac6be8229a | 64 | for( uint32_t i = 0; i < types_length; i++){ |
Gary Servin |
0:04ac6be8229a | 65 | uint32_t length_typesi = strlen(this->types[i]); |
Gary Servin |
0:04ac6be8229a | 66 | varToArr(outbuffer + offset, length_typesi); |
Gary Servin |
0:04ac6be8229a | 67 | offset += 4; |
Gary Servin |
0:04ac6be8229a | 68 | memcpy(outbuffer + offset, this->types[i], length_typesi); |
Gary Servin |
0:04ac6be8229a | 69 | offset += length_typesi; |
Gary Servin |
0:04ac6be8229a | 70 | } |
Gary Servin |
0:04ac6be8229a | 71 | *(outbuffer + offset + 0) = (this->base_classes_length >> (8 * 0)) & 0xFF; |
Gary Servin |
0:04ac6be8229a | 72 | *(outbuffer + offset + 1) = (this->base_classes_length >> (8 * 1)) & 0xFF; |
Gary Servin |
0:04ac6be8229a | 73 | *(outbuffer + offset + 2) = (this->base_classes_length >> (8 * 2)) & 0xFF; |
Gary Servin |
0:04ac6be8229a | 74 | *(outbuffer + offset + 3) = (this->base_classes_length >> (8 * 3)) & 0xFF; |
Gary Servin |
0:04ac6be8229a | 75 | offset += sizeof(this->base_classes_length); |
Gary Servin |
0:04ac6be8229a | 76 | for( uint32_t i = 0; i < base_classes_length; i++){ |
Gary Servin |
0:04ac6be8229a | 77 | uint32_t length_base_classesi = strlen(this->base_classes[i]); |
Gary Servin |
0:04ac6be8229a | 78 | varToArr(outbuffer + offset, length_base_classesi); |
Gary Servin |
0:04ac6be8229a | 79 | offset += 4; |
Gary Servin |
0:04ac6be8229a | 80 | memcpy(outbuffer + offset, this->base_classes[i], length_base_classesi); |
Gary Servin |
0:04ac6be8229a | 81 | offset += length_base_classesi; |
Gary Servin |
0:04ac6be8229a | 82 | } |
Gary Servin |
0:04ac6be8229a | 83 | return offset; |
Gary Servin |
0:04ac6be8229a | 84 | } |
Gary Servin |
0:04ac6be8229a | 85 | |
Gary Servin |
0:04ac6be8229a | 86 | virtual int deserialize(unsigned char *inbuffer) |
Gary Servin |
0:04ac6be8229a | 87 | { |
Gary Servin |
0:04ac6be8229a | 88 | int offset = 0; |
Gary Servin |
0:04ac6be8229a | 89 | uint32_t types_lengthT = ((uint32_t) (*(inbuffer + offset))); |
Gary Servin |
0:04ac6be8229a | 90 | types_lengthT |= ((uint32_t) (*(inbuffer + offset + 1))) << (8 * 1); |
Gary Servin |
0:04ac6be8229a | 91 | types_lengthT |= ((uint32_t) (*(inbuffer + offset + 2))) << (8 * 2); |
Gary Servin |
0:04ac6be8229a | 92 | types_lengthT |= ((uint32_t) (*(inbuffer + offset + 3))) << (8 * 3); |
Gary Servin |
0:04ac6be8229a | 93 | offset += sizeof(this->types_length); |
Gary Servin |
0:04ac6be8229a | 94 | if(types_lengthT > types_length) |
Gary Servin |
0:04ac6be8229a | 95 | this->types = (char**)realloc(this->types, types_lengthT * sizeof(char*)); |
Gary Servin |
0:04ac6be8229a | 96 | types_length = types_lengthT; |
Gary Servin |
0:04ac6be8229a | 97 | for( uint32_t i = 0; i < types_length; i++){ |
Gary Servin |
0:04ac6be8229a | 98 | uint32_t length_st_types; |
Gary Servin |
0:04ac6be8229a | 99 | arrToVar(length_st_types, (inbuffer + offset)); |
Gary Servin |
0:04ac6be8229a | 100 | offset += 4; |
Gary Servin |
0:04ac6be8229a | 101 | for(unsigned int k= offset; k< offset+length_st_types; ++k){ |
Gary Servin |
0:04ac6be8229a | 102 | inbuffer[k-1]=inbuffer[k]; |
Gary Servin |
0:04ac6be8229a | 103 | } |
Gary Servin |
0:04ac6be8229a | 104 | inbuffer[offset+length_st_types-1]=0; |
Gary Servin |
0:04ac6be8229a | 105 | this->st_types = (char *)(inbuffer + offset-1); |
Gary Servin |
0:04ac6be8229a | 106 | offset += length_st_types; |
Gary Servin |
0:04ac6be8229a | 107 | memcpy( &(this->types[i]), &(this->st_types), sizeof(char*)); |
Gary Servin |
0:04ac6be8229a | 108 | } |
Gary Servin |
0:04ac6be8229a | 109 | uint32_t base_classes_lengthT = ((uint32_t) (*(inbuffer + offset))); |
Gary Servin |
0:04ac6be8229a | 110 | base_classes_lengthT |= ((uint32_t) (*(inbuffer + offset + 1))) << (8 * 1); |
Gary Servin |
0:04ac6be8229a | 111 | base_classes_lengthT |= ((uint32_t) (*(inbuffer + offset + 2))) << (8 * 2); |
Gary Servin |
0:04ac6be8229a | 112 | base_classes_lengthT |= ((uint32_t) (*(inbuffer + offset + 3))) << (8 * 3); |
Gary Servin |
0:04ac6be8229a | 113 | offset += sizeof(this->base_classes_length); |
Gary Servin |
0:04ac6be8229a | 114 | if(base_classes_lengthT > base_classes_length) |
Gary Servin |
0:04ac6be8229a | 115 | this->base_classes = (char**)realloc(this->base_classes, base_classes_lengthT * sizeof(char*)); |
Gary Servin |
0:04ac6be8229a | 116 | base_classes_length = base_classes_lengthT; |
Gary Servin |
0:04ac6be8229a | 117 | for( uint32_t i = 0; i < base_classes_length; i++){ |
Gary Servin |
0:04ac6be8229a | 118 | uint32_t length_st_base_classes; |
Gary Servin |
0:04ac6be8229a | 119 | arrToVar(length_st_base_classes, (inbuffer + offset)); |
Gary Servin |
0:04ac6be8229a | 120 | offset += 4; |
Gary Servin |
0:04ac6be8229a | 121 | for(unsigned int k= offset; k< offset+length_st_base_classes; ++k){ |
Gary Servin |
0:04ac6be8229a | 122 | inbuffer[k-1]=inbuffer[k]; |
Gary Servin |
0:04ac6be8229a | 123 | } |
Gary Servin |
0:04ac6be8229a | 124 | inbuffer[offset+length_st_base_classes-1]=0; |
Gary Servin |
0:04ac6be8229a | 125 | this->st_base_classes = (char *)(inbuffer + offset-1); |
Gary Servin |
0:04ac6be8229a | 126 | offset += length_st_base_classes; |
Gary Servin |
0:04ac6be8229a | 127 | memcpy( &(this->base_classes[i]), &(this->st_base_classes), sizeof(char*)); |
Gary Servin |
0:04ac6be8229a | 128 | } |
Gary Servin |
0:04ac6be8229a | 129 | return offset; |
Gary Servin |
0:04ac6be8229a | 130 | } |
Gary Servin |
0:04ac6be8229a | 131 | |
Gary Servin |
0:04ac6be8229a | 132 | const char * getType(){ return LISTCONTROLLERTYPES; }; |
Gary Servin |
0:04ac6be8229a | 133 | const char * getMD5(){ return "c1d4cd11aefa9f97ba4aeb5b33987f4e"; }; |
Gary Servin |
0:04ac6be8229a | 134 | |
Gary Servin |
0:04ac6be8229a | 135 | }; |
Gary Servin |
0:04ac6be8229a | 136 | |
Gary Servin |
0:04ac6be8229a | 137 | class ListControllerTypes { |
Gary Servin |
0:04ac6be8229a | 138 | public: |
Gary Servin |
0:04ac6be8229a | 139 | typedef ListControllerTypesRequest Request; |
Gary Servin |
0:04ac6be8229a | 140 | typedef ListControllerTypesResponse Response; |
Gary Servin |
0:04ac6be8229a | 141 | }; |
Gary Servin |
0:04ac6be8229a | 142 | |
Gary Servin |
0:04ac6be8229a | 143 | } |
Gary Servin |
0:04ac6be8229a | 144 | #endif |