gusimplewhiteboard
SwitchSubsumption.hpp
Go to the documentation of this file.
1/*
2 * SwitchSubsumption.h
3 * gusimplewhiteboard
4 *
5 * Created by Vlad Estivill-Castro on 20/11/2015.
6 * Copyright © 2015 Vlad Estivill-Castro. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above
16 * copyright notice, this list of conditions and the following
17 * disclaimer in the documentation and/or other materials
18 * provided with the distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgement:
22 *
23 * This product includes software developed by Rene Hexel.
24 *
25 * 4. Neither the name of the author nor the names of contributors
26 * may be used to endorse or promote products derived from this
27 * software without specific prior written permission.
28 *
29 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
30 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
31 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
32 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
33 * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
34 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
35 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
36 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
37 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
38 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
39 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
40 *
41 * -----------------------------------------------------------------------
42 * This program is free software; you can redistribute it and/or
43 * modify it under the above terms or under the terms of the GNU
44 * General Public License as published by the Free Software Foundation;
45 * either version 2 of the License, or (at your option) any later version.
46 *
47 * This program is distributed in the hope that it will be useful,
48 * but WITHOUT ANY WARRANTY; without even the implied warranty of
49 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
50 * GNU General Public License for more details.
51 *
52 * You should have received a copy of the GNU General Public License
53 * along with this program; if not, see http://www.gnu.org/licenses/
54 * or write to the Free Software Foundation, Inc., 51 Franklin Street,
55 * Fifth Floor, Boston, MA 02110-1301, USA.
56 *
57 */
58
59#ifndef SwitchSubsumption_DEFINED
60#define SwitchSubsumption_DEFINED
61
62
64#ifdef WHITEBOARD_POSTER_STRING_CONVERSION
65#include <sstream>
66#include <ctype.h>
67#endif
68
69namespace guWhiteboard
70{
76 {
77 public:
79
80#ifdef WHITEBOARD_POSTER_STRING_CONVERSION
82 SwitchSubsumption(const std::string &motion_command): wb_switch_subsumption()
83 { from_string(motion_command); }
84
86 std::string description() const
87 {
88 std::ostringstream ss;
89 for (int i=0 ; i< SUBSUMPTION_LEVELS; i++)
90 switch (theMotions(i))
91 { case TOTO_NO_COMMAND : ss << "null, "; break;
92 case TOTO_STOP : ss << "stop, "; break;
93 case TOTO_BACKWARDS : ss << "back, "; break;
94 case TOTO_MOVE_FORWARD : ss << "forwards, "; break;
95 case TOTO_TURN_LEFT : ss << "left, "; break;
96 case TOTO_TURN_RIGHT : ss << "right, "; break;
97 }
98 return ss.str();
99 }
100
102 void from_string(const std::string &str)
103 { std::istringstream iss(str);
104 std::string token;
105 for (int i = 0; i < SUBSUMPTION_LEVELS && getline(iss, token, ',') ; i++)
106 { const int n = atoi(token.c_str());
107 enum TotoMotionCommand &comamnd = theMotions(i);
108 if (n<=0) comamnd=TOTO_NO_COMMAND;
109 switch (n)
110 { case 1 : comamnd=TOTO_STOP; break;
111 case 2 : comamnd=TOTO_BACKWARDS; break;
112 case 3 : comamnd=TOTO_MOVE_FORWARD; break;
113 case 4 : comamnd=TOTO_TURN_LEFT; break;
114 case 5 : comamnd=TOTO_TURN_RIGHT; break;
115 }
116 }
117 }
118#endif
119 };
120
126 {
127 public:
129
130#ifdef WHITEBOARD_POSTER_STRING_CONVERSION
132 TotoDoingMotion(const std::string &motion_command): wb_toto_doing_motion()
133 { from_string(motion_command); }
134
136 std::string description() const
137 {
138 std::ostringstream ss;
139 switch (_motionCommand)
140 { case TOTO_NO_COMMAND : ss << "null, "; break;
141 case TOTO_STOP : ss << "stop, "; break;
142 case TOTO_BACKWARDS : ss << "back, "; break;
143 case TOTO_MOVE_FORWARD : ss << "forwards, "; break;
144 case TOTO_TURN_LEFT : ss << "left, "; break;
145 case TOTO_TURN_RIGHT : ss << "right, "; break;
146 }
147 return ss.str();
148 }
149
151 void from_string(const std::string &str)
152 { std::istringstream iss(str);
153 std::string token;
154 for (int i = 0; i < 1 && getline(iss, token, ',') ; i++)
155 { const int n = atoi(token.c_str());
156 if (n<=0) _motionCommand=TOTO_NO_COMMAND;
157 switch (n)
158 { case 1 : _motionCommand=TOTO_STOP; break;
159 case 2 : _motionCommand=TOTO_BACKWARDS; break;
160 case 3 : _motionCommand=TOTO_MOVE_FORWARD; break;
161 case 4 : _motionCommand=TOTO_TURN_LEFT; break;
162 case 5 : _motionCommand=TOTO_TURN_RIGHT; break;
163 }
164 }
165 }
166#endif
167 };
168
169}
170#endif /* SwitchSubsumption_DEFINED */
Subsumption SWITCH that select highest priority command.
std::string description() const
convert to a string
SwitchSubsumption(const std::string &motion_command)
string constructor
void from_string(const std::string &str)
convert from a string
TOTO motion of what is doing.
std::string description() const
convert to a string
void from_string(const std::string &str)
convert from a string
TotoDoingMotion(const std::string &motion_command)
string constructor
/file APM_Interface.h
TotoMotionCommand
@ TOTO_TURN_LEFT
@ TOTO_NO_COMMAND
@ TOTO_MOVE_FORWARD
@ TOTO_BACKWARDS
@ TOTO_TURN_RIGHT
#define SUBSUMPTION_LEVELS
/file wb_switch_subsumption.h