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 <visp3/core/vpConfig.h>
#include <visp3/core/vpDebug.h>
#ifdef VISP_HAVE_AFMA4
#include <stdlib.h>
#include <unistd.h>
#include <visp3/io/vpParseArgv.h>
#include <visp3/robot/vpRobotAfma4.h>
#define GETOPTARGS "mh"
#ifdef ENABLE_VISP_NAMESPACE
#endif
void usage(const char *name, const char *badparam)
{
fprintf(stdout, "\n\
Example of a positioning 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], nullptr);
return false;
break;
default:
usage(argv[0], optarg);
return false;
break;
}
}
if ((c == 1) || (c == -1)) {
usage(argv[0], nullptr);
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) {
return EXIT_FAILURE;
}
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);
#if 0
std::cout << "Velocity control: in articular..." << std::endl;
q = 0;
std::cout << " rotation around 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);
#endif
std::cout << "Velocity control: in camera frame..." << std::endl;
q.resize(6);
q = 0.0;
std::cout << " rx rotation: " << q[0] << std::endl;
if (control)
sleep(5);
q.resize(6);
q = 0.0;
std::cout << " ry rotation: " << q[1] << std::endl;
if (control)
sleep(5);
std::cout << "The end" << std::endl;
return EXIT_SUCCESS;
}
std::cout << "Catch a ViSP exception: " << e << std::endl;
return EXIT_FAILURE;
}
}
#else
int main()
{
std::cout << "You do not have an afma4 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.
static double rad(double deg)
static bool parse(int *argcPtr, const char **argv, vpArgvInfo *argTable, int flags)
Control of Irisa's cylindrical robot named Afma4.
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.
virtual vpRobotStateType setRobotState(const vpRobot::vpRobotStateType newState)