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