Example of a real robot control, the Biclops robot (pan-tilt turret) by Traclabs. The robot is controlled first in position, then in velocity.
#include <iostream>
#include <visp3/core/vpConfig.h>
#ifdef VISP_HAVE_BICLOPS
#include <visp3/robot/vpRobotBiclops.h>
#include <visp3/io/vpParseArgv.h>
#define GETOPTARGS "c:h"
#ifdef ENABLE_VISP_NAMESPACE
#endif
void usage(const char *name, const char *badparam, std::string conf)
{
fprintf(stdout, "\n\
Move the Biclops robot\n\
\n\
SYNOPSIS\n\
%s [-c <Biclops configuration file>] [-h]\n\
",
name);
fprintf(stdout, "\n\
OPTIONS: Default\n\
-c <Biclops configuration file> %s\n\
Sets the Biclops robot configuration file.\n\n",
conf.c_str());
if (badparam) {
fprintf(stderr, "ERROR: \n");
fprintf(stderr, "\nBad parameter [%s]\n", badparam);
}
}
bool getOptions(int argc, const char **argv, std::string &conf)
{
const char *optarg_;
int c;
switch (c) {
case 'c':
conf = optarg_;
break;
case 'h':
usage(argv[0], nullptr, conf);
return false;
break;
default:
usage(argv[0], optarg_, conf);
return false;
break;
}
}
if ((c == 1) || (c == -1)) {
usage(argv[0], nullptr, conf);
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)
{
std::string opt_conf = "/usr/share/BiclopsDefault.cfg";
if (getOptions(argc, argv, opt_conf) == false) {
return EXIT_FAILURE;
}
try {
q = 0;
std::cout << "Set Joint position "
<<
" tilt: " <<
vpMath::deg(q[1]) <<
" deg" << std::endl;
robot.setPositioningVelocity(30.);
std::cout << " Joint position "
std::cout << " Joint velocity "
std::cout << "Set Joint position "
<<
" tilt: " <<
vpMath::deg(q[1]) <<
" deg" << std::endl;
robot.setPositioningVelocity(10);
std::cout << " Joint position: "
std::cout << " Joint velocity: "
std::cout << "Set STATE_VELOCITY_CONTROL" << std::endl;
std::cout << " Joint position: "
<<
" tilt: " <<
vpMath::deg(qm[1]) <<
" deg" << std::endl;
std::cout << " Joint velocity "
qdot = 0;
std::cout << "Set joint velocity for 5 sec"
<<
" tilt: " <<
vpMath::deg(qdot[1]) <<
" deg/s" << std::endl;
std::cout << " Joint position "
<<
" tilt: " <<
vpMath::deg(qm[1]) <<
" deg" << std::endl;
std::cout << " Joint velocity "
qdot = 0;
std::cout << "Set joint velocity for 3 sec"
<<
" tilt: " <<
vpMath::deg(qdot[1]) <<
" deg/s" << std::endl;
std::cout << " Joint position "
<<
" tilt: " <<
vpMath::deg(qm[1]) <<
" deg" << std::endl;
std::cout << " Joint velocity "
qdot = 0;
std::cout << "Set joint velocity for 2 sec"
<<
" tilt: " <<
vpMath::deg(qdot[1]) <<
" deg/s" << std::endl;
std::cout << " Joint position "
<<
" tilt: " <<
vpMath::deg(qm[1]) <<
" deg" << std::endl;
std::cout << " Joint velocity "
qdot = 0;
std::cout << "Set joint velocity for 2 sec"
<<
" tilt: " <<
vpMath::deg(qdot[1]) <<
" deg/s" << std::endl;
std::cout << " Joint position "
<<
" tilt: " <<
vpMath::deg(qm[1]) <<
" deg" << std::endl;
std::cout << " Joint velocity "
return EXIT_SUCCESS;
}
std::cout <<
"Catch an exception: " << e.
getMessage() << std::endl;
return EXIT_FAILURE;
}
}
#else
int main()
{
std::cout << "You do not have an Biclops PT robot connected to your computer..." << std::endl;
return EXIT_SUCCESS;
}
#endif
static const unsigned int ndof
Number of dof.
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)
static bool parse(int *argcPtr, const char **argv, vpArgvInfo *argTable, int flags)
Interface for the Biclops, pan, tilt head control.
void getVelocity(const vpRobot::vpControlFrameType frame, vpColVector &velocity)
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)
VISP_EXPORT int wait(double t0, double t)