Example of a eye-to-hand control law. We control here a real robot, the Afma6 robot (cartesian robot, with 6 degrees of freedom). The robot is controlled in the camera frame.
#include <cmath>
#include <limits>
#include <list>
#include <stdlib.h>
#include <visp3/core/vpConfig.h>
#include <visp3/core/vpDebug.h>
#if (defined(VISP_HAVE_AFMA6) && defined(VISP_HAVE_DC1394))
#define SAVE 0
#include <visp3/blob/vpDot.h>
#include <visp3/core/vpDisplay.h>
#include <visp3/core/vpException.h>
#include <visp3/core/vpHomogeneousMatrix.h>
#include <visp3/core/vpImage.h>
#include <visp3/core/vpImagePoint.h>
#include <visp3/core/vpMath.h>
#include <visp3/core/vpPoint.h>
#include <visp3/gui/vpDisplayGTK.h>
#include <visp3/gui/vpDisplayOpenCV.h>
#include <visp3/gui/vpDisplayX.h>
#include <visp3/io/vpImageIo.h>
#include <visp3/robot/vpRobotAfma6.h>
#include <visp3/sensor/vp1394TwoGrabber.h>
#include <visp3/vision/vpPose.h>
#include <visp3/visual_features/vpFeatureBuilder.h>
#include <visp3/visual_features/vpFeaturePoint.h>
#include <visp3/vs/vpServo.h>
#include <visp3/vs/vpServoDisplay.h>
#define L 0.006
#define D 0
int main()
{
try {
int i;
#ifdef VISP_HAVE_X11
#elif defined(VISP_HAVE_OPENCV)
#elif defined(VISP_HAVE_GTK)
#endif
std::cout << std::endl;
std::cout << "-------------------------------------------------------" << std::endl;
std::cout << " Test program for vpServo " << std::endl;
std::cout << " Eye-to-hand task control" << std::endl;
std::cout << " Simulation " << std::endl;
std::cout << " task : servo a point " << std::endl;
std::cout << "-------------------------------------------------------" << std::endl;
std::cout << std::endl;
int nbPoint = 7;
for (i = 0; i < nbPoint; i++) {
}
for (i = 0; i < nbPoint; i++) {
double x = 0, y = 0;
}
std::cout << cMo << std::endl;
std::cout << " Learning 0/1 " << std::endl;
char name[FILENAME_MAX];
sprintf(name, "cdMo.dat");
int learning;
std::cin >> learning;
if (learning == 1) {
vpTRACE(
"Save the location of the object in a file cdMo.dat");
std::ofstream f(name);
f.close();
exit(1);
}
{
vpTRACE(
"Loading desired location from cdMo.dat");
std::ifstream f("cdMo.dat");
f.close();
}
for (i = 0; i < nbPoint; i++) {
}
vpTRACE(
"\t we want an eye-in-hand control law");
vpTRACE(
"\t robot is controlled in the camera frame");
for (i = 0; i < nbPoint; i++) {
}
vpTRACE(
"Display task information ");
double convergence_threshold = 0.00;
double error = 1;
unsigned int iter = 0;
oMcamrobot[0][3] = -0.05;
int it = 0;
double lambda_av = 0.1;
double alpha = 1;
double beta = 3;
std::cout << "alpha 0.7" << std::endl;
std::cin >> alpha;
std::cout << "beta 5" << std::endl;
std::cin >> beta;
std::list<vpImagePoint> Lcog;
while (error > convergence_threshold) {
std::cout << "---------------------------------------------" << iter++ << std::endl;
try {
for (i = 0; i < nbPoint; i++) {
Lcog.push_back(dot[i].getCog());
}
} catch (...) {
vpTRACE(
"Error detected while tracking visual features");
exit(1);
}
for (i = 0; i < nbPoint; i++) {
double x = 0, y = 0;
}
cMe = cMo * oMcamrobot * camrobotMe;
double gain;
if (iter > 2) {
if (std::fabs(alpha) <= std::numeric_limits<double>::epsilon())
gain = lambda_av;
else {
gain = alpha * exp(-beta * (task.
getError()).sumSquare()) + lambda_av;
}
} else
gain = lambda_av;
if (SAVE == 1)
gain = gain / 5;
vpTRACE(
"%f %f %f %f %f", alpha, beta, lambda_av, (task.
getError()).sumSquare(), gain);
for (std::list<vpImagePoint>::const_iterator it_cog = Lcog.begin(); it_cog != Lcog.end(); ++it_cog) {
}
std::cout << "|| s - s* || = " << error << std::endl;
if (error > 7) {
vpTRACE(
"Error detected while tracking visual features");
exit(1);
}
if ((SAVE == 1) && (iter % 3 == 0)) {
sprintf(name, "/tmp/marchand/image.%04d.ppm", it++);
}
}
v = 0;
return EXIT_SUCCESS;
}
std::cout << "Test failed with exception: " << e << std::endl;
return EXIT_FAILURE;
}
}
#else
int main()
{
std::cout << "You do not have an afma6 robot connected to your computer..." << std::endl;
return EXIT_SUCCESS;
}
#endif