-
Notifications
You must be signed in to change notification settings - Fork 50
/
Copy pathnaobehavior.h
249 lines (192 loc) · 8.42 KB
/
naobehavior.h
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
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
#ifndef NAOBEHAVIOR_H
#define NAOBEHAVIOR_H
#include "behavior.h"
#include "../headers/headers.h"
#include "../parser/parser.h"
#include "../worldmodel/worldmodel.h"
#include "../bodymodel/bodymodel.h"
#include "../particlefilter/PFLocalization.h"
#include "../skills/skill.h"
// For UT Walk
#include <MotionCore.h>
#include <memory/Memory.h>
#include <memory/FrameInfoBlock.h>
#include <memory/SensorBlock.h>
#include <memory/JointBlock.h>
#include <memory/JointCommandBlock.h>
#include <memory/SimEffectorBlock.h>
#include <memory/WalkRequestBlock.h>
using namespace std;
// TODO: Temporary home. Not sure if this this the best place to put this.
struct WalkVelocity
{
WalkRequestBlock::ParamSet paramSet;
double x; // X direction velocity (unspecified unit)
double y; // Y direction velocity
double rot; // Rotational velocity about the Z-axis
WalkVelocity() : paramSet(WalkRequestBlock::PARAMS_DEFAULT), x(0), y(0), rot(0) {}
WalkVelocity(const double& velX, const double& velY, const double& velRot) :
paramSet(WalkRequestBlock::PARAMS_DEFAULT), x(velX), y(velY), rot(velRot) {}
WalkVelocity(WalkRequestBlock::ParamSet param, const double& velX, const double& velY, const double& velRot) :
paramSet(param), x(velX), y(velY), rot(velRot) {}
friend std::ostream& operator<<(std::ostream &out, const WalkVelocity& v)
{
out << "Parameter Set: " << v.paramSet << " T: (" << v.x << ", " << v.y << ") |R: " << v.rot;
return out;
}
};
class NaoBehavior : public Behavior {
friend class KickClassifier;
protected:
double currentFallStateStartTime;
// TODO: eliminate these and use a better solution
string classname;
map< SkillType, boost::shared_ptr<Skill> > skills;
const map<string, string>& namedParams;
string rsg;
std::string agentTeamName;
int agentUNum;
Parser *parser;
WorldModel *worldModel;
BodyModel *bodyModel;
PFLocalization* particleFilter;
// For UT Walk
MotionCore* core;
Memory *memory_;
FrameInfoBlock* frame_info_;
FrameInfoBlock* vision_frame_info_;
SensorBlock* raw_sensors_;
JointBlock* raw_joint_angles_;
JointCommandBlock* raw_joint_commands_;
JointBlock* processed_joint_angles_;
JointCommandBlock* processed_joint_commands_;
SimEffectorBlock* sim_effectors_;
WalkVelocity velocity;
// For UT Walk
void calculateAngles();
void preProcessJoints();
void postProcessJoints();
double hoverTime;
bool mInit;
bool initBeamed;
double beamTime;
bool initialized;
SkillType skill;
int skillState;
int fallState;
bool fallenLeft, fallenRight, fallenDown, fallenUp;
double fallTimeStamp;
double fallTimeWait;
VecPosition kickDirection;
int kickType;
VecPosition kickTarget;
double kickVerticalAngle;
double lastGetupRecoveryTime;
SkillType currentKick;
int currentKickType;
VecPosition me;
VecPosition myXDirection, myYDirection, myZDirection;
VecPosition ball;
//SCORE
int scoreMe;
int scoreOpp;
string monMsg;
bool fParsedVision;
string composeAction();
virtual void resetSkills();
void resetScales();
void refresh();
void act();
// ----------------------------------------------------
// --------- THESE FUNCTIONS ARE
// --------- TO BE OVERRIDEN BY AGENTS...
virtual SkillType selectSkill();
virtual void beam( double& beamX, double& beamY, double& beamAngle );
virtual void updateFitness() {}
// ----------------------------------------------------
bool checkingFall();
/**
* Trims the value to within [min, max].
*
* value - The value to trim.
* min - The minimum that the value can be.
* max - The maximum that the value can be.
*/
double trim(const double& value, const double& min, const double&max);
/**
* Returns the skill that will best approximate the desired
* walk direction and rotation using the currently implemented
* walk. This function was designed for use by selectSkill().
* It allows for a more general implementation of selectSkill()
* that does not depend (as much) on the currently implemented
* walk. This function delivers the fastest possible speed, so it
* is not appropriate for alignment/fine-tuning.
*
* For the purpose of this implementation, rotation = 0 is not
* the same as 360 is not the same as -360. 0 means no rotation,
* 360 means rotate to the left, while -360 means rotate to the
* right.
*
* direction - The angle to walk in degrees relative to the
* direction the robot is facing.
* rotation - The angle in degrees to turn the robot.
* speed - The percentage of maximum walk speed to use. Should
* be a value between 0 and 1. Default 1. This argument
* does not affect turn speed.
* fAllowOver180Turn - allow for turns greater than abs(180) instead
* of mapping them to their complement
*
*/
SkillType getWalk(const double& direction, const double& rotation, double speed = 1.0, bool fAllowOver180Turn=false);
SkillType getWalk(WalkRequestBlock::ParamSet paramSet, const double& direction, double rotation, double speed, bool fAllowOver180Turn=false);
/**
* Returns the skill that's needed to get to the target location facing the target
* rotation. All targets are offsets relative to the robot's current location and
* orientation. Note that something like (globalTarget - me) is NOT the correct local
* target. g2l(globalTarget) should be used instead.
*/
SkillType goToTargetRelative(const VecPosition& targetLoc, const double& targetRot, double speed=1, bool fAllowOver180Turn=false, WalkRequestBlock::ParamSet paramSet=WalkRequestBlock::PARAMS_DEFAULT);
SkillType goToTarget(const VecPosition &target);
VecPosition collisionAvoidance(bool avoidTeammate, bool avoidOpponent, bool avoidBall, double PROXIMITY_THRESH, double COLLISION_THRESH, VecPosition target, bool fKeepDistance=true);
VecPosition collisionAvoidanceCorrection(VecPosition start, double PROXIMITY_THRESH, double COLLISION_THRESH, VecPosition target, VecPosition obstacle);
VecPosition collisionAvoidanceApproach(double PROXIMITY_THRESH, double COLLISION_THRESH, VecPosition target, VecPosition obstacle);
VecPosition collisionAvoidanceApproach(VecPosition start, double PROXIMITY_THRESH, double COLLISION_THRESH, VecPosition target, VecPosition obstacle);
VecPosition navigateAroundBall(VecPosition target, double PROXIMITY_THRESH, double COLLISION_THRESH );
void resetKickState();
double computeKickCost(VecPosition target, SkillType kickType);
SkillType kickBall(const int kickTypeToUse, const VecPosition &target, const double kickVerticalAngle=0.0);
SkillType kickBallAtPresetTarget();
void getTargetDistanceAndAngle(const VecPosition &target, double &distance, double &angle);
SkillType kickBallAtTargetSimplePositioning( const VecPosition &targetToKickAt, SkillType kick_skill, int kickType);
/**
* Returns the maximum direction at which we can walk and still maintain maximum forward speed.
* In other words, returns the angle theta such that if we walk in any direction in [-theta, theta],
* our forward translation will be the maximum that the walk engine will allow.
*/
double getLimitingAngleForward();
bool beamablePlayMode();
bool improperPlayMode();
bool improperPlayMode(int pm);
bool kickPlayMode();
bool kickPlayMode(int pm, bool eitherTeam=false);
bool isIndirectKick();
bool isIndirectKick(int pm);
void readSkillsFromFile( const std::string& filename);
bool isRightSkill( SkillType skill );
bool isLeftSkill( SkillType skill );
double getParameter(const std::string& name);
double getStdNameParameter(const SkillType kick_skill, const std::string& parameter);
void getSkillsForKickType(int kickType, SkillType skillsForType[]);
SkillType demoKickingCircle();
public:
NaoBehavior(const std::string teamName, int uNum, const map<string, string>& namedParams_, const string& rsg_);
virtual ~NaoBehavior();
virtual std::string Init();
virtual std::string Think(const std::string& message);
void setMonMessage(const std::string& msg);
string getMonMessage();
inline MotionCore* getCore() {
return core;
}
};
#endif // NAOBEHAVIOR_H