gusimplewhiteboard
DifferentialRobotControlStatus.hpp
Go to the documentation of this file.
1#ifndef DifferentialRobotControlStatus_DEFINED
2#define DifferentialRobotControlStatus_DEFINED
3
4#include <cstdlib>
5#include <stdlib.h>
6#include <cstring>
7#include <sstream>
8#include <gu_util.h>
9#include "gusimplewhiteboard.h"
11
12namespace guWhiteboard {
18 public:
21
22#ifdef WHITEBOARD_POSTER_STRING_CONVERSION
24 DifferentialRobotControlStatus(const std::string &name) {
25 from_string(name);
26 }
27
29 std::string description() {
30 using namespace std;
31 ostringstream ss;
32 const wb_kinematic_motor &l = left_motor();
33 const wb_kinematic_motor &r = right_motor();
34 ss << static_cast<int>(l.speed()) << "," << static_cast<int>(r.speed()) \
35 << ", " << l.odo() << "," << r.odo() << ", " << static_cast<unsigned>(l.accel()) \
36 << "," << static_cast<unsigned>(r.accel());
37 return ss.str();
38 }
39
41 void from_string (std::string str) {
42 using namespace std;
43 vector<string> elements = components_of_string_separated(str, ',', true);
44 wb_kinematic_motor &l = left_motor();
45 wb_kinematic_motor &r = right_motor();
46 if (elements.size() == 0) return;
47 l.set_speed(static_cast<int8_t>(atoi(elements[0].c_str())));
48 if (elements.size() < 2) return;
49 r.set_speed(static_cast<int8_t>(atoi(elements[1].c_str())));
50 if (elements.size() < 3) return;
51 l.set_odo(static_cast<uint16_t>(atoi(elements[2].c_str())));
52 if (elements.size() < 4) return;
53 r.set_odo(static_cast<uint16_t>(atoi(elements[3].c_str())));
54 if (elements.size() < 5) return;
55 l.set_accel(static_cast<uint8_t>(atoi(elements[4].c_str())));
56 if (elements.size() < 6) return;
57 r.set_accel(static_cast<uint8_t>(atoi(elements[5].c_str())));
58 }
59#endif
62 wb_kinematic_motor &l = left_motor();
63 wb_kinematic_motor &r = right_motor();
64 const wb_kinematic_motor &sl = s.left_motor();
65 const wb_kinematic_motor &sr = s.right_motor();
66
67 if (l.speed() == sl.speed()
68 && l.accel() == sl.accel()
69 && l.odo() == sl.odo()
70 && r.speed() == sr.speed()
71 && r.accel() == sr.accel()
72 && r.odo() == sr.odo()) {
73 return true;
74 } else {
75 return false;
76 }
77 }
78
80 void stop() {
81 wb_kinematic_motor &l = left_motor();
82 wb_kinematic_motor &r = right_motor();
83
84 l.set_speed (static_cast<int8_t> (0));
85 r.set_speed (static_cast<int8_t> (0));
86 l.set_accel (static_cast<uint8_t> (0));
87 r.set_accel (static_cast<uint8_t> (0));
88 }
89 };
90}
91#endif //DifferentialRobotControlStatus_DEFINED
Class for controlling differential robots Defines whiteboard message.
DifferentialRobotControlStatus(const std::string &name)
String constructor.
bool operator==(const DifferentialRobotControlStatus &s)
override equality operator so we can compare instances
/file APM_Interface.h
Differential, kinematic robot model.
Basic kinematic motor (i.e.