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)
{
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 IP : " << robot.
getNetworkIP() <<std::endl;
return EXIT_SUCCESS;
}
if(opt_reset) {
std::cout << "Reset PTU axis" <<std::endl;
return EXIT_SUCCESS;
}
{
std::cout << "** Test limits getter" << std::endl;
}
{
std::cout << "** Test limits setter" << std::endl;
std::cout << "Modified user min/max limits: " << 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;
q = 0;
std::cout << "Enter a caracter to apply" << std::endl;
scanf("%d", &answer);
std::cout <<
"Position reached [deg]: " <<
vpMath::deg(q_mes[0]) <<
" " <<
vpMath::deg(q_mes[1]) << std::endl << std::endl;
}
{
std::cout << "** Test joint positioning" << std::endl;
std::cout << "Enter a caracter to apply" << std::endl;
scanf("%d", &answer);
std::cout <<
"Position reached [deg]: " <<
vpMath::deg(q_mes[0]) <<
" " <<
vpMath::deg(q_mes[1]) << std::endl << std::endl;
}
{
std::cout << "** Test joint velocity" << std::endl;
std::cout <<
"Set velocity for 4s: " <<
vpMath::deg(qdot[0]) <<
" " <<
vpMath::deg(qdot[1]) <<
" [deg/s]" << std::endl;
std::cout << "Enter a caracter to apply" << std::endl;
scanf("%d", &answer);
do {
std::cout <<
"Position reached: " <<
vpMath::deg(q_mes[0]) <<
" " <<
vpMath::deg(q_mes[1]) <<
" [deg]" << 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] << " [m/s] "
std::cout << "Enter a caracter to apply" << std::endl;
scanf("%d", &answer);
do {
std::cout <<
"Position reached: " <<
vpMath::deg(q_mes[0]) <<
" " <<
vpMath::deg(q_mes[1]) <<
" [deg]" << 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