gusimplewhiteboard
NaoWalkStatus.hpp
Go to the documentation of this file.
1/*
2 * file NaoWalkStatus.hpp
3 *
4 * This file was generated by classgenerator from naoWalkStatus.gen.
5 * DO NOT CHANGE MANUALLY!
6 *
7 * Copyright © 2021 Carl Lusty. 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 Carl Lusty.
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_NaoWalkStatus_h
61#define guWhiteboard_NaoWalkStatus_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_nao_walk_status.h"
71
72#undef guWhiteboard_NaoWalkStatus_DEFINED
73#define guWhiteboard_NaoWalkStatus_DEFINED
74
75#undef NaoWalkStatus_DEFINED
76#define NaoWalkStatus_DEFINED
77
78#include "Odometry.h"
79
80namespace guWhiteboard {
81
86
87 private:
88
92 void init(enum WalkEngineState t_walkEngineState = wes_Disconnected, struct wb_odometry t_odometry = wb_odometry(), uint8_t t_odometryResetCounter = 0) {
93 set_walkEngineState(t_walkEngineState);
94 set_odometry(t_odometry);
95 set_odometryResetCounter(t_odometryResetCounter);
96 }
97
98 public:
99
103 NaoWalkStatus(enum WalkEngineState t_walkEngineState = wes_Disconnected, struct wb_odometry t_odometry = wb_odometry(), uint8_t t_odometryResetCounter = 0) {
104 this->init(t_walkEngineState, t_odometry, t_odometryResetCounter);
105 }
106
111 this->init(t_other.walkEngineState(), t_other.odometry(), t_other.odometryResetCounter());
112 }
113
118 this->init(t_other.walkEngineState, t_other.odometry, t_other.odometryResetCounter);
119 }
120
125 this->init(t_other.walkEngineState(), t_other.odometry(), t_other.odometryResetCounter());
126 return *this;
127 }
128
133 this->init(t_other.walkEngineState, t_other.odometry, t_other.odometryResetCounter);
134 return *this;
135 }
136
137 bool operator ==(const NaoWalkStatus &t_other) const
138 {
139 return walkEngineState() == t_other.walkEngineState()
140 && Odometry(odometry()) == Odometry(t_other.odometry())
142 }
143
144 bool operator !=(const NaoWalkStatus &t_other) const
145 {
146 return !(*this == t_other);
147 }
148
149 bool operator ==(const wb_nao_walk_status &t_other) const
150 {
151 return *this == NaoWalkStatus(t_other);
152 }
153
154 bool operator !=(const wb_nao_walk_status &t_other) const
155 {
156 return !(*this == t_other);
157 }
158
160 {
162 }
163
164 const enum WalkEngineState & walkEngineState() const
165 {
167 }
168
169 void set_walkEngineState(const enum WalkEngineState &t_newValue)
170 {
172 }
173
175 {
176 return const_cast<Odometry &>(static_cast<const Odometry &>(wb_nao_walk_status::odometry));
177 }
178
179 const Odometry & odometry() const
180 {
181 return static_cast<const Odometry &>(wb_nao_walk_status::odometry);
182 }
183
184 void set_odometry(const Odometry &t_newValue)
185 {
186 wb_nao_walk_status::odometry = static_cast<wb_odometry>(t_newValue);
187 }
188
190 {
192 }
193
194 const uint8_t & odometryResetCounter() const
195 {
197 }
198
199 void set_odometryResetCounter(const uint8_t &t_newValue)
200 {
202 }
203
204#ifdef WHITEBOARD_POSTER_STRING_CONVERSION
208 NaoWalkStatus(const std::string &t_str) {
209 this->init();
210 this->from_string(t_str);
211 }
212
213 std::string description() {
214#ifdef USE_WB_NAO_WALK_STATUS_C_CONVERSION
216 wb_nao_walk_status_description(this, buffer, sizeof(buffer));
217 std::string descr = buffer;
218 return descr;
219#else
220 std::ostringstream ss;
221 switch (this->walkEngineState()) {
222 case wes_Disconnected:
223 {
224 ss << "walkEngineState=" << "wes_Disconnected";
225 break;
226 }
227 case wes_StoppedReady:
228 {
229 ss << "walkEngineState=" << "wes_StoppedReady";
230 break;
231 }
233 {
234 ss << "walkEngineState=" << "wes_StoppedStanding";
235 break;
236 }
237 case wes_Walking:
238 {
239 ss << "walkEngineState=" << "wes_Walking";
240 break;
241 }
242 }
243 ss << ", ";
244 ss << "odometry=" << "{" << Odometry(this->odometry()).description() << "}";
245 ss << ", ";
246 ss << "odometryResetCounter=" << static_cast<unsigned>(this->odometryResetCounter());
247 return ss.str();
248#endif
249 }
250
251 std::string to_string() {
252#ifdef USE_WB_NAO_WALK_STATUS_C_CONVERSION
254 wb_nao_walk_status_to_string(this, buffer, sizeof(buffer));
255 std::string toString = buffer;
256 return toString;
257#else
258 std::ostringstream ss;
259 switch (this->walkEngineState()) {
260 case wes_Disconnected:
261 {
262 ss << "wes_Disconnected";
263 break;
264 }
265 case wes_StoppedReady:
266 {
267 ss << "wes_StoppedReady";
268 break;
269 }
271 {
272 ss << "wes_StoppedStanding";
273 break;
274 }
275 case wes_Walking:
276 {
277 ss << "wes_Walking";
278 break;
279 }
280 }
281 ss << ", ";
282 ss << "{" << Odometry(this->odometry()).to_string() << "}";
283 ss << ", ";
284 ss << static_cast<unsigned>(this->odometryResetCounter());
285 return ss.str();
286#endif
287 }
288
289#ifdef USE_WB_NAO_WALK_STATUS_C_CONVERSION
290 void from_string(const std::string &t_str) {
291 wb_nao_walk_status_from_string(this, t_str.c_str());
292#else
293 void from_string(const std::string &t_str) {
294 char * str_cstr = const_cast<char *>(t_str.c_str());
295 size_t temp_length = strlen(str_cstr);
296 int length = (temp_length <= INT_MAX) ? static_cast<int>(static_cast<ssize_t>(temp_length)) : -1;
297 if (length < 1 || length > NAOWALKSTATUS_DESC_BUFFER_SIZE) {
298 return;
299 }
300 char var_str_buffer[NAOWALKSTATUS_DESC_BUFFER_SIZE + 1];
301 char* var_str = &var_str_buffer[0];
302 char key_buffer[21];
303 char* key = &key_buffer[0];
304 int bracecount = 0;
305 int startVar = 0;
306 int index = 0;
307 int startKey = 0;
308 int endKey = -1;
309 int varIndex = 0;
310 if (index == 0 && str_cstr[0] == '{') {
311 index = 1;
312 }
313 startVar = index;
314 startKey = startVar;
315 do {
316 for (int i = index; i < length; i++) {
317 index = i + 1;
318 if (bracecount == 0 && str_cstr[i] == '=') {
319 endKey = i - 1;
320 startVar = index;
321 continue;
322 }
323 if (bracecount == 0 && isspace(str_cstr[i])) {
324 startVar = index;
325 if (endKey == -1) {
326 startKey = index;
327 }
328 continue;
329 }
330 if (bracecount == 0 && str_cstr[i] == ',') {
331 index = i - 1;
332 break;
333 }
334 if (str_cstr[i] == '{') {
335 bracecount++;
336 continue;
337 }
338 if (str_cstr[i] == '}') {
339 bracecount--;
340 if (bracecount < 0) {
341 index = i - 1;
342 break;
343 }
344 }
345 if (i == length - 1) {
346 index = i;
347 }
348 }
349 if (endKey >= startKey && endKey - startKey < length) {
350 strncpy(key, str_cstr + startKey, static_cast<size_t>((endKey - startKey) + 1));
351 key[(endKey - startKey) + 1] = 0;
352 } else {
353 key[0] = 0;
354 }
355 strncpy(var_str, str_cstr + startVar, static_cast<size_t>((index - startVar) + 1));
356 var_str[(index - startVar) + 1] = 0;
357 bracecount = 0;
358 index += 2;
359 startVar = index;
360 startKey = startVar;
361 endKey = -1;
362 if (strlen(key) > 0) {
363 if (0 == strcmp("walkEngineState", key)) {
364 varIndex = 0;
365 } else if (0 == strcmp("odometry", key)) {
366 varIndex = 1;
367 } else if (0 == strcmp("odometryResetCounter", key)) {
368 varIndex = 2;
369 } else {
370 varIndex = -1;
371 }
372 }
373 switch (varIndex) {
374 case -1: { break; }
375 case 0:
376 {
377 if (strcmp("wes_Disconnected", var_str) == 0) {
378#pragma clang diagnostic push
379#pragma clang diagnostic ignored "-Wbad-function-cast"
381#pragma clang diagnostic pop
382 } else if (strcmp("wes_StoppedReady", var_str) == 0) {
383#pragma clang diagnostic push
384#pragma clang diagnostic ignored "-Wbad-function-cast"
386#pragma clang diagnostic pop
387 } else if (strcmp("wes_StoppedStanding", var_str) == 0) {
388#pragma clang diagnostic push
389#pragma clang diagnostic ignored "-Wbad-function-cast"
391#pragma clang diagnostic pop
392 } else if (strcmp("wes_Walking", var_str) == 0) {
393#pragma clang diagnostic push
394#pragma clang diagnostic ignored "-Wbad-function-cast"
396#pragma clang diagnostic pop
397 } else {
398#pragma clang diagnostic push
399#pragma clang diagnostic ignored "-Wbad-function-cast"
400 this->set_walkEngineState(static_cast<enum WalkEngineState>(atoi(var_str)));
401#pragma clang diagnostic pop
402 }
403 break;
404 }
405 case 1:
406 {
407 Odometry odometry_temp = Odometry();
408 odometry_temp.from_string(var_str);
409 this->set_odometry(odometry_temp);
410 break;
411 }
412 case 2:
413 {
414 this->set_odometryResetCounter(static_cast<uint8_t>(atoi(var_str)));
415 break;
416 }
417 }
418 if (varIndex >= 0) {
419 varIndex++;
420 }
421 } while(index < length);
422#endif
423 }
424#endif
425 };
426
427}
428
429#endif
Provides a C++ wrapper around wb_nao_walk_status.
void from_string(const std::string &t_str)
void set_odometryResetCounter(const uint8_t &t_newValue)
NaoWalkStatus(enum WalkEngineState t_walkEngineState=wes_Disconnected, struct wb_odometry t_odometry=wb_odometry(), uint8_t t_odometryResetCounter=0)
Create a new NaoWalkStatus.
void set_walkEngineState(const enum WalkEngineState &t_newValue)
void set_odometry(const Odometry &t_newValue)
bool operator==(const NaoWalkStatus &t_other) const
NaoWalkStatus(const struct wb_nao_walk_status &t_other)
Copy Constructor.
bool operator!=(const NaoWalkStatus &t_other) const
NaoWalkStatus(const NaoWalkStatus &t_other)
Copy Constructor.
NaoWalkStatus & operator=(const NaoWalkStatus &t_other)
Copy Assignment Operator.
const uint8_t & odometryResetCounter() const
NaoWalkStatus(const std::string &t_str)
String Constructor.
enum WalkEngineState & walkEngineState() const
const Odometry & odometry() const
enum WalkEngineState & walkEngineState()
Provides a C++ wrapper around wb_odometry.
Definition: Odometry.hpp:84
std::string description()
Definition: Odometry.hpp:212
void from_string(const std::string &t_str)
Definition: Odometry.hpp:250
std::string to_string()
Definition: Odometry.hpp:229
/file APM_Interface.h
WHITEBOARD_POSTER_STRING_CONVERSION.
enum WalkEngineState walkEngineState
The current state of the walk engine, see enum documentation.
struct wb_odometry odometry
Current odometry object.
uint8_t odometryResetCounter
A counter used to reset the odometry object, change this value and send it via NaoWalkCommand to trig...
WHITEBOARD_POSTER_STRING_CONVERSION.
Definition: wb_odometry.h:109
const char * wb_nao_walk_status_description(const struct wb_nao_walk_status *self, char *descString, size_t bufferSize)
Convert to a description string.
const char * wb_nao_walk_status_to_string(const struct wb_nao_walk_status *self, char *toString, size_t bufferSize)
Convert to a string.
struct wb_nao_walk_status * wb_nao_walk_status_from_string(struct wb_nao_walk_status *self, const char *str)
Convert from a string.
#define NAOWALKSTATUS_DESC_BUFFER_SIZE
WalkEngineState
@ wes_StoppedReady
In the Crouched stance, ready to walk again straight away but not currently moving anywhere.
@ wes_StoppedStanding
In the Standing position, this position uses less power than Stopped / Crouched, it is a minimal stif...
@ wes_Walking
Walking around, includes stopping, kicking, transition from Standing etc... basically the walk engine...
@ wes_Disconnected
Not connected to the DCM, does not control any joints in this state.
#define NAOWALKSTATUS_TO_STRING_BUFFER_SIZE