Example of a real robot control, the Afma4 robot (cylindrical robot, with 4 degrees of freedom). The robot is controlled first in position, then in velocity.
#include <visp/vpConfig.h>
#include <visp/vpDebug.h>
#ifdef VISP_HAVE_AFMA4
#include <unistd.h>
#include <stdlib.h>
#include <visp/vpParseArgv.h>
#include <visp/vpRobotAfma4.h>
#define GETOPTARGS "mh"
void usage(const char *name, const char *badparam)
{
fprintf(stdout, "\n\
Example of a positionning control followed by a velocity control \n\
of the Afma4 robot.\n \
\n\
SYNOPSIS\n\
%s [-m] [-h]\n \
", name);
fprintf(stdout, "\n\
OPTIONS: Default\n\
-m\n\
Turn off the control of the robot. This option is\n\
essentially useful for security reasons during nightly\n\
tests.\n\
\n\
-h\n\
Print the help.\n\n");
if (badparam) {
fprintf(stderr, "ERROR: \n" );
fprintf(stderr, "\nBad parameter [%s]\n", badparam);
}
}
bool getOptions(int argc, const char **argv, bool &control)
{
const char *optarg;
int c;
switch (c) {
case 'm': control = false; break;
case 'h': usage(argv[0], NULL); return false; break;
default:
usage(argv[0], optarg); return false; break;
}
}
if ((c == 1) || (c == -1)) {
usage(argv[0], NULL);
std::cerr << "ERROR: " << std::endl;
std::cerr << " Bad argument " << optarg << std::endl << std::endl;
return false;
}
return true;
}
int
main(int argc, const char ** argv)
{
try
{
bool control = true;
if (getOptions(argc, argv, control) == false) {
exit (-1);
}
qd[1] = -0.1;
std::cout << "Position control: in articular..." << std::endl;
std::cout << " position to reach: " << qd.t() << std::endl;
if (control)
sleep(1) ;
std::cout << " measured position: " << q.t() ;
sleep(1) ;
std::cout << "Velocity control: in articular..." << std::endl;
q = 0 ;
std::cout << " rotation arround vertical axis: " << q[0] << std::endl;
if (control)
sleep(5) ;
q = 0 ;
q[1] = 0.2 ;
std::cout << " vertical translation: " << q[1] << std::endl;
if (control)
sleep(5) ;
q = 0 ;
q[1] = -0.2 ;
std::cout << " vertical translation: " << q[1] << std::endl;
if (control)
sleep(5) ;
q = 0 ;
std::cout << " pan rotation: " << q[2] << std::endl;
if (control)
sleep(5) ;
q = 0 ;
std::cout << " tilt rotation: " << q[3] << std::endl;
if (control)
sleep(5) ;
std::cout << "Velocity control: in camera frame..." << std::endl;
q.resize(2) ;
q = 0.0;
std::cout << " rx rotation: " << q[0] << std::endl;
if (control)
sleep(5) ;
q.resize(2) ;
q = 0.0;
std::cout << " ry rotation: " << q[1] << std::endl;
if (control)
sleep(5) ;
std::cout << "The end" << std::endl;
}
catch (...) {
}
return 0;
}
#else
int
main()
{
vpERROR_TRACE(
"You do not have an afma4 robot connected to your computer...");
return 0;
}
#endif