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 "Aria.h"
00027
00036
00037 class JoydriveAction : public ArAction
00038 {
00039 public:
00040
00041 JoydriveAction(void);
00042
00043 virtual ~JoydriveAction(void);
00044
00045 virtual ArActionDesired *fire(ArActionDesired currentDesired);
00046
00047 bool joystickInited(void);
00048 protected:
00049
00050 ArActionDesired myDesired;
00051
00052 ArJoyHandler myJoyHandler;
00053 };
00054
00055
00056
00057
00058 JoydriveAction::JoydriveAction(void) :
00059 ArAction("Joydrive Action", "This action reads the joystick and sets the translational and rotational velocity based on this.")
00060 {
00061
00062 myJoyHandler.init();
00063
00064 myJoyHandler.setSpeeds(50, 700);
00065 }
00066
00067 JoydriveAction::~JoydriveAction(void)
00068 {
00069 }
00070
00071
00072 bool JoydriveAction::joystickInited(void)
00073 {
00074 return myJoyHandler.haveJoystick();
00075 }
00076
00077
00078 ArActionDesired *JoydriveAction::fire(ArActionDesired currentDesired)
00079 {
00080 int rot, trans;
00081
00082
00083 printf("\rx %6.1f y %6.1f tth %6.1f vel %7.1f mpacs %3d", myRobot->getX(),
00084 myRobot->getY(), myRobot->getTh(), myRobot->getVel(),
00085 myRobot->getMotorPacCount());
00086 fflush(stdout);
00087
00088
00089 if (myJoyHandler.haveJoystick() && (myJoyHandler.getButton(1) ||
00090 myJoyHandler.getButton(2)))
00091 {
00092
00093 myJoyHandler.getAdjusted(&rot, &trans);
00094
00095 myDesired.setVel(trans);
00096 myDesired.setDeltaHeading(-rot);
00097
00098 return &myDesired;
00099 }
00100 else
00101 {
00102
00103 myDesired.setVel(0);
00104 myDesired.setDeltaHeading(0);
00105
00106 return &myDesired;
00107 }
00108 }
00109
00110
00111 int main(int argc, char **argv)
00112 {
00113 ArRobot robot;
00114 Aria::init();
00115 ArSimpleConnector connector(&argc, argv);
00116 if (!connector.parseArgs() || argc > 1)
00117 {
00118 connector.logOptions();
00119 return 1;
00120 }
00121
00122
00123 JoydriveAction jdAct;
00124
00125
00126 if (!jdAct.joystickInited())
00127 {
00128 printf("Do not have a joystick, set up the joystick then rerun the program\n\n");
00129 Aria::shutdown();
00130 return 1;
00131 }
00132
00133
00134 if (!connector.connectRobot(&robot))
00135 {
00136 printf("Could not connect to robot... exiting\n");
00137 return 2;
00138 }
00139
00140
00141
00142 robot.comInt(ArCommands::SONAR, 0);
00143 robot.comInt(ArCommands::ENABLE, 1);
00144 robot.comInt(ArCommands::SOUNDTOG, 0);
00145
00146
00147 robot.addAction(&jdAct, 100);
00148
00149 robot.run(true);
00150
00151
00152 Aria::shutdown();
00153 return 0;
00154 }
00155