This repository was archived by the owner on Sep 2, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathBehaviour.cpp
More file actions
executable file
·196 lines (170 loc) · 6.85 KB
/
Behaviour.cpp
File metadata and controls
executable file
·196 lines (170 loc) · 6.85 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
/*! @file Behaviour.cpp
@brief Implementation of behaviour class
@author Jason Kulk
Copyright (c) 2009 Jason Kulk
This file is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This file is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with NUbot. If not, see <http://www.gnu.org/licenses/>.
*/
#include "targetconfig.h"
#include "Behaviour.h"
#include "BehaviourProvider.h"
#include "MiscBehaviours/SelectBehaviourProvider.h"
#include "NUSoccer/NUSoccerProvider.h"
#include "Soccer/SoccerProvider.h"
#include "MiscBehaviours/VisionCalibrationProvider.h"
#include "ChaseBall/ChaseBallProvider.h"
#include "Zombie/ZombieProvider.h"
#include "Ragdoll/RagdollProvider.h"
#include "WalkOptimisation/WalkOptimisationProvider.h"
#include "Kicker/KickerProvider.h"
#include "PassingChallenge/PassingChallengeProvider.h"
#include "MiscBehaviours/PoseProvider.h"
#include "MiscBehaviours/ScriptedPoseProvider.h"
#include "MiscBehaviours/ForwardWalkProvider.h"
#include "MiscBehaviours/IKTestProvider.h"
#include "RoboPedestrian/RoboPedestrianProvider.h"
#include "GoalKeeperTest/TestKeeperProvider.h"
#include "FootSlipTest/SlipTestProvider.h"
#include "HeadBehaviourTester/HBTProvider.h"
#include "ScriptTuner/ScriptTunerProvider.h"
#include "NUSoccer/NUSoccerProvider.h"
#include "CameraCalibration/CameraCalibrationProvider.h"
#include "EnvironmentalEmotions/EnvironmentalEmotionsProvider.h"
#ifdef TARGET_IS_BEAR
#include "BearMode/BearModeProvider.h"
#endif
#ifdef TARGET_IS_CYCLOID
#include "Cycloid/QuietStance/QuietStanceProvider.h"
#endif
#include "debug.h"
#include "debugverbositybehaviour.h"
Behaviour::Behaviour()
{
#if defined(TARGET_IS_NAOWEBOTS)
//m_behaviour = new ForwardWalkProvider(this);
//m_behaviour = new WalkOptimisationProvider(this);
m_behaviour = new IKTestProvider(this);
//m_behaviour = new SoccerProvider(this);
#elif defined(TARGET_IS_DARWINWEBOTS)
m_behaviour = new SoccerProvider(this);
//m_behaviour = new ZombieProvider(this);
#elif defined(TARGET_IS_BEAR)
m_behaviour = new BearModeProvider(this);
#elif defined(TARGET_IS_CYCLOID)
m_behaviour = new QuietStanceProvider(this);
#else
//m_behaviour = new ScriptedPoseProvider(this);
// m_behaviour = new SoccerProvider(this);
// m_behaviour = new ScriptTunerProvider(this);
m_behaviour = new NUSoccerProvider(this);
//m_behaviour = new ScriptedPoseProvider
//m_behaviour = new ZombieProvider(this);
//m_behaviour = new HBTProvider(this);
//m_behaviour = new RagdollProvider(this);
//m_behaviour = new ChaseBallProvider(this);
//m_behaviour = new WalkOptimisationProvider(this);
//m_behaviour = new ForwardWalkProvider(this);
//m_behaviour = new SlipTestProvider(this);
#endif
m_next_behaviour = NULL;
}
Behaviour::~Behaviour()
{
delete m_behaviour;
if (m_next_behaviour != NULL)
delete m_next_behaviour;
}
/*! @brief The main behaviour process function.
Calls the process function of the current behaviour provider and handles
change of provider when there is a next one.
@param jobs the nubot job std::list
@param data the nubot sensor data
@param actions the nubot actionators data
@param fieldobjects the nubot world model
@param gameinfo the nubot game information
@param teaminfo the nubot team information
*/
void Behaviour::process(JobList* jobs, NUSensorsData* data, NUActionatorsData* actions,
FieldObjects* fieldobjects, GameInformation* gameinfo,
TeamInformation* teaminfo)
{
#if DEBUG_BEHAVIOUR_VERBOSITY > 0
debug << "Behaviour::process()" << std::endl;
#endif
if (m_next_behaviour != NULL)
{
#if DEBUG_BEHAVIOUR_VERBOSITY > 0
debug << "Behaviour::process() is swaping the behaviour provider" << std::endl;
#endif
delete m_behaviour;
m_behaviour = m_next_behaviour;
m_next_behaviour = NULL;
}
m_behaviour->process(jobs, data, actions, fieldobjects, gameinfo, teaminfo);
}
void Behaviour::setNextBehaviour(std::string name)
{
m_next_behaviour = nameToProvider(name);
}
void Behaviour::setNextBehaviour(BehaviourProvider* behaviour)
{
m_next_behaviour = behaviour;
}
BehaviourProvider* Behaviour::nameToProvider(std::string name)
{
name = simplifyName(name);
if (name.compare("selectbehaviour") == 0)
return new SelectBehaviourProvider(this);
else if (name.find("soccer") != std::string::npos)
return new SoccerProvider(this);
else if (name.compare("chaseball") == 0)
return new ChaseBallProvider(this);
else if (name.compare("visioncalibration") == 0 or name.find("saveimage") != std::string::npos)
return new VisionCalibrationProvider(this);
else if (name.find("walkoptimis") != std::string::npos)
return new WalkOptimisationProvider(this);
else if (name.find("kicker") != std::string::npos)
return new KickerProvider(this);
else if (name.compare("scriptedpose") == 0)
return new ScriptedPoseProvider(this);
else if (name.compare("pose") == 0)
return new PoseProvider(this);
else if (name.compare("robopedestrian") == 0)
return new RoboPedestrianProvider(this);
else if (name.compare("cameracalibration") == 0)
return new CameraCalibrationProvider(this);
else if (name.find("enviro") != std::string::npos)
return new EnvironmentalEmotionsProvider(this);
else
return NULL;
}
/*! @brief Simplifies a name. The name is converted to lowercase, and spaces,
underscores, forward slash, backward slash and dots are removed
from the name.
@param input the name to be simplified
@return the simplified std::string
*/
std::string Behaviour::simplifyName(const std::string& input)
{
std::string namebuffer, currentletter;
// compare each letter to a space and an underscore and a forward slash
for (unsigned int j=0; j<input.size(); j++)
{
currentletter = input.substr(j, 1);
if (currentletter.compare(std::string(" ")) != 0 &&
currentletter.compare(std::string("_")) != 0 &&
currentletter.compare(std::string("/")) != 0 &&
currentletter.compare(std::string("\\")) != 0 &&
currentletter.compare(std::string(".")) != 0)
namebuffer += tolower(currentletter[0]);
}
return namebuffer;
}