It is also possible to specify the type of PTU in program configuration (in the ARIA robot parameter files or program command-line arguments) instead. For an example of that, see cameraPTZExample.cpp instead.
UP,DOWN – tilt up/down by one positional increment LEFT,RIGHT – pan left/right by one positional increment SPACE – perform reset calibration I – initialize PTU to default settings <,> – increase/decrease the posIncrement by 0.5 degree +,- – increase/decrease the speed by 1 degree/sec A – awaits the completion of last issued positional command R – change pan/tilt movements to relative or absolute movements Z – move pan and tilt axes to zero 1 – move to stored position 1 (-90, 0) 2 – move to stored position 2 (90, 0) 3 – move to stored position 3 (0, -45) 4 – move to stored position 4 (0, 30) M – Enter or Exit monitor (continuous scan) mode H – Halt all motion S – print current variable values ESC – quit
#include "Aria.h"
#define SERIAL_PORT ArUtil::COM4
#define POS_INC_ADJUSTMENT 1
class KeyPTU
{
public:
~KeyPTU(void);
void up(void);
void down(void);
void left(void);
void right(void);
void space(void);
void i(void);
void plus(void);
void minus(void);
void greater(void);
void less(void);
void question(void);
void status(void);
void a(void);
void m(void);
void h(void);
void r(void);
void gotoPos(double p, double t);
void drive(void);
protected:
int myPanValPTU;
int myTiltValPTU;
int myDesiredPanPos;
int myDesiredTiltPos;
int mySlew;
int myPosIncrement;
int mySlewIncrement;
int POS_INCREMENT_ADJUSTMENT;
bool myMonitor;
bool myReset;
bool myInit;
bool myAbsolute;
bool myPTUInited;
};
myUpCB(this, &KeyPTU::up),
myDownCB(this, &KeyPTU::down),
myLeftCB(this, &KeyPTU::left),
myRightCB(this, &KeyPTU::right),
mySpaceCB(this, &KeyPTU::space),
myICB(this, &KeyPTU::i),
myPlusCB(this, &KeyPTU::plus),
myMinusCB(this, &KeyPTU::minus),
myGreaterCB(this, &KeyPTU::greater),
myLessCB(this, &KeyPTU::less),
myQuestionCB(this, &KeyPTU::question),
mySCB(this, &KeyPTU::status),
myACB(this, &KeyPTU::a),
myMCB(this, &KeyPTU::m),
myHCB(this, &KeyPTU::h),
myRCB(this, &KeyPTU::r),
myPos0CB(this, &KeyPTU::gotoPos, 0, 0),
myPos1CB(this, &KeyPTU::gotoPos, -90.0, 0.0),
myPos2CB(this, &KeyPTU::gotoPos, 90.0, 0.0),
myPos3CB(this, &KeyPTU::gotoPos, 0.0, -45.0),
myPos4CB(this, &KeyPTU::gotoPos, 0.0, 30.0),
myPTU(robot),
myDriveCB(this, &KeyPTU::drive),
mySerialConnection(NULL)
{
#ifdef SERIAL_PORT
if(mySerialConnection->open(SERIAL_PORT) != 0)
{
ArLog::log(
ArLog::Terse,
"dpptuExample: Error: Could not open computer serial port %s for DPPTU!", SERIAL_PORT);
}
myPTU.setDeviceConnection(mySerialConnection);
#endif
myRobot = robot;
{
myRobot->attachKeyHandler(keyHandler);
}
"The key handler already has a key for left, keydrive will not work correctly.");
"The key handler already has a key for right, keydrive will not work correctly.");
"The key handler already has a key for space, keydrive will not work correctly.");
"The key handler already has a key for 'i', keydrive will not work correctly.");
"The key handler already has a key for '+', keydrive will not work correctly.");
"The key handler already has a key for '-', keydrive will not work correctly.");
"The key handler already has a key for '>', keydrive will not work correctly.");
"The key handler already has a key for '<', keydrive will not work correctly.");
"The key handler already has a key for '?', keydrive will not work correctly.");
"The key handler already has a key for 'S', keydrive will not work correctly.");
"The key handler already has a key for 'A', keydrive will not work correctly.");
"The key handler already has a key for 'Z', keydrive will not work correctly.");
"The key handler already has a key for 'M', keydrive will not work correctly.");
"The key handler already has a key for 'H', keydrive will not work correctly.");
"The key handler already has a key for 'R', keydrive will not work correctly.");
"The key handler already has a key for 'Z', keydrive will not work correctly.");
"The key handler already has a key for '1', keydrive will not work correctly.");
"The key handler already has a key for '2', keydrive will not work correctly.");
"The key handler already has a key for '3', keydrive will not work correctly.");
"The key handler already has a key for '4', keydrive will not work correctly.");
myReset = false;
myInit = true;
myDesiredPanPos = 0;
myDesiredTiltPos = 0;
myPosIncrement = 1;
mySlewIncrement = 1;
myPTUInited = false;
myMonitor = false;
}
KeyPTU::~KeyPTU()
{
if(mySerialConnection)
{
myPTU.setDeviceConnection(NULL);
delete mySerialConnection;
}
}
void KeyPTU::left(void)
{
myDesiredPanPos += myPosIncrement;
if (myDesiredPanPos > myPTU.getMaxPosPan())
myDesiredPanPos = myPTU.getMaxPosPan();
}
void KeyPTU::right(void)
{
myDesiredPanPos -= myPosIncrement;
if (myDesiredPanPos < myPTU.getMaxNegPan())
myDesiredPanPos = myPTU.getMaxNegPan();
}
void KeyPTU::up(void)
{
myDesiredTiltPos += myPosIncrement;
if (myDesiredTiltPos > myPTU.getMaxPosTilt())
myDesiredTiltPos = myPTU.getMaxPosTilt();
}
void KeyPTU::down(void)
{
myDesiredTiltPos -= myPosIncrement;
if (myDesiredTiltPos < myPTU.getMaxNegTilt())
myDesiredTiltPos = myPTU.getMaxNegTilt();
}
void KeyPTU::space(void)
{
myReset = true;
}
void KeyPTU::i(void)
{
myInit = true;
}
void KeyPTU::plus(void)
{
mySlew += mySlewIncrement;
if (mySlew > myPTU.getMaxPanSlew())
mySlew = myPTU.getMaxPanSlew();
status();
}
void KeyPTU::minus(void)
{
mySlew -= mySlewIncrement;
if (mySlew < myPTU.getMinPanSlew())
mySlew = myPTU.getMinPanSlew();
status();
}
void KeyPTU::greater(void)
{
myPosIncrement += POS_INCREMENT_ADJUSTMENT;
if (myPosIncrement > myPTU.getMaxPosPan())
myPosIncrement = myPTU.getMaxPosPan();
status();
}
void KeyPTU::less(void)
{
myPosIncrement -= POS_INCREMENT_ADJUSTMENT;
if (myPosIncrement < 0)
myPosIncrement = 0;
status();
}
void KeyPTU::a(void)
{
myPTU.awaitExec();
}
void KeyPTU::gotoPos(double p, double t)
{
myDesiredPanPos = p;
myDesiredTiltPos = t;
status();
}
void KeyPTU::question(void)
{
}
void KeyPTU::status(void)
{
if (myAbsolute)
else
}
void KeyPTU::m(void)
{
if (!myMonitor)
{
myMonitor = true;
myPTU.initMon(-60,60,30,-30);
}
else
{
myPTU.blank();
myMonitor = false;
}
}
void KeyPTU::h(void)
{
myPTU.haltAll();
}
void KeyPTU::r(void)
{
if (!myAbsolute)
{
myAbsolute = true;
}
else
{
myAbsolute = false;
}
status();
}
void KeyPTU::drive(void)
{
if (!myPTUInited && myRobot->isConnected())
{
myPTU.init();
myPTU.resetCalib();
myPTU.awaitExec();
mySlew = myPTU.getPanSlew();
myPTU.awaitExec();
myPTUInited = true;
myInit = false;
myAbsolute = true;
}
if (myInit == true)
{
myPTU.init();
myInit = false;
myDesiredPanPos = myPTU.getPan();
myDesiredTiltPos = myPTU.getTilt();
mySlew = myPTU.getPanSlew();
myReset = false;
}
if (myReset == true)
{
myPTU.resetCalib();
myPTU.awaitExec();
myDesiredPanPos = myPTU.getPan();
myDesiredTiltPos = myPTU.getTilt();
myReset = false;
}
else
{
if(myPTU.canGetRealPanTilt())
printf("Position (%.1f deg, %.1f deg) [Incr. %d deg] Press ? for help \r", myPTU.getPan(), myPTU.getTilt(), myPosIncrement);
else
printf("Requested (%.1f deg, %.1f deg) [Incr. %d deg] Press ? for help \r", myPTU.getPan(), myPTU.getTilt(), myPosIncrement);
if (myDesiredPanPos != myPTU.getLastPanRequest())
{
if (myAbsolute)
myPTU.pan(myDesiredPanPos);
else
myPTU.panRel(myDesiredPanPos - myPTU.getPan());
}
if (myDesiredTiltPos != myPTU.getLastTiltRequest())
{
if (myAbsolute)
myPTU.tilt(myDesiredTiltPos);
else
myPTU.tiltRel(myDesiredTiltPos - myPTU.getTilt());
}
if (mySlew != myPTU.getPanSlew())
{
myPTU.panSlew(mySlew);
myPTU.tiltSlew(mySlew);
}
}
}
int main(int argc, char **argv)
{
{
{
}
}
{
}
KeyPTU ptu(&robot);
printf("Press '?' for available commands\r\n");
}