This is an example using the Canon VC-C4 Pan/Tilt/Zoom camera.
This program uses key commands to control the pan, tilt, and zoom of the camera. It uses the same slew for the pan and tilt axes. It defaults to use the microcontroller port Aux1. See the setport comments below to use the computer's serial port, or a different aux port on the microcontroller.
UP,DOWN – tilt up/down by 1 degree LEFT,RIGHT – pan left/right by 1 degree X,C – zoom in/out by 10 units (80 total) I – initialize PTU to default settings >,< – increase/decrease the positional increment by one 1 degree +,- – increase/decrease the slew by 5 degrees/sec Z – move pan and tilt axes to zero H – Halt all motion S – Status of camera position and variable values P – Power on/off the camera ESC – Exit program
#include "Aria.h"
class KeyPTU
{
public:
~KeyPTU(void) {}
void up(void);
void down(void);
void left(void);
void right(void);
void plus(void);
void minus(void);
void greater(void);
void less(void);
void question(void);
void status(void);
void c(void);
void h(void);
void i(void);
void p(void);
void x(void);
void z(void);
void r(void);
void drive(void);
protected:
int myPanSlew;
int myTiltSlew;
int myPosIncrement;
int mySlewIncrement;
int myZoomIncrement;
bool myMonitor;
bool myInit;
bool myAbsolute;
bool myExercise;
void exercise(void) { myExercise = !myExercise; }
void autoupdate(void);
bool myPTUInitRequested;
};
myUpCB(this, &KeyPTU::up),
myDownCB(this, &KeyPTU::down),
myLeftCB(this, &KeyPTU::left),
myRightCB(this, &KeyPTU::right),
myPlusCB(this, &KeyPTU::plus),
myMinusCB(this, &KeyPTU::minus),
myGreaterCB(this, &KeyPTU::greater),
myLessCB(this, &KeyPTU::less),
myQuestionCB(this, &KeyPTU::question),
mySCB(this, &KeyPTU::status),
myECB(this, &KeyPTU::exercise),
myACB(this, &KeyPTU::autoupdate),
myCCB(this, &KeyPTU::c),
myHCB(this, &KeyPTU::h),
myICB(this, &KeyPTU::i),
myPCB(this, &KeyPTU::p),
myXCB(this, &KeyPTU::x),
myZCB(this, &KeyPTU::z),
myRCB(this, &KeyPTU::r),
myPTU(robot),
myDriveCB(this, &KeyPTU::drive)
{
myRobot = robot;
myPTU.setLEDControlMode(2);
myExerciseTime.setToNow();
myExercise = false;
{
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 '+', 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 'C', 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 'I', keydrive will not work correctly.");
"The key handler already has a key for 'P', 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 'S', keydrive will not work correctly.");
"The key handler already has a key for 'X', keydrive will not work correctly.");
"The key handler already has a key for 'Z', keydrive will not work correctly.");
myPTUInitRequested = false;
myPosIncrement = 1;
mySlewIncrement = 5;
myZoomIncrement = 50;
}
void KeyPTU::autoupdate(void)
{
if (myPTU.getAutoUpdate())
myPTU.disableAutoUpdate();
else
myPTU.enableAutoUpdate();
}
void KeyPTU::right(void)
{
myPTU.panRel(myPosIncrement);
}
void KeyPTU::left(void)
{
myPTU.panRel(-myPosIncrement);
}
void KeyPTU::up(void)
{
myPTU.tiltRel(myPosIncrement);
}
void KeyPTU::down(void)
{
myPTU.tiltRel(-myPosIncrement);
}
void KeyPTU::x(void)
{
myPTU.zoom(myPTU.getZoom() + myZoomIncrement);
}
void KeyPTU::c(void)
{
myPTU.zoom(myPTU.getZoom() - myZoomIncrement);
}
void KeyPTU::i(void)
{
myPTU.init();
}
void KeyPTU::plus(void)
{
myPTU.panSlew(myPTU.getPanSlew() + mySlewIncrement);
myPTU.tiltSlew(myPTU.getTiltSlew() + mySlewIncrement);
status();
}
void KeyPTU::minus(void)
{
myPTU.panSlew(myPTU.getPanSlew() - mySlewIncrement);
myPTU.tiltSlew(myPTU.getTiltSlew() - mySlewIncrement);
status();
}
void KeyPTU::greater(void)
{
myPosIncrement += 1;
if (myPosIncrement > myPTU.getMaxPosPan())
myPosIncrement = myPTU.getMaxPosPan();
status();
}
void KeyPTU::less(void)
{
myPosIncrement -= 1;
if (myPosIncrement < 0)
myPosIncrement = 0;
status();
}
void KeyPTU::z(void)
{
myPTU.panTilt(0,0);
myPTU.zoom(0);
status();
}
void KeyPTU::r(void)
{
myPTU.reset();
}
void KeyPTU::question(void)
{
}
void KeyPTU::status(void)
{
if (myPTU.getPower())
else
}
void KeyPTU::h(void)
{
myPTU.haltPanTilt();
myPTU.haltZoom();
}
void KeyPTU::p(void)
{
if (myPTU.getPower())
myPTU.power(0);
else
myPTU.power(1);
status();
}
void KeyPTU::drive(void)
{
if (!myPTUInitRequested && !myPTU.isInitted() && myRobot->isConnected())
{
printf("\nWaiting for Camera to Initialize\n");
myAbsolute = true;
myPTUInitRequested = true;
myPTU.init();
}
if (myPTUInitRequested && !myPTU.isInitted())
{
return;
}
if (myPTUInitRequested && myPTU.isInitted())
{
myPTUInitRequested = false;
myPanSlew = myPTU.getPanSlew();
myTiltSlew = myPTU.getTiltSlew();
printf("Done.\n");
question();
}
if (myExerciseTime.secSince() > 5 && myExercise)
{
int pan,tilt;
else
else
myPTU.panTilt(pan, tilt);
myExerciseTime.setToNow();
}
}
int main(int argc, char **argv)
{
std::string str;
KeyPTU ptu(&robot);
{
printf("Could not connect to robot... exiting\n");
return 1;
}
printf("Press '?' for available commands\r\n");
return 0;
}