Example of eye-in-hand control law. We control here a real robot, the ADEPT Viper 850 robot (arm, with 6 degrees of freedom). The velocity is computed in the camera frame. The visual feature is the center of gravity of a point. We use here a linear Kalman filter with a constant velocity state model to estimate the moving target motion.
#include <visp/vpConfig.h>
#include <visp/vpDebug.h>
#include <stdlib.h>
#include <stdio.h>
#include <iostream>
#include <fstream>
#include <sstream>
#if (defined (VISP_HAVE_VIPER850) && defined (VISP_HAVE_DC1394_2))
#include <visp/vp1394TwoGrabber.h>
#include <visp/vpImage.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/vpRobotViper850.h>
#include <visp/vpIoTools.h>
#include <visp/vpException.h>
#include <visp/vpMatrixException.h>
#include <visp/vpServoDisplay.h>
#include <visp/vpImageIo.h>
#include <visp/vpDot2.h>
#include <visp/vpAdaptiveGain.h>
#include <visp/vpLinearKalmanFilterInstantiation.h>
#include <visp/vpDisplay.h>
#include <visp/vpDisplayX.h>
#include <visp/vpDisplayOpenCV.h>
#include <visp/vpDisplayGTK.h>
int
main()
{
std::string username;
std::string logdirname;
logdirname ="/tmp/" + username;
try {
}
catch (...) {
std::cerr << std::endl
<< "ERROR:" << std::endl;
std::cerr << " Cannot create " << logdirname << std::endl;
exit(-1);
}
}
std::string logfilename;
logfilename = logdirname + "/log.dat";
std::ofstream flog(logfilename.c_str());
try {
unsigned int nsignal = 2;
double rho = 0.3;
unsigned int state_size = 0;
sigma_state.
resize(state_size*nsignal);
sigma_state = 0.00001;
sigma_measure = 0.05;
double dummy = 0;
kalman.
initFilter(nsignal, sigma_state, sigma_measure, rho, dummy);
bool reset = false;
#if 1
#else
#endif
double Tloop = 1./80.f;
switch(fps) {
default: break;
}
#ifdef VISP_HAVE_X11
#elif defined(VISP_HAVE_OPENCV)
#elif defined(VISP_HAVE_GTK)
#endif
for (int i=0; i< 10; i++)
std::cout << "Click on a dot..." << std::endl;
task.addFeature(p,pd) ;
task.setLambda(lambda) ;
task.print() ;
std::cout << "\nHit CTRL-C to stop the loop...\n" << std::flush;
int iter = 0;
double t_0, t_1, Tv;
dc1394video_frame_t *frame = NULL;
for ( ; ; ) {
try {
Tv = (double)(t_0 - t_1) / 1000.0;
t_1 = t_0;
v1 = task.computeControlLaw() ;
err = task.getError();
if (iter==0){
err_1 = 0;
dedt_mes = 0;
}
else{
dedt_mes = (err - err_1)/(Tv) - J1 *vm;
err_1 = err;
}
if (iter < 2)
dedt_mes = 0;
for (unsigned int i=0; i < nsignal; i++) {
dedt_filt[i] = kalman.
Xest[i*state_size];
}
if (iter < 2)
dedt_filt = 0;
vpMatrix J1p = task.getTaskJacobianPseudoInverse();
v2 = - J1p*dedt_filt;
v = v1 + v2;
iter ++;
}
catch(...) {
std::cout << "Tracking failed... Stop the robot." << std::endl;
v = 0;
task.kill();
return 0;
}
flog << v[0] << " " << v[1] << " " << v[2] << " "
<< v[3] << " " << v[4] << " " << v[5] << " ";
flog << qvel[0] << " " << qvel[1] << " " << qvel[2] << " "
<< qvel[3] << " " << qvel[4] << " " << qvel[5] << " ";
flog << q[0] << " " << q[1] << " " << q[2] << " "
<< q[3] << " " << q[4] << " " << q[5] << " ";
flog << ( task.getError() ).t() << std::endl;
}
flog.close() ;
task.print() ;
task.kill();
return 0;
}
catch (...)
{
flog.close() ;
task.kill();
return 0;
}
}
#else
int
main()
{
vpERROR_TRACE(
"You do not have a Viper robot or a firewire framegrabber connected to your computer...");
}
#endif