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 "ArActionLimiterForwards.h"
00029 #include "ArRobot.h"
00030
00039 AREXPORT ArActionLimiterForwards::ArActionLimiterForwards(const char *name,
00040 double stopDistance,
00041 double slowDistance,
00042 double slowSpeed,
00043 double widthRatio) :
00044 ArAction(name,
00045 "Slows the robot down so as not to hit anything in front of it.")
00046 {
00047 setNextArgument(ArArg("stop distance", &myStopDist,
00048 "Distance at which to stop. (mm)"));
00049 myStopDist = stopDistance;
00050
00051 setNextArgument(ArArg("slow distance", &mySlowDist,
00052 "Distance at which to slow down. (mm)"));
00053 mySlowDist = slowDistance;
00054
00055 setNextArgument(ArArg("slow speed", &mySlowSpeed,
00056 "Speed at which to slow to at the slow distance, (mm/sec)"));
00057 mySlowSpeed = slowSpeed;
00058
00059 setNextArgument(ArArg("width ratio", &myWidthRatio,
00060 "Ratio of the width of the box to look at to the robot radius (multiplier)"));
00061 myWidthRatio = widthRatio;
00062 myLastStopped = false;
00063 }
00064
00065 AREXPORT ArActionLimiterForwards::~ArActionLimiterForwards()
00066 {
00067
00068 }
00069
00077 AREXPORT void ArActionLimiterForwards::setParameters(double stopDistance,
00078 double slowDistance,
00079 double slowSpeed,
00080 double widthRatio)
00081 {
00082 myStopDist = stopDistance;
00083 mySlowDist = slowDistance;
00084 mySlowSpeed = slowSpeed;
00085 myWidthRatio = widthRatio;
00086 }
00087
00088 AREXPORT ArActionDesired *
00089 ArActionLimiterForwards::fire(ArActionDesired currentDesired)
00090 {
00091 double dist;
00092 double maxVel;
00093 bool printing = false;
00094 double checkDist;
00095
00096 if (myStopDist > mySlowDist)
00097 checkDist = myStopDist;
00098 else
00099 checkDist = mySlowDist;
00100
00101 myDesired.reset();
00102 dist = myRobot->checkRangeDevicesCurrentBox(0,
00103 -myRobot->getRobotWidth()/2.0 * myWidthRatio,
00104 checkDist + myRobot->getRobotLength()/2,
00105 myRobot->getRobotWidth()/2.0 * myWidthRatio);
00106 dist -= myRobot->getRobotLength() / 2;
00107
00108 if (dist < myStopDist)
00109 {
00110 if (printing && !myLastStopped)
00111 printf("Stopping\n");
00112 myLastStopped = true;
00113 myDesired.setMaxVel(0);
00114 return &myDesired;
00115 }
00116
00117 if (printing && myLastStopped)
00118 printf("Going\n");
00119 myLastStopped = false;
00120
00121 if (dist > mySlowDist)
00122 {
00123
00124 return NULL;
00125
00126 }
00127
00128
00129 maxVel = mySlowSpeed * ((dist - myStopDist) / (mySlowDist - myStopDist));
00130
00131 myDesired.setMaxVel(maxVel);
00132 return &myDesired;
00133
00134 }