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 "ArRatioInputJoydrive.h"
00029 #include "ArRobot.h"
00030 #include "ariaInternal.h"
00031
00054 AREXPORT ArRatioInputJoydrive::ArRatioInputJoydrive(
00055 ArRobot *robot,
00056 ArActionRatioInput *input,
00057 int priority,
00058 bool stopIfNoButtonPressed,
00059 bool useOSCalForJoystick) :
00060 myFireCB(this, &ArRatioInputJoydrive::fireCallback)
00061 {
00062 myRobot = robot;
00063 myInput = input;
00064 myInput->addFireCallback(priority, &myFireCB);
00065 myFireCB.setName("Joydrive");
00066 if ((myJoyHandler = Aria::getJoyHandler()) == NULL)
00067 {
00068 myJoyHandler = new ArJoyHandler;
00069 myJoyHandler->init();
00070 Aria::setJoyHandler(myJoyHandler);
00071 }
00072
00073 myUseOSCal = useOSCalForJoystick;
00074 myPreviousUseOSCal = myUseOSCal;
00075 myStopIfNoButtonPressed = stopIfNoButtonPressed;
00076 myFiredLast = false;
00077 myPrinting = false;
00078 }
00079
00080 AREXPORT ArRatioInputJoydrive::~ArRatioInputJoydrive()
00081 {
00082 myInput->remFireCallback(&myFireCB);
00083 }
00084
00085 AREXPORT void ArRatioInputJoydrive::setStopIfNoButtonPressed(
00086 bool stopIfNoButtonPressed)
00087 {
00088 myStopIfNoButtonPressed = stopIfNoButtonPressed;
00089 }
00090
00091 AREXPORT bool ArRatioInputJoydrive::getStopIfNoButtonPressed(void)
00092 {
00093 return myStopIfNoButtonPressed;
00094 }
00095
00096 AREXPORT bool ArRatioInputJoydrive::joystickInited(void)
00097 {
00098 return myJoyHandler->haveJoystick();
00099 }
00100
00104 AREXPORT void ArRatioInputJoydrive::setUseOSCal(bool useOSCal)
00105 {
00106 myUseOSCal = useOSCal;
00107 myPreviousUseOSCal = useOSCal;
00108 myJoyHandler->setUseOSCal(useOSCal);
00109 }
00110
00114 AREXPORT bool ArRatioInputJoydrive::getUseOSCal(void)
00115 {
00116 return myUseOSCal;
00117 }
00118
00119
00120 void ArRatioInputJoydrive::fireCallback(void)
00121 {
00122 double rot, trans, throttle;
00123
00124 if (myPreviousUseOSCal != myUseOSCal)
00125 {
00126 myJoyHandler->setUseOSCal(myUseOSCal);
00127 myPreviousUseOSCal = myUseOSCal;
00128 }
00129
00130 if (myJoyHandler->haveJoystick() && myJoyHandler->getButton(1))
00131 {
00132
00133 myJoyHandler->getDoubles(&rot, &trans);
00134
00135 if (!myJoyHandler->haveZAxis())
00136 {
00137 throttle = 1;
00138 }
00139
00140
00141 else
00142 {
00143 throttle = myJoyHandler->getAxis(3);
00144 throttle += 1.0;
00145 throttle /= 2.0;
00146 }
00147 myInput->setRatios(trans * 100, -rot * 100, throttle * 100);
00148 myFiredLast = true;
00149 if (myPrinting)
00150 printf("joy %g %g %g\n", trans * 100, -rot * 100, throttle * 100);
00151 }
00152 else if (myJoyHandler->haveJoystick() && (myStopIfNoButtonPressed ||
00153 myFiredLast))
00154 {
00155 if (myPrinting)
00156 printf("joy nothing\n");
00157 myFiredLast = false;
00158 myInput->setRatios(0, 0, myInput->getThrottleRatio());
00159 }
00160
00161 }