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 <visp/vpConfig.h>
#include <visp/vpDebug.h>
#include <stdlib.h>
#include <cmath>
#include <limits>
#include <list>
#if (defined (VISP_HAVE_AFMA6) && defined (VISP_HAVE_DC1394_2))
#define SAVE 0
#include <visp/vp1394TwoGrabber.h>
#include <visp/vpImage.h>
#include <visp/vpImagePoint.h>
#include <visp/vpMath.h>
#include <visp/vpHomogeneousMatrix.h>
#include <visp/vpFeaturePoint.h>
#include <visp/vpPoint.h>
#include <visp/vpServo.h>
#include <visp/vpFeatureBuilder.h>
#include <visp/vpRobotAfma6.h>
#include <visp/vpException.h>
#include <visp/vpMatrixException.h>
#include <visp/vpServoDisplay.h>
#include <visp/vpDot.h>
#include <visp/vpPose.h>
#include <visp/vpImageIo.h>
#include <visp/vpDisplay.h>
#include <visp/vpDisplayX.h>
#include <visp/vpDisplayOpenCV.h>
#include <visp/vpDisplayGTK.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)
{
}
error = ( task.
getError() ).sumSquare() ;
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 ;
}
catch (...)
{
return 0;
}
}
#else
int
main()
{
vpERROR_TRACE(
"You do not have an afma6 robot or a firewire framegrabber connected to your computer...");
}
#endif