rosserial library for mbed Inspired by nucho's rosserial library This library is still under development
Dependents: mbed_roshydro_test
Library still under development!
sensor_msgs/Imu.h@0:30537dec6e0b, 2015-02-15 (annotated)
- Committer:
- akashvibhute
- Date:
- Sun Feb 15 10:53:43 2015 +0000
- Revision:
- 0:30537dec6e0b
First commit; Library still need to be debugged, compilation issues with new mbed and modserial updates.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
akashvibhute | 0:30537dec6e0b | 1 | #ifndef _ROS_sensor_msgs_Imu_h |
akashvibhute | 0:30537dec6e0b | 2 | #define _ROS_sensor_msgs_Imu_h |
akashvibhute | 0:30537dec6e0b | 3 | |
akashvibhute | 0:30537dec6e0b | 4 | #include <stdint.h> |
akashvibhute | 0:30537dec6e0b | 5 | #include <string.h> |
akashvibhute | 0:30537dec6e0b | 6 | #include <stdlib.h> |
akashvibhute | 0:30537dec6e0b | 7 | #include "ros/msg.h" |
akashvibhute | 0:30537dec6e0b | 8 | #include "std_msgs/Header.h" |
akashvibhute | 0:30537dec6e0b | 9 | #include "geometry_msgs/Quaternion.h" |
akashvibhute | 0:30537dec6e0b | 10 | #include "geometry_msgs/Vector3.h" |
akashvibhute | 0:30537dec6e0b | 11 | |
akashvibhute | 0:30537dec6e0b | 12 | namespace sensor_msgs |
akashvibhute | 0:30537dec6e0b | 13 | { |
akashvibhute | 0:30537dec6e0b | 14 | |
akashvibhute | 0:30537dec6e0b | 15 | class Imu : public ros::Msg |
akashvibhute | 0:30537dec6e0b | 16 | { |
akashvibhute | 0:30537dec6e0b | 17 | public: |
akashvibhute | 0:30537dec6e0b | 18 | std_msgs::Header header; |
akashvibhute | 0:30537dec6e0b | 19 | geometry_msgs::Quaternion orientation; |
akashvibhute | 0:30537dec6e0b | 20 | float orientation_covariance[9]; |
akashvibhute | 0:30537dec6e0b | 21 | geometry_msgs::Vector3 angular_velocity; |
akashvibhute | 0:30537dec6e0b | 22 | float angular_velocity_covariance[9]; |
akashvibhute | 0:30537dec6e0b | 23 | geometry_msgs::Vector3 linear_acceleration; |
akashvibhute | 0:30537dec6e0b | 24 | float linear_acceleration_covariance[9]; |
akashvibhute | 0:30537dec6e0b | 25 | |
akashvibhute | 0:30537dec6e0b | 26 | virtual int serialize(unsigned char *outbuffer) const |
akashvibhute | 0:30537dec6e0b | 27 | { |
akashvibhute | 0:30537dec6e0b | 28 | int offset = 0; |
akashvibhute | 0:30537dec6e0b | 29 | offset += this->header.serialize(outbuffer + offset); |
akashvibhute | 0:30537dec6e0b | 30 | offset += this->orientation.serialize(outbuffer + offset); |
akashvibhute | 0:30537dec6e0b | 31 | unsigned char * orientation_covariance_val = (unsigned char *) this->orientation_covariance; |
akashvibhute | 0:30537dec6e0b | 32 | for( uint8_t i = 0; i < 9; i++){ |
akashvibhute | 0:30537dec6e0b | 33 | int32_t * val_orientation_covariancei = (long *) &(this->orientation_covariance[i]); |
akashvibhute | 0:30537dec6e0b | 34 | int32_t exp_orientation_covariancei = (((*val_orientation_covariancei)>>23)&255); |
akashvibhute | 0:30537dec6e0b | 35 | if(exp_orientation_covariancei != 0) |
akashvibhute | 0:30537dec6e0b | 36 | exp_orientation_covariancei += 1023-127; |
akashvibhute | 0:30537dec6e0b | 37 | int32_t sig_orientation_covariancei = *val_orientation_covariancei; |
akashvibhute | 0:30537dec6e0b | 38 | *(outbuffer + offset++) = 0; |
akashvibhute | 0:30537dec6e0b | 39 | *(outbuffer + offset++) = 0; |
akashvibhute | 0:30537dec6e0b | 40 | *(outbuffer + offset++) = 0; |
akashvibhute | 0:30537dec6e0b | 41 | *(outbuffer + offset++) = (sig_orientation_covariancei<<5) & 0xff; |
akashvibhute | 0:30537dec6e0b | 42 | *(outbuffer + offset++) = (sig_orientation_covariancei>>3) & 0xff; |
akashvibhute | 0:30537dec6e0b | 43 | *(outbuffer + offset++) = (sig_orientation_covariancei>>11) & 0xff; |
akashvibhute | 0:30537dec6e0b | 44 | *(outbuffer + offset++) = ((exp_orientation_covariancei<<4) & 0xF0) | ((sig_orientation_covariancei>>19)&0x0F); |
akashvibhute | 0:30537dec6e0b | 45 | *(outbuffer + offset++) = (exp_orientation_covariancei>>4) & 0x7F; |
akashvibhute | 0:30537dec6e0b | 46 | if(this->orientation_covariance[i] < 0) *(outbuffer + offset -1) |= 0x80; |
akashvibhute | 0:30537dec6e0b | 47 | } |
akashvibhute | 0:30537dec6e0b | 48 | offset += this->angular_velocity.serialize(outbuffer + offset); |
akashvibhute | 0:30537dec6e0b | 49 | unsigned char * angular_velocity_covariance_val = (unsigned char *) this->angular_velocity_covariance; |
akashvibhute | 0:30537dec6e0b | 50 | for( uint8_t i = 0; i < 9; i++){ |
akashvibhute | 0:30537dec6e0b | 51 | int32_t * val_angular_velocity_covariancei = (long *) &(this->angular_velocity_covariance[i]); |
akashvibhute | 0:30537dec6e0b | 52 | int32_t exp_angular_velocity_covariancei = (((*val_angular_velocity_covariancei)>>23)&255); |
akashvibhute | 0:30537dec6e0b | 53 | if(exp_angular_velocity_covariancei != 0) |
akashvibhute | 0:30537dec6e0b | 54 | exp_angular_velocity_covariancei += 1023-127; |
akashvibhute | 0:30537dec6e0b | 55 | int32_t sig_angular_velocity_covariancei = *val_angular_velocity_covariancei; |
akashvibhute | 0:30537dec6e0b | 56 | *(outbuffer + offset++) = 0; |
akashvibhute | 0:30537dec6e0b | 57 | *(outbuffer + offset++) = 0; |
akashvibhute | 0:30537dec6e0b | 58 | *(outbuffer + offset++) = 0; |
akashvibhute | 0:30537dec6e0b | 59 | *(outbuffer + offset++) = (sig_angular_velocity_covariancei<<5) & 0xff; |
akashvibhute | 0:30537dec6e0b | 60 | *(outbuffer + offset++) = (sig_angular_velocity_covariancei>>3) & 0xff; |
akashvibhute | 0:30537dec6e0b | 61 | *(outbuffer + offset++) = (sig_angular_velocity_covariancei>>11) & 0xff; |
akashvibhute | 0:30537dec6e0b | 62 | *(outbuffer + offset++) = ((exp_angular_velocity_covariancei<<4) & 0xF0) | ((sig_angular_velocity_covariancei>>19)&0x0F); |
akashvibhute | 0:30537dec6e0b | 63 | *(outbuffer + offset++) = (exp_angular_velocity_covariancei>>4) & 0x7F; |
akashvibhute | 0:30537dec6e0b | 64 | if(this->angular_velocity_covariance[i] < 0) *(outbuffer + offset -1) |= 0x80; |
akashvibhute | 0:30537dec6e0b | 65 | } |
akashvibhute | 0:30537dec6e0b | 66 | offset += this->linear_acceleration.serialize(outbuffer + offset); |
akashvibhute | 0:30537dec6e0b | 67 | unsigned char * linear_acceleration_covariance_val = (unsigned char *) this->linear_acceleration_covariance; |
akashvibhute | 0:30537dec6e0b | 68 | for( uint8_t i = 0; i < 9; i++){ |
akashvibhute | 0:30537dec6e0b | 69 | int32_t * val_linear_acceleration_covariancei = (long *) &(this->linear_acceleration_covariance[i]); |
akashvibhute | 0:30537dec6e0b | 70 | int32_t exp_linear_acceleration_covariancei = (((*val_linear_acceleration_covariancei)>>23)&255); |
akashvibhute | 0:30537dec6e0b | 71 | if(exp_linear_acceleration_covariancei != 0) |
akashvibhute | 0:30537dec6e0b | 72 | exp_linear_acceleration_covariancei += 1023-127; |
akashvibhute | 0:30537dec6e0b | 73 | int32_t sig_linear_acceleration_covariancei = *val_linear_acceleration_covariancei; |
akashvibhute | 0:30537dec6e0b | 74 | *(outbuffer + offset++) = 0; |
akashvibhute | 0:30537dec6e0b | 75 | *(outbuffer + offset++) = 0; |
akashvibhute | 0:30537dec6e0b | 76 | *(outbuffer + offset++) = 0; |
akashvibhute | 0:30537dec6e0b | 77 | *(outbuffer + offset++) = (sig_linear_acceleration_covariancei<<5) & 0xff; |
akashvibhute | 0:30537dec6e0b | 78 | *(outbuffer + offset++) = (sig_linear_acceleration_covariancei>>3) & 0xff; |
akashvibhute | 0:30537dec6e0b | 79 | *(outbuffer + offset++) = (sig_linear_acceleration_covariancei>>11) & 0xff; |
akashvibhute | 0:30537dec6e0b | 80 | *(outbuffer + offset++) = ((exp_linear_acceleration_covariancei<<4) & 0xF0) | ((sig_linear_acceleration_covariancei>>19)&0x0F); |
akashvibhute | 0:30537dec6e0b | 81 | *(outbuffer + offset++) = (exp_linear_acceleration_covariancei>>4) & 0x7F; |
akashvibhute | 0:30537dec6e0b | 82 | if(this->linear_acceleration_covariance[i] < 0) *(outbuffer + offset -1) |= 0x80; |
akashvibhute | 0:30537dec6e0b | 83 | } |
akashvibhute | 0:30537dec6e0b | 84 | return offset; |
akashvibhute | 0:30537dec6e0b | 85 | } |
akashvibhute | 0:30537dec6e0b | 86 | |
akashvibhute | 0:30537dec6e0b | 87 | virtual int deserialize(unsigned char *inbuffer) |
akashvibhute | 0:30537dec6e0b | 88 | { |
akashvibhute | 0:30537dec6e0b | 89 | int offset = 0; |
akashvibhute | 0:30537dec6e0b | 90 | offset += this->header.deserialize(inbuffer + offset); |
akashvibhute | 0:30537dec6e0b | 91 | offset += this->orientation.deserialize(inbuffer + offset); |
akashvibhute | 0:30537dec6e0b | 92 | uint8_t * orientation_covariance_val = (uint8_t*) this->orientation_covariance; |
akashvibhute | 0:30537dec6e0b | 93 | for( uint8_t i = 0; i < 9; i++){ |
akashvibhute | 0:30537dec6e0b | 94 | uint32_t * val_orientation_covariancei = (uint32_t*) &(this->orientation_covariance[i]); |
akashvibhute | 0:30537dec6e0b | 95 | offset += 3; |
akashvibhute | 0:30537dec6e0b | 96 | *val_orientation_covariancei = ((uint32_t)(*(inbuffer + offset++))>>5 & 0x07); |
akashvibhute | 0:30537dec6e0b | 97 | *val_orientation_covariancei |= ((uint32_t)(*(inbuffer + offset++)) & 0xff)<<3; |
akashvibhute | 0:30537dec6e0b | 98 | *val_orientation_covariancei |= ((uint32_t)(*(inbuffer + offset++)) & 0xff)<<11; |
akashvibhute | 0:30537dec6e0b | 99 | *val_orientation_covariancei |= ((uint32_t)(*(inbuffer + offset)) & 0x0f)<<19; |
akashvibhute | 0:30537dec6e0b | 100 | uint32_t exp_orientation_covariancei = ((uint32_t)(*(inbuffer + offset++))&0xf0)>>4; |
akashvibhute | 0:30537dec6e0b | 101 | exp_orientation_covariancei |= ((uint32_t)(*(inbuffer + offset)) & 0x7f)<<4; |
akashvibhute | 0:30537dec6e0b | 102 | if(exp_orientation_covariancei !=0) |
akashvibhute | 0:30537dec6e0b | 103 | *val_orientation_covariancei |= ((exp_orientation_covariancei)-1023+127)<<23; |
akashvibhute | 0:30537dec6e0b | 104 | if( ((*(inbuffer+offset++)) & 0x80) > 0) this->orientation_covariance[i] = -this->orientation_covariance[i]; |
akashvibhute | 0:30537dec6e0b | 105 | } |
akashvibhute | 0:30537dec6e0b | 106 | offset += this->angular_velocity.deserialize(inbuffer + offset); |
akashvibhute | 0:30537dec6e0b | 107 | uint8_t * angular_velocity_covariance_val = (uint8_t*) this->angular_velocity_covariance; |
akashvibhute | 0:30537dec6e0b | 108 | for( uint8_t i = 0; i < 9; i++){ |
akashvibhute | 0:30537dec6e0b | 109 | uint32_t * val_angular_velocity_covariancei = (uint32_t*) &(this->angular_velocity_covariance[i]); |
akashvibhute | 0:30537dec6e0b | 110 | offset += 3; |
akashvibhute | 0:30537dec6e0b | 111 | *val_angular_velocity_covariancei = ((uint32_t)(*(inbuffer + offset++))>>5 & 0x07); |
akashvibhute | 0:30537dec6e0b | 112 | *val_angular_velocity_covariancei |= ((uint32_t)(*(inbuffer + offset++)) & 0xff)<<3; |
akashvibhute | 0:30537dec6e0b | 113 | *val_angular_velocity_covariancei |= ((uint32_t)(*(inbuffer + offset++)) & 0xff)<<11; |
akashvibhute | 0:30537dec6e0b | 114 | *val_angular_velocity_covariancei |= ((uint32_t)(*(inbuffer + offset)) & 0x0f)<<19; |
akashvibhute | 0:30537dec6e0b | 115 | uint32_t exp_angular_velocity_covariancei = ((uint32_t)(*(inbuffer + offset++))&0xf0)>>4; |
akashvibhute | 0:30537dec6e0b | 116 | exp_angular_velocity_covariancei |= ((uint32_t)(*(inbuffer + offset)) & 0x7f)<<4; |
akashvibhute | 0:30537dec6e0b | 117 | if(exp_angular_velocity_covariancei !=0) |
akashvibhute | 0:30537dec6e0b | 118 | *val_angular_velocity_covariancei |= ((exp_angular_velocity_covariancei)-1023+127)<<23; |
akashvibhute | 0:30537dec6e0b | 119 | if( ((*(inbuffer+offset++)) & 0x80) > 0) this->angular_velocity_covariance[i] = -this->angular_velocity_covariance[i]; |
akashvibhute | 0:30537dec6e0b | 120 | } |
akashvibhute | 0:30537dec6e0b | 121 | offset += this->linear_acceleration.deserialize(inbuffer + offset); |
akashvibhute | 0:30537dec6e0b | 122 | uint8_t * linear_acceleration_covariance_val = (uint8_t*) this->linear_acceleration_covariance; |
akashvibhute | 0:30537dec6e0b | 123 | for( uint8_t i = 0; i < 9; i++){ |
akashvibhute | 0:30537dec6e0b | 124 | uint32_t * val_linear_acceleration_covariancei = (uint32_t*) &(this->linear_acceleration_covariance[i]); |
akashvibhute | 0:30537dec6e0b | 125 | offset += 3; |
akashvibhute | 0:30537dec6e0b | 126 | *val_linear_acceleration_covariancei = ((uint32_t)(*(inbuffer + offset++))>>5 & 0x07); |
akashvibhute | 0:30537dec6e0b | 127 | *val_linear_acceleration_covariancei |= ((uint32_t)(*(inbuffer + offset++)) & 0xff)<<3; |
akashvibhute | 0:30537dec6e0b | 128 | *val_linear_acceleration_covariancei |= ((uint32_t)(*(inbuffer + offset++)) & 0xff)<<11; |
akashvibhute | 0:30537dec6e0b | 129 | *val_linear_acceleration_covariancei |= ((uint32_t)(*(inbuffer + offset)) & 0x0f)<<19; |
akashvibhute | 0:30537dec6e0b | 130 | uint32_t exp_linear_acceleration_covariancei = ((uint32_t)(*(inbuffer + offset++))&0xf0)>>4; |
akashvibhute | 0:30537dec6e0b | 131 | exp_linear_acceleration_covariancei |= ((uint32_t)(*(inbuffer + offset)) & 0x7f)<<4; |
akashvibhute | 0:30537dec6e0b | 132 | if(exp_linear_acceleration_covariancei !=0) |
akashvibhute | 0:30537dec6e0b | 133 | *val_linear_acceleration_covariancei |= ((exp_linear_acceleration_covariancei)-1023+127)<<23; |
akashvibhute | 0:30537dec6e0b | 134 | if( ((*(inbuffer+offset++)) & 0x80) > 0) this->linear_acceleration_covariance[i] = -this->linear_acceleration_covariance[i]; |
akashvibhute | 0:30537dec6e0b | 135 | } |
akashvibhute | 0:30537dec6e0b | 136 | return offset; |
akashvibhute | 0:30537dec6e0b | 137 | } |
akashvibhute | 0:30537dec6e0b | 138 | |
akashvibhute | 0:30537dec6e0b | 139 | virtual const char * getType(){ return "sensor_msgs/Imu"; }; |
akashvibhute | 0:30537dec6e0b | 140 | virtual const char * getMD5(){ return "6a62c6daae103f4ff57a132d6f95cec2"; }; |
akashvibhute | 0:30537dec6e0b | 141 | |
akashvibhute | 0:30537dec6e0b | 142 | }; |
akashvibhute | 0:30537dec6e0b | 143 | |
akashvibhute | 0:30537dec6e0b | 144 | } |
akashvibhute | 0:30537dec6e0b | 145 | #endif |