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
00028
00029
00030
00031
00032
00033
00034
00035
00036 class Joydrive
00037 {
00038 public:
00039
00040 Joydrive(ArRobot *robot);
00041
00042 ~Joydrive(void);
00043
00044
00045 void drive(void);
00046
00047 protected:
00048
00049 ArJoyHandler myJoyHandler;
00050
00051 ArRobot *myRobot;
00052
00053 ArFunctorC<Joydrive> myDriveCB;
00054 };
00055
00056
00057
00058
00059 Joydrive::Joydrive(ArRobot *robot) :
00060 myDriveCB(this, &Joydrive::drive)
00061 {
00062
00063 myRobot = robot;
00064 if (myRobot != NULL)
00065 myRobot->addUserTask("joydrive", 50, &myDriveCB);
00066
00067
00068 myJoyHandler.init();
00069
00070 myJoyHandler.setSpeeds(100, 700);
00071
00072
00073 if (myJoyHandler.haveJoystick())
00074 {
00075 printf("Have a joystick\n\n");
00076 }
00077
00078 else
00079 {
00080 printf("Do not have a joystick, set up the joystick then rerun the program\n\n");
00081 Aria::shutdown();
00082 exit(1);
00083 }
00084 }
00085
00086 Joydrive::~Joydrive(void)
00087 {
00088
00089 if (myRobot != NULL)
00090 myRobot->remUserTask(&myDriveCB);
00091 }
00092
00093 void Joydrive::drive(void)
00094 {
00095 int trans, rot;
00096
00097
00098 printf("\rx %6.1f y %6.1f tth %6.1f vel %7.1f mpacs %3d ",
00099 myRobot->getX(), myRobot->getY(), myRobot->getTh(),
00100 myRobot->getVel(), myRobot->getMotorPacCount());
00101 fflush(stdout);
00102
00103
00104 if (myJoyHandler.haveJoystick() && (myJoyHandler.getButton(1) ||
00105 myJoyHandler.getButton(2)))
00106 {
00107
00108 myJoyHandler.getAdjusted(&rot, &trans);
00109
00110 myRobot->setVel(trans);
00111 myRobot->setRotVel(-rot);
00112 }
00113
00114 else
00115 {
00116 myRobot->setVel(0);
00117 myRobot->setRotVel(0);
00118 }
00119 }
00120
00121 int main(int argc, char **argv)
00122 {
00123 std::string str;
00124 int ret;
00125
00126
00127 ArTcpConnection con;
00128
00129 ArRobot robot(NULL, false);
00130
00131 Joydrive joyd(&robot);
00132
00133
00134 Aria::init();
00135
00136
00137 if ((ret = con.open()) != 0)
00138 {
00139 str = con.getOpenMessage(ret);
00140 printf("Open failed: %s\n", str.c_str());
00141 Aria::shutdown();
00142 return 1;
00143 }
00144
00145
00146 robot.setDeviceConnection(&con);
00147
00148 if (!robot.blockingConnect())
00149 {
00150 printf("Could not connect to robot... exiting\n");
00151 Aria::shutdown();
00152 return 1;
00153 }
00154
00155
00156 robot.comInt(ArCommands::SONAR, 0);
00157 robot.comInt(ArCommands::ENABLE, 1);
00158 robot.comInt(ArCommands::SOUNDTOG, 0);
00159
00160
00161 robot.run(true);
00162
00163 Aria::shutdown();
00164 return 0;
00165 }
00166