gusimplewhiteboard
BallPosition.hpp
Go to the documentation of this file.
1/*
2 * file BallPosition.hpp
3 *
4 * This file was generated by classgenerator from ball_position.gen.
5 * DO NOT CHANGE MANUALLY!
6 *
7 * Copyright © 2021 Callum McColl. 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 Callum McColl.
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_BallPosition_h
61#define guWhiteboard_BallPosition_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_ball_position.h"
71
72#undef guWhiteboard_BallPosition_DEFINED
73#define guWhiteboard_BallPosition_DEFINED
74
75#undef BallPosition_DEFINED
76#define BallPosition_DEFINED
77
78namespace guWhiteboard {
79
84
85 private:
86
90 void init(int16_t t_x = 0, int16_t t_y = 0, int16_t t_pitchInDegrees = 0, int16_t t_yawInDegrees = 0, int16_t t_rollInDegrees = 0, uint8_t t_confidence = 0) {
91 set_x(t_x);
92 set_y(t_y);
93 set_pitchInDegrees(t_pitchInDegrees);
94 set_yawInDegrees(t_yawInDegrees);
95 set_rollInDegrees(t_rollInDegrees);
96 set_confidence(t_confidence);
97 }
98
99 public:
100
104 BallPosition(int16_t t_x = 0, int16_t t_y = 0, int16_t t_pitchInDegrees = 0, int16_t t_yawInDegrees = 0, int16_t t_rollInDegrees = 0, uint8_t t_confidence = 0) {
105 this->init(t_x, t_y, t_pitchInDegrees, t_yawInDegrees, t_rollInDegrees, t_confidence);
106 }
107
112 this->init(t_other.x(), t_other.y(), t_other.pitchInDegrees(), t_other.yawInDegrees(), t_other.rollInDegrees(), t_other.confidence());
113 }
114
119 this->init(t_other.x, t_other.y, t_other.pitchInDegrees, t_other.yawInDegrees, t_other.rollInDegrees, t_other.confidence);
120 }
121
126 this->init(t_other.x(), t_other.y(), t_other.pitchInDegrees(), t_other.yawInDegrees(), t_other.rollInDegrees(), t_other.confidence());
127 return *this;
128 }
129
133 BallPosition &operator = (const struct wb_ball_position &t_other) {
134 this->init(t_other.x, t_other.y, t_other.pitchInDegrees, t_other.yawInDegrees, t_other.rollInDegrees, t_other.confidence);
135 return *this;
136 }
137
138 bool operator ==(const BallPosition &t_other) const
139 {
140 return x() == t_other.x()
141 && y() == t_other.y()
142 && pitchInDegrees() == t_other.pitchInDegrees()
143 && yawInDegrees() == t_other.yawInDegrees()
144 && rollInDegrees() == t_other.rollInDegrees()
145 && confidence() == t_other.confidence();
146 }
147
148 bool operator !=(const BallPosition &t_other) const
149 {
150 return !(*this == t_other);
151 }
152
153 bool operator ==(const wb_ball_position &t_other) const
154 {
155 return *this == BallPosition(t_other);
156 }
157
158 bool operator !=(const wb_ball_position &t_other) const
159 {
160 return !(*this == t_other);
161 }
162
163 int16_t & x()
164 {
165 return wb_ball_position::x;
166 }
167
168 const int16_t & x() const
169 {
170 return wb_ball_position::x;
171 }
172
173 void set_x(const int16_t &t_newValue)
174 {
175 wb_ball_position::x = t_newValue;
176 }
177
178 int16_t & y()
179 {
180 return wb_ball_position::y;
181 }
182
183 const int16_t & y() const
184 {
185 return wb_ball_position::y;
186 }
187
188 void set_y(const int16_t &t_newValue)
189 {
190 wb_ball_position::y = t_newValue;
191 }
192
193 int16_t & pitchInDegrees()
194 {
196 }
197
198 const int16_t & pitchInDegrees() const
199 {
201 }
202
203 void set_pitchInDegrees(const int16_t &t_newValue)
204 {
206 }
207
208 int16_t & yawInDegrees()
209 {
211 }
212
213 const int16_t & yawInDegrees() const
214 {
216 }
217
218 void set_yawInDegrees(const int16_t &t_newValue)
219 {
221 }
222
223 int16_t & rollInDegrees()
224 {
226 }
227
228 const int16_t & rollInDegrees() const
229 {
231 }
232
233 void set_rollInDegrees(const int16_t &t_newValue)
234 {
236 }
237
238 uint8_t & confidence()
239 {
241 }
242
243 const uint8_t & confidence() const
244 {
246 }
247
248 void set_confidence(const uint8_t &t_newValue)
249 {
250 wb_ball_position::confidence = t_newValue;
251 }
252
253#ifdef WHITEBOARD_POSTER_STRING_CONVERSION
257 BallPosition(const std::string &t_str) {
258 this->init();
259 this->from_string(t_str);
260 }
261
262 std::string description() {
263#ifdef USE_WB_BALL_POSITION_C_CONVERSION
265 wb_ball_position_description(this, buffer, sizeof(buffer));
266 std::string descr = buffer;
267 return descr;
268#else
269 std::ostringstream ss;
270 ss << "x=" << static_cast<signed>(this->x());
271 ss << ", ";
272 ss << "y=" << static_cast<signed>(this->y());
273 ss << ", ";
274 ss << "pitchInDegrees=" << static_cast<signed>(this->pitchInDegrees());
275 ss << ", ";
276 ss << "yawInDegrees=" << static_cast<signed>(this->yawInDegrees());
277 ss << ", ";
278 ss << "rollInDegrees=" << static_cast<signed>(this->rollInDegrees());
279 ss << ", ";
280 ss << "confidence=" << static_cast<unsigned>(this->confidence());
281 return ss.str();
282#endif
283 }
284
285 std::string to_string() {
286#ifdef USE_WB_BALL_POSITION_C_CONVERSION
288 wb_ball_position_to_string(this, buffer, sizeof(buffer));
289 std::string toString = buffer;
290 return toString;
291#else
292 std::ostringstream ss;
293 ss << static_cast<signed>(this->x());
294 ss << ", ";
295 ss << static_cast<signed>(this->y());
296 ss << ", ";
297 ss << static_cast<signed>(this->pitchInDegrees());
298 ss << ", ";
299 ss << static_cast<signed>(this->yawInDegrees());
300 ss << ", ";
301 ss << static_cast<signed>(this->rollInDegrees());
302 ss << ", ";
303 ss << static_cast<unsigned>(this->confidence());
304 return ss.str();
305#endif
306 }
307
308#ifdef USE_WB_BALL_POSITION_C_CONVERSION
309 void from_string(const std::string &t_str) {
310 wb_ball_position_from_string(this, t_str.c_str());
311#else
312 void from_string(const std::string &t_str) {
313 char * str_cstr = const_cast<char *>(t_str.c_str());
314 size_t temp_length = strlen(str_cstr);
315 int length = (temp_length <= INT_MAX) ? static_cast<int>(static_cast<ssize_t>(temp_length)) : -1;
316 if (length < 1 || length > BALL_POSITION_DESC_BUFFER_SIZE) {
317 return;
318 }
319 char var_str_buffer[BALL_POSITION_DESC_BUFFER_SIZE + 1];
320 char* var_str = &var_str_buffer[0];
321 char key_buffer[15];
322 char* key = &key_buffer[0];
323 int bracecount = 0;
324 int startVar = 0;
325 int index = 0;
326 int startKey = 0;
327 int endKey = -1;
328 int varIndex = 0;
329 if (index == 0 && str_cstr[0] == '{') {
330 index = 1;
331 }
332 startVar = index;
333 startKey = startVar;
334 do {
335 for (int i = index; i < length; i++) {
336 index = i + 1;
337 if (bracecount == 0 && str_cstr[i] == '=') {
338 endKey = i - 1;
339 startVar = index;
340 continue;
341 }
342 if (bracecount == 0 && isspace(str_cstr[i])) {
343 startVar = index;
344 if (endKey == -1) {
345 startKey = index;
346 }
347 continue;
348 }
349 if (bracecount == 0 && str_cstr[i] == ',') {
350 index = i - 1;
351 break;
352 }
353 if (str_cstr[i] == '{') {
354 bracecount++;
355 continue;
356 }
357 if (str_cstr[i] == '}') {
358 bracecount--;
359 if (bracecount < 0) {
360 index = i - 1;
361 break;
362 }
363 }
364 if (i == length - 1) {
365 index = i;
366 }
367 }
368 if (endKey >= startKey && endKey - startKey < length) {
369 strncpy(key, str_cstr + startKey, static_cast<size_t>((endKey - startKey) + 1));
370 key[(endKey - startKey) + 1] = 0;
371 } else {
372 key[0] = 0;
373 }
374 strncpy(var_str, str_cstr + startVar, static_cast<size_t>((index - startVar) + 1));
375 var_str[(index - startVar) + 1] = 0;
376 bracecount = 0;
377 index += 2;
378 startVar = index;
379 startKey = startVar;
380 endKey = -1;
381 if (strlen(key) > 0) {
382 if (0 == strcmp("x", key)) {
383 varIndex = 0;
384 } else if (0 == strcmp("y", key)) {
385 varIndex = 1;
386 } else if (0 == strcmp("pitchInDegrees", key)) {
387 varIndex = 2;
388 } else if (0 == strcmp("yawInDegrees", key)) {
389 varIndex = 3;
390 } else if (0 == strcmp("rollInDegrees", key)) {
391 varIndex = 4;
392 } else if (0 == strcmp("confidence", key)) {
393 varIndex = 5;
394 } else {
395 varIndex = -1;
396 }
397 }
398 switch (varIndex) {
399 case -1: { break; }
400 case 0:
401 {
402 this->set_x(static_cast<int16_t>(atoi(var_str)));
403 break;
404 }
405 case 1:
406 {
407 this->set_y(static_cast<int16_t>(atoi(var_str)));
408 break;
409 }
410 case 2:
411 {
412 this->set_pitchInDegrees(static_cast<int16_t>(atoi(var_str)));
413 break;
414 }
415 case 3:
416 {
417 this->set_yawInDegrees(static_cast<int16_t>(atoi(var_str)));
418 break;
419 }
420 case 4:
421 {
422 this->set_rollInDegrees(static_cast<int16_t>(atoi(var_str)));
423 break;
424 }
425 case 5:
426 {
427 this->set_confidence(static_cast<uint8_t>(atoi(var_str)));
428 break;
429 }
430 }
431 if (varIndex >= 0) {
432 varIndex++;
433 }
434 } while(index < length);
435#endif
436 }
437#endif
438
446 double confidencePercent() const
447 {
448 return static_cast<double>(confidence() - 0) / static_cast<double>(255 - 0);
449 }
450
459 void set_confidencePercent(const double newValue)
460 {
461 set_confidence(static_cast<uint8_t>(round(newValue * static_cast<double>(255 - 0)) + 0));
462 }
463 };
464
465}
466
467#endif
Provides a C++ wrapper around wb_ball_position.
void set_yawInDegrees(const int16_t &t_newValue)
void from_string(const std::string &t_str)
void set_y(const int16_t &t_newValue)
const int16_t & y() const
BallPosition(const struct wb_ball_position &t_other)
Copy Constructor.
BallPosition(int16_t t_x=0, int16_t t_y=0, int16_t t_pitchInDegrees=0, int16_t t_yawInDegrees=0, int16_t t_rollInDegrees=0, uint8_t t_confidence=0)
Create a new BallPosition.
void set_x(const int16_t &t_newValue)
const int16_t & pitchInDegrees() const
const uint8_t & confidence() const
double confidencePercent() const
WHITEBOARD_POSTER_STRING_CONVERSION.
const int16_t & rollInDegrees() const
void set_rollInDegrees(const int16_t &t_newValue)
const int16_t & x() const
void set_confidence(const uint8_t &t_newValue)
BallPosition & operator=(const BallPosition &t_other)
Copy Assignment Operator.
const int16_t & yawInDegrees() const
BallPosition(const std::string &t_str)
String Constructor.
void set_confidencePercent(const double newValue)
Converts and stores a percentage floating point value in BallPosition.confidence.
bool operator==(const BallPosition &t_other) const
BallPosition(const BallPosition &t_other)
Copy Constructor.
bool operator!=(const BallPosition &t_other) const
void set_pitchInDegrees(const int16_t &t_newValue)
/file APM_Interface.h
WHITEBOARD_POSTER_STRING_CONVERSION.
int16_t x
The x coordinate.
uint8_t confidence
The confidence that the ball is at this position.
int16_t y
The y coordinate.
int16_t rollInDegrees
The roll orientation.
int16_t pitchInDegrees
The pitch orientation.
int16_t yawInDegrees
The yaw orientation.
const char * wb_ball_position_to_string(const struct wb_ball_position *self, char *toString, size_t bufferSize)
Convert to a string.
const char * wb_ball_position_description(const struct wb_ball_position *self, char *descString, size_t bufferSize)
Convert to a description string.
struct wb_ball_position * wb_ball_position_from_string(struct wb_ball_position *self, const char *str)
Convert from a string.
#define BALL_POSITION_DESC_BUFFER_SIZE
#define BALL_POSITION_TO_STRING_BUFFER_SIZE