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