00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026 #include "ArExport.h"
00027 #include "ariaOSDef.h"
00028 #include "ArActionLimiterBackwards.h"
00029 #include "ArRobot.h"
00030
00039 AREXPORT ArActionLimiterBackwards::ArActionLimiterBackwards(
00040 const char *name, double stopDistance, double slowDistance,
00041 double maxBackwardsSpeed, double widthRatio) :
00042 ArAction(name,
00043 "Slows the robot down so as not to hit anything in front of it.")
00044 {
00045 setNextArgument(ArArg("stop distance", &myStopDist,
00046 "Distance at which to stop. (mm)"));
00047 myStopDist = stopDistance;
00048
00049 setNextArgument(ArArg("slow distance", &mySlowDist,
00050 "Distance at which to slow down. (mm)"));
00051 mySlowDist = slowDistance;
00052
00053 setNextArgument(ArArg("maximum backwards speed", &myMaxBackwardsSpeed,
00054 "Maximum backwards speed, scales from this to 0 at stopDistance (-mm/sec)"));
00055 myMaxBackwardsSpeed = maxBackwardsSpeed;
00056
00057 setNextArgument(ArArg("width ratio", &myWidthRatio,
00058 "The ratio of robot width to how wide an area to check (ratio)"));
00059 myWidthRatio = widthRatio;
00060
00061 }
00062
00063 AREXPORT ArActionLimiterBackwards::~ArActionLimiterBackwards()
00064 {
00065
00066 }
00067
00068 AREXPORT ArActionDesired *
00069 ArActionLimiterBackwards::fire(ArActionDesired currentDesired)
00070 {
00071 double dist;
00072 double maxVel;
00073
00074 double slowStopDist = ArUtil::findMax(myStopDist, mySlowDist);
00075
00076
00077 myDesired.reset();
00078 dist = myRobot->checkRangeDevicesCurrentBox(-myRobot->getRobotLength()/2,
00079 -(myRobot->getRobotWidth()/2.0 *
00080 myWidthRatio),
00081 slowStopDist + (-myRobot->getRobotLength()),
00082 (myRobot->getRobotWidth()/2.0 *
00083 myWidthRatio));
00084 dist -= myRobot->getRobotRadius();
00085 if (dist < -myStopDist)
00086 {
00087
00088 myDesired.setMaxNegVel(0);
00089 return &myDesired;
00090 }
00091 if (dist > -mySlowDist)
00092 {
00093
00094 myDesired.setMaxNegVel(-ArMath::fabs(myMaxBackwardsSpeed));
00095 return &myDesired;
00096 }
00097
00098
00099 maxVel = -ArMath::fabs(myMaxBackwardsSpeed) * ((-dist - myStopDist) / (mySlowDist - myStopDist));
00100
00101 myDesired.setMaxNegVel(maxVel);
00102 return &myDesired;
00103
00104 }