60#ifndef guWhiteboard_BallPosition_h
61#define guWhiteboard_BallPosition_h
63#ifdef WHITEBOARD_POSTER_STRING_CONVERSION
72#undef guWhiteboard_BallPosition_DEFINED
73#define guWhiteboard_BallPosition_DEFINED
75#undef BallPosition_DEFINED
76#define BallPosition_DEFINED
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) {
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);
140 return x() == t_other.
x()
141 &&
y() == t_other.
y()
150 return !(*
this == t_other);
160 return !(*
this == t_other);
168 const int16_t &
x()
const
173 void set_x(
const int16_t &t_newValue)
183 const int16_t &
y()
const
188 void set_y(
const int16_t &t_newValue)
253#ifdef WHITEBOARD_POSTER_STRING_CONVERSION
263#ifdef USE_WB_BALL_POSITION_C_CONVERSION
266 std::string descr = buffer;
269 std::ostringstream ss;
270 ss <<
"x=" <<
static_cast<signed>(this->
x());
272 ss <<
"y=" <<
static_cast<signed>(this->
y());
274 ss <<
"pitchInDegrees=" <<
static_cast<signed>(this->
pitchInDegrees());
276 ss <<
"yawInDegrees=" <<
static_cast<signed>(this->
yawInDegrees());
278 ss <<
"rollInDegrees=" <<
static_cast<signed>(this->
rollInDegrees());
280 ss <<
"confidence=" <<
static_cast<unsigned>(this->
confidence());
286#ifdef USE_WB_BALL_POSITION_C_CONVERSION
289 std::string toString = buffer;
292 std::ostringstream ss;
293 ss << static_cast<signed>(this->
x());
295 ss << static_cast<signed>(this->
y());
303 ss << static_cast<unsigned>(this->
confidence());
308#ifdef USE_WB_BALL_POSITION_C_CONVERSION
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;
320 char* var_str = &var_str_buffer[0];
322 char* key = &key_buffer[0];
329 if (index == 0 && str_cstr[0] ==
'{') {
335 for (
int i = index; i < length; i++) {
337 if (bracecount == 0 && str_cstr[i] ==
'=') {
342 if (bracecount == 0 && isspace(str_cstr[i])) {
349 if (bracecount == 0 && str_cstr[i] ==
',') {
353 if (str_cstr[i] ==
'{') {
357 if (str_cstr[i] ==
'}') {
359 if (bracecount < 0) {
364 if (i == length - 1) {
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;
374 strncpy(var_str, str_cstr + startVar,
static_cast<size_t>((index - startVar) + 1));
375 var_str[(index - startVar) + 1] = 0;
381 if (strlen(key) > 0) {
382 if (0 == strcmp(
"x", key)) {
384 }
else if (0 == strcmp(
"y", key)) {
386 }
else if (0 == strcmp(
"pitchInDegrees", key)) {
388 }
else if (0 == strcmp(
"yawInDegrees", key)) {
390 }
else if (0 == strcmp(
"rollInDegrees", key)) {
392 }
else if (0 == strcmp(
"confidence", key)) {
402 this->
set_x(
static_cast<int16_t
>(atoi(var_str)));
407 this->
set_y(
static_cast<int16_t
>(atoi(var_str)));
434 }
while(index < length);
448 return static_cast<double>(
confidence() - 0) /
static_cast<double>(255 - 0);
461 set_confidence(
static_cast<uint8_t
>(round(newValue *
static_cast<double>(255 - 0)) + 0));
Provides a C++ wrapper around wb_ball_position.
void set_yawInDegrees(const int16_t &t_newValue)
void from_string(const std::string &t_str)
std::string description()
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.
int16_t & pitchInDegrees()
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)
int16_t & rollInDegrees()
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