sensors.cpp
Go to the documentation of this file.
1 
10 /*****************************************************************************
11 ** Includes
12 *****************************************************************************/
13 
14 #include "../../include/xbot_driver/packets/sensors.hpp"
15 #include "../../include/xbot_driver/packet_handler/payload_headers.hpp"
16 
17 /*****************************************************************************
18 ** Namespaces
19 *****************************************************************************/
20 
21 namespace xbot {
22 
23 /*****************************************************************************
24 ** Implementation
25 *****************************************************************************/
26 
28  // buildBytes(Header::ImuSensors, byteStream);
29  // buildBytes(length, byteStream);
30  // buildBytes(data.time_stamp, byteStream); //2
31  // buildBytes(data.bumper, byteStream); //1
32  // buildBytes(data.wheel_drop, byteStream); //1
33  // buildBytes(data.cliff, byteStream); //1
34  // buildBytes(data.left_encoder, byteStream); //2
35  // buildBytes(data.right_encoder, byteStream); //2
36  // buildBytes(data.left_pwm, byteStream); //1
37  // buildBytes(data.right_pwm, byteStream); //1
38  // buildBytes(data.buttons, byteStream); //1
39  // buildBytes(data.charger, byteStream); //1
40  // buildBytes(data.battery, byteStream); //1
41  // buildBytes(data.over_current, byteStream); //1
42 
43  return true;
44 }
46  // if (byteStream.size() < length+2)
47  // {
48  // std::cout<<"length:"<<(unsigned int)length<<std::endl;
49  // std::cout <<
50  // "bytestream.size:"<<byteStream.size()<<std::endl<<"xbot_node:
51  // xbot_default: deserialise failed. not enough byte stream." << std::endl;
52  // return false;
53  // }
54 
55  unsigned char header_id;
56  buildVariable(header_id, byteStream);
57  //标志位,0x11
58  if (header_id != Header::Sensors) {
59  std::cout << "header_id is wrong. header_id:" << (unsigned int)header_id
60  << std::endl;
61 
62  return false;
63  }
64  // 水平转台角度
66  // 竖直转台角度
68  // 音频状态
69  buildVariable(data.sound_enabled, byteStream);
70 
71  int16_t tmp;
72  buildVariable(tmp, byteStream);
73  data.acc_x = tmp * 0.00006086 * 9.8;
74  buildVariable(tmp, byteStream);
75  data.acc_y = tmp * 0.00006086 * 9.8;
76  buildVariable(tmp, byteStream);
77  data.acc_z = tmp * 0.00006086 * 9.8;
78  buildVariable(tmp, byteStream);
79  data.gyro_x = tmp * 4 * 0.0152139846947314 * 3.1415926 / 180;
80  buildVariable(tmp, byteStream);
81  data.gyro_y = tmp * 4 * 0.0152139846947314 * 3.1415926 / 180;
82  buildVariable(tmp, byteStream);
83  data.gyro_z = tmp * 4 * 0.0152139846947314 * 3.1415926 / 180;
84 
85  buildVariable(tmp, byteStream);
86  data.mag_x = tmp * 0.15;
87  buildVariable(tmp, byteStream);
88  data.mag_y = tmp * 0.15;
89  buildVariable(tmp, byteStream);
90  data.mag_z = tmp * 0.15;
91 
92  // IMU9250计算出的三轴角度
93 
94  buildVariable(data.yaw, byteStream);
95  buildVariable(data.pitch, byteStream);
96  buildVariable(data.roll, byteStream);
97  // IMU9250计算出的四元数
98  buildVariable(data.q1, byteStream);
99  buildVariable(data.q2, byteStream);
100  buildVariable(data.q3, byteStream);
101  buildVariable(data.q4, byteStream);
102 
103  // 舵机故障状态
104  buildVariable(data.error_status, byteStream);
105 
106  // 时间戳,4字节无符号整形,单位us
107  buildVariable(data.timestamp, byteStream);
108 
109  //软件版本
110  buildVariable(data.version, byteStream);
111 
112  return true;
113 }
114 
115 } // namespace xbot
unsigned char error_status
Definition: sensors.hpp:61
unsigned char yaw_platform_degree
Definition: sensors.hpp:41
unsigned char pitch_platform_degree
Definition: sensors.hpp:42
EndOfLine endl
uint32_t timestamp
Definition: sensors.hpp:62
bool serialise(ecl::PushAndPop< unsigned char > &byteStream)
Definition: sensors.cpp:27
struct xbot::Sensors::Data data
void buildVariable(T &V, ecl::PushAndPop< unsigned char > &buffer)
bool deserialise(ecl::PushAndPop< unsigned char > &byteStream)
Definition: sensors.cpp:45
Definition: command.hpp:30


xbot_driver
Author(s): Roc, wangpeng@droid.ac.cn
autogenerated on Sat Oct 10 2020 03:27:38