Test that show how to control FLIR PTU pan/tilt axis in position and velocity.
#include <iostream>
#include <visp3/core/vpConfig.h>
#ifdef VISP_HAVE_FLIR_PTU_SDK
#include <visp3/robot/vpRobotFlirPtu.h>
int main(int argc, char **argv)
{
#ifdef ENABLE_VISP_NAMESPACE
#endif
std::string opt_portname;
int opt_baudrate = 9600;
bool opt_network = false;
bool opt_reset = false;
if (argc == 1) {
std::cout << "To see how to use this test, run: " << argv[0] << " --help" << std::endl;
return EXIT_SUCCESS;
}
for (int i = 1; i < argc; i++) {
if ((std::string(argv[i]) == "--portname" || std::string(argv[i]) == "-p") && (i + 1 < argc)) {
opt_portname = std::string(argv[i + 1]);
}
else if ((std::string(argv[i]) == "--baudrate" || std::string(argv[i]) == "-b") && (i + 1 < argc)) {
opt_baudrate = std::atoi(argv[i + 1]);
}
else if ((std::string(argv[i]) == "--network" || std::string(argv[i]) == "-n")) {
opt_network = true;
}
else if ((std::string(argv[i]) == "--reset" || std::string(argv[i]) == "-r")) {
opt_reset = true;
}
else if (std::string(argv[i]) == "--help" || std::string(argv[i]) == "-h") {
std::cout << "SYNOPSIS" << std::endl
<< " " << argv[0] << " [--portname <portname>] [--baudrate <rate>] [--network] [--reset] [--help] [-h]"
<< std::endl
<< std::endl
<< "DESCRIPTION" << std::endl
<< " --portname, -p <portname>" << std::endl
<< " Set serial or tcp port name." << std::endl
<< std::endl
<< " --baudrate, -b <rate>" << std::endl
<< " Set serial communication baud rate. Default: " << opt_baudrate << "." << std::endl
<< std::endl
<< " --network, -n" << std::endl
<< " Get PTU network information (Hostname, IP, Gateway) and exit. " << std::endl
<< std::endl
<< " --reset, -r" << std::endl
<< " Reset PTU axis and exit. " << std::endl
<< std::endl
<< " --help, -h" << std::endl
<< " Print this helper message. " << std::endl
<< std::endl
<< "EXAMPLE" << std::endl
<< " - How to get network IP" << std::endl
#ifdef _WIN32
<< " $ " << argv[0] << " -p /dev/ttyUSB0 --network" << std::endl
#else
<< " $ " << argv[0] << " --portname COM1 --network" << std::endl
#endif
<< " Try to connect FLIR PTU to port: /dev/ttyUSB0 with baudrate: 9600" << std::endl
<< " PTU HostName: PTU-5" << std::endl
<< " PTU IP : 169.254.110.254" << std::endl
<< " PTU Gateway : 0.0.0.0" << std::endl
<< " - How to run this binary using serial communication" << std::endl
#ifdef _WIN32
<< " $ " << argv[0] << " --portname COM1" << std::endl
#else
<< " $ " << argv[0] << " --portname /dev/ttyUSB0" << std::endl
#endif
<< " - How to run this binary using network communication" << std::endl
<< " $ " << argv[0] << " --portname tcp:169.254.110.254" << std::endl;
return EXIT_SUCCESS;
}
}
if (opt_portname.empty()) {
std::cout << "Error, portname unspecified. Run " << argv[0] << " --help" << std::endl;
return EXIT_SUCCESS;
}
try {
int answer;
std::cout << "Try to connect FLIR PTU to port: " << opt_portname << " with baudrate: " << opt_baudrate << std::endl;
robot.connect(opt_portname, opt_baudrate);
if (opt_network) {
std::cout << "PTU HostName: " << robot.getNetworkHostName() << std::endl;
std::cout << "PTU IP : " << robot.getNetworkIP() << std::endl;
std::cout << "PTU Gateway : " << robot.getNetworkGateway() << std::endl;
return EXIT_SUCCESS;
}
if (opt_reset) {
std::cout << "Reset PTU axis" << std::endl;
robot.reset();
return EXIT_SUCCESS;
}
{
std::cout << "** Test limits getter" << std::endl;
std::cout <<
"Pan pos min/max [deg]: " <<
vpMath::deg(robot.getPanPosLimits()[0]) <<
" "
<<
vpMath::deg(robot.getPanPosLimits()[1]) << std::endl;
std::cout <<
"Tilt pos min/max [deg]: " <<
vpMath::deg(robot.getTiltPosLimits()[0]) <<
" "
<<
vpMath::deg(robot.getTiltPosLimits()[1]) << std::endl;
std::cout <<
"Pan/tilt vel max [deg/s]: " <<
vpMath::deg(robot.getPanTiltVelMax()[0]) <<
" "
<<
vpMath::deg(robot.getPanTiltVelMax()[1]) << std::endl
<< std::endl;
}
{
std::cout << "** Test limits setter" << std::endl;
robot.setPanPosLimits(pan_pos_limits);
robot.setTiltPosLimits(tilt_pos_limits);
std::cout << "Modified user min/max limits: " << std::endl;
std::cout <<
"Pan pos min/max [deg]: " <<
vpMath::deg(robot.getPanPosLimits()[0]) <<
" "
<<
vpMath::deg(robot.getPanPosLimits()[1]) << std::endl;
std::cout <<
"Tilt pos min/max [deg]: " <<
vpMath::deg(robot.getTiltPosLimits()[0]) <<
" "
<<
vpMath::deg(robot.getTiltPosLimits()[1]) << std::endl;
std::cout <<
"Pan/tilt vel max [deg/s]: " <<
vpMath::deg(robot.getPanTiltVelMax()[0]) <<
" "
<<
vpMath::deg(robot.getPanTiltVelMax()[1]) << std::endl
<< std::endl;
}
{
std::cout << "** Test position getter" << std::endl;
std::cout <<
"Current position [deg]: " <<
vpMath::deg(q_mes[0]) <<
" " <<
vpMath::deg(q_mes[1]) << std::endl;
std::cout << "Initialisation done." << std::endl << std::endl;
}
{
std::cout << "** Test joint positioning" << std::endl;
2.);
q = 0;
std::cout << "Enter a caracter to apply" << std::endl;
scanf("%d", &answer);
robot.setPositioningVelocity(50);
<< std::endl;
}
{
std::cout << "** Test joint positioning" << std::endl;
std::cout << "Enter a caracter to apply" << std::endl;
scanf("%d", &answer);
<< std::endl;
}
{
std::cout << "** Test joint velocity" << std::endl;
<< std::endl;
std::cout << "Enter a caracter to apply" << std::endl;
scanf("%d", &answer);
do {
<< std::endl
<< std::endl;
}
{
std::cout << "** Test cartesian velocity with robot Jacobien eJe" << std::endl;
std::cout << "Set cartesian velocity in end-effector frame for 4s: " << v_e[0] << " " << v_e[1] << " " << v_e[2]
<< " [deg/s]" << std::endl;
std::cout << "Enter a caracter to apply" << std::endl;
scanf("%d", &answer);
do {
<< std::endl
<< std::endl;
}
std::cout << "** The end" << std::endl;
}
std::cout <<
"Catch Flir Ptu signal exception: " << e.
getMessage() << std::endl;
}
std::cout <<
"Catch Flir Ptu exception: " << e.
getMessage() << std::endl;
}
return EXIT_SUCCESS;
}
#else
int main()
{
std::cout << "You do not have an Flir Ptu robot connected to your computer..." << std::endl;
return EXIT_SUCCESS;
}
#endif
Implementation of column vector and the associated operations.
error that can be emitted by ViSP classes.
const char * getMessage() const
static double rad(double deg)
static double deg(double rad)
Error that can be emitted by the vpRobot class and its derivatives.
void get_eJe(vpMatrix &eJe) VP_OVERRIDE
void setVelocity(const vpRobot::vpControlFrameType frame, const vpColVector &vel) VP_OVERRIDE
@ STATE_POSITION_CONTROL
Initialize the position controller.
@ STATE_VELOCITY_CONTROL
Initialize the velocity controller.
@ STATE_STOP
Stops robot motion especially in velocity and acceleration control.
virtual vpRobotStateType setRobotState(const vpRobot::vpRobotStateType newState)
void setMaxRotationVelocity(double maxVr)
VISP_EXPORT void sleepMs(double t)
VISP_EXPORT double measureTimeMs()