Statistics
| Branch: | Revision:

root / quad2 / arduino / src / ros_lib / sensor_msgs / Imu.h @ c1426757

History | View | Annotate | Download (8.03 KB)

1
#ifndef _ROS_sensor_msgs_Imu_h
2
#define _ROS_sensor_msgs_Imu_h
3

    
4
#include <stdint.h>
5
#include <string.h>
6
#include <stdlib.h>
7
#include "ros/msg.h"
8
#include "std_msgs/Header.h"
9
#include "geometry_msgs/Quaternion.h"
10
#include "geometry_msgs/Vector3.h"
11

    
12
namespace sensor_msgs
13
{
14

    
15
  class Imu : public ros::Msg
16
  {
17
    public:
18
      std_msgs::Header header;
19
      geometry_msgs::Quaternion orientation;
20
      float orientation_covariance[9];
21
      geometry_msgs::Vector3 angular_velocity;
22
      float angular_velocity_covariance[9];
23
      geometry_msgs::Vector3 linear_acceleration;
24
      float linear_acceleration_covariance[9];
25

    
26
    virtual int serialize(unsigned char *outbuffer) const
27
    {
28
      int offset = 0;
29
      offset += this->header.serialize(outbuffer + offset);
30
      offset += this->orientation.serialize(outbuffer + offset);
31
      unsigned char * orientation_covariance_val = (unsigned char *) this->orientation_covariance;
32
      for( uint8_t i = 0; i < 9; i++){
33
      int32_t * val_orientation_covariancei = (long *) &(this->orientation_covariance[i]);
34
      int32_t exp_orientation_covariancei = (((*val_orientation_covariancei)>>23)&255);
35
      if(exp_orientation_covariancei != 0)
36
        exp_orientation_covariancei += 1023-127;
37
      int32_t sig_orientation_covariancei = *val_orientation_covariancei;
38
      *(outbuffer + offset++) = 0;
39
      *(outbuffer + offset++) = 0;
40
      *(outbuffer + offset++) = 0;
41
      *(outbuffer + offset++) = (sig_orientation_covariancei<<5) & 0xff;
42
      *(outbuffer + offset++) = (sig_orientation_covariancei>>3) & 0xff;
43
      *(outbuffer + offset++) = (sig_orientation_covariancei>>11) & 0xff;
44
      *(outbuffer + offset++) = ((exp_orientation_covariancei<<4) & 0xF0) | ((sig_orientation_covariancei>>19)&0x0F);
45
      *(outbuffer + offset++) = (exp_orientation_covariancei>>4) & 0x7F;
46
      if(this->orientation_covariance[i] < 0) *(outbuffer + offset -1) |= 0x80;
47
      }
48
      offset += this->angular_velocity.serialize(outbuffer + offset);
49
      unsigned char * angular_velocity_covariance_val = (unsigned char *) this->angular_velocity_covariance;
50
      for( uint8_t i = 0; i < 9; i++){
51
      int32_t * val_angular_velocity_covariancei = (long *) &(this->angular_velocity_covariance[i]);
52
      int32_t exp_angular_velocity_covariancei = (((*val_angular_velocity_covariancei)>>23)&255);
53
      if(exp_angular_velocity_covariancei != 0)
54
        exp_angular_velocity_covariancei += 1023-127;
55
      int32_t sig_angular_velocity_covariancei = *val_angular_velocity_covariancei;
56
      *(outbuffer + offset++) = 0;
57
      *(outbuffer + offset++) = 0;
58
      *(outbuffer + offset++) = 0;
59
      *(outbuffer + offset++) = (sig_angular_velocity_covariancei<<5) & 0xff;
60
      *(outbuffer + offset++) = (sig_angular_velocity_covariancei>>3) & 0xff;
61
      *(outbuffer + offset++) = (sig_angular_velocity_covariancei>>11) & 0xff;
62
      *(outbuffer + offset++) = ((exp_angular_velocity_covariancei<<4) & 0xF0) | ((sig_angular_velocity_covariancei>>19)&0x0F);
63
      *(outbuffer + offset++) = (exp_angular_velocity_covariancei>>4) & 0x7F;
64
      if(this->angular_velocity_covariance[i] < 0) *(outbuffer + offset -1) |= 0x80;
65
      }
66
      offset += this->linear_acceleration.serialize(outbuffer + offset);
67
      unsigned char * linear_acceleration_covariance_val = (unsigned char *) this->linear_acceleration_covariance;
68
      for( uint8_t i = 0; i < 9; i++){
69
      int32_t * val_linear_acceleration_covariancei = (long *) &(this->linear_acceleration_covariance[i]);
70
      int32_t exp_linear_acceleration_covariancei = (((*val_linear_acceleration_covariancei)>>23)&255);
71
      if(exp_linear_acceleration_covariancei != 0)
72
        exp_linear_acceleration_covariancei += 1023-127;
73
      int32_t sig_linear_acceleration_covariancei = *val_linear_acceleration_covariancei;
74
      *(outbuffer + offset++) = 0;
75
      *(outbuffer + offset++) = 0;
76
      *(outbuffer + offset++) = 0;
77
      *(outbuffer + offset++) = (sig_linear_acceleration_covariancei<<5) & 0xff;
78
      *(outbuffer + offset++) = (sig_linear_acceleration_covariancei>>3) & 0xff;
79
      *(outbuffer + offset++) = (sig_linear_acceleration_covariancei>>11) & 0xff;
80
      *(outbuffer + offset++) = ((exp_linear_acceleration_covariancei<<4) & 0xF0) | ((sig_linear_acceleration_covariancei>>19)&0x0F);
81
      *(outbuffer + offset++) = (exp_linear_acceleration_covariancei>>4) & 0x7F;
82
      if(this->linear_acceleration_covariance[i] < 0) *(outbuffer + offset -1) |= 0x80;
83
      }
84
      return offset;
85
    }
86

    
87
    virtual int deserialize(unsigned char *inbuffer)
88
    {
89
      int offset = 0;
90
      offset += this->header.deserialize(inbuffer + offset);
91
      offset += this->orientation.deserialize(inbuffer + offset);
92
      uint8_t * orientation_covariance_val = (uint8_t*) this->orientation_covariance;
93
      for( uint8_t i = 0; i < 9; i++){
94
      uint32_t * val_orientation_covariancei = (uint32_t*) &(this->orientation_covariance[i]);
95
      offset += 3;
96
      *val_orientation_covariancei = ((uint32_t)(*(inbuffer + offset++))>>5 & 0x07);
97
      *val_orientation_covariancei |= ((uint32_t)(*(inbuffer + offset++)) & 0xff)<<3;
98
      *val_orientation_covariancei |= ((uint32_t)(*(inbuffer + offset++)) & 0xff)<<11;
99
      *val_orientation_covariancei |= ((uint32_t)(*(inbuffer + offset)) & 0x0f)<<19;
100
      uint32_t exp_orientation_covariancei = ((uint32_t)(*(inbuffer + offset++))&0xf0)>>4;
101
      exp_orientation_covariancei |= ((uint32_t)(*(inbuffer + offset)) & 0x7f)<<4;
102
      if(exp_orientation_covariancei !=0)
103
        *val_orientation_covariancei |= ((exp_orientation_covariancei)-1023+127)<<23;
104
      if( ((*(inbuffer+offset++)) & 0x80) > 0) this->orientation_covariance[i] = -this->orientation_covariance[i];
105
      }
106
      offset += this->angular_velocity.deserialize(inbuffer + offset);
107
      uint8_t * angular_velocity_covariance_val = (uint8_t*) this->angular_velocity_covariance;
108
      for( uint8_t i = 0; i < 9; i++){
109
      uint32_t * val_angular_velocity_covariancei = (uint32_t*) &(this->angular_velocity_covariance[i]);
110
      offset += 3;
111
      *val_angular_velocity_covariancei = ((uint32_t)(*(inbuffer + offset++))>>5 & 0x07);
112
      *val_angular_velocity_covariancei |= ((uint32_t)(*(inbuffer + offset++)) & 0xff)<<3;
113
      *val_angular_velocity_covariancei |= ((uint32_t)(*(inbuffer + offset++)) & 0xff)<<11;
114
      *val_angular_velocity_covariancei |= ((uint32_t)(*(inbuffer + offset)) & 0x0f)<<19;
115
      uint32_t exp_angular_velocity_covariancei = ((uint32_t)(*(inbuffer + offset++))&0xf0)>>4;
116
      exp_angular_velocity_covariancei |= ((uint32_t)(*(inbuffer + offset)) & 0x7f)<<4;
117
      if(exp_angular_velocity_covariancei !=0)
118
        *val_angular_velocity_covariancei |= ((exp_angular_velocity_covariancei)-1023+127)<<23;
119
      if( ((*(inbuffer+offset++)) & 0x80) > 0) this->angular_velocity_covariance[i] = -this->angular_velocity_covariance[i];
120
      }
121
      offset += this->linear_acceleration.deserialize(inbuffer + offset);
122
      uint8_t * linear_acceleration_covariance_val = (uint8_t*) this->linear_acceleration_covariance;
123
      for( uint8_t i = 0; i < 9; i++){
124
      uint32_t * val_linear_acceleration_covariancei = (uint32_t*) &(this->linear_acceleration_covariance[i]);
125
      offset += 3;
126
      *val_linear_acceleration_covariancei = ((uint32_t)(*(inbuffer + offset++))>>5 & 0x07);
127
      *val_linear_acceleration_covariancei |= ((uint32_t)(*(inbuffer + offset++)) & 0xff)<<3;
128
      *val_linear_acceleration_covariancei |= ((uint32_t)(*(inbuffer + offset++)) & 0xff)<<11;
129
      *val_linear_acceleration_covariancei |= ((uint32_t)(*(inbuffer + offset)) & 0x0f)<<19;
130
      uint32_t exp_linear_acceleration_covariancei = ((uint32_t)(*(inbuffer + offset++))&0xf0)>>4;
131
      exp_linear_acceleration_covariancei |= ((uint32_t)(*(inbuffer + offset)) & 0x7f)<<4;
132
      if(exp_linear_acceleration_covariancei !=0)
133
        *val_linear_acceleration_covariancei |= ((exp_linear_acceleration_covariancei)-1023+127)<<23;
134
      if( ((*(inbuffer+offset++)) & 0x80) > 0) this->linear_acceleration_covariance[i] = -this->linear_acceleration_covariance[i];
135
      }
136
     return offset;
137
    }
138

    
139
    const char * getType(){ return "sensor_msgs/Imu"; };
140
    const char * getMD5(){ return "6a62c6daae103f4ff57a132d6f95cec2"; };
141

    
142
  };
143

    
144
}
145
#endif