gusimplewhiteboard
NAO_State.hpp
Go to the documentation of this file.
1
9#ifndef NAO_State_DEFINED
10#define NAO_State_DEFINED
11
12#include <sys/types.h>
13#include <sstream>
14#ifdef WHITEBOARD_POSTER_STRING_CONVERSION
15#include <ctype.h>
16#endif
17
18#include "wb_nao_state.h"
19
20namespace guWhiteboard
21{
22#ifdef WHITEBOARD_POSTER_STRING_CONVERSION
24 static const char *Robot_Stance_stringValues[NUM_OF_STANCES] =
25 {
26 "Standing",
27 "FallenForward",
28 "FallenBack",
29 "FallenLeft",
30 "FallenRight",
31 "Sitting", //NYI
32 "Kneeling", //NYI
33 "Knitting", //NYI to be implemented by Rene
34 "PickedUp",
35 "KickingWithLeftFoot",
36 "KickingWithRightFoot"
37 };
38
40 static const char *Robot_Walk_stringValues[NUM_OF_WALKS] =
41 {
42 "Modded_UNSW_Walk",
43 "ALMotion_Walk"
44 };
45#endif
46
61 class NAO_State : public wb_nao_state
62 {
63 public:
66
68 bool fallen() const { return stance() == FallenForward || stance() == FallenBack || stance() == FallenLeft || stance() == FallenRight; }
69
70#ifdef WHITEBOARD_POSTER_STRING_CONVERSION
74 NAO_State(const std::string &command): wb_nao_state() { from_string(command); }
75
79 std::string description()
80 {
81 std::stringstream ss;
82
83 ss << Robot_Stance_stringValues[int(stance())] << ", " << Robot_Walk_stringValues[int(walk())] << ", " << (chest_pressed_long() ? "L" : "") << int(chest_pressed()) << " @chest, " << (left_foot_pressed_long() ? "L" : "") << int(left_foot_pressed()) << " @lfoot, " << (right_foot_pressed_long() ? "L" : "") << int(right_foot_pressed()) << " @rfoot";
84
85 return ss.str();
86 }
87
91 void from_string(const std::string &str)
92 {
93 std::istringstream iss(str);
94 std::string token;
95 getline(iss, token, ',');
96 gu_trim(token);
97
98 if (token.length() && (token[0] == 'l' || token[0] == 'L' || isdigit(*token.c_str()))) goto chest_button;
99
100 for (int i = Standing; i < NUM_OF_STANCES; i++)
101 {
102 if (token == Robot_Stance_stringValues[i])
103 {
104 set_stance(Robot_Stance(i));
105 break;
106 }
107 }
108
109 if (!getline(iss, token, ',')) return;
110 gu_trim(token);
111
112 for (int i = Modded_UNSW_Walk; i < NUM_OF_WALKS; i++)
113 {
114 if (token == Robot_Walk_stringValues[i])
115 {
116 set_walk(Robot_Walk(i));
117 break;
118 }
119 }
120
121 if (!getline(iss, token, ',')) return;
122 gu_trim(token);
123
124 chest_button:
125 if (token.length())
126 {
127 const char *value = token.c_str();
128 if (*value == 'l' || *value == 'L')
129 {
130 set_chest_pressed_long(true);
131 value++;
132 }
133 set_chest_pressed(bool(value));
134 }
135
136 if (!getline(iss, token, ',')) return;
137 gu_trim(token);
138 if (token.length())
139 {
140 const char *value = token.c_str();
141 if (*value == 'l' || *value == 'L')
142 {
143 set_left_foot_pressed_long(true);
144 value++;
145 }
146 set_left_foot_pressed(bool(value));
147 }
148
149 if (!getline(iss, token, ',')) return;
150 gu_trim(token);
151 if (token.length())
152 {
153 const char *value = token.c_str();
154 if (*value == 'l' || *value == 'L')
155 {
156 set_right_foot_pressed_long(true);
157 value++;
158 }
159 set_right_foot_pressed(bool(value));
160 }
161 }
162#endif // WHITEBOARD_POSTER_STRING_CONVERSION
163 };
164}
165
166
167#endif //NAO_State_DEFINED
This class is for the robot to report its current state.
Definition: NAO_State.hpp:62
std::string description()
pretty print method for showing the current property values
Definition: NAO_State.hpp:79
bool fallen() const
Convenience method for checking the Fallen values.
Definition: NAO_State.hpp:68
void from_string(const std::string &str)
parse class properties from a string
Definition: NAO_State.hpp:91
NAO_State(const std::string &command)
string constructor (see from_string() below)
Definition: NAO_State.hpp:74
NAO_State()
Constructor, calls the data structs default constructor, which sets some default values.
Definition: NAO_State.hpp:65
stance
enum values for all stances
/file APM_Interface.h
nao state c struct
Definition: wb_nao_state.h:41
Robot_Stance
/file wb_nao_state.h
Definition: wb_nao_state.h:15
@ NUM_OF_STANCES
Definition: wb_nao_state.h:27
@ FallenBack
Definition: wb_nao_state.h:18
@ FallenForward
Definition: wb_nao_state.h:17
@ FallenRight
Definition: wb_nao_state.h:20
@ Standing
Definition: wb_nao_state.h:16
@ FallenLeft
Definition: wb_nao_state.h:19
Robot_Walk
which type of walk engine is currently running
Definition: wb_nao_state.h:31
@ NUM_OF_WALKS
Definition: wb_nao_state.h:34
@ Modded_UNSW_Walk
Definition: wb_nao_state.h:32