Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members | Related Pages

Modules/BehaviorControl/GT2004BehaviorControl/GT2004BasicBehaviors/GT2004PotentialFieldBasicBehaviors.cpp

Go to the documentation of this file.
00001 /** 
00002 * @file GT2004PotentialFieldBasicBehaviors.cpp
00003 *
00004 * Implementation of basic behaviors defined in potential-field-basic-behaviors.xml.
00005 *
00006 * @author <a href="mailto:timlaue@tzi.de">Tim Laue</a>
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   //Compute a position to rotate to:
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   //double relAngleToBall(Vector2<double>(knownBallPos-rP).angle());
00153   Vector2<double> absGoalVec((double)xPosOpponentGoal,0.0);
00154   //double relAngleToGoal((absGoalVec-rP).angle());
00155  /* if(fabs( relAngleToBall - relAngleToGoal) < pi/2)
00156   {
00157     double desAngle(((relAngleToBall + relAngleToGoal) /2) - (fabs(relAngleToBall) < fabs(relAngleToGoal) ? relAngleToBall:relAngleToGoal));
00158     destination2.translation = Geometry::vectorTo(robotPose, Vector2<double>(rP.x+cos(desAngle),rP.y+sin(desAngle)));
00159   }
00160 
00161   else
00162   {
00163      destination2.translation = knownBallPosRobotRelative;
00164   }*/
00165   destination2.translation = knownBallPos;
00166   //Execute potential field behavior:
00167   potentialfields.execute(robotPose, ballModel, playerPoseCollection, 
00168                           obstaclesModel, teamMessageCollection, destination, destination2, 2, result);
00169   //Set motion request:
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 * $Log: GT2004PotentialFieldBasicBehaviors.cpp,v $
00210 * Revision 1.7  2004/09/08 14:39:02  wachter
00211 * - Fixed some doxygen-errors
00212 *
00213 * Revision 1.6  2004/07/01 12:27:45  dassler
00214 * removed warning
00215 *
00216 * Revision 1.5  2004/06/18 11:18:09  tim
00217 * temporary workaound
00218 *
00219 * Revision 1.4  2004/06/17 16:18:38  tim
00220 * added potential field support behaviors
00221 *
00222 * Revision 1.3  2004/06/16 15:09:58  tim
00223 * added potential field support behavior
00224 *
00225 * Revision 1.2  2004/06/02 17:18:23  spranger
00226 * MotionRequest cleanup
00227 *
00228 * Revision 1.1  2004/05/25 12:59:39  tim
00229 * added potential-field-go-to-pose
00230 *
00231 */
00232 

Generated on Thu Sep 23 19:57:26 2004 for GT2004 by doxygen 1.3.6