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 "ArRatioInputRobotJoydrive.h"
00030 #include "ArRobot.h"
00031 #include "ArRobotJoyHandler.h"
00032 #include "ariaInternal.h"
00033 #include "ArCommands.h"
00034
00041 ArRatioInputRobotJoydrive::ArRatioInputRobotJoydrive(
00042 ArRobot *robot, ArActionRatioInput *input,
00043 int priority, bool requireDeadmanPushed) :
00044 myFireCB(this, &ArRatioInputRobotJoydrive::fireCallback)
00045 {
00046 myRobot = robot;
00047 myInput = input;
00048 myInput->addFireCallback(priority, &myFireCB);
00049 myRequireDeadmanPushed = requireDeadmanPushed;
00050 myDeadZoneLast = false;
00051 myFireCB.setName("RobotJoydrive");
00052
00053 if ((myRobotJoyHandler = Aria::getRobotJoyHandler()) == NULL)
00054 {
00055 myRobotJoyHandler = new ArRobotJoyHandler(robot);
00056 Aria::setRobotJoyHandler(myRobotJoyHandler);
00057 }
00058
00059 }
00060
00061 ArRatioInputRobotJoydrive::~ArRatioInputRobotJoydrive()
00062 {
00063
00064 }
00065
00066 void ArRatioInputRobotJoydrive::fireCallback(void)
00067 {
00068 bool printing = false;
00069
00070 bool button1 = myRobotJoyHandler->getButton1();
00071
00072 if (myRequireDeadmanPushed && !button1)
00073 {
00074 if (printing)
00075 printf("Nothing\n");
00076 myDeadZoneLast = false;
00077 return;
00078 }
00079
00080 double rotRatio;
00081 double transRatio;
00082 double throttleRatio;
00083
00084 myRobotJoyHandler->getDoubles(&rotRatio, &transRatio, &throttleRatio);
00085
00086 rotRatio *= 100.0;
00087 transRatio *= 100.0;
00088 throttleRatio *= 100.0;
00089
00090 bool doTrans = true;
00091 bool doRot = true;
00092
00093
00094 if (!myRequireDeadmanPushed)
00095 {
00096 doTrans = ArMath::fabs(transRatio) > 33;
00097 doRot = ArMath::fabs(rotRatio) > 33;
00098 }
00099
00100 if (!doTrans && !doRot)
00101 {
00102
00103
00104 if (myDeadZoneLast && !myRequireDeadmanPushed)
00105 {
00106 if (printing)
00107 printf("deadzone Nothing\n");
00108 return;
00109 }
00110
00111 if (printing)
00112 printf("deadzone\n");
00113
00114 myInput->setRatios(0, 0, throttleRatio);
00115 myDeadZoneLast = true;
00116 return;
00117 }
00118
00119 myDeadZoneLast = false;
00120 if (!doRot)
00121 rotRatio = 0;
00122 if (!doTrans)
00123 transRatio = 0;
00124
00125 if (printing)
00126 printf("%.0f %.0f %.0f\n", transRatio, rotRatio, throttleRatio);
00127
00128 if (printing)
00129 printf("(%ld ms ago) we got %d %d %.2f %.2f %.2f (speed %.0f %.0f)\n",
00130 myRobotJoyHandler->getDataReceivedTime().mSecSince(),
00131 button1, myRobotJoyHandler->getButton2(), transRatio, rotRatio,
00132 throttleRatio, myRobot->getVel(), myRobot->getRotVel());
00133
00134 myInput->setRatios(transRatio, rotRatio, throttleRatio);
00135 }