gusimplewhiteboard
APM_Interface.hpp
Go to the documentation of this file.
1
9#ifndef APM_Interface_DEFINED
10#define APM_Interface_DEFINED
11
12#include "wb_apm_interface.h"
13
14#ifdef WHITEBOARD_POSTER_STRING_CONVERSION
15#include <sstream>
16#endif
17
18namespace guWhiteboard
19{
33 {
34 public:
35
39
40
42 inline bool operator == (const APM_Interface &s)
43 {
44 if(this->mode() != s.mode())
45 return false;
46#pragma clang diagnostic push
47#pragma clang diagnostic ignored "-Wswitch-enum"
48 switch (this->mode())
49 {
50 case Quad:
51#define QUAD(o, p) ( o ).data().quad. p ()
52 if(QUAD(*this, thrust) != QUAD(s, thrust) ||
53 QUAD(*this, pitch) != QUAD(s, pitch) ||
54 QUAD(*this, roll) != QUAD(s, roll) ||
55 QUAD(*this, yaw) != QUAD(s, yaw))
56 return false;
57 break;
58 case Plane:
59#define PLANE(o, p) ( o ).data().plane. p ()
60 if(PLANE(*this, thrust) != PLANE(s, thrust))
61 return false;
62 break;
63 default:
64 break;
65 }
66#pragma clang diagnostic pop
67 return true;
68 }
69
71 inline bool operator != (const APM_Interface &s)
72 {
73 return !(*this == s);
74 }
75
76#ifdef WHITEBOARD_POSTER_STRING_CONVERSION
80 APM_Interface(const std::string &str) { from_string(str); }
81
85 void from_string(const std::string &str)
86 {
87#define DELIMITER ','
88 std::vector<std::string> v = components_of_string_separated(str, DELIMITER, true);
89 if (v.size() < 2)
90 {
91 fprintf(stderr, "APM_Interface couldn't parse this string, have it back %s\n", str.c_str());
92 return;
93 }
94 apm_mode m = static_cast<apm_mode>(atoi(v.at(0).c_str()));
95 this->set_mode(m);
96#pragma clang diagnostic push
97#pragma clang diagnostic ignored "-Wswitch-enum"
98 try { switch (m)
99 {
100 case Quad:
101 this->data().quad.set_thrust(static_cast<uint8_t>(atoi(v.at(1).c_str())));
102 this->data().quad.set_pitch(static_cast<int16_t>(atoi(v.at(2).c_str())));
103 this->data().quad.set_roll(static_cast<int16_t>(atoi(v.at(3).c_str())));
104 this->data().quad.set_yaw(static_cast<int16_t>(atoi(v.at(4).c_str())));
105 break;
106 case Plane:
107 this->data().plane.set_thrust(static_cast<uint8_t>(atoi(v.at(1).c_str())));
108 fprintf(stderr, "APM_Interface mode 'Plane' is NYI\n");
109 break;
110 default:
111 break;
112 } } catch (...) {
113 fprintf(stderr, "APM_Interface couldn't parse this string, have it back %s\n", str.c_str());
114 return;
115 }
116#pragma clang diagnostic pop
117 }
118
122 std::string description() const
123 {
124 std::stringstream ss;
125
126#pragma clang diagnostic push
127#pragma clang diagnostic ignored "-Wswitch-enum"
128 switch (this->mode())
129 {
130 case Quad:
131 ss << "Thrust: " << static_cast<int>(this->data().quad.thrust()) << ", ";
132 ss << "Pitch: " << this->data().quad.pitch() << ", ";
133 ss << "Roll: " << this->data().quad.roll() << ", ";
134 ss << "Yaw: " << this->data().quad.yaw() << "";
135 break;
136 case Plane:
137 ss << "Plane mode NYI";
138 break;
139 default:
140 break;
141 }
142#pragma clang diagnostic pop
143 return ss.str();
144 }
145#endif // WHITEBOARD_POSTER_STRING_CONVERSION
146 };
147}
148
149#endif //APM_Interface_DEFINED
#define DELIMITER
#define PLANE(o, p)
#define QUAD(o, p)
Class for interacting with and reading the values of APM sensors and motors.
APM_Interface(const std::string &str)
string constructor (see from_string() below)
APM_Interface()
default constructor
bool operator==(const APM_Interface &s)
comparison operator
std::string description() const
pretty print method for showing the current property values
bool operator!=(const APM_Interface &s)
return false if the two interfaces are the same
void from_string(const std::string &str)
parse class properties from a string
/file APM_Interface.h
Interface for talking with an APM.
apm_mode
/file wb_apm_interface.h
@ Quad
@ Plane