00001
00002
00003
00004
00005
00006
00007
00008
00009 #include "GT2004PotentialFieldBasicBehaviors.h"
00010 #include "Tools/FieldDimensions.h"
00011
00012
00013 GT2004PotentialFieldBasicBehaviorGoToPose::GT2004PotentialFieldBasicBehaviorGoToPose(const BehaviorControlInterfaces& interfaces,
00014 Xabsl2ErrorHandler& errorHandler):
00015 GT2004PotentialFieldBasicBehavior(interfaces, errorHandler, "potential-field-go-to-pose","GT2004/gotopose.pfc")
00016 {
00017 registerParameter("potential-field-go-to-pose.x", x);
00018 registerParameter("potential-field-go-to-pose.y", y);
00019 registerParameter("potential-field-go-to-pose.destination-angle", destinationAngle);
00020 registerParameter("potential-field-go-to-pose.max-speed", maxSpeed);
00021 }
00022
00023
00024 void GT2004PotentialFieldBasicBehaviorGoToPose::execute()
00025 {
00026 Pose2D destination1(fromDegrees(destinationAngle),x,y);
00027 Pose2D dummyDestination;
00028 potentialfields.execute(robotPose, ballModel, playerPoseCollection,
00029 obstaclesModel, teamMessageCollection, destination1, dummyDestination, 1, result);
00030
00031 motionRequest.motionType = MotionRequest::walk;
00032 motionRequest.walkRequest.walkType = WalkRequest::normal;
00033 Vector2<double> relVec(-robotPose.translation + destination1.translation);
00034 double distanceToPoint(relVec.abs());
00035 if(result.action == "do-turn")
00036 {
00037 double rotationDifference = destination1.rotation - robotPose.rotation;
00038 while(rotationDifference>pi) rotationDifference -= 2*pi;
00039 while(rotationDifference<-pi) rotationDifference += 2*pi;
00040 if(fabs(toDegrees(rotationDifference))<10)
00041 {
00042 if(distanceToPoint < 50.0)
00043 {
00044 motionRequest.motionType = MotionRequest::stand;
00045 }
00046 else
00047 {
00048 double ca(cos(-robotPose.rotation));
00049 double sa(sin(-robotPose.rotation));
00050 double newX(relVec.x*ca - relVec.y*sa);
00051 relVec.y = relVec.y*ca + relVec.x*sa;
00052 relVec.x = newX;
00053 motionRequest.walkRequest.walkParams.translation = relVec;
00054 motionRequest.walkRequest.walkParams.translation.normalize();
00055 motionRequest.walkRequest.walkParams.translation *= 60.0;
00056 motionRequest.walkRequest.walkParams.rotation = 0;
00057 }
00058 }
00059 else
00060 {
00061 motionRequest.walkRequest.walkParams.translation.x = 0;
00062 motionRequest.walkRequest.walkParams.translation.y = 0;
00063 motionRequest.walkRequest.walkParams.rotation = rotationDifference;
00064 if(fabs(toDegrees(rotationDifference)) < 30.0)
00065 {
00066 motionRequest.walkRequest.walkParams.rotation /= fabs(rotationDifference);
00067 motionRequest.walkRequest.walkParams.rotation *= fromDegrees(30.0);
00068 }
00069 }
00070 }
00071 else
00072 {
00073 motionRequest.walkRequest.walkParams.translation.x = maxSpeed * result.motion.pos.x;
00074 motionRequest.walkRequest.walkParams.translation.y = maxSpeed * result.motion.pos.y;
00075 motionRequest.walkRequest.walkParams.rotation = result.motion.rotation;
00076 if(distanceToPoint < 150)
00077 {
00078 motionRequest.walkRequest.walkParams.translation.x /= 3.0;
00079 motionRequest.walkRequest.walkParams.translation.y /= 3.0;
00080 }
00081 if(fabs(toDegrees(motionRequest.walkRequest.walkParams.rotation)) > 60)
00082 {
00083 motionRequest.walkRequest.walkParams.translation.x = 0;
00084 motionRequest.walkRequest.walkParams.translation.y = 0;
00085 }
00086 }
00087 }
00088
00089
00090 GT2004PotentialFieldBasicBehaviorSupport::GT2004PotentialFieldBasicBehaviorSupport(
00091 const BehaviorControlInterfaces& interfaces,
00092 Xabsl2ErrorHandler& errorHandler):
00093 GT2004PotentialFieldBasicBehavior(interfaces, errorHandler, "potential-field-support","GT2004/support.pfc")
00094 {
00095 registerParameter("potential-field-support.x", x);
00096 registerParameter("potential-field-support.y", y);
00097 registerParameter("potential-field-support.max-speed", maxSpeed);
00098 }
00099
00100
00101 void GT2004PotentialFieldBasicBehaviorSupport::execute()
00102 {
00103 Pose2D destination(0.0,x,y);
00104 Pose2D dummy;
00105 potentialfields.execute(robotPose, ballModel, playerPoseCollection,
00106 obstaclesModel, teamMessageCollection, destination, dummy, 1, result);
00107 motionRequest.motionType = MotionRequest::walk;
00108 motionRequest.walkRequest.walkType = WalkRequest::normal;
00109
00110 Vector2<double> relVec(-robotPose.translation + destination.translation);
00111 double distanceToPoint(relVec.abs());
00112 if(fabs(result.motion.speed) > 1.0) result.motion.speed = 1.0;
00113 motionRequest.walkRequest.walkParams.translation.x = maxSpeed * result.motion.speed * result.motion.pos.x;
00114 motionRequest.walkRequest.walkParams.translation.y = maxSpeed * result.motion.speed * result.motion.pos.y;
00115 motionRequest.walkRequest.walkParams.rotation = result.motion.rotation;
00116 if((distanceToPoint < 50.0) && fabs(toDegrees(result.motion.rotation)) < 15)
00117 {
00118 motionRequest.motionType = MotionRequest::stand;
00119 }
00120 else if(distanceToPoint < 50.0)
00121 {
00122 motionRequest.walkRequest.walkParams.translation.x = 0.0;
00123 motionRequest.walkRequest.walkParams.translation.y = 0.0;
00124 }
00125 else if(distanceToPoint < 150)
00126 {
00127 motionRequest.walkRequest.walkParams.translation.x /= 3.0;
00128 motionRequest.walkRequest.walkParams.translation.y /= 3.0;
00129 }
00130 }
00131
00132
00133 GT2004PotentialFieldBasicBehaviorOffensiveSupport::GT2004PotentialFieldBasicBehaviorOffensiveSupport(
00134 const BehaviorControlInterfaces& interfaces,
00135 Xabsl2ErrorHandler& errorHandler):
00136 GT2004PotentialFieldBasicBehavior(interfaces, errorHandler, "potential-field-offensive-support","GT2004/offsupp.pfc")
00137 {
00138 registerParameter("potential-field-offensive-support.x", x);
00139 registerParameter("potential-field-offensive-support.y", y);
00140 registerParameter("potential-field-offensive-support.max-speed", maxSpeed);
00141 }
00142
00143
00144 void GT2004PotentialFieldBasicBehaviorOffensiveSupport::execute()
00145 {
00146 Pose2D destination(0.0,x,y);
00147
00148 Pose2D destination2;
00149 Vector2<double> knownBallPos(ballModel.getKnownPosition(BallModel::behaviorControlTimeAfterWhichCommunicatedBallsAreAccepted));
00150 Vector2<double> knownBallPosRobotRelative(Geometry::vectorTo(robotPose, knownBallPos));
00151 Vector2<double> rP(robotPose.translation);
00152
00153 Vector2<double> absGoalVec((double)xPosOpponentGoal,0.0);
00154
00155
00156
00157
00158
00159
00160
00161
00162
00163
00164
00165 destination2.translation = knownBallPos;
00166
00167 potentialfields.execute(robotPose, ballModel, playerPoseCollection,
00168 obstaclesModel, teamMessageCollection, destination, destination2, 2, result);
00169
00170 motionRequest.motionType = MotionRequest::walk;
00171 motionRequest.walkRequest.walkType = WalkRequest::normal;
00172
00173 Vector2<double> relVec(-robotPose.translation + destination.translation);
00174 double distanceToPoint(relVec.abs());
00175 if(fabs(result.motion.speed) > 1.0) result.motion.speed = 1.0;
00176 motionRequest.walkRequest.walkParams.translation.x = maxSpeed * result.motion.speed * result.motion.pos.x;
00177 motionRequest.walkRequest.walkParams.translation.y = maxSpeed * result.motion.speed * result.motion.pos.y;
00178 motionRequest.walkRequest.walkParams.rotation = result.motion.rotation;
00179 if((distanceToPoint < 50.0) && fabs(toDegrees(result.motion.rotation)) < 15)
00180 {
00181 motionRequest.motionType = MotionRequest::stand;
00182 }
00183 else if(distanceToPoint < 50.0)
00184 {
00185 motionRequest.walkRequest.walkParams.translation.x = 0.0;
00186 motionRequest.walkRequest.walkParams.translation.y = 0.0;
00187 }
00188 else if(distanceToPoint < 150)
00189 {
00190 motionRequest.walkRequest.walkParams.translation.x /= 3.0;
00191 motionRequest.walkRequest.walkParams.translation.y /= 3.0;
00192 }
00193 }
00194
00195
00196 void GT2004PotentialFieldBasicBehaviors::registerBasicBehaviors(Xabsl2Engine& engine)
00197 {
00198 engine.registerBasicBehavior(potentialFieldGoToPose);
00199 engine.registerBasicBehavior(potentialFieldSupport);
00200 engine.registerBasicBehavior(potentialFieldOffensiveSupport);
00201 }
00202
00203
00204 void GT2004PotentialFieldBasicBehaviors::update()
00205 {
00206 }
00207
00208
00209
00210
00211
00212
00213
00214
00215
00216
00217
00218
00219
00220
00221
00222
00223
00224
00225
00226
00227
00228
00229
00230
00231
00232