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