core_sensors.cpp
Go to the documentation of this file.
1 
10 /*****************************************************************************
11 ** Includes
12 *****************************************************************************/
13 
14 #include "../../include/xbot_driver/packets/core_sensors.hpp"
15 #include "../../include/xbot_driver/packet_handler/payload_headers.hpp"
16 #include <time.h>
17 /*****************************************************************************
18 ** Namespaces
19 *****************************************************************************/
20 
21 namespace xbot {
22 
23 /*****************************************************************************
24 ** Implementation
25 *****************************************************************************/
26 
28 {
29 // buildBytes(Header::CoreSensors, byteStream);
30 // buildBytes(length, byteStream);
31 // buildBytes(data.time_stamp, byteStream); //2
32 // buildBytes(data.bumper, byteStream); //1
33 // buildBytes(data.wheel_drop, byteStream); //1
34 // buildBytes(data.cliff, byteStream); //1
35 // buildBytes(data.left_encoder, byteStream); //2
36 // buildBytes(data.right_encoder, byteStream); //2
37 // buildBytes(data.left_pwm, byteStream); //1
38 // buildBytes(data.right_pwm, byteStream); //1
39 // buildBytes(data.buttons, byteStream); //1
40 // buildBytes(data.charger, byteStream); //1
41 // buildBytes(data.battery, byteStream); //1
42 // buildBytes(data.over_current, byteStream); //1
43 
44  return true;
45 }
46 
47 
48 
50 {
51 // std::cout<<byteStream.size()<<std::endl;
52 
53 // if (byteStream.size() < length+2)
54 // {
55 // std::cout<<"length:"<<(unsigned int)length<<std::endl;
56 // std::cout << "bytestream.size:"<<byteStream.size()<<std::endl<<"xbot_node: xbot_default: deserialise failed. not enough byte stream." << std::endl;
57 // return false;
58 // }
59 // 标志位,固定0x10
60  unsigned char header_id;//0x10 marker
61  buildVariable(header_id, byteStream);
62 
63  if( header_id != Header::CoreSensors )
64  {
65  std::cout<<"header_id is wrong. header_id:"<<(unsigned int)header_id<<std::endl;
66 
67  return false;
68  }
69 // std::cout<<"header_id:"<<(unsigned int)header_id<<std::endl;
70 
71  uint16_t tempvariable = 0;
72  uint8_t tmp = 0;
73 // 码盘
74  buildVariable(data.left_encoder, byteStream);
75  buildVariable(data.right_encoder, byteStream);
76 
77 // 电源,充电状态与电量
78 
79  buildVariable(tempvariable, byteStream);//充电电流,单位10mA
80 
81  data.is_charging = (tempvariable < 0)?false:true;
82  buildVariable(data.power_percent,byteStream);
83 
84 
85 
86 // 前后各一路超声,均值滤波,25个邻域数据取均值,每秒50帧数据,取0.5s内的平均
87 
88  buildVariable(tempvariable, byteStream); //front_left not used
89 
90  buildVariable(tempvariable, byteStream);
91  queue_front_echo.lpush(tempvariable);
93 
94  buildVariable(tempvariable, byteStream); //front_right not used
95 
96 
97  buildVariable(tempvariable, byteStream);//rear_left not used
98 
99  buildVariable(tempvariable, byteStream);
100  queue_rear_echo.lpush(tempvariable);
102 
103  buildVariable(tempvariable, byteStream);//rear_right not used
104 
105 // 前后各一路红外,均值滤波,25个邻域数据取均值,每秒50帧数据,取0.5s内的平均
106  buildVariable(tempvariable, byteStream);//front left not used
107 
108  buildVariable(tempvariable, byteStream);
109  queue_front_infrared.lpush(tempvariable);
111 
112  buildVariable(tempvariable, byteStream);//front right not used
113  buildVariable(tempvariable, byteStream);//rear left not used
114 
115  buildVariable(tempvariable, byteStream);
116  queue_rear_infrared.lpush(tempvariable);
118 
119  buildVariable(tempvariable, byteStream);//rear right not used
120 
121 
122 // 急停开关状态反馈
123  buildVariable(data.motor_enabled,byteStream);
124 
125 // 两路电机电流
128 
129 // 时间戳,4字节无符号整形,单位us
130  buildVariable(data.timestamp, byteStream);
131 
132 // 故障状态显示
133  buildVariable(data.error_state, byteStream);
134 
135  //软件版本
136  buildVariable(data.version, byteStream);
137 
138 
139  return true;
140 }
141 
143 {
144  if (byteStream.size() < 2)
145  return;
146 
147  unsigned char a, b;
148  buildVariable(a,byteStream);
149  buildVariable(b,byteStream);
150  variable = ((unsigned int)(a&0x0f))/100.0;
151 
152  variable += ((unsigned int)(a>>4))/10.0;
153 
154  variable += (unsigned int)(b&0x0f);
155 
156  variable += ((unsigned int)(b>>4))*10;
157 
158 
159 }
160 
161 
162 } // namespace xbot
unsigned int size() const
lqueue< uint > queue_rear_echo
unsigned char power_percent
void build_special_variable(float &variable, ecl::PushAndPop< unsigned char > &byteStream)
T mean()
Definition: lqueue.h:68
void lpush(T node)
Definition: lqueue.h:29
bool serialise(ecl::PushAndPop< unsigned char > &byteStream)
EndOfLine endl
struct xbot::CoreSensors::Data data
lqueue< uint > queue_front_echo
void buildVariable(T &V, ecl::PushAndPop< unsigned char > &buffer)
bool deserialise(ecl::PushAndPop< unsigned char > &byteStream)
lqueue< uint > queue_rear_infrared
lqueue< uint > queue_front_infrared
Definition: command.hpp:30


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