63 #include <visp/vpConfig.h>
64 #include <visp/vpDebug.h>
66 #if (defined (VISP_HAVE_AFMA4) && defined (VISP_HAVE_DC1394_2))
68 #include <visp/vp1394TwoGrabber.h>
69 #include <visp/vpImage.h>
70 #include <visp/vpDisplay.h>
71 #include <visp/vpDisplayX.h>
72 #include <visp/vpDisplayOpenCV.h>
73 #include <visp/vpDisplayGTK.h>
75 #include <visp/vpMath.h>
76 #include <visp/vpHomogeneousMatrix.h>
77 #include <visp/vpFeaturePoint.h>
78 #include <visp/vpPoint.h>
79 #include <visp/vpServo.h>
80 #include <visp/vpFeatureBuilder.h>
81 #include <visp/vpRobotAfma4.h>
82 #include <visp/vpIoTools.h>
83 #include <visp/vpException.h>
84 #include <visp/vpMatrixException.h>
85 #include <visp/vpServoDisplay.h>
86 #include <visp/vpParseArgv.h>
87 #include <visp/vpDot2.h>
88 #include <visp/vpAdaptiveGain.h>
89 #include <visp/vpLinearKalmanFilterInstantiation.h>
93 #define GETOPTARGS "hK:l:"
110 void usage(
const char *name,
const char *badparam,
114 Tests a control law with the following characteristics:\n\
115 - eye-in-hand control\n\
116 - camera velocity are computed\n\
117 - servo on 1 points.\n\
118 - Kalman filtering\n\
121 %s [-K <0|1|2|3>] [-h]\n", name);
126 Set the constant gain. By default adaptive gain. \n\
132 2: acceleration model\n\
135 Print the help.\n", (
int) kalman);
138 fprintf(stderr,
"ERROR: \n" );
139 fprintf(stderr,
"\nBad parameter [%s]\n", badparam);
158 bool getOptions(
int argc,
const char **argv, KalmanType &kalman,
159 bool &doAdaptativeGain,
168 kalman = (KalmanType) atoi(optarg);
171 doAdaptativeGain =
false;
174 case 'h': usage(argv[0], NULL, kalman);
178 usage(argv[0], optarg, kalman);
183 if ((c == 1) || (c == -1)) {
185 usage(argv[0], NULL, kalman);
186 std::cerr <<
"ERROR: " << std::endl;
187 std::cerr <<
" Bad argument " << optarg << std::endl << std::endl;
195 main(
int argc,
const char ** argv)
198 KalmanType opt_kalman = K_NONE;
200 bool doAdaptativeGain =
true;
202 int opt_cam_frequency = 60;
205 if (getOptions(argc, argv, opt_kalman, doAdaptativeGain, lambda) ==
false) {
215 std::string username;
220 std::string logdirname;
221 logdirname =
"/tmp/" + username;
230 std::cerr << std::endl
231 <<
"ERROR:" << std::endl;
232 std::cerr <<
" Cannot create " << logdirname << std::endl;
236 std::string logfilename;
237 logfilename = logdirname +
"/log.dat";
240 std::ofstream flog(logfilename.c_str());
247 switch(opt_cam_frequency) {
254 for (
int i=0; i < 10; i++)
258 vpDisplayX display(I,100,100,
"Current image") ;
259 #elif defined(VISP_HAVE_OPENCV)
261 #elif defined(VISP_HAVE_GTK)
268 std::cout << std::endl ;
269 std::cout <<
"-------------------------------------------------------" << std::endl ;
270 std::cout <<
"Test program for target motion compensation using a Kalman filter " <<std::endl ;
271 std::cout <<
"Eye-in-hand task control, velocity computed in the camera frame" << std::endl ;
272 std::cout <<
"Task : servo a point \n" << std::endl ;
277 std::cout <<
"Servo with no target motion compensation (see -K option)\n";
280 std::cout <<
"Servo with target motion compensation using a Kalman filter\n"
281 <<
"with constant velocity modelization (see -K option)\n";
284 std::cout <<
"Servo with target motion compensation using a Kalman filter\n"
285 <<
"with constant acceleration modelization (see -K option)\n";
288 std::cout <<
"-------------------------------------------------------" << std::endl ;
289 std::cout << std::endl ;
293 std::cout <<
"Click on the dot..." << std::endl;
324 std::cout << std::endl ;
325 task.addFeature(p,pd) ;
328 task.setLambda(lambda) ;
341 unsigned int nsignal = 2;
345 unsigned int state_size = 0;
352 sigma_state.
resize(state_size*nsignal);
353 sigma_state = 0.00001;
354 sigma_measure = 0.05;
356 kalman.
initFilter(nsignal, sigma_state, sigma_measure, rho, dummy);
360 case K_ACCELERATION: {
364 sigma_state.
resize(state_size*nsignal);
365 sigma_state = 0.00001;
366 sigma_measure = 0.05;
367 double dt = 1./opt_cam_frequency;
368 kalman.
initFilter(nsignal, sigma_state, sigma_measure, rho, dt );
379 double t_0, t_1, Tv, Tv_0, Tv_1;
397 std::cout <<
"\nHit CTRL-C to stop the loop...\n" << std::flush;
401 Tv = (double)(t_0 - t_1) / 1000.0;
435 v1 = task.computeControlLaw() ;
450 dedt_mes = (err_0 - err_1)/(Tv_1) - task.J1*vm_0;
468 for (
unsigned int i=0; i < nsignal; i++) {
469 dedt_filt[i] = kalman.
Xest[i*state_size];
475 vpMatrix J1p = task.getTaskJacobianPseudoInverse();
476 v2 = - J1p*dedt_filt;
500 flog << v[0] <<
" " << v[1] <<
" " << v[2] <<
" "
501 << v[3] <<
" " << v[4] <<
" " << v[5] <<
" ";
506 flog << task.error[0] <<
" " << task.error[1] <<
" ";
513 flog << dedt_mes[0] <<
" " << dedt_mes[1] <<
" ";
516 flog << dedt_filt[0] <<
" " << dedt_filt[1] <<
" ";
538 std::cout <<
"Catch a ViSP exception: " << e << std::endl;
549 vpERROR_TRACE(
"You do not have an afma4 robot or a firewire framegrabber connected to your computer...");
Definition of the vpMatrix class.
Adaptive gain computation.
unsigned int getStateSize()
unsigned int getWidth() const
void initFilter(unsigned int nsignal, vpColVector &sigma_state, vpColVector &sigma_measure, double rho, double dt)
void filter(vpColVector &z)
void setVelocity(const vpRobot::vpControlFrameType frame, const vpColVector &velocity)
Define the X11 console to display images.
error that can be emited by ViSP classes.
Class that defines a 2D point visual feature which is composed by two parameters that are the cartes...
static double measureTimeMs()
static const vpColor green
This tracker is meant to track a blob (connex pixels with same gray level) on a vpImage.
void track(const vpImage< unsigned char > &I)
static void flush(const vpImage< unsigned char > &I)
static bool parse(int *argcPtr, const char **argv, vpArgvInfo *argTable, int flags)
vpImagePoint getCog() const
void initStandard(double gain_at_zero, double gain_at_infinity, double slope_at_zero)
Initialize the velocity controller.
static void display(const vpImage< unsigned char > &I)
The vpDisplayOpenCV allows to display image using the opencv library.
virtual void displayCross(const vpImagePoint &ip, unsigned int size, const vpColor &color, unsigned int thickness=1)=0
Generic class defining intrinsic camera parameters.
void initFromConstant(double c)
The vpDisplayGTK allows to display image using the GTK+ library version 1.2.
void buildFrom(const double x, const double y, const double Z)
vpRobot::vpRobotStateType setRobotState(vpRobot::vpRobotStateType newState)
Class that provides a data structure for the column vectors as well as a set of operations on these v...
void getVelocity(const vpRobot::vpControlFrameType frame, vpColVector &velocity)
Control of Irisa's cylindrical robot named Afma4.
void initTracking(const vpImage< unsigned char > &I, unsigned int size=0)
This class provides an implementation of some specific linear Kalman filters.
unsigned int getHeight() const
void setStateModel(vpStateModel model)
Class for firewire ieee1394 video devices using libdc1394-2.x api.
Class that defines a 2D point in an image. This class is useful for image processing and stores only ...
static void create(vpFeaturePoint &s, const vpCameraParameters &cam, const vpDot &d)
static void display(const vpServo &s, const vpCameraParameters &cam, const vpImage< unsigned char > &I, vpColor currentColor=vpColor::green, vpColor desiredColor=vpColor::red, unsigned int thickness=1)
void setGraphics(const bool activate)
static const vpColor blue
void resize(const unsigned int i, const bool flagNullify=true)