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 "ArActionTurn.h"
00029 #include "ArRobot.h"
00030
00031 AREXPORT ArActionTurn::ArActionTurn(const char *name, double speedStartTurn,
00032 double speedFullTurn, double turnAmount) :
00033 ArAction(name,
00034 "Turns the robot depending on actions by higher priority actions.")
00035 {
00036 setNextArgument(ArArg("speed start turn", &mySpeedStart,
00037 "max vel at which to start turning (mm/sec)"));
00038 mySpeedStart = speedStartTurn;
00039
00040 setNextArgument(ArArg("speed full turn", &mySpeedFull,
00041 "max vel at which to turn the full amount (mm/sec)"));
00042 mySpeedFull = speedFullTurn;
00043
00044 setNextArgument(ArArg("turn amount", &myTurnAmount,
00045 "max vel at which to start turning (mm/sec)"));
00046 myTurnAmount = turnAmount;
00047
00048 myTurning = 0;
00049
00050 }
00051
00052 AREXPORT ArActionTurn::~ArActionTurn()
00053 {
00054
00055 }
00056
00057 AREXPORT ArActionDesired *ArActionTurn::fire(ArActionDesired currentDesired)
00058 {
00059 myDesired.reset();
00060 double turnAmount;
00061 double angle;
00062
00063
00064
00065 if (myRobot->getVel() > mySpeedStart)
00066 {
00067 if (myTurning != 0)
00068 {
00069
00070 myTurning = 0;
00071 }
00072 return NULL;
00073 }
00074
00075
00076
00077
00078 if (myRobot->getVel() < mySpeedFull)
00079 {
00080
00081 turnAmount = myTurnAmount;
00082 }
00083
00084 else
00085 {
00086 turnAmount = ((mySpeedStart - myRobot->getVel()) /
00087 (mySpeedStart - mySpeedFull)) * myTurnAmount;
00088
00089
00090 }
00091
00092 if (myTurning != 0)
00093 turnAmount *= myTurning;
00094
00095 else
00096 {
00097 if (myRobot->checkRangeDevicesCurrentPolar(-90, 90, &angle) < 3000)
00098 {
00099 if (angle > 0)
00100 {
00101
00102 myTurning = -1;
00103 }
00104 else
00105 {
00106
00107 myTurning = 1;
00108 }
00109 }
00110 else
00111 {
00112
00113 myTurning = 1;
00114 }
00115 turnAmount *= myTurning;
00116 }
00117 myDesired.setDeltaHeading(turnAmount);
00118 return &myDesired;
00119 }