gusimplewhiteboard
Odometry.hpp
Go to the documentation of this file.
1/*
2 * file Odometry.hpp
3 *
4 * This file was generated by classgenerator from odometry.gen.
5 * DO NOT CHANGE MANUALLY!
6 *
7 * Copyright © 2021 Dimitri Joukoff. All rights reserved.
8 *
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
11 * are met:
12 *
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 *
16 * 2. Redistributions in binary form must reproduce the above
17 * copyright notice, this list of conditions and the following
18 * disclaimer in the documentation and/or other materials
19 * provided with the distribution.
20 *
21 * 3. All advertising materials mentioning features or use of this
22 * software must display the following acknowledgement:
23 *
24 * This product includes software developed by Dimitri Joukoff.
25 *
26 * 4. Neither the name of the author nor the names of contributors
27 * may be used to endorse or promote products derived from this
28 * software without specific prior written permission.
29 *
30 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
31 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
32 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
33 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
34 * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
35 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
36 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
37 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
38 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
39 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
40 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
41 *
42 * -----------------------------------------------------------------------
43 * This program is free software; you can redistribute it and/or
44 * modify it under the above terms or under the terms of the GNU
45 * General Public License as published by the Free Software Foundation;
46 * either version 2 of the License, or (at your option) any later version.
47 *
48 * This program is distributed in the hope that it will be useful,
49 * but WITHOUT ANY WARRANTY; without even the implied warranty of
50 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
51 * GNU General Public License for more details.
52 *
53 * You should have received a copy of the GNU General Public License
54 * along with this program; if not, see http://www.gnu.org/licenses/
55 * or write to the Free Software Foundation, Inc., 51 Franklin Street,
56 * Fifth Floor, Boston, MA 02110-1301, USA.
57 *
58 */
59
60#ifndef guWhiteboard_Odometry_h
61#define guWhiteboard_Odometry_h
62
63#ifdef WHITEBOARD_POSTER_STRING_CONVERSION
64#include <cstdlib>
65#include <string.h>
66#include <sstream>
67#endif
68
69#include <gu_util.h>
70#include "wb_odometry.h"
71#include <float.h>
72
73#undef guWhiteboard_Odometry_DEFINED
74#define guWhiteboard_Odometry_DEFINED
75
76#undef Odometry_DEFINED
77#define Odometry_DEFINED
78
79namespace guWhiteboard {
80
84 class Odometry: public wb_odometry {
85
86 private:
87
91 void init(float t_forward = 0.0f, float t_left = 0.0f, float t_turn = 0.0f) {
92 set_forward(t_forward);
93 set_left(t_left);
94 set_turn(t_turn);
95 }
96
97 public:
98
102 Odometry(float t_forward = 0.0f, float t_left = 0.0f, float t_turn = 0.0f) {
103 this->init(t_forward, t_left, t_turn);
104 }
105
109 Odometry(const Odometry &t_other): wb_odometry() {
110 this->init(t_other.forward(), t_other.left(), t_other.turn());
111 }
112
116 Odometry(const struct wb_odometry &t_other): wb_odometry() {
117 this->init(t_other.forward, t_other.left, t_other.turn);
118 }
119
123 Odometry &operator = (const Odometry &t_other) {
124 this->init(t_other.forward(), t_other.left(), t_other.turn());
125 return *this;
126 }
127
131 Odometry &operator = (const struct wb_odometry &t_other) {
132 this->init(t_other.forward, t_other.left, t_other.turn);
133 return *this;
134 }
135
136 bool operator ==(const Odometry &t_other) const
137 {
138 return fabsf(forward() - t_other.forward()) < FLT_EPSILON
139 && fabsf(left() - t_other.left()) < FLT_EPSILON
140 && fabsf(turn() - t_other.turn()) < FLT_EPSILON;
141 }
142
143 bool operator !=(const Odometry &t_other) const
144 {
145 return !(*this == t_other);
146 }
147
148 bool operator ==(const wb_odometry &t_other) const
149 {
150 return *this == Odometry(t_other);
151 }
152
153 bool operator !=(const wb_odometry &t_other) const
154 {
155 return !(*this == t_other);
156 }
157
158 float & forward()
159 {
161 }
162
163 const float & forward() const
164 {
166 }
167
168 void set_forward(const float &t_newValue)
169 {
170 wb_odometry::forward = t_newValue;
171 }
172
173 float & left()
174 {
175 return wb_odometry::left;
176 }
177
178 const float & left() const
179 {
180 return wb_odometry::left;
181 }
182
183 void set_left(const float &t_newValue)
184 {
185 wb_odometry::left = t_newValue;
186 }
187
188 float & turn()
189 {
190 return wb_odometry::turn;
191 }
192
193 const float & turn() const
194 {
195 return wb_odometry::turn;
196 }
197
198 void set_turn(const float &t_newValue)
199 {
200 wb_odometry::turn = t_newValue;
201 }
202
203#ifdef WHITEBOARD_POSTER_STRING_CONVERSION
207 Odometry(const std::string &t_str) {
208 this->init();
209 this->from_string(t_str);
210 }
211
212 std::string description() {
213#ifdef USE_WB_ODOMETRY_C_CONVERSION
214 char buffer[ODOMETRY_DESC_BUFFER_SIZE];
215 wb_odometry_description(this, buffer, sizeof(buffer));
216 std::string descr = buffer;
217 return descr;
218#else
219 std::ostringstream ss;
220 ss << "forward=" << this->forward();
221 ss << ", ";
222 ss << "left=" << this->left();
223 ss << ", ";
224 ss << "turn=" << this->turn();
225 return ss.str();
226#endif
227 }
228
229 std::string to_string() {
230#ifdef USE_WB_ODOMETRY_C_CONVERSION
232 wb_odometry_to_string(this, buffer, sizeof(buffer));
233 std::string toString = buffer;
234 return toString;
235#else
236 std::ostringstream ss;
237 ss << this->forward();
238 ss << ", ";
239 ss << this->left();
240 ss << ", ";
241 ss << this->turn();
242 return ss.str();
243#endif
244 }
245
246#ifdef USE_WB_ODOMETRY_C_CONVERSION
247 void from_string(const std::string &t_str) {
248 wb_odometry_from_string(this, t_str.c_str());
249#else
250 void from_string(const std::string &t_str) {
251 char * str_cstr = const_cast<char *>(t_str.c_str());
252 size_t temp_length = strlen(str_cstr);
253 int length = (temp_length <= INT_MAX) ? static_cast<int>(static_cast<ssize_t>(temp_length)) : -1;
254 if (length < 1 || length > ODOMETRY_DESC_BUFFER_SIZE) {
255 return;
256 }
257 char var_str_buffer[ODOMETRY_DESC_BUFFER_SIZE + 1];
258 char* var_str = &var_str_buffer[0];
259 char key_buffer[8];
260 char* key = &key_buffer[0];
261 int bracecount = 0;
262 int startVar = 0;
263 int index = 0;
264 int startKey = 0;
265 int endKey = -1;
266 int varIndex = 0;
267 if (index == 0 && str_cstr[0] == '{') {
268 index = 1;
269 }
270 startVar = index;
271 startKey = startVar;
272 do {
273 for (int i = index; i < length; i++) {
274 index = i + 1;
275 if (bracecount == 0 && str_cstr[i] == '=') {
276 endKey = i - 1;
277 startVar = index;
278 continue;
279 }
280 if (bracecount == 0 && isspace(str_cstr[i])) {
281 startVar = index;
282 if (endKey == -1) {
283 startKey = index;
284 }
285 continue;
286 }
287 if (bracecount == 0 && str_cstr[i] == ',') {
288 index = i - 1;
289 break;
290 }
291 if (str_cstr[i] == '{') {
292 bracecount++;
293 continue;
294 }
295 if (str_cstr[i] == '}') {
296 bracecount--;
297 if (bracecount < 0) {
298 index = i - 1;
299 break;
300 }
301 }
302 if (i == length - 1) {
303 index = i;
304 }
305 }
306 if (endKey >= startKey && endKey - startKey < length) {
307 strncpy(key, str_cstr + startKey, static_cast<size_t>((endKey - startKey) + 1));
308 key[(endKey - startKey) + 1] = 0;
309 } else {
310 key[0] = 0;
311 }
312 strncpy(var_str, str_cstr + startVar, static_cast<size_t>((index - startVar) + 1));
313 var_str[(index - startVar) + 1] = 0;
314 bracecount = 0;
315 index += 2;
316 startVar = index;
317 startKey = startVar;
318 endKey = -1;
319 if (strlen(key) > 0) {
320 if (0 == strcmp("forward", key)) {
321 varIndex = 0;
322 } else if (0 == strcmp("left", key)) {
323 varIndex = 1;
324 } else if (0 == strcmp("turn", key)) {
325 varIndex = 2;
326 } else {
327 varIndex = -1;
328 }
329 }
330 switch (varIndex) {
331 case -1: { break; }
332 case 0:
333 {
334 this->set_forward(static_cast<float>(atof(var_str)));
335 break;
336 }
337 case 1:
338 {
339 this->set_left(static_cast<float>(atof(var_str)));
340 break;
341 }
342 case 2:
343 {
344 this->set_turn(static_cast<float>(atof(var_str)));
345 break;
346 }
347 }
348 if (varIndex >= 0) {
349 varIndex++;
350 }
351 } while(index < length);
352#endif
353 }
354#endif
355
356 inline void clear() {
357 set_forward(0.0f);
358 set_left(0.0f);
359 set_turn(0.0f);
360 }
361
362 inline Odometry operator+(const Odometry& a) const {
363 Odometry c;
364 c.set_forward(forward() + a.forward());
365 c.set_left(left() + a.left());
366 c.set_turn(turn() + a.turn());
367 return c;
368 }
369
370 inline Odometry operator-(const Odometry& a) const {
371 Odometry c;
372 c.set_forward(forward() - a.forward());
373 c.set_left(left() - a.left());
374 c.set_turn(turn() - a.turn());
375 return c;
376 }
377 };
378
379}
380
381#endif
Provides a C++ wrapper around wb_odometry.
Definition: Odometry.hpp:84
void set_left(const float &t_newValue)
Definition: Odometry.hpp:183
std::string description()
Definition: Odometry.hpp:212
Odometry(float t_forward=0.0f, float t_left=0.0f, float t_turn=0.0f)
Create a new Odometry.
Definition: Odometry.hpp:102
void clear()
WHITEBOARD_POSTER_STRING_CONVERSION.
Definition: Odometry.hpp:356
const float & forward() const
Definition: Odometry.hpp:163
Odometry & operator=(const Odometry &t_other)
Copy Assignment Operator.
Definition: Odometry.hpp:123
bool operator==(const Odometry &t_other) const
Definition: Odometry.hpp:136
const float & turn() const
Definition: Odometry.hpp:193
const float & left() const
Definition: Odometry.hpp:178
void from_string(const std::string &t_str)
Definition: Odometry.hpp:250
Odometry(const struct wb_odometry &t_other)
Copy Constructor.
Definition: Odometry.hpp:116
Odometry operator-(const Odometry &a) const
Definition: Odometry.hpp:370
void set_turn(const float &t_newValue)
Definition: Odometry.hpp:198
Odometry(const std::string &t_str)
String Constructor.
Definition: Odometry.hpp:207
void set_forward(const float &t_newValue)
Definition: Odometry.hpp:168
bool operator!=(const Odometry &t_other) const
Definition: Odometry.hpp:143
Odometry(const Odometry &t_other)
Copy Constructor.
Definition: Odometry.hpp:109
std::string to_string()
Definition: Odometry.hpp:229
Odometry operator+(const Odometry &a) const
Definition: Odometry.hpp:362
/file APM_Interface.h
WHITEBOARD_POSTER_STRING_CONVERSION.
Definition: wb_odometry.h:109
float left
/< sideways, mm/s
Definition: wb_odometry.h:119
float turn
/< rotation, deg/s
Definition: wb_odometry.h:124
float forward
/< forward, mm/s
Definition: wb_odometry.h:114
const char * wb_odometry_to_string(const struct wb_odometry *self, char *toString, size_t bufferSize)
Convert to a string.
Definition: wb_odometry.c:157
const char * wb_odometry_description(const struct wb_odometry *self, char *descString, size_t bufferSize)
Convert to a description string.
Definition: wb_odometry.c:125
struct wb_odometry * wb_odometry_from_string(struct wb_odometry *self, const char *str)
Convert from a string.
Definition: wb_odometry.c:189
#define ODOMETRY_DESC_BUFFER_SIZE
Definition: wb_odometry.h:97
#define ODOMETRY_TO_STRING_BUFFER_SIZE
Definition: wb_odometry.h:98