Example program that activates an onboard gyro if it exists and uses its data to correct the robot pose.This program uses ArActionKeydrive and ArActionJoydrive to allow teleoperation with the keyboard or joystick, and displays gyro data. Additional keys (numbers 0-9 and letters q, w, e, r, t, y, u, i, o, p) activate preset rotation velocities.
#include "Aria.h"
#include "ArAnalogGyro.h"
class GyroTask
{
public:
~GyroTask(void) {}
void doTask(void);
protected:
bool gotGyroPacket;
};
GyroTask::GyroTask(
ArRobot *robot) :
myTaskCB(this, &GyroTask::doTask),
myPacketHandlerCB(this, &GyroTask::handlePacket),
gotGyroPacket(false)
{
myRobot = robot;
{
if (myRobot != NULL)
myRobot->attachKeyHandler(keyHandler);
else
ArLog::log(
ArLog::Terse,
"GyroTask: No robot to attach a keyHandler to, keyHandling won't work... either make your own keyHandler and drive it yourself, make a keyhandler and attach it to a robot, or give this a robot to attach to.");
}
}
void GyroTask::doTask(void)
{
printf("gyro th (mode 1 only):%8.4f encoder th:%8.4f ArRobot mixed th:%8.4f temp:%d ave:%g gyro packets:%s\n", myGyro->getHeading(), myRobot->getRawEncoderPose().getTh(), myRobot->getTh(), myGyro->getTemperature(), myGyro->getAverage(), gotGyroPacket?"received":"not received");
}
{
gotGyroPacket = true;
return true;
}
int main(int argc, char **argv)
{
GyroTask gyro(&robot);
{
return 1;
}
printf("This program will allow you to use a joystick or keyboard to control the robot.\nYou can use the arrow keys to drive, and the spacebar to stop.\nFor joystick control press the trigger button and then drive.\nPress escape to exit.\n");
printf("Do not have a joystick, only the arrow keys on the keyboard will work.\n");
{
printf("Could not connect to robot... exiting\n");
return 1;
}
return 0;
}