Connects to both robot and GPS, allows teleoperation, and prints robot position and GPS data.
#include "Aria.h"
#include "ArGPS.h"
#include "ArGPSConnector.h"
#include <assert.h>
class GPSLogTask {
public:
myRobot(robot),
myGPS(gps),
myTaskFunctor(this, &GPSLogTask::doTask),
myJoyHandler(joy),
myButtonDown(false)
{
puts("RobotX\tRobotY\tRobotTh\tRobotVel\tRobotRotVel\tRobotLatVel\tLatitude\tLongitude\tAltitude\tSpeed\tGPSTimeSec\tGPSTimeMSec\tFixType\tNumSats\tPDOP\tHDOP\tVDOP\tGPSDataReceived");
}
void lock() { myMutex.lock(); }
void unlock() { myMutex.unlock(); }
protected:
void doTask()
{
if(myJoyHandler)
{
for(unsigned int b = 2; b <= myJoyHandler->getNumButtons(); ++b)
if(myJoyHandler->getButton(b)) {
if(!myButtonDown)
printf("--------------- Joystick button %d pressed.\n", b);
myButtonDown = true;
}
else
myButtonDown = false;
}
lock();
int f = myGPS->read(50);
printf("%.4f\t%.4f\t%.4f\t%.4f\t%.4f\t%.4f"
"\t%2.8f\t%2.8f\t%4.4f\t%4.4f"
"\t%lu\t%lu\t%s"
"\t%u\t%2.4f\t%2.4f\t%2.4f"
"\t%s\n",
myRobot->getX(), myRobot->getY(), myRobot->getTh(), myRobot->getVel(), myRobot->getRotVel(), (myRobot->hasLatVel())?(myRobot->getLatVel()):0,
myGPS->getLatitude(), myGPS->getLongitude(), myGPS->getAltitude(), myGPS->getSpeed(),
myGPS->getGPSPositionTimestamp().getSec(), myGPS->getGPSPositionTimestamp().getMSec(), myGPS->getFixTypeName(),
myGPS->getNumSatellitesTracked(), myGPS->getPDOP(), myGPS->getHDOP(), myGPS->getVDOP(),
((f&ArGPS::ReadUpdated)?"yes":"no")
);
unlock();
}
private:
bool myButtonDown;
};
int main(int argc, char** argv)
{
{
return -1;
}
{
return -2;
}
assert(gps);
{
ArLog::log(
ArLog::Terse,
"gpsRobotTaskExample: Error connecting to GPS device. Try -gpsType, -gpsPort, and/or -gpsBaud command-line arguments. Use -help for help. Exiting.");
return -3;
}
return 0;
}