Message_cmd.cpp
Go to the documentation of this file.
1 
47 
48 
49 #include <cstring>
50 #include <iostream>
51 #include <typeinfo>
52 
53 using namespace std;
54 
55 #include "roch_base/core/Number.h"
56 // Conditions on the below to handle compiling for nonstandard hardware
57 #ifdef LOGGING_AVAIL
58 #include "roch_base/core/Logger.h"
59 #endif
60 #ifdef DEBUG_INFO
61 #include "roch_base/roch_hardware.h"//test for ROS_DEBUG_STREAM
62 #endif
63 namespace sawyer
64 {
65 
66  long CmdMessage::total_destroyed = 0;
67  long CmdMessage::total_sent = 0;
68 
69  CmdMessage::~CmdMessage()
70  {
71  ++total_destroyed;
72  if (!is_sent)
73  {
74 #ifdef LOGGING_AVAIL
75  CPR_WARN() << "Command message destroyed without being sent. Type: "
76  << "0x" << hex << getType() << dec
77  << ". Total unsent: " << (total_destroyed-total_sent) << endl;
78 #endif
79  }
80  else
81  {
82  total_sent++;
83  }
84  }
85 
86 
87  CmdProcessorReset::CmdProcessorReset() : CmdMessage()
88  {
90  utob(getPayloadPointer(), 2, (uint16_t) 0x3A18);
92  makeValid();
93  }
94 
96  {
97  }
98 
99 
101  {
102 #ifdef DEBUG_INFO
103  ROS_DEBUG_STREAM("CmdRestoreSettings: flags:%x",(uint8_t) (flags));
104 #endif
105  setPayloadLength(3);
106 
107  utob(getPayloadPointer(), 2, (uint16_t) (0x3a18));
108  *getPayloadPointer(2) = (uint8_t) (flags);
110 
111  makeValid();
112  }
113 
115  {
116  }
117 
118 
120  {
121  setPayloadLength(2);
122 
123  utob(getPayloadPointer(), 2, (uint16_t) (0x3a18));
125 
126  makeValid();
127  }
128 
130  {
131  }
132 
133 
134  SetAckermannOutput::SetAckermannOutput(double steer, double throt, double brake) : CmdMessage()
135  {
136 #ifdef DEBUG_INFO
137  ROS_DEBUG_STREAM("SetAckermannOutput: steer:%.2lf, throt:%.2lf, brake:%.2lf",steer,throt,brake);
138 #endif
140 
141  ftob(getPayloadPointer(STEERING), 2, steer, 100);
142  ftob(getPayloadPointer(THROTTLE), 2, throt, 100);
143  ftob(getPayloadPointer(BRAKE), 2, brake, 100);
144 
146  makeValid();
147  }
148 
150  {
151  }
152 
153 
155  double p,
156  double i,
157  double d)
158  : CmdMessage()
159  {
160 #ifdef DEBUG_INFO
161  ROS_DEBUG_STREAM("SetDifferentialControl: P:%.2lf,I:%.2lf,D:%.2lf.", p, i, d);
162 #endif
163 
165 
166  ftob(getPayloadPointer(LEFT_P), 2, p, 10000);
167  ftob(getPayloadPointer(LEFT_I), 2, i, 10000);
168  ftob(getPayloadPointer(LEFT_D), 2, d, 10000);
169 
170  ftob(getPayloadPointer(RIGHT_P), 2, p, 10000);
171  ftob(getPayloadPointer(RIGHT_I), 2, i, 10000);
172  ftob(getPayloadPointer(RIGHT_D), 2, d, 10000);
173 
175  makeValid();
176  }
177 
179  double left_p,
180  double left_i,
181  double left_d,
182  double right_p,
183  double right_i,
184  double right_d)
185  : CmdMessage()
186  {
187 #ifdef DEBUG_INFO
188  ROS_DEBUG_STREAM("SetDifferentialControl: left_p:%.2lf,left_i:%.2lf,left_d:%.2lf"
189  "right_p:%.2lf,right_i:%.2lf,right_d:%.2lf.", left_p,
190  left_i,
191  left_d,
192  right_p,
193  right_i,
194  right_d);
195 #endif
197 
198  ftob(getPayloadPointer(LEFT_P), 2, left_p, 10000);
199  ftob(getPayloadPointer(LEFT_I), 2, left_i, 10000);
200  ftob(getPayloadPointer(LEFT_D), 2, left_d, 10000);
201 
202  ftob(getPayloadPointer(RIGHT_P), 2, right_p, 10000);
203  ftob(getPayloadPointer(RIGHT_I), 2, right_i, 10000);
204  ftob(getPayloadPointer(RIGHT_D), 2, right_d, 10000);
205 
207  makeValid();
208  }
209 
211  : CmdMessage(other)
212  {
213  }
214 
215 
217  {
218 #ifdef DEBUG_INFO
219  ROS_DEBUG_STREAM("SetDifferentialOutput: left:%.2lf,right:%.2lf",left,right);
220 #endif
222  ftob(getPayloadPointer(LEFT), 2, left, 100);
223  ftob(getPayloadPointer(RIGHT), 2, right, 100);
224 
226  makeValid();
227  }
228 
230  : CmdMessage(other)
231  {
232  }
233 
234 
235  SetDifferentialSpeed::SetDifferentialSpeed(double left_speed, double right_speed,
236  double left_accel, double right_accel)
237  : CmdMessage()
238  {
240  ftob(getPayloadPointer(LEFT_SPEED), 2, left_speed, 100);
241  ftob(getPayloadPointer(LEFT_ACCEL), 2, left_accel, 100);
242  ftob(getPayloadPointer(RIGHT_SPEED), 2, right_speed, 100);
243  ftob(getPayloadPointer(RIGHT_ACCEL), 2, right_accel, 100);
244 #ifdef DEBUG_SEND_SPEED
245  ROS_DEBUG_STREAM("SetDifferentialSpeed: left_speed:%.2lf,right_speed:%.2lf,left_accel:%.2lf,right_accel:%.2lf",left_speed,right_speed,left_accel,right_accel);
246 #endif
248  makeValid();
249  }
250 
252  {
253  }
254 
255 
256  SetGear::SetGear(uint8_t gear) : CmdMessage()
257  {
258 #ifdef DEBUG_INFO
259  ROS_DEBUG_STREAM("SetGear: gear:%x",gear);
260 #endif
261  setPayloadLength(1);
262  getPayloadPointer()[0] = gear;
264  makeValid();
265  }
266 
267  SetGear::SetGear(const SetGear &other) : CmdMessage(other)
268  {
269  }
270 
271 
272  SetMaxAccel::SetMaxAccel(double max_fwd, double max_rev) : CmdMessage()
273  {
275 
276  ftob(getPayloadPointer(MAX_FWD), 2, max_fwd, 100);
277  ftob(getPayloadPointer(MAX_REV), 2, max_rev, 100);
278 #ifdef DEBUG_INFO
279  ROS_DEBUG_STREAM("SetMaxAccel: max_fwd:%.2lf, max_rev:%.2lf",max_fwd,max_rev);
280 #endif
282  makeValid();
283  }
284 
286  {
287  }
288 
289 
290  SetMaxSpeed::SetMaxSpeed(double max_fwd, double max_rev) : CmdMessage()
291  {
293 
294  ftob(getPayloadPointer(MAX_FWD), 2, max_fwd, 100);
295  ftob(getPayloadPointer(MAX_REV), 2, max_rev, 100);
296 #ifdef DEBUG_INFO
297  ROS_DEBUG_STREAM("SetMaxSpeed: max_fwd:%.2lf, max_rev:%.2lf",max_fwd,max_rev);
298 #endif
300  makeValid();
301  }
302 
304  {
305  }
306 
307 
309  {
310  size_t cpy_len = strlen(name);
311  size_t max_len = MAX_MSG_LENGTH - HEADER_LENGTH - CRC_LENGTH - 1 /* for size field */;
312  if (cpy_len > max_len) { cpy_len = max_len; }
313 #ifdef DEBUG_INFO
314  ROS_DEBUG_STREAM("SetPlatformName: name:%s",name);
315 #endif
316  setPayloadLength(cpy_len + 1);
317  getPayloadPointer()[0] = cpy_len;
318  memcpy(getPayloadPointer(1), name, cpy_len);
319 
321 
322  makeValid();
323  }
324 
326  {
327  }
328 
329 
331  {
332 #ifdef DEBUG_INFO
333  ROS_DEBUG_STREAM("SetPlatformTime: name:%d",time);
334 #endif
335  setPayloadLength(4);
336  utob(getPayloadPointer(), 4, time);
338  makeValid();
339  }
340 
342  {
343  }
344 
345 
347  {
348 #ifdef DEBUG_INFO
349  ROS_DEBUG_STREAM("SetSafetySystem: flags:%x",flags);
350 #endif
351  setPayloadLength(2);
352  utob(getPayloadPointer(), 2, flags);
354  makeValid();
355  }
356 
358  {
359  }
360 
361 
362  SetTurn::SetTurn(double trans, double rad, double accel) : CmdMessage()
363  {
365 #ifdef DEBUG_INFO
366  ROS_DEBUG_STREAM("SetTurn: rad:%.2lf, accel:%.2lf",trans,accel);
367 #endif
368 
369  ftob(getPayloadPointer(TRANSLATIONAL), 2, trans, 100);
370  ftob(getPayloadPointer(TURN_RADIUS), 2, rad, 100);
371  ftob(getPayloadPointer(TRANS_ACCEL), 2, accel, 100);
372 
374  makeValid();
375  }
376 
377  SetTurn::SetTurn(const SetTurn &other) : CmdMessage(other)
378  {
379  }
380 
381  SetWheelInfo::SetWheelInfo(double wheel_gauge, double wheel_diameter) : CmdMessage()
382  {
384 #ifdef DEBUG_INFO
385  ROS_DEBUG_STREAM("Set Wheel gauge: %.2lf, wheel diameter: %.2lf .",wheel_gauge,wheel_diameter);
386 #endif
387 
388  ftob(getPayloadPointer(WHEEL_GAUGE), 2, wheel_gauge, 10000);
389  ftob(getPayloadPointer(WHEEL_DIAMETER), 2, wheel_diameter, 10000);
390 
392  makeValid();
393  }
394 
396  {
397  }
398 
399  SetVelocity::SetVelocity(double trans, double rot, double accel) : CmdMessage()
400  {
402 #ifdef DEBUG_INFO
403  ROS_DEBUG_STREAM("SetVelocity: trans:%.2lf, rot:%.2lf, accel:%.2lf",trans,rot,accel);
404 #endif
405 
406  ftob(getPayloadPointer(TRANSLATIONAL), 2, trans, 100);
407  ftob(getPayloadPointer(ROTATIONAL), 2, rot, 100);
408  ftob(getPayloadPointer(TRANS_ACCEL), 2, accel, 100);
409 
411  makeValid();
412  }
413 
415  {
416  }
417 
418 
419 }; // namespace sawyer
420 
SetWheelInfo(double wheel_gauge, double Wheel_diameter)
static const size_t MAX_MSG_LENGTH
Definition: Message.h:70
void setType(uint16_t type)
Definition: Message.cpp:272
SetDifferentialControl(double p, double i, double d)
void utob(void *dest, size_t dest_len, uint64_t src)
Definition: Number.cpp:55
uint8_t * getPayloadPointer(size_t offset=0)
Definition: Message.cpp:218
SetTurn(double trans, double rad, double accel)
SetMaxSpeed(double max_fwd, double max_rev)
SetDifferentialSpeed(double left_spd, double right_speed, double left_accel, double right_accel)
SetMaxAccel(double max_fwd, double max_rev)
void setPayloadLength(uint8_t len)
Definition: Message.cpp:282
#define ROS_DEBUG_STREAM(args)
void ftob(void *dest, size_t dest_len, double src, double scale)
Definition: Number.cpp:92
static const size_t CRC_LENGTH
Definition: Message.h:77
SetPlatformName(const char *name)
void makeValid()
Definition: Message.cpp:372
SetPlatformTime(uint32_t time)
SetAckermannOutput(double steering, double throt, double brake)
SetSafetySystem(uint16_t flags)
SetDifferentialOutput(double left, double right)
#define CPR_WARN()
Definition: Logger.h:98
CmdRestoreSettings(enum restoreFlags flags)
static const size_t HEADER_LENGTH
Definition: Message.h:80
SetGear(uint8_t gear)
SetVelocity(double trans, double rot, double accel)


roch_base
Author(s): Mike Purvis , Paul Bovbel , Chen
autogenerated on Mon Jun 10 2019 14:41:13