![](/media/cache/profiles/94aef38441efa3380a3bed3faf1f9d5d.50x50_q85.jpg)
This program is porting rosserial_arduino for mbed http://www.ros.org/wiki/rosserial_arduino This program supported the revision of 169 of rosserial. This program contains an example.
Dependencies: rosserial_mbed_lib mbed Servo
nav_msgs/OccupancyGrid.h@0:06fc856e99ca, 2011-08-19 (annotated)
- Committer:
- nucho
- Date:
- Fri Aug 19 09:06:16 2011 +0000
- Revision:
- 0:06fc856e99ca
- Child:
- 1:098e75fd5ad2
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
nucho | 0:06fc856e99ca | 1 | #ifndef ros_OccupancyGrid_h |
nucho | 0:06fc856e99ca | 2 | #define ros_OccupancyGrid_h |
nucho | 0:06fc856e99ca | 3 | |
nucho | 0:06fc856e99ca | 4 | #include <stdint.h> |
nucho | 0:06fc856e99ca | 5 | #include <string.h> |
nucho | 0:06fc856e99ca | 6 | #include <stdlib.h> |
nucho | 0:06fc856e99ca | 7 | #include "../ros/msg.h" |
nucho | 0:06fc856e99ca | 8 | #include "std_msgs/Header.h" |
nucho | 0:06fc856e99ca | 9 | #include "nav_msgs/MapMetaData.h" |
nucho | 0:06fc856e99ca | 10 | |
nucho | 0:06fc856e99ca | 11 | namespace nav_msgs |
nucho | 0:06fc856e99ca | 12 | { |
nucho | 0:06fc856e99ca | 13 | |
nucho | 0:06fc856e99ca | 14 | class OccupancyGrid : public ros::Msg |
nucho | 0:06fc856e99ca | 15 | { |
nucho | 0:06fc856e99ca | 16 | public: |
nucho | 0:06fc856e99ca | 17 | std_msgs::Header header; |
nucho | 0:06fc856e99ca | 18 | nav_msgs::MapMetaData info; |
nucho | 0:06fc856e99ca | 19 | unsigned char data_length; |
nucho | 0:06fc856e99ca | 20 | signed char st_data; |
nucho | 0:06fc856e99ca | 21 | signed char * data; |
nucho | 0:06fc856e99ca | 22 | |
nucho | 0:06fc856e99ca | 23 | virtual int serialize(unsigned char *outbuffer) |
nucho | 0:06fc856e99ca | 24 | { |
nucho | 0:06fc856e99ca | 25 | int offset = 0; |
nucho | 0:06fc856e99ca | 26 | offset += this->header.serialize(outbuffer + offset); |
nucho | 0:06fc856e99ca | 27 | offset += this->info.serialize(outbuffer + offset); |
nucho | 0:06fc856e99ca | 28 | *(outbuffer + offset++) = data_length; |
nucho | 0:06fc856e99ca | 29 | *(outbuffer + offset++) = 0; |
nucho | 0:06fc856e99ca | 30 | *(outbuffer + offset++) = 0; |
nucho | 0:06fc856e99ca | 31 | *(outbuffer + offset++) = 0; |
nucho | 0:06fc856e99ca | 32 | for( unsigned char i = 0; i < data_length; i++){ |
nucho | 0:06fc856e99ca | 33 | union { |
nucho | 0:06fc856e99ca | 34 | signed char real; |
nucho | 0:06fc856e99ca | 35 | unsigned char base; |
nucho | 0:06fc856e99ca | 36 | } u_datai; |
nucho | 0:06fc856e99ca | 37 | u_datai.real = this->data[i]; |
nucho | 0:06fc856e99ca | 38 | *(outbuffer + offset + 0) = (u_datai.base >> (8 * 0)) & 0xFF; |
nucho | 0:06fc856e99ca | 39 | offset += sizeof(this->data[i]); |
nucho | 0:06fc856e99ca | 40 | } |
nucho | 0:06fc856e99ca | 41 | return offset; |
nucho | 0:06fc856e99ca | 42 | } |
nucho | 0:06fc856e99ca | 43 | |
nucho | 0:06fc856e99ca | 44 | virtual int deserialize(unsigned char *inbuffer) |
nucho | 0:06fc856e99ca | 45 | { |
nucho | 0:06fc856e99ca | 46 | int offset = 0; |
nucho | 0:06fc856e99ca | 47 | offset += this->header.deserialize(inbuffer + offset); |
nucho | 0:06fc856e99ca | 48 | offset += this->info.deserialize(inbuffer + offset); |
nucho | 0:06fc856e99ca | 49 | unsigned char data_lengthT = *(inbuffer + offset++); |
nucho | 0:06fc856e99ca | 50 | if(data_lengthT > data_length) |
nucho | 0:06fc856e99ca | 51 | this->data = (signed char*)realloc(this->data, data_lengthT * sizeof(signed char)); |
nucho | 0:06fc856e99ca | 52 | offset += 3; |
nucho | 0:06fc856e99ca | 53 | data_length = data_lengthT; |
nucho | 0:06fc856e99ca | 54 | for( unsigned char i = 0; i < data_length; i++){ |
nucho | 0:06fc856e99ca | 55 | union { |
nucho | 0:06fc856e99ca | 56 | signed char real; |
nucho | 0:06fc856e99ca | 57 | unsigned char base; |
nucho | 0:06fc856e99ca | 58 | } u_st_data; |
nucho | 0:06fc856e99ca | 59 | u_st_data.base = 0; |
nucho | 0:06fc856e99ca | 60 | u_st_data.base |= ((typeof(u_st_data.base)) (*(inbuffer + offset + 0))) << (8 * 0); |
nucho | 0:06fc856e99ca | 61 | this->st_data = u_st_data.real; |
nucho | 0:06fc856e99ca | 62 | offset += sizeof(this->st_data); |
nucho | 0:06fc856e99ca | 63 | memcpy( &(this->data[i]), &(this->st_data), sizeof(signed char)); |
nucho | 0:06fc856e99ca | 64 | } |
nucho | 0:06fc856e99ca | 65 | return offset; |
nucho | 0:06fc856e99ca | 66 | } |
nucho | 0:06fc856e99ca | 67 | |
nucho | 0:06fc856e99ca | 68 | virtual const char * getType(){ return "nav_msgs/OccupancyGrid"; }; |
nucho | 0:06fc856e99ca | 69 | |
nucho | 0:06fc856e99ca | 70 | }; |
nucho | 0:06fc856e99ca | 71 | |
nucho | 0:06fc856e99ca | 72 | } |
nucho | 0:06fc856e99ca | 73 | #endif |