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

Modules/BehaviorControl/GT2004BehaviorControl/GT2004BasicBehaviors/GT2004SimpleBasicBehaviors.cpp

Go to the documentation of this file.
00001 /** 
00002 * @file GT2004SimpleBasicBehaviors.cpp
00003 *
00004 * Implementation of basic behaviors defined in simple-basic-behaviors.xml.
00005 *
00006 * @author Uwe Düffert
00007 * @author Jan Hoffmann
00008 * @author Matthias Jüngel
00009 * @author Martin Lötzsch
00010 * @author Max Risler
00011 */
00012 
00013 #include "Tools/Math/PIDsmoothedValue.h"
00014 #include "GT2004SimpleBasicBehaviors.h"
00015 #include "Tools/Math/Geometry.h"
00016 #include "Tools/Math/Matrix2x2.h"
00017 #include "Tools/Math/Common.h"
00018 
00019 #include "Tools/Debugging/DebugDrawings.h"
00020 #include "Tools/Debugging/Debugging.h"
00021 
00022 //needed for dribbleInCenterOfField and getBehindBall2
00023 #include "Tools/FieldDimensions.h"
00024 
00025 void GT2004BasicBehaviorGoToBall::execute()
00026 {
00027   //accelerationRestrictor.saveLastWalkParameters();
00028   
00029   double targetAngle;
00030   
00031   if (maxSpeed == 0) maxSpeed = 350;
00032   if (maxSpeedY == 0) maxSpeed = 350;
00033   if (targetAngleToBall == 0) 
00034     targetAngle = 0;
00035   else 
00036     targetAngle = targetAngleToBall;
00037   
00038   
00039   double maxTurnSpeed;
00040   if (this->maxTurnSpeed == 0)
00041     maxTurnSpeed = fromDegrees(180);
00042   else
00043     maxTurnSpeed = fromDegrees(this->maxTurnSpeed);
00044   
00045   Vector2<double> ballInWorldCoord = ballModel.getKnownPosition(
00046     BallModel::behaviorControlTimeAfterWhichCommunicatedBallsAreAccepted);
00047   double angleToBall = Geometry::angleTo(robotPose.getPose(),ballInWorldCoord);
00048   double distanceToBall = Geometry::distanceTo(robotPose.getPose(),ballInWorldCoord);
00049   
00050   // if distance is between 400 and 600,
00051   // perform linear interpolation
00052   double factor = 1 - (distanceToBall - 400) / 200;
00053   if (factor > 1) factor = 1;
00054   if (factor < 0) factor = 0;
00055   
00056   //targetAngle *= factor;
00057   //angleToBall += targetAngle;  
00058   
00059   // destination = ball position in robot 
00060   // coordintes plus 200mm in x direction
00061   Vector2<double> destination(
00062     distanceToBall * cos(angleToBall) + 400, 
00063     distanceToBall * sin(angleToBall) + targetAngleToBall + yOffset);
00064   
00065   // adjust forward speed:
00066   // if a lot of turning is necessary, don't walk so fast!
00067   factor = (pi-fabs(angleToBall))/pi;
00068   if (factor > 1) factor = 1;
00069   if (factor < 0) factor = 0;
00070   
00071   destination.normalize();
00072   destination *= (maxSpeed*factor);
00073   
00074   /*
00075   factor = .2 + distanceToBall / 500;
00076   if (factor > 1) factor = 1;
00077   if (factor < 0) factor = 0;
00078   
00079     destination *= factor;
00080   */
00081   
00082   motionRequest.motionType = MotionRequest::walk;
00083   motionRequest.walkRequest.walkType   = static_cast<WalkRequest::WalkType>(static_cast<int>(walkType));
00084   motionRequest.walkRequest.walkParams.translation.x = destination.x;
00085   motionRequest.walkRequest.walkParams.translation.y = destination.y;
00086   
00087   if (motionRequest.walkRequest.walkParams.translation.y > maxSpeedY)
00088     motionRequest.walkRequest.walkParams.translation.y = maxSpeedY;
00089   
00090   factor = 1.5;
00091   /*
00092   factor = .2 + 1.5 * distanceToBall / 800;
00093   if (factor > 1.5) factor = 1.5;
00094   if (factor < 0) factor = 0;
00095   */
00096   motionRequest.walkRequest.walkParams.rotation = angleToBall * factor; /* this should also be factored!!!! */
00097   
00098   // clip rotation speed
00099   motionRequest.walkRequest.walkParams.rotation = min(motionRequest.walkRequest.walkParams.rotation, maxTurnSpeed);
00100   motionRequest.walkRequest.walkParams.rotation = max(motionRequest.walkRequest.walkParams.rotation, -maxTurnSpeed);  
00101 }
00102 
00103 void GT2004BasicBehaviorGoToBallWithoutTurning::execute()
00104 {
00105   if (maxSpeed == 0) maxSpeed = 250;
00106 
00107   Vector2<double> ballInWorldCoord = ballModel.getKnownPosition(
00108     BallModel::behaviorControlTimeAfterWhichCommunicatedBallsAreAccepted);
00109   double angleToBall = Geometry::angleTo(robotPose.getPose(),ballInWorldCoord);
00110   double distanceToBall = Geometry::distanceTo(robotPose.getPose(),ballInWorldCoord);
00111 
00112   Vector2<double> destination(
00113     distanceToBall * cos(angleToBall), 
00114     distanceToBall * sin(angleToBall) );
00115 
00116   destination.normalize();
00117   destination *= maxSpeed;
00118 
00119   motionRequest.motionType = MotionRequest::walk;
00120   motionRequest.walkRequest.walkType = WalkRequest::normal;  
00121   motionRequest.walkRequest.walkParams.translation.x = destination.x;
00122   motionRequest.walkRequest.walkParams.translation.y = destination.y;
00123   
00124   motionRequest.walkRequest.walkParams.rotation = 0;
00125 }
00126 
00127 void GT2004BasicBehaviorGoaliePosition::execute()
00128 {
00129   
00130   if (!basicBehaviorWasActiveDuringLastExecutionOfEngine) {
00131     goaliePose = lastRobotPose = robotPose;
00132     lastOdometry = odometryData;
00133   }
00134   
00135   // optional parameter initialising
00136   if (maxSpeed == 0 )
00137     maxSpeed = 150;
00138   
00139   //Aldi
00140   if (cutY == 0)
00141     cutY = 300; // max distance from middle of goal
00142   if (guardDirectToGoal == 0)
00143     guardDirectToGoal = 200; // if Ball.x distance to goal < this, goalie goes back to groundline
00144 
00145   if (guardLine == 0)
00146     guardLine = -150;
00147 
00148   // begin improved localization
00149   // use *goaliePose* instead of robotPose
00150   
00151   Pose2D diffPose;
00152   diffPose.translation = robotPose.translation - lastGoaliePose.translation;
00153   diffPose.rotation = (robotPose.rotation - lastGoaliePose.rotation);
00154 
00155   Pose2D diffOdo = odometryData - lastOdometry;
00156   Vector2<double> diffTranslation = (diffPose.translation*weightPose + diffOdo.translation*weightOdo);
00157 
00158   goaliePose.translation += diffTranslation;
00159   goaliePose.rotation += (diffPose.rotation*weightPose) + (diffOdo.rotation*weightOdo);
00160   
00161   CIRCLE(goaliePositionField, goaliePose.translation.x, goaliePose.translation.y, 200, 6, 0, Drawings::blue);
00162   CIRCLE(goaliePositionField, robotPose.translation.x, robotPose.translation.y, 180, 6, 0, Drawings::yellow);
00163   //CIRCLE(goaliePositionField, diffPose.translation.x, diffPose.translation.y, 140, 6, 0, Drawings::blue);
00164   //CIRCLE(goaliePositionField, diffOdo.translation.x, diffOdo.translation.y, 140, 6, 0, Drawings::red);
00165   //CIRCLE(goaliePositionField, diffTranslation.x, diffTranslation.y, 140, 6, 0, Drawings::yellow);
00166   
00167   // end improved localization
00168   
00169   // begin calculating guardPosition 
00170   Vector2<double> ballInWorldCoord = ballModel.getKnownPosition(
00171     BallModel::behaviorControlTimeAfterWhichCommunicatedBallsAreAccepted);
00172   double angleToBall = Geometry::angleTo(goaliePose,ballInWorldCoord);
00173   
00174   Vector2<double> guardPosition; //(Range<double>(-3000,3000),Range<double>(-200,200));
00175   
00176   // x-pos: Goalie stays *guardDirectToGoal* mm before goalline, except the half balldistance.x is shorter
00177   guardPosition.x = min(xPosOwnGroundline + guardDirectToGoal, xPosOwnGroundline - (xPosOwnGroundline-ballInWorldCoord.x)/2);
00178   
00179   
00180   //guardPosition.y = ballInWorldCoord.y / 2;
00181   
00182     //line from xPosOwnGroundline+guardLine   
00183   double deltaX = ballInWorldCoord.x - (xPosOwnGroundline+guardLine);
00184   double m = 0;
00185   if (deltaX != 0)
00186     m = ballInWorldCoord.y / deltaX;
00187   double n = ballInWorldCoord.y - m*ballInWorldCoord.x;
00188   
00189   guardPosition.y = m*goaliePose.translation.x + n;
00190   ARROW(goaliePositionField, xPosOwnGroundline+guardLine,0,ballInWorldCoord.x,ballInWorldCoord.y,6,0,Drawings::gray);
00191   Vector2<double> pointToGuard = ballInWorldCoord - Vector2<double>(xPosOwnGroundline,0);
00192   
00193   if (fabs(guardPosition.y) > cutY){
00194     guardPosition.y = min(cutY, guardPosition.y);
00195     guardPosition.y = max(-cutY, guardPosition.y);
00196     LINE(goaliePositionField,xPosOwnGroundline, guardPosition.y,-xPosOwnGroundline,guardPosition.y,6,0,Drawings::red);
00197   }
00198 
00199   if (xPosOwnGroundline-ballInWorldCoord.x > -guardDirectToGoal){
00200     guardPosition.x = xPosOwnGroundline+67;
00201     LINE (goaliePositionField,xPosOwnGroundline, 1000,xPosOwnGroundline+67, -1000,6,0,Drawings::red);
00202   }
00203   
00204   //guardPosition.normalize();
00205   
00206   CIRCLE(goaliePositionField, guardPosition.x, guardPosition.y, 150, 3, 0, Drawings::red);
00207   // end calculation guardPosition
00208   
00209   // begin calculation direction
00210   Vector2<double> direction = guardPosition - goaliePose.translation;
00211   Vector2<double> c1(cos(goaliePose.rotation), -sin(goaliePose.rotation)), 
00212     c2(sin(goaliePose.rotation), cos(goaliePose.rotation));
00213   Matrix2x2<double> rotate(c1, c2);
00214   
00215   direction = rotate*direction;
00216   if (direction.abs() > maxSpeed)
00217   {
00218     direction.normalize();
00219     direction *= maxSpeed;
00220   }
00221   
00222   double rotation = angleToBall;
00223   //end calculation direction
00224   
00225   // begin generation motionRequest with clipping
00226   // anti-zucking
00227   if( (fabs(rotation) < 0.2) && (abs(int(direction.x)) < minXTrans) && (abs(int(direction.y)) < minYTrans)){
00228     motionRequest.motionType = MotionRequest::stand;
00229   //  goaliePose = lastGoaliePose;
00230   }
00231   else 
00232   { 
00233     motionRequest.motionType = MotionRequest::walk;
00234     motionRequest.walkRequest.walkType = WalkRequest::normal;  
00235     if (!((abs(int(direction.x)) < minXTrans) && (abs(int(direction.y)) < minYTrans))){
00236       motionRequest.walkRequest.walkParams.translation.x = direction.x;
00237       motionRequest.walkRequest.walkParams.translation.y = direction.y;
00238     }
00239     if(!(fabs(rotation) < 0.2))
00240       motionRequest.walkRequest.walkParams.rotation = rotation; 
00241   }
00242   lastGoaliePose = goaliePose;
00243   lastOdometry = odometryData;
00244   lastRobotPose = robotPose;
00245   //end generation motion request
00246   DEBUG_DRAWING_FINISHED(goaliePositionField);  
00247 
00248 }
00249 
00250 void GT2004BasicBehaviorGoaliePositionReturn::execute()
00251 {
00252   Vector2<double> destination(x,y);
00253   const Vector2<double>& self = robotPose.translation;
00254   
00255   double distanceToDestination = Geometry::distanceTo(self,destination);
00256   
00257   double angleDifference = normalize(fromDegrees(destinationAngle) - robotPose.rotation);
00258   
00259   if ((fabs(toDegrees(angleDifference))<25)&&(distanceToDestination<90))
00260   {
00261     motionRequest.motionType = MotionRequest::stand;
00262   }
00263   else
00264   {
00265     accelerationRestrictor.saveLastWalkParameters();
00266     
00267     if (maxSpeed==0) maxSpeed = 200;
00268     
00269     double maxTurnSpeed = fromDegrees(90);
00270     
00271     double angleToDestination = Geometry::angleTo(robotPose,destination);
00272     
00273     motionRequest.motionType = MotionRequest::walk;
00274     motionRequest.walkRequest.walkType = WalkRequest::normal;
00275     
00276     //this time does not necessarily include time for turning!:
00277     
00278     if (distanceToDestination > 200)
00279     {
00280       motionRequest.walkRequest.walkParams.translation.x = cos(angleToDestination) * maxSpeed;
00281       motionRequest.walkRequest.walkParams.translation.y = sin(angleToDestination) * maxSpeed;
00282     }
00283     else
00284     {
00285       motionRequest.walkRequest.walkParams.translation.x = 
00286         cos(angleToDestination) * maxSpeed*distanceToDestination/200;
00287       motionRequest.walkRequest.walkParams.translation.y = 
00288         sin(angleToDestination) * maxSpeed*distanceToDestination/200;
00289     }
00290     
00291     
00292     motionRequest.walkRequest.walkParams.rotation = angleDifference * 2;
00293     
00294     if (motionRequest.walkRequest.walkParams.rotation < -maxTurnSpeed)
00295       motionRequest.walkRequest.walkParams.rotation = -maxTurnSpeed;
00296     
00297     if (motionRequest.walkRequest.walkParams.rotation > maxTurnSpeed)
00298       motionRequest.walkRequest.walkParams.rotation = maxTurnSpeed;
00299     
00300     
00301     
00302     accelerationRestrictor.restrictAccelerations(150,150,100);
00303   }
00304   
00305 }
00306 void GT2004BasicBehaviorTurnAroundPoint::execute()
00307 {
00308   double maxTurnSpeed = fromDegrees(240);
00309   if (forwardComponent == 0) forwardComponent = 200.0;
00310   
00311   Vector2<double> destinationInWorldCoord(x,y);
00312   double angleToDestination = Geometry::angleTo(robotPose.getPose(), destinationInWorldCoord);
00313   double distance = Geometry::distanceTo(robotPose.getPose(), destinationInWorldCoord);
00314   
00315   // destination = ball position in robot 
00316   // coordintes plus 100mm in x direction
00317   Vector2<double> destination(
00318     distance * cos(angleToDestination), 
00319     distance * sin(angleToDestination));
00320   
00321   double factor = 
00322     Range<double>::Range(0, 1).
00323       limit((distance - radius) / (3*radius));
00324 
00325   destination *= factor;
00326   destination.y += (leftRight > 0 ? 1 : -1)*(200)*(1-factor);
00327   
00328   if (destination.x < forwardComponent)   
00329     destination.x = forwardComponent;
00330   
00331   double slowDownForMuchTurning = 
00332     Range<double>::Range(0.1, 1).limit
00333     ((pi-fabs(angleToDestination))/pi);
00334 
00335   motionRequest.motionType = MotionRequest::walk;
00336   motionRequest.walkRequest.walkType = WalkRequest::normal;  
00337   motionRequest.walkRequest.walkParams.translation.x = destination.x * slowDownForMuchTurning;
00338   motionRequest.walkRequest.walkParams.translation.y = destination.y * slowDownForMuchTurning;
00339   
00340   // set rotation speed in range
00341   motionRequest.walkRequest.walkParams.rotation = 
00342     Range<double>::Range(-maxTurnSpeed, maxTurnSpeed).
00343     limit(angleToDestination + .6*(leftRight > 0 ? -1 : 1)*(1-factor));
00344 }
00345 
00346 void GT2004BasicBehaviorGoForwardToPoint::execute()
00347 {
00348   accelerationRestrictor.saveLastWalkParameters();
00349   
00350   Vector2<double> destination(x,y);
00351   
00352   if (maxSpeed == 0) maxSpeed = 350;
00353   
00354   double maxTurnSpeed = fromDegrees(120);
00355   
00356   double angleToDestination = Geometry::angleTo(robotPose,destination);
00357   
00358   
00359   motionRequest.motionType = MotionRequest::walk;
00360   motionRequest.walkRequest.walkType = WalkRequest::normal;
00361   
00362   motionRequest.walkRequest.walkParams.translation.x = cos(angleToDestination) * maxSpeed;
00363   motionRequest.walkRequest.walkParams.translation.y = sin(angleToDestination) * maxSpeed;
00364   
00365   motionRequest.walkRequest.walkParams.rotation = angleToDestination*2;
00366   if (motionRequest.walkRequest.walkParams.rotation > maxTurnSpeed)
00367   {
00368     motionRequest.walkRequest.walkParams.rotation = maxTurnSpeed;
00369   }
00370   if (motionRequest.walkRequest.walkParams.rotation < -maxTurnSpeed) 
00371   {
00372     motionRequest.walkRequest.walkParams.rotation = -maxTurnSpeed;
00373   }
00374   
00375   accelerationRestrictor.restrictAccelerations(300,300,200);
00376   
00377 }
00378 
00379 void GT2004BasicBehaviorGoToPointAndAvoidObstacles::execute()
00380 {
00381   double 
00382     obstacleAvoidanceDistance,
00383     distanceToDestination = Geometry::distanceTo(robotPose.getPose(),Vector2<double>(x,y)),
00384     angleToDestination = Geometry::angleTo(robotPose.getPose(),Vector2<double>(x,y)),
00385     targetSpeed, targetAngle, 
00386     freeSpaceInFront,
00387     widthOfCorridor,
00388     minSpeed,
00389     distanceBelowWhichObstaclesAreAvoided;
00390   
00391   // reset PIDs if last execution is long ago
00392   if (SystemCall::getTimeSince(lastTimeExecuted) > 500)
00393   {
00394     speedX.resetTo(100);
00395     speedY.resetTo(0);
00396     turnSpeed.resetTo(0); 
00397   }
00398   lastTimeExecuted = SystemCall::getCurrentSystemTime();
00399   
00400   if (maxSpeed == 0) maxSpeed = 350;
00401     
00402   // avoidance level:
00403   // 0 = rugby (very little avoidance)
00404   // 1 = football (medium...)
00405   // 2 = standard, stay clear of obstacles
00406   
00407 //  switch((int)avoidanceLevel)
00408 //  {
00409 //  case 0: widthOfCorridor = 150; break;
00410 //  case 1: widthOfCorridor = 200; break;
00411 //  case 2: 
00412 //  default: widthOfCorridor = 250; break;
00413 //  }
00414   
00415   widthOfCorridor = 250;
00416   
00417   distanceBelowWhichObstaclesAreAvoided = 500;
00418   minSpeed = -150;
00419   
00420   // perform clipping ...
00421   obstacleAvoidanceDistance = Range<double>::Range(0, distanceBelowWhichObstaclesAreAvoided).limit(distanceToDestination);
00422   
00423   // derive the forward speed of the robot
00424   // from the free range in front of the robot
00425   freeSpaceInFront = obstaclesModel.getDistanceInCorridor(0.0, widthOfCorridor);
00426   targetSpeed = Range<double>::Range(minSpeed, maxSpeed).limit(freeSpaceInFront - 300);
00427   
00428   // default: head to where there's more free space (necessary when close to obstacles!)
00429   double leftForward = obstaclesModel.getTotalFreeSpaceInSector(.7, 1.39, obstacleAvoidanceDistance);
00430   double rightForward = obstaclesModel.getTotalFreeSpaceInSector(-.7, 1.39, obstacleAvoidanceDistance);
00431   targetAngle = (leftForward - rightForward) / (leftForward + rightForward);
00432       
00433   // determine the next free sector in the desired direction
00434   double nextFree = obstaclesModel.getAngleOfNextFreeSector(pi/4, angleToDestination, (int )obstacleAvoidanceDistance);
00435   
00436   // check if there is enough space in the direction of "nextFree"
00437   if (obstaclesModel.getDistanceInCorridor(nextFree, widthOfCorridor) > obstacleAvoidanceDistance)
00438   {
00439     if (fabs(nextFree) < .8)
00440       targetAngle = nextFree;
00441   } 
00442   
00443   // double check: if there's enough space in the direction of the destination, directly head there 
00444   if (obstaclesModel.getDistanceInCorridor(angleToDestination, widthOfCorridor) > obstacleAvoidanceDistance)
00445     targetAngle = angleToDestination;
00446     
00447   // what is this good for?
00448   //if(obstaclesModel.getDistanceInCorridor((double)sgn(targetAngle) * pi/2, distanceBelowWhichObstaclesAreAvoided/2) < 100)
00449   //{
00450   //  targetSpeed = maxSpeed;
00451   //  targetAngle = 0;  
00452   //}
00453   
00454   // adjust forward speed: if a lot of turning is required, reduce the forward speed!
00455   if (targetSpeed == maxSpeed)
00456     targetSpeed *= Range<double>::Range(0.1, 1).limit( 
00457       (pi-fabs(targetAngle))/pi );
00458 
00459   // if at destination, stop
00460   if (distanceToDestination < 150)
00461   {
00462     motionRequest.motionType = MotionRequest::stand;
00463   }
00464   else
00465   {
00466     motionRequest.motionType = MotionRequest::walk;
00467     motionRequest.walkRequest.walkType = WalkRequest::normal;
00468     motionRequest.walkRequest.walkParams.translation.x = speedX.approximateVal(targetSpeed);
00469     motionRequest.walkRequest.walkParams.translation.y = speedY.approximateVal(0);
00470     motionRequest.walkRequest.walkParams.rotation = turnSpeed.approximateVal(2*targetAngle);
00471   }
00472 }
00473 
00474 
00475 
00476 void GT2004BasicBehaviorGoToPoint::execute()
00477 {
00478   accelerationRestrictor.saveLastWalkParameters();
00479   
00480   Vector2<double> destination(x,y);
00481   const Vector2<double>& self = robotPose.translation;
00482   
00483   if (maxSpeed==0) maxSpeed = 350;
00484   if (maxSpeedY==0) maxSpeedY = 350;
00485   
00486   double maxTurnSpeed = fromDegrees(40);
00487   
00488   double distanceToDestination = Geometry::distanceTo(self,destination);
00489   
00490   double angleDifference = normalize(fromDegrees(destinationAngle) - robotPose.rotation);
00491   
00492   double angleToDestination = Geometry::angleTo(robotPose,destination);
00493   
00494   
00495   motionRequest.motionType = MotionRequest::walk;
00496   motionRequest.walkRequest.walkType = static_cast<WalkRequest::WalkType>(static_cast<int>(walkType));
00497   
00498   //this time does not necessarily include time for turning!:
00499   double estimatedTimeToReachDestination;
00500   if (distanceToDestination > 200)
00501   {
00502     estimatedTimeToReachDestination = (distanceToDestination+200) / maxSpeed;
00503     
00504     motionRequest.walkRequest.walkParams.translation.x = cos(angleToDestination) * maxSpeed;
00505     motionRequest.walkRequest.walkParams.translation.y = sin(angleToDestination) * maxSpeed;
00506   }
00507   else
00508   {
00509     estimatedTimeToReachDestination = 2*distanceToDestination / maxSpeed + 2*fabs(angleDifference) / maxTurnSpeed;
00510 //     OUTPUT (idText, text, "Time2ReachDestination previous: " << 
00511 //      2*distanceToDestination / maxSpeed << "\nTime2ReachDestination now: " << estimatedTimeToReachDestination);
00512     
00513     if (distanceToDestination > 30)
00514     {
00515       motionRequest.walkRequest.walkParams.translation.x = 
00516         cos(angleToDestination) * maxSpeed * distanceToDestination/200;
00517       motionRequest.walkRequest.walkParams.translation.y = 
00518         sin(angleToDestination) * maxSpeed * distanceToDestination/200;
00519     }
00520     else
00521     {
00522       motionRequest.walkRequest.walkParams.translation.x = 0;
00523       motionRequest.walkRequest.walkParams.translation.y = 0;
00524     }
00525   }
00526 
00527   // If the estimated time is 0, position is already reached, so nothing has to be done anymore
00528   if (estimatedTimeToReachDestination != 0)
00529   {
00530   /* 
00531   {
00532     estimatedTimeToReachDestination = 0.001;
00533   }
00534   */
00535   
00536     if (fabs(toDegrees(angleDifference)) > 20)
00537     {
00538       motionRequest.walkRequest.walkParams.rotation =
00539         angleDifference / estimatedTimeToReachDestination;
00540       motionRequest.walkRequest.walkParams.rotation =
00541         min (maxTurnSpeed, motionRequest.walkRequest.walkParams.rotation);
00542       motionRequest.walkRequest.walkParams.rotation =
00543         max (-maxTurnSpeed, motionRequest.walkRequest.walkParams.rotation);
00544     }
00545     else
00546     {
00547       motionRequest.walkRequest.walkParams.rotation = 2*angleDifference;
00548     }
00549     
00550     /*
00551     if (motionRequest.walkRequest.walkParams.translation.y > maxSpeedY)
00552     motionRequest.walkRequest.walkParams.translation.y = maxSpeedY;
00553     */
00554 
00555     motionRequest.walkRequest.walkParams.translation.y =
00556       min (maxSpeedY, motionRequest.walkRequest.walkParams.translation.y);
00557     
00558     if ((fabs(toDegrees(angleDifference))<angleRemain)&&(distanceToDestination<distanceRemain))
00559     {
00560       motionRequest.walkRequest.walkParams.translation.x = 0;
00561       motionRequest.walkRequest.walkParams.translation.y = 0;
00562       motionRequest.walkRequest.walkParams.rotation = 0;
00563     }
00564     
00565     accelerationRestrictor.restrictAccelerations(150,150,100);
00566     
00567   } // if (estimatedTime != 0)
00568   else  //only to be sure the robot won't move if desired position is reached
00569   {
00570     motionRequest.walkRequest.walkParams.translation.x = 0;
00571     motionRequest.walkRequest.walkParams.translation.y = 0;
00572     motionRequest.walkRequest.walkParams.rotation = 0;
00573   }
00574 }
00575 
00576 
00577 
00578 void GT2004BasicBehaviorMoveTheBridge::execute()
00579 {
00580   outgoingBehaviorTeamMessage.walkRequest.type = type;
00581   outgoingBehaviorTeamMessage.walkRequest.x = x;
00582   if (outgoingBehaviorTeamMessage.walkRequest.x > 50)
00583     outgoingBehaviorTeamMessage.walkRequest.x = 50;
00584   if (outgoingBehaviorTeamMessage.walkRequest.x < -50)
00585     outgoingBehaviorTeamMessage.walkRequest.x = -50;
00586   
00587   outgoingBehaviorTeamMessage.walkRequest.y = y;
00588   if (outgoingBehaviorTeamMessage.walkRequest.y > 50)
00589     outgoingBehaviorTeamMessage.walkRequest.y = 50;
00590   if (outgoingBehaviorTeamMessage.walkRequest.y < -50)
00591     outgoingBehaviorTeamMessage.walkRequest.y = -50;
00592   
00593   outgoingBehaviorTeamMessage.walkRequest.rotation = rotation;
00594   if (outgoingBehaviorTeamMessage.walkRequest.rotation > 2)
00595     outgoingBehaviorTeamMessage.walkRequest.rotation = 2;
00596   if (outgoingBehaviorTeamMessage.walkRequest.rotation < -2)
00597     outgoingBehaviorTeamMessage.walkRequest.rotation = -2;
00598 }
00599 
00600 void GT2004BasicBehaviorDogAsJoystick::execute()
00601 {
00602   
00603 /*  headControlMode.pidData.setValues(JointData::legFR1,0,0,0);
00604 pidData.setValues(JointData::legFR2,0,0,0);
00605 pidData.setValues(JointData::legFL1,0,0,0);
00606 pidData.setValues(JointData::legFL2,0,0,0);
00607   */
00608   double tmpr1 = toDegrees(fromMicroRad(sensorDataBuffer.lastFrame().data[SensorData::legFR1]));
00609   double tmpr2 = toDegrees(fromMicroRad(sensorDataBuffer.lastFrame().data[SensorData::legFR2]));
00610   //double tmpr3 = toDegrees(fromMicroRad(sensorDataBuffer.lastFrame().data[SensorData::legFR3]));
00611   double tmpl1 = toDegrees(fromMicroRad(sensorDataBuffer.lastFrame().data[SensorData::legFL1]));
00612   double tmpl2 = toDegrees(fromMicroRad(sensorDataBuffer.lastFrame().data[SensorData::legFL2]));
00613   //double tmpl3 = toDegrees(fromMicroRad(sensorDataBuffer.lastFrame().data[SensorData::legFL3]));
00614   
00615   outgoingBehaviorTeamMessage.walkRequest.type = 0;
00616   outgoingBehaviorTeamMessage.walkRequest.x = (tmpr1+tmpl1)*2.5;
00617   outgoingBehaviorTeamMessage.walkRequest.y = (tmpr2-tmpl2)*2.5;
00618   //  outgoingBehaviorTeamMessage.walkRequest.rotation = (tmpl1-tmpr1)/2  ;
00619   outgoingBehaviorTeamMessage.walkRequest.rotation = (tmpl1-tmpr1)/20  ;
00620 }
00621 
00622 /*
00623 * Change Log
00624 * 
00625 * $Log: GT2004SimpleBasicBehaviors.cpp,v $
00626 * Revision 1.32  2004/07/20 21:56:45  spranger
00627 * reintroduced martin loetzschs goalie-position for the return states in playing-goalie
00628 *
00629 * Revision 1.31  2004/07/20 14:16:28  spranger
00630 * removed intercept-at-x and intercept-test-batchman
00631 *
00632 * Revision 1.30  2004/07/16 15:30:35  goetzke
00633 * converted "goalie-position-benjamin" in "goalie-position"
00634 *
00635 * Revision 1.29  2004/07/01 09:08:46  jhoffman
00636 * - parameter tweaking in turn around point
00637 *
00638 * Revision 1.28  2004/06/30 16:16:15  jhoffman
00639 * - state removed from "get-to-position-and-avoid-obstacles" because basic behavior now does the turning
00640 * - basic behavior "go-to-point-and-avoide-obstacles" improved (faster, stops when destination is reached)
00641 *
00642 * Revision 1.27  2004/06/30 10:42:28  spranger
00643 * renamed goalie-clear-ball to tun-without-ball
00644 *
00645 * Revision 1.26  2004/06/29 18:13:08  altmeyer
00646 * adjust parameters in GoaliePosititonBenjamin
00647 *
00648 * Revision 1.25  2004/06/29 17:51:41  schmitt
00649 * goToPoint
00650 * - rotation time is now considered in estimatedTime
00651 * - simplified some calculations
00652 *
00653 * Revision 1.24  2004/06/29 10:10:53  altmeyer
00654 * adjust paramaters goalie-benjamin
00655 *
00656 * Revision 1.23  2004/06/28 19:51:29  altmeyer
00657 * adjust goalie-position-benjamin parameters
00658 *
00659 * Revision 1.22  2004/06/27 17:00:07  altmeyer
00660 * fixed warning
00661 *
00662 * Revision 1.21  2004/06/27 16:36:01  altmeyer
00663 * improved GoaliePositionBenjamin
00664 *
00665 * Revision 1.20  2004/06/27 14:59:23  goehring
00666 * goToPoint has parameter distanceRemain and angleRemain
00667 *
00668 * Revision 1.19  2004/06/27 14:53:51  altmeyer
00669 * new GoaliePositionBenjamin and new debug key send_goaliePositionField
00670 *
00671 * Revision 1.18  2004/06/23 20:59:04  juengel
00672 * Added basicBehaviorGoalieClearBall.
00673 *
00674 * Revision 1.17  2004/06/23 16:19:27  loetzsch
00675 * reactivated and improved old ath goalie
00676 *
00677 * Revision 1.16  2004/06/18 10:56:33  altmeyer
00678 * improved goalie-position
00679 *
00680 * Revision 1.15  2004/06/18 00:32:18  risler
00681 * added walk-type to go-to-point
00682 * added max-speed.y to go-to-ball and go-to-point
00683 *
00684 * Revision 1.14  2004/06/17 15:54:04  altmeyer
00685 * fixed warning
00686 *
00687 * Revision 1.13  2004/06/17 15:30:04  altmeyer
00688 * new GoaliePosition (Parameters, Motion-Glätting ;-)
00689 *
00690 * Revision 1.12  2004/06/16 17:35:04  altmeyer
00691 * added GoaliePosition (author: Jan Hoffmann)
00692 *
00693 * Revision 1.11  2004/06/15 16:15:40  risler
00694 * added go-to-ball parameters max-turn-speed and walk-type
00695 *
00696 * Revision 1.10  2004/06/02 17:18:23  spranger
00697 * MotionRequest cleanup
00698 *
00699 * Revision 1.9  2004/05/27 18:49:17  kerdels
00700 * added a small 5 frames sliding average for the relative ballspeed,
00701 * added new ballState Representation and adjusted the apropriate files
00702 *
00703 * Revision 1.8  2004/05/26 19:19:29  spranger
00704 * added yOffset to go-to-ball basicbehavior
00705 *
00706 * Revision 1.7  2004/05/25 14:19:19  kerdels
00707 * adjusted intercept-at-x
00708 *
00709 * Revision 1.6  2004/05/25 09:58:20  huelsbusch
00710 * intercept added
00711 *
00712 * Revision 1.5  2004/05/25 09:35:50  kerdels
00713 * intercept at x ...
00714 *
00715 * Revision 1.4  2004/05/24 16:58:25  kerdels
00716 * intercept at x added
00717 *
00718 * Revision 1.3  2004/05/24 16:31:24  loetzsch
00719 * added basic behavior intercept-batch-man
00720 *
00721 * Revision 1.2  2004/05/22 20:44:16  juengel
00722 * Renamed ballP_osition to ballModel.
00723 *
00724 * Revision 1.1.1.1  2004/05/22 17:18:01  cvsadm
00725 * created new repository GT2004_WM
00726 *
00727 * Revision 1.5  2004/05/14 22:53:07  roefer
00728 * Warnings removed
00729 *
00730 * Revision 1.4  2004/05/13 22:11:38  hamerla
00731 * OpenChallenge use a dog as joystick for the bridgemove
00732 *
00733 * Revision 1.3  2004/05/08 16:18:13  hamerla
00734 * Open Challenge
00735 *
00736 * Revision 1.2  2004/05/04 10:48:58  loetzsch
00737 * replaced all enums
00738 * xxxBehaviorControlTimeAfterWhichCommunicatedBallsAreAccepted
00739 * by
00740 * behaviorControlTimeAfterWhichCommunicatedBallsAreAccepted
00741 * (this mechanism was neither fully implemented nor used)
00742 *
00743 * Revision 1.1  2004/05/02 13:24:39  juengel
00744 * Added GT2004BehaviorControl.
00745 *
00746 */
00747 

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