ros melodic library with custom message

Dependents:   Robot_team1_QEI_Douglas Robot_team1

Committer:
scarter1
Date:
Wed Oct 30 14:59:49 2019 +0000
Revision:
0:020db18a476d
melodic library;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
scarter1 0:020db18a476d 1 #ifndef _ROS_nav_msgs_OccupancyGrid_h
scarter1 0:020db18a476d 2 #define _ROS_nav_msgs_OccupancyGrid_h
scarter1 0:020db18a476d 3
scarter1 0:020db18a476d 4 #include <stdint.h>
scarter1 0:020db18a476d 5 #include <string.h>
scarter1 0:020db18a476d 6 #include <stdlib.h>
scarter1 0:020db18a476d 7 #include "ros/msg.h"
scarter1 0:020db18a476d 8 #include "std_msgs/Header.h"
scarter1 0:020db18a476d 9 #include "nav_msgs/MapMetaData.h"
scarter1 0:020db18a476d 10
scarter1 0:020db18a476d 11 namespace nav_msgs
scarter1 0:020db18a476d 12 {
scarter1 0:020db18a476d 13
scarter1 0:020db18a476d 14 class OccupancyGrid : public ros::Msg
scarter1 0:020db18a476d 15 {
scarter1 0:020db18a476d 16 public:
scarter1 0:020db18a476d 17 typedef std_msgs::Header _header_type;
scarter1 0:020db18a476d 18 _header_type header;
scarter1 0:020db18a476d 19 typedef nav_msgs::MapMetaData _info_type;
scarter1 0:020db18a476d 20 _info_type info;
scarter1 0:020db18a476d 21 uint32_t data_length;
scarter1 0:020db18a476d 22 typedef int8_t _data_type;
scarter1 0:020db18a476d 23 _data_type st_data;
scarter1 0:020db18a476d 24 _data_type * data;
scarter1 0:020db18a476d 25
scarter1 0:020db18a476d 26 OccupancyGrid():
scarter1 0:020db18a476d 27 header(),
scarter1 0:020db18a476d 28 info(),
scarter1 0:020db18a476d 29 data_length(0), data(NULL)
scarter1 0:020db18a476d 30 {
scarter1 0:020db18a476d 31 }
scarter1 0:020db18a476d 32
scarter1 0:020db18a476d 33 virtual int serialize(unsigned char *outbuffer) const
scarter1 0:020db18a476d 34 {
scarter1 0:020db18a476d 35 int offset = 0;
scarter1 0:020db18a476d 36 offset += this->header.serialize(outbuffer + offset);
scarter1 0:020db18a476d 37 offset += this->info.serialize(outbuffer + offset);
scarter1 0:020db18a476d 38 *(outbuffer + offset + 0) = (this->data_length >> (8 * 0)) & 0xFF;
scarter1 0:020db18a476d 39 *(outbuffer + offset + 1) = (this->data_length >> (8 * 1)) & 0xFF;
scarter1 0:020db18a476d 40 *(outbuffer + offset + 2) = (this->data_length >> (8 * 2)) & 0xFF;
scarter1 0:020db18a476d 41 *(outbuffer + offset + 3) = (this->data_length >> (8 * 3)) & 0xFF;
scarter1 0:020db18a476d 42 offset += sizeof(this->data_length);
scarter1 0:020db18a476d 43 for( uint32_t i = 0; i < data_length; i++){
scarter1 0:020db18a476d 44 union {
scarter1 0:020db18a476d 45 int8_t real;
scarter1 0:020db18a476d 46 uint8_t base;
scarter1 0:020db18a476d 47 } u_datai;
scarter1 0:020db18a476d 48 u_datai.real = this->data[i];
scarter1 0:020db18a476d 49 *(outbuffer + offset + 0) = (u_datai.base >> (8 * 0)) & 0xFF;
scarter1 0:020db18a476d 50 offset += sizeof(this->data[i]);
scarter1 0:020db18a476d 51 }
scarter1 0:020db18a476d 52 return offset;
scarter1 0:020db18a476d 53 }
scarter1 0:020db18a476d 54
scarter1 0:020db18a476d 55 virtual int deserialize(unsigned char *inbuffer)
scarter1 0:020db18a476d 56 {
scarter1 0:020db18a476d 57 int offset = 0;
scarter1 0:020db18a476d 58 offset += this->header.deserialize(inbuffer + offset);
scarter1 0:020db18a476d 59 offset += this->info.deserialize(inbuffer + offset);
scarter1 0:020db18a476d 60 uint32_t data_lengthT = ((uint32_t) (*(inbuffer + offset)));
scarter1 0:020db18a476d 61 data_lengthT |= ((uint32_t) (*(inbuffer + offset + 1))) << (8 * 1);
scarter1 0:020db18a476d 62 data_lengthT |= ((uint32_t) (*(inbuffer + offset + 2))) << (8 * 2);
scarter1 0:020db18a476d 63 data_lengthT |= ((uint32_t) (*(inbuffer + offset + 3))) << (8 * 3);
scarter1 0:020db18a476d 64 offset += sizeof(this->data_length);
scarter1 0:020db18a476d 65 if(data_lengthT > data_length)
scarter1 0:020db18a476d 66 this->data = (int8_t*)realloc(this->data, data_lengthT * sizeof(int8_t));
scarter1 0:020db18a476d 67 data_length = data_lengthT;
scarter1 0:020db18a476d 68 for( uint32_t i = 0; i < data_length; i++){
scarter1 0:020db18a476d 69 union {
scarter1 0:020db18a476d 70 int8_t real;
scarter1 0:020db18a476d 71 uint8_t base;
scarter1 0:020db18a476d 72 } u_st_data;
scarter1 0:020db18a476d 73 u_st_data.base = 0;
scarter1 0:020db18a476d 74 u_st_data.base |= ((uint8_t) (*(inbuffer + offset + 0))) << (8 * 0);
scarter1 0:020db18a476d 75 this->st_data = u_st_data.real;
scarter1 0:020db18a476d 76 offset += sizeof(this->st_data);
scarter1 0:020db18a476d 77 memcpy( &(this->data[i]), &(this->st_data), sizeof(int8_t));
scarter1 0:020db18a476d 78 }
scarter1 0:020db18a476d 79 return offset;
scarter1 0:020db18a476d 80 }
scarter1 0:020db18a476d 81
scarter1 0:020db18a476d 82 const char * getType(){ return "nav_msgs/OccupancyGrid"; };
scarter1 0:020db18a476d 83 const char * getMD5(){ return "3381f2d731d4076ec5c71b0759edbe4e"; };
scarter1 0:020db18a476d 84
scarter1 0:020db18a476d 85 };
scarter1 0:020db18a476d 86
scarter1 0:020db18a476d 87 }
scarter1 0:020db18a476d 88 #endif