Example ArAction object that uses ArJoyHandler to get joystick input.This program just drives the robot around with a joystick, by way of an ArAction class which reads data fram an ArJoyHandler. Its a practical example of actions.
#include "Aria.h"
{
public:
JoydriveAction(void);
virtual ~JoydriveAction(void);
bool joystickInited(void);
protected:
};
JoydriveAction::JoydriveAction(void) :
ArAction(
"Joydrive Action",
"This action reads the joystick and sets the translational and rotational velocity based on this.")
{
myJoyHandler.init();
myJoyHandler.setSpeeds(50, 700);
}
JoydriveAction::~JoydriveAction(void)
{
}
bool JoydriveAction::joystickInited(void)
{
return myJoyHandler.haveJoystick();
}
{
int rot, trans;
printf(
"\rx %6.1f y %6.1f tth %6.1f vel %7.1f mpacs %3d",
myRobot->
getX(),
fflush(stdout);
if (myJoyHandler.haveJoystick() && (myJoyHandler.getButton(1) ||
myJoyHandler.getButton(2)))
{
myJoyHandler.getAdjusted(&rot, &trans);
myDesired.setVel(trans);
myDesired.setDeltaHeading(-rot);
return &myDesired;
}
else
{
myDesired.setVel(0);
myDesired.setDeltaHeading(0);
return &myDesired;
}
}
int main(int argc, char **argv)
{
{
return 1;
}
JoydriveAction jdAct;
if (!jdAct.joystickInited())
{
printf("Do not have a joystick, set up the joystick then rerun the program\n\n");
return 1;
}
{
printf("Could not connect to robot... exiting\n");
return 2;
}
return 0;
}