Message_data.cpp
Go to the documentation of this file.
4 
5 #include <iostream>
6 #include <string>
7 #include <string.h>
8 #include <sstream>
9 
10 using namespace std;
11 
12 namespace clearpath
13 {
14 
24 #define MESSAGE_CONSTRUCTORS(MessageClass, ExpectedLength) \
25 MessageClass::MessageClass(void* input, size_t msg_len) : Message(input, msg_len) \
26 { \
27  if( ((ExpectedLength) >= 0) && ((ssize_t)getPayloadLength() != (ExpectedLength)) ) { \
28  stringstream ss; \
29  ss << "Bad payload length: actual="<<getPayloadLength(); \
30  ss <<" vs. expected="<<(ExpectedLength); \
31  throw new MessageException(ss.str().c_str(), MessageException::INVALID_LENGTH); \
32  } \
33 } \
34 MessageClass::MessageClass(const MessageClass& other) : Message(other) {}
35 
36 
41 #define MESSAGE_CONVENIENCE_FNS(MessageClass, DataMsgID) \
42 MessageClass* MessageClass::popNext() { \
43  return dynamic_cast<MessageClass*>(Transport::instance().popNext(DataMsgID)); \
44 } \
45 \
46 MessageClass* MessageClass::waitNext(double timeout) { \
47  return dynamic_cast<MessageClass*>(Transport::instance().waitNext(DataMsgID, timeout)); \
48 } \
49 \
50 MessageClass* MessageClass::getUpdate(double timeout) { \
51  Transport::instance().flush(DataMsgID); \
52  subscribe(0); \
53  return dynamic_cast<MessageClass*>( \
54  Transport::instance().waitNext(DataMsgID, timeout) ); \
55 }\
56 \
57 void MessageClass::subscribe(uint16_t freq) { \
58  Request(DataMsgID-0x4000, freq).send(); \
59 } \
60 \
61 enum MessageTypes MessageClass::getTypeID() { \
62  return DataMsgID; \
63 }
64 
65  MESSAGE_CONSTRUCTORS(DataAckermannOutput, PAYLOAD_LEN)
66 
68 
69  double DataAckermannOutput::getSteering()
70  {
71  return btof(getPayloadPointer(STEERING), 2, 100);
72  }
73 
74  double DataAckermannOutput::getThrottle()
75  {
76  return btof(getPayloadPointer(THROTTLE), 2, 100);
77  }
78 
79  double DataAckermannOutput::getBrake()
80  {
81  return btof(getPayloadPointer(BRAKE), 2, 100);
82  }
83 
84  ostream &DataAckermannOutput::printMessage(ostream &stream)
85  {
86  stream << "Ackermann Control" << endl;
87  stream << "=================" << endl;
88  stream << "Steering: " << getSteering() << endl;
89  stream << "Throttle: " << getThrottle() << endl;
90  stream << "Brake : " << getBrake() << endl;
91  return stream;
92  }
93 
94 
95 
97 
99 
100  double DataDifferentialControl::getLeftP()
101  {
102  return btof(getPayloadPointer(LEFT_P), 2, 100);
103  }
104 
105  double DataDifferentialControl::getLeftI()
106  {
107  return btof(getPayloadPointer(LEFT_I), 2, 100);
108  }
109 
110  double DataDifferentialControl::getLeftD()
111  {
112  return btof(getPayloadPointer(LEFT_D), 2, 100);
113  }
114 
115  double DataDifferentialControl::getLeftFeedForward()
116  {
117  return btof(getPayloadPointer(LEFT_FEEDFWD), 2, 100);
118  }
119 
120  double DataDifferentialControl::getLeftStiction()
121  {
122  return btof(getPayloadPointer(LEFT_STIC), 2, 100);
123  }
124 
125  double DataDifferentialControl::getLeftIntegralLimit()
126  {
127  return btof(getPayloadPointer(LEFT_INT_LIM), 2, 100);
128  }
129 
130  double DataDifferentialControl::getRightP()
131  {
132  return btof(getPayloadPointer(RIGHT_P), 2, 100);
133  }
134 
135  double DataDifferentialControl::getRightI()
136  {
137  return btof(getPayloadPointer(RIGHT_I), 2, 100);
138  }
139 
140  double DataDifferentialControl::getRightD()
141  {
142  return btof(getPayloadPointer(RIGHT_D), 2, 100);
143  }
144 
145  double DataDifferentialControl::getRightFeedForward()
146  {
147  return btof(getPayloadPointer(RIGHT_FEEDFWD), 2, 100);
148  }
149 
150  double DataDifferentialControl::getRightStiction()
151  {
152  return btof(getPayloadPointer(RIGHT_STIC), 2, 100);
153  }
154 
155  double DataDifferentialControl::getRightIntegralLimit()
156  {
157  return btof(getPayloadPointer(RIGHT_INT_LIM), 2, 100);
158  }
159 
160  ostream &DataDifferentialControl::printMessage(ostream &stream)
161  {
162  stream << "Differential Control Constant Data" << endl;
163  stream << "==================================" << endl;
164  stream << "Left P : " << getLeftP() << endl;
165  stream << "Left I : " << getLeftI() << endl;
166  stream << "Left D : " << getLeftD() << endl;
167  stream << "Left Feed Forward : " << getLeftFeedForward() << endl;
168  stream << "Left Stiction : " << getLeftStiction() << endl;
169  stream << "Left Integral Limit : " << getLeftIntegralLimit() << endl;
170  stream << "Right P : " << getRightP() << endl;
171  stream << "Right I : " << getRightI() << endl;
172  stream << "Right D : " << getRightD() << endl;
173  stream << "Right Feed Forward : " << getRightFeedForward() << endl;
174  stream << "Right Stiction : " << getRightStiction() << endl;
175  stream << "Right Integral Limit: " << getRightIntegralLimit() << endl;
176  return stream;
177  }
178 
179 
181 
183 
184  double DataDifferentialOutput::getLeft()
185  {
186  return btof(getPayloadPointer(LEFT), 2, 100);
187  }
188 
189  double DataDifferentialOutput::getRight()
190  {
191  return btof(getPayloadPointer(RIGHT), 2, 100);
192  }
193 
194  ostream &DataDifferentialOutput::printMessage(ostream &stream)
195  {
196  stream << "Differential Output Data" << endl;
197  stream << "========================" << endl;
198  stream << "Left : " << getLeft() << endl;
199  stream << "Right: " << getRight() << endl;
200  return stream;
201  }
202 
203 
204 
206 
208 
209  double DataDifferentialSpeed::getLeftSpeed()
210  {
211  return btof(getPayloadPointer(LEFT_SPEED), 2, 100);
212  }
213 
214  double DataDifferentialSpeed::getLeftAccel()
215  {
216  return btof(getPayloadPointer(LEFT_ACCEL), 2, 100);
217  }
218 
219  double DataDifferentialSpeed::getRightSpeed()
220  {
221  return btof(getPayloadPointer(RIGHT_SPEED), 2, 100);
222  }
223 
224  double DataDifferentialSpeed::getRightAccel()
225  {
226  return btof(getPayloadPointer(RIGHT_ACCEL), 2, 100);
227  }
228 
229  ostream &DataDifferentialSpeed::printMessage(ostream &stream)
230  {
231  stream << "Differential Speed Data" << endl;
232  stream << "=======================" << endl;
233  stream << "Left Speed : " << getLeftSpeed() << endl;
234  stream << "Left Accel : " << getLeftAccel() << endl;
235  stream << "Right Speed: " << getRightSpeed() << endl;
236  stream << "Right Accel: " << getRightAccel() << endl;
237  return stream;
238  }
239 
240 
242 
244 
245  ostream &DataEcho::printMessage(ostream &stream)
246  {
247  stream << "Echo!";
248  return stream;
249  }
250 
251 
252  DataEncoders::DataEncoders(void *input, size_t msg_len) : Message(input, msg_len)
253  {
254  if ((ssize_t) getPayloadLength() != (1 + getCount() * 6))
255  {
256  stringstream ss;
257  ss << "Bad payload length: actual=" << getPayloadLength();
258  ss << " vs. expected=" << (1 + getCount() * 6);
259  throw new MessageException(ss.str().c_str(), MessageException::INVALID_LENGTH);
260  }
261  travels_offset = 1;
262  speeds_offset = travels_offset + (getCount() * 4);
263  }
264 
266  {
267  }
268 
270 
272  {
273  return *getPayloadPointer(0);
274  }
275 
276  double DataEncoders::getTravel(uint8_t index)
277  {
278  return btof(getPayloadPointer(travels_offset + index * 4), 4, 1000);
279  }
280 
281  double DataEncoders::getSpeed(uint8_t index)
282  {
283  return btof(getPayloadPointer(speeds_offset + index * 2), 2, 1000);
284  }
285 
286  ostream &DataEncoders::printMessage(ostream &stream)
287  {
288  stream << "Encoder Data" << endl;
289  stream << "============" << endl;
290  stream << "Count : " << (int) (getCount()) << endl;
291  for (unsigned i = 0; i < getCount(); ++i)
292  {
293  stream << "Encoder " << i << ":" << endl;
294  stream << " Travel: " << getTravel(i) << endl;
295  stream << " Speed : " << getSpeed(i) << endl;
296  }
297  return stream;
298  }
299 
300 
301 
303 
305 
306  uint8_t DataEncodersRaw::getCount()
307  {
308  return *getPayloadPointer(0);
309  }
310 
311  int32_t DataEncodersRaw::getTicks(uint8_t inx)
312  {
313  return btoi(getPayloadPointer(1 + inx * 4), 4);
314  }
315 
316  ostream &DataEncodersRaw::printMessage(ostream &stream)
317  {
318  stream << "Raw Encoder Data" << endl;
319  stream << "================" << endl;
320  for (int i = 0; i < getCount(); ++i)
321  {
322  stream << "Encoder " << i << ": " << getTicks(i) << endl;
323  }
324  return stream;
325  }
326 
327 
328 
330 
332 
333  uint8_t DataFirmwareInfo::getMajorFirmwareVersion()
334  {
335  return *getPayloadPointer(MAJOR_FIRM_VER);
336  }
337 
339  {
340  return *getPayloadPointer(MINOR_FIRM_VER);
341  }
342 
344  {
345  return *getPayloadPointer(MAJOR_PROTO_VER);
346  }
347 
349  {
350  return *getPayloadPointer(MINOR_PROTO_VER);
351  }
352 
354  {
355  return WriteTime(btou(getPayloadPointer(WRITE_TIME), 4));
356  }
357 
358  ostream &DataFirmwareInfo::printMessage(ostream &stream)
359  {
360  stream << "Firmware Info" << endl;
361  stream << "=============" << endl;
362  stream << "Major firmware version: " << (int) getMajorFirmwareVersion() << endl;
363  stream << "Minor firmware version: " << (int) getMinorFirmwareVersion() << endl;
364  stream << "Major protocol version: " << (int) getMajorProtocolVersion() << endl;
365  stream << "Minor protocol version: " << (int) getMinorProtocolVersion() << endl;
366  WriteTime t = getWriteTime();
367  stream << "Firmware write time : ";
368  stream << (2000 + t.year()) << "-" << (int) t.month() << "-" << (int) t.day() << " ";
369  stream << (int) t.hour() << ":" << (int) t.minute() << endl;
370  return stream;
371  }
372 
373 
374 
376 
378 
379  uint8_t DataGear::getGear()
380  {
381  return getPayloadPointer()[0];
382  }
383 
384  ostream &DataGear::printMessage(ostream &stream)
385  {
386  stream << "Gear" << endl;
387  stream << "====" << endl;
388  stream << "Gear: " << (int) getGear() << endl;
389  return stream;
390  }
391 
392 
393 
395 
397 
398  double DataMaxAcceleration::getForwardMax()
399  {
400  return btof(getPayloadPointer(FORWARD_MAX), 2, 100);
401  }
402 
404  {
405  return btof(getPayloadPointer(REVERSE_MAX), 2, 100);
406  }
407 
408  ostream &DataMaxAcceleration::printMessage(ostream &stream)
409  {
410  stream << "Max Acceleration Data" << endl;
411  stream << "=====================" << endl;
412  stream << "Max Forward: " << getForwardMax() << endl;
413  stream << "Max Reverse: " << getReverseMax() << endl;
414  return stream;
415  }
416 
417 
418 
419  MESSAGE_CONSTRUCTORS(DataMaxSpeed, PAYLOAD_LEN)
420 
422 
423  double DataMaxSpeed::getForwardMax()
424  {
425  return btof(getPayloadPointer(FORWARD_MAX), 2, 100);
426  }
427 
429  {
430  return btof(getPayloadPointer(REVERSE_MAX), 2, 100);
431  }
432 
433  ostream &DataMaxSpeed::printMessage(ostream &stream)
434  {
435  stream << "Max Speed Data" << endl;
436  stream << "==============" << endl;
437  stream << "Max Forward: " << getForwardMax() << endl;
438  stream << "Max Reverse: " << getReverseMax() << endl;
439  return stream;
440  }
441 
442 
443 
445 
447 
449  {
450  return btof(getPayloadPointer(X), 2, 1000);
451  }
452 
454  {
455  return btof(getPayloadPointer(Y), 2, 1000);
456  }
457 
459  {
460  return btof(getPayloadPointer(Z), 2, 1000);
461  }
462 
463  ostream &DataPlatformAcceleration::printMessage(ostream &stream)
464  {
465  stream << "Platform Acceleration" << endl;
466  stream << "=====================" << endl;
467  stream << "X: " << getX() << endl;
468  stream << "Y: " << getY() << endl;
469  stream << "Z: " << getZ() << endl;
470  return stream;
471  }
472 
473 
474 
475  MESSAGE_CONSTRUCTORS(DataPlatformInfo, (int) strlenModel() + 6)
476 
478 
479  uint8_t DataPlatformInfo::strlenModel()
480  {
481  return *getPayloadPointer();
482  }
483 
485  {
486  char buf[256];
487  // NB: cpy_len cannot be larger than 255 (one byte field!)
488  size_t cpy_len = strlenModel();
489  memcpy(buf, getPayloadPointer(1), cpy_len);
490  buf[cpy_len] = '\0';
491 
492  return string(buf);
493  }
494 
496  {
497  char offset = strlenModel() + 1;
498  return *getPayloadPointer(offset);
499  }
500 
502  {
503  char offset = strlenModel() + 2;
504  return btou(getPayloadPointer(offset), 4);
505  }
506 
507  std::ostream &DataPlatformInfo::printMessage(std::ostream &stream)
508  {
509  stream << "Platform Info" << endl;
510  stream << "=============" << endl;
511  stream << "Model : " << getModel() << endl;
512  stream << "Revision: " << (int) (getRevision()) << endl;
513  stream << "Serial : " << getSerial() << endl;
514  return stream;
515  }
516 
517 
518 
520 
522 
523  string DataPlatformName::getName()
524  {
525  char buf[256];
526  size_t cpy_len = *getPayloadPointer();
527  memcpy(buf, getPayloadPointer(1), cpy_len);
528  buf[cpy_len] = '\0';
529  return string(buf);
530  }
531 
532  std::ostream &DataPlatformName::printMessage(std::ostream &stream)
533  {
534  stream << "Platform Name" << endl;
535  stream << "=============" << endl;
536  stream << "Name: " << getName() << endl;
537  return stream;
538  }
539 
540 
541 
543 
545 
547  {
548  return btof(getPayloadPointer(X), 2, 1000);
549  }
550 
552  {
553  return btof(getPayloadPointer(Y), 2, 1000);
554  }
555 
557  {
558  return btof(getPayloadPointer(Z), 2, 1000);
559  }
560 
561  ostream &DataPlatformMagnetometer::printMessage(ostream &stream)
562  {
563  stream << "PlatformMagnetometer Data" << endl;
564  stream << "=================" << endl;
565  stream << "X: " << getX() << endl;
566  stream << "Y: " << getY() << endl;
567  stream << "Z: " << getZ() << endl;
568  return stream;
569  }
570 
571 
572 
574 
576 
577  double DataPlatformOrientation::getRoll()
578  {
579  return btof(getPayloadPointer(ROLL), 2, 1000);
580  }
581 
583  {
584  return btof(getPayloadPointer(PITCH), 2, 1000);
585  }
586 
588  {
589  return btof(getPayloadPointer(YAW), 2, 1000);
590  }
591 
592  ostream &DataPlatformOrientation::printMessage(ostream &stream)
593  {
594  stream << "Platform Orientation" << endl;
595  stream << "====================" << endl;
596  stream << "Roll : " << getRoll() << endl;
597  stream << "Pitch: " << getPitch() << endl;
598  stream << "Yaw : " << getYaw() << endl;
599 
600  return stream;
601  }
602 
603 
604 
606 
608 
609  double DataPlatformRotation::getRollRate()
610  {
611  return btof(getPayloadPointer(ROLL_RATE), 2, 1000);
612  }
613 
615  {
616  return btof(getPayloadPointer(PITCH_RATE), 2, 1000);
617  }
618 
620  {
621  return btof(getPayloadPointer(YAW_RATE), 2, 1000);
622  }
623 
624  ostream &DataPlatformRotation::printMessage(ostream &stream)
625  {
626  stream << "Platform Rotationa Rate Data" << endl;
627  stream << "============================" << endl;
628  stream << "Roll : " << getRollRate() << endl;
629  stream << "Pitch: " << getPitchRate() << endl;
630  stream << "Yaw : " << getYawRate() << endl;
631  return stream;
632  }
633 
634 
635 
636  MESSAGE_CONSTRUCTORS(DataPowerSystem, 1 + getBatteryCount() * 5)
637 
639 
640  uint8_t DataPowerSystem::getBatteryCount()
641  {
642  return *getPayloadPointer(0);
643  }
644 
645  double DataPowerSystem::getChargeEstimate(uint8_t battery)
646  {
647  int offset = 1 /* num batteries */
648  + battery * 2;
649  return btof(getPayloadPointer(offset), 2, 100);
650  }
651 
652  int16_t DataPowerSystem::getCapacityEstimate(uint8_t battery)
653  {
654  int offset = 1 /* num batteries */
655  + 2 * getBatteryCount() /*charge estimate data*/
656  + battery * 2;
657  return btoi(getPayloadPointer(offset), 2);
658  }
659 
661  {
662  int offset = 1 /* num batteries */
663  + 4 * getBatteryCount() /* charge and capacity estimate data */
664  + battery;
665  return BatteryDescription(*getPayloadPointer(offset));
666  }
667 
668  ostream &DataPowerSystem::printMessage(ostream &stream)
669  {
670  stream << "Power System Status Data" << endl;
671  stream << "========================" << endl;
672  int num_bat = getBatteryCount();
673  stream << "Number of Batteries: " << num_bat << endl;
674  for (int i = 0; i < num_bat; ++i)
675  {
676  stream << "Battery " << i << ":" << endl;
677  stream << " Charge Estimate : " << getChargeEstimate(i) << endl;
678  stream << " Capacity Estimate: " << getCapacityEstimate(i) << endl;
679  stream << " Present : " << (getDescription(0).isPresent() ? "yes" : "no") << endl;
680  stream << " In Use : " << (getDescription(0).isInUse() ? "yes" : "no") << endl;
681  stream << " Type : ";
682  switch (getDescription(0).getType())
683  {
684  case BatteryDescription::EXTERNAL:
685  stream << "External" << endl;
686  break;
687  case BatteryDescription::LEAD_ACID:
688  stream << "Lead-Acid" << endl;
689  break;
690  case BatteryDescription::NIMH:
691  stream << "NiMH" << endl;
692  break;
693  case BatteryDescription::GASOLINE:
694  stream << "Internal Combustion Engine" << endl;
695  break;
696  default:
697  stream << "Unknown Type" << endl;
698  break;
699  }
700  }
701 
702  return stream;
703  }
704 
705 
706 
707  MESSAGE_CONSTRUCTORS(DataProcessorStatus, (1 + getProcessCount() * 2))
708 
710 
711  uint8_t DataProcessorStatus::getProcessCount()
712  {
713  return *getPayloadPointer();
714  }
715 
717  {
718  return btoi(getPayloadPointer(1 + process * 2), 2);
719  }
720 
721  ostream &DataProcessorStatus::printMessage(ostream &stream)
722  {
723  stream << "Processor Status" << endl;
724  stream << "================" << endl;
725  stream << "Process Count : " << (int) (getProcessCount()) << endl;
726  for (unsigned int i = 0; i < getProcessCount(); ++i)
727  {
728  stream << "Process " << i << " Errors: " << getErrorCount(i) << endl;
729  }
730  return stream;
731  }
732 
733 
734 
735  MESSAGE_CONSTRUCTORS(DataRangefinders, (1 + getRangefinderCount() * 2))
736 
738 
739  uint8_t DataRangefinders::getRangefinderCount()
740  {
741  return *getPayloadPointer();
742  }
743 
744  int16_t DataRangefinders::getDistance(int rangefinder)
745  {
746  return btoi(getPayloadPointer(1 + 2 * rangefinder), 2);
747  }
748 
749  ostream &DataRangefinders::printMessage(ostream &stream)
750  {
751  stream << "Rangefinder Data" << endl;
752  stream << "================" << endl;
753  stream << "Rangefinder Count: " << (int) (getRangefinderCount()) << endl;
754  for (unsigned int i = 0; i < getRangefinderCount(); ++i)
755  {
756  stream << "Distance " << i << " : " << getDistance(i) << endl;
757  }
758  return stream;
759  }
760 
761 
762 
763  MESSAGE_CONSTRUCTORS(DataRangefinderTimings, (1 + getRangefinderCount() * 6))
764 
766 
767  uint8_t DataRangefinderTimings::getRangefinderCount()
768  {
769  return *getPayloadPointer();
770  }
771 
772  int16_t DataRangefinderTimings::getDistance(int rangefinder)
773  {
774  return btoi(getPayloadPointer(1 + 2 * rangefinder), 2);
775  }
776 
778  {
779  return btou(getPayloadPointer(1 + 2 * getRangefinderCount() + 4 * rangefinder), 4);
780  }
781 
782  ostream &DataRangefinderTimings::printMessage(ostream &stream)
783  {
784  stream << "Rangefinder Timing Data" << endl;
785  stream << "=======================" << endl;
786  stream << "Rangefinder Count : " << (int) (getRangefinderCount()) << endl;
787  for (unsigned int i = 0; i < getRangefinderCount(); ++i)
788  {
789  stream << "Rangefinder " << i << ":" << endl;
790  stream << " Distance : " << getDistance(i) << endl;
791  stream << " Acquisition Time: " << getAcquisitionTime(i) << endl;
792  }
793  return stream;
794  }
795 
796 
797 
799 
801 
802  uint16_t DataRawAcceleration::getX()
803  {
804  return btou(getPayloadPointer(X), 2);
805  }
806 
808  {
809  return btou(getPayloadPointer(Y), 2);
810  }
811 
813  {
814  return btou(getPayloadPointer(Z), 2);
815  }
816 
817  ostream &DataRawAcceleration::printMessage(ostream &stream)
818  {
819  stream << "Raw Acceleration Data" << endl;
820  stream << "=====================" << endl;
821  stream << "X: 0x" << hex << getX() << endl;
822  stream << "Y: 0x" << getY() << endl;
823  stream << "Z: 0x" << getZ() << dec << endl;
824  return stream;
825  }
826 
827 
828 
829  MESSAGE_CONSTRUCTORS(DataRawCurrent, (1 + getCurrentCount() * 2))
830 
832 
833  uint8_t DataRawCurrent::getCurrentCount()
834  {
835  return *getPayloadPointer();
836  }
837 
838  uint16_t DataRawCurrent::getCurrent(int current)
839  {
840  return btou(getPayloadPointer(1 + current * 2), 2);
841  }
842 
843  ostream &DataRawCurrent::printMessage(ostream &stream)
844  {
845  stream << "Raw Current Data" << endl;
846  stream << "================" << endl;
847  stream << hex;
848  for (unsigned int i = 0; i < getCurrentCount(); ++i)
849  {
850  stream << "Current " << i << ": 0x" << getCurrent(i) << endl;
851  }
852  stream << dec;
853  return stream;
854  }
855 
856 
857 
858  MESSAGE_CONSTRUCTORS(DataRawGyro, PAYLOAD_LEN)
859 
861 
862  uint16_t DataRawGyro::getRoll()
863  {
864  return btou(getPayloadPointer(ROLL), 2);
865  }
866 
868  {
869  return btou(getPayloadPointer(PITCH), 2);
870  }
871 
873  {
874  return btou(getPayloadPointer(YAW), 2);
875  }
876 
877  ostream &DataRawGyro::printMessage(ostream &stream)
878  {
879  stream << "Raw Gyro Data" << endl;
880  stream << "=============" << endl;
881  stream << "Roll : 0x" << hex << getRoll() << endl;
882  stream << "Pitch: 0x" << getPitch() << endl;
883  stream << "Yaw : 0x" << getYaw() << dec << endl;
884  return stream;
885  }
886 
887 
888 
890 
892 
893  uint16_t DataRawMagnetometer::getX()
894  {
895  return btou(getPayloadPointer(X), 2);
896  }
897 
899  {
900  return btou(getPayloadPointer(Y), 2);
901  }
902 
904  {
905  return btou(getPayloadPointer(Z), 2);
906  }
907 
908  ostream &DataRawMagnetometer::printMessage(ostream &stream)
909  {
910  stream << "Raw Magnetometer Data" << endl;
911  stream << "=====================" << endl;
912  stream << "X: 0x" << hex << getX() << endl;
913  stream << "Y: 0x" << getY() << endl;
914  stream << "Z: 0x" << getZ() << dec << endl;
915  return stream;
916  }
917 
918 
919 
921 
923 
924  uint16_t DataRawOrientation::getRoll()
925  {
926  return btou(getPayloadPointer(ROLL), 2);
927  }
928 
930  {
931  return btou(getPayloadPointer(PITCH), 2);
932  }
933 
935  {
936  return btou(getPayloadPointer(YAW), 2);
937  }
938 
939  ostream &DataRawOrientation::printMessage(ostream &stream)
940  {
941  stream << "Raw Orientation Data" << endl;
942  stream << "====================" << endl;
943  stream << "Roll : 0x" << hex << getRoll() << endl;
944  stream << "Pitch: 0x" << getPitch() << endl;
945  stream << "Yaw : 0x" << getYaw() << dec << endl;
946  return stream;
947  }
948 
949 
950 
951  MESSAGE_CONSTRUCTORS(DataRawTemperature, (1 + 2 * getTemperatureCount()))
952 
954 
955  uint8_t DataRawTemperature::getTemperatureCount()
956  {
957  return *getPayloadPointer();
958  }
959 
960  uint16_t DataRawTemperature::getTemperature(int temperature)
961  {
962  return btou(getPayloadPointer(1 + 2 * temperature), 2);
963  }
964 
965  ostream &DataRawTemperature::printMessage(ostream &stream)
966  {
967  stream << "Raw Temperature Data" << endl;
968  stream << "====================" << endl;
969  stream << "Temperature Count: " << (int) (getTemperatureCount()) << endl;
970  stream << hex;
971  for (unsigned i = 0; i < getTemperatureCount(); ++i)
972  {
973  stream << "Temperature " << i << " : 0x" << getTemperature(i) << endl;
974  }
975  stream << dec;
976  return stream;
977  }
978 
979 
980 
981  MESSAGE_CONSTRUCTORS(DataRawVoltage, (1 + 2 * getVoltageCount()))
982 
984 
985  uint8_t DataRawVoltage::getVoltageCount()
986  {
987  return *getPayloadPointer();
988  }
989 
990  uint16_t DataRawVoltage::getVoltage(int temperature)
991  {
992  return btou(getPayloadPointer(1 + 2 * temperature), 2);
993  }
994 
995  ostream &DataRawVoltage::printMessage(ostream &stream)
996  {
997  stream << "Raw Voltage Data" << endl;
998  stream << "================" << endl;
999  stream << "Voltage Count: " << (int) (getVoltageCount()) << endl;
1000  stream << hex;
1001  for (unsigned i = 0; i < getVoltageCount(); ++i)
1002  {
1003  stream << "Voltage " << i << " : 0x" << getVoltage(i) << endl;
1004  }
1005  stream << dec;
1006  return stream;
1007  }
1008 
1009 
1010 
1012 
1014 
1016  {
1017  return btou(getPayloadPointer(), 2);
1018  }
1019 
1020  ostream &DataSafetySystemStatus::printMessage(ostream &stream)
1021  {
1022  stream << "Safety System Status Data" << endl;
1023  stream << "=========================" << endl;
1024  stream << "Flags: " << getFlags() << endl;
1025  return stream;
1026  }
1027 
1028 
1029  DataSystemStatus::DataSystemStatus(void *input, size_t msg_len) : Message(input, msg_len)
1030  {
1031  voltages_offset = 4;
1034 
1035  size_t expect_len = (7 + 2 * getVoltagesCount() + 2 * getCurrentsCount() + 2 * getTemperaturesCount());
1036  if (getPayloadLength() != expect_len)
1037  {
1038  stringstream ss;
1039  ss << "Bad payload length: actual=" << getPayloadLength();
1040  ss << " vs. expected=" << expect_len;
1041  throw new MessageException(ss.str().c_str(), MessageException::INVALID_LENGTH);
1042  }
1043  }
1044 
1046  {
1047  }
1048 
1050 
1052  {
1053  return btou(getPayloadPointer(0), 4);
1054  }
1055 
1057  {
1059  }
1060 
1061  double DataSystemStatus::getVoltage(uint8_t index)
1062  {
1063  return btof(getPayloadPointer(voltages_offset + 1 + (index * 2)), 2, 100);
1064  }
1065 
1067  {
1069  }
1070 
1071  double DataSystemStatus::getCurrent(uint8_t index)
1072  {
1073  return btof(getPayloadPointer(currents_offset + 1 + (index * 2)), 2, 100);
1074  }
1075 
1077  {
1079  }
1080 
1081  double DataSystemStatus::getTemperature(uint8_t index)
1082  {
1083  return btof(getPayloadPointer(temperatures_offset + 1 + (index * 2)), 2, 100);
1084  }
1085 
1086  ostream &DataSystemStatus::printMessage(ostream &stream)
1087  {
1088  stream << "System Status" << endl;
1089  stream << "=============" << endl;
1090  stream << "Uptime : " << getUptime() << endl;
1091  stream << "Voltage Count : " << (int) (getVoltagesCount()) << endl;
1092  stream << "Voltages : ";
1093  for (unsigned i = 0; i < getVoltagesCount(); ++i)
1094  {
1095  stream << getVoltage(i);
1096  if ((int) i != (getVoltagesCount() - 1)) { stream << ", "; }
1097  }
1098  stream << endl;
1099  stream << "Current Count : " << (int) (getCurrentsCount()) << endl;
1100  stream << "Currents : ";
1101  for (unsigned i = 0; i < getCurrentsCount(); ++i)
1102  {
1103  stream << getCurrent(i);
1104  if ((int) i != (getCurrentsCount() - 1)) { stream << ", "; }
1105  }
1106  stream << endl;
1107  stream << "Temperature Count: " << (int) (getTemperaturesCount()) << endl;
1108  stream << "Temperatures : ";
1109  for (unsigned i = 0; i < getTemperaturesCount(); ++i)
1110  {
1111  stream << getTemperature(i);
1112  if ((int) i != (getTemperaturesCount() - 1)) { stream << ", "; }
1113  }
1114  stream << endl;
1115  return stream;
1116  }
1117 
1118 
1119 
1120  MESSAGE_CONSTRUCTORS(DataVelocity, PAYLOAD_LEN)
1121 
1123 
1124  double DataVelocity::getTranslational()
1125  {
1126  return btof(getPayloadPointer(TRANS_VEL), 2, 100);
1127  }
1128 
1130  {
1131  return btof(getPayloadPointer(ROTATIONAL), 2, 100);
1132  }
1133 
1135  {
1136  return btof(getPayloadPointer(TRANS_ACCEL), 2, 100);
1137  }
1138 
1139  ostream &DataVelocity::printMessage(ostream &stream)
1140  {
1141  stream << "Velocity Setpoints" << endl;
1142  stream << "==================" << endl;
1143  stream << "Translational:" << getTranslational() << endl;
1144  stream << "Rotational: " << getRotational() << endl;
1145  stream << "Trans Accel: " << getTransAccel() << endl;
1146  return stream;
1147  }
1148 
1149 }; // namespace clearpath
1150 
uint16_t getTemperature(int temperature)
double getCurrent(uint8_t index)
int64_t btoi(void *src, size_t src_len)
Definition: Number.cpp:136
virtual std::ostream & printMessage(std::ostream &stream=std::cout)
double getVoltage(uint8_t index)
TFSIMD_FORCE_INLINE const tfScalar & getX() const
virtual std::ostream & printMessage(std::ostream &stream=std::cout)
virtual std::ostream & printMessage(std::ostream &stream=std::cout)
uint8_t getFlags()
Definition: Message.cpp:206
virtual std::ostream & printMessage(std::ostream &stream=std::cout)
virtual std::ostream & printMessage(std::ostream &stream=std::cout)
::std::string string
uint64_t btou(void *src, size_t src_len)
Definition: Number.cpp:121
uint32_t getAcquisitionTime(int rangefinder)
virtual std::ostream & printMessage(std::ostream &stream=std::cout)
std::string getName(void *handle)
int16_t getCapacityEstimate(uint8_t battery)
virtual std::ostream & printMessage(std::ostream &stream=std::cout)
virtual std::ostream & printMessage(std::ostream &stream=std::cout)
#define MESSAGE_CONVENIENCE_FNS(MessageClass, DataMsgID)
virtual std::ostream & printMessage(std::ostream &stream=std::cout)
virtual std::ostream & printMessage(std::ostream &stream=std::cout)
geometry_msgs::TransformStamped t
virtual std::ostream & printMessage(std::ostream &stream=std::cout)
virtual std::ostream & printMessage(std::ostream &stream=std::cout)
int16_t getDistance(int rangefinder)
uint8_t * getPayloadPointer(size_t offset=0)
Definition: Message.cpp:181
#define MESSAGE_CONSTRUCTORS(MessageClass, ExpectedLength)
virtual std::ostream & printMessage(std::ostream &stream=std::cout)
int16_t getErrorCount(int process)
virtual std::ostream & printMessage(std::ostream &stream=std::cout)
virtual std::ostream & printMessage(std::ostream &stream=std::cout)
virtual std::ostream & printMessage(std::ostream &stream=std::cout)
uint16_t getCurrent(int current)
virtual std::ostream & printMessage(std::ostream &stream=std::cout)
virtual std::ostream & printMessage(std::ostream &stream=std::cout)
virtual std::ostream & printMessage(std::ostream &stream=std::cout)
double getSpeed(uint8_t index)
DataEncoders(void *input, size_t msg_len)
MESSAGE_CONVENIENCE_FNS(DataDifferentialSpeed, DATA_DIFF_WHEEL_SPEEDS)
MESSAGE_CONSTRUCTORS(DataDifferentialSpeed, PAYLOAD_LEN)
int32_t getTicks(uint8_t inx)
double getChargeEstimate(uint8_t battery)
virtual std::ostream & printMessage(std::ostream &stream=std::cout)
BatteryDescription getDescription(uint8_t battery)
virtual std::ostream & printMessage(std::ostream &stream=std::cout)
double getTravel(uint8_t index)
virtual std::ostream & printMessage(std::ostream &stream=std::cout)
double getTemperature(uint8_t index)
size_t getPayloadLength()
Definition: Message.h:167
int16_t getDistance(int rangefinder)
double getYaw(const tf2::Quaternion quat)
virtual std::ostream & printMessage(std::ostream &stream=std::cout)
TFSIMD_FORCE_INLINE const tfScalar & getZ() const
uint16_t getVoltage(int temperature)
virtual std::ostream & printMessage(std::ostream &stream=std::cout)
double btof(void *src, size_t src_len, double scale)
Definition: Number.cpp:161
virtual std::ostream & printMessage(std::ostream &stream=std::cout)
virtual std::ostream & printMessage(std::ostream &stream=std::cout)
TFSIMD_FORCE_INLINE const tfScalar & getY() const
DataSystemStatus(void *input, size_t msg_len)


husky_base
Author(s): Mike Purvis , Paul Bovbel
autogenerated on Fri Oct 2 2020 03:40:07