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>
73 #include <visp/vpMath.h>
74 #include <visp/vpHomogeneousMatrix.h>
75 #include <visp/vpFeaturePoint.h>
76 #include <visp/vpPoint.h>
77 #include <visp/vpServo.h>
78 #include <visp/vpFeatureBuilder.h>
79 #include <visp/vpRobotAfma4.h>
80 #include <visp/vpIoTools.h>
81 #include <visp/vpException.h>
82 #include <visp/vpMatrixException.h>
83 #include <visp/vpServoDisplay.h>
84 #include <visp/vpParseArgv.h>
85 #include <visp/vpDot2.h>
86 #include <visp/vpAdaptiveGain.h>
87 #include <visp/vpLinearKalmanFilterInstantiation.h>
91 #define GETOPTARGS "hK:l:"
108 void usage(
const char *name,
const char *badparam,
112 Tests a control law with the following characteristics:\n\
113 - eye-in-hand control\n\
114 - camera velocity are computed\n\
115 - servo on 1 points.\n\
116 - Kalman filtering\n\
119 %s [-K <0|1|2|3>] [-h]\n", name);
124 Set the constant gain. By default adaptive gain. \n\
130 2: acceleration model\n\
133 Print the help.\n", (
int) kalman);
136 fprintf(stderr,
"ERROR: \n" );
137 fprintf(stderr,
"\nBad parameter [%s]\n", badparam);
156 bool getOptions(
int argc,
const char **argv, KalmanType &kalman,
157 bool &doAdaptativeGain,
166 kalman = (KalmanType) atoi(optarg);
169 doAdaptativeGain =
false;
172 case 'h': usage(argv[0], NULL, kalman);
176 usage(argv[0], optarg, kalman);
181 if ((c == 1) || (c == -1)) {
183 usage(argv[0], NULL, kalman);
184 std::cerr <<
"ERROR: " << std::endl;
185 std::cerr <<
" Bad argument " << optarg << std::endl << std::endl;
193 main(
int argc,
const char ** argv)
195 KalmanType opt_kalman = K_NONE;
197 bool doAdaptativeGain =
true;
199 int opt_cam_frequency = 60;
202 if (getOptions(argc, argv, opt_kalman, doAdaptativeGain, lambda) ==
false) {
212 std::string username;
217 std::string logdirname;
218 logdirname =
"/tmp/" + username;
227 std::cerr << std::endl
228 <<
"ERROR:" << std::endl;
229 std::cerr <<
" Cannot create " << logdirname << std::endl;
233 std::string logfilename;
234 logfilename = logdirname +
"/log.dat";
237 std::ofstream flog(logfilename.c_str());
245 switch(opt_cam_frequency) {
252 for (
int i=0; i < 10; i++)
255 vpDisplayX display(I,100,100,
"Current image") ;
260 std::cout << std::endl ;
261 std::cout <<
"-------------------------------------------------------" << std::endl ;
262 std::cout <<
"Test program for target motion compensation using a Kalman filter " <<std::endl ;
263 std::cout <<
"Eye-in-hand task control, velocity computed in the camera frame" << std::endl ;
264 std::cout <<
"Task : servo a point \n" << std::endl ;
269 std::cout <<
"Servo with no target motion compensation (see -K option)\n";
272 std::cout <<
"Servo with target motion compensation using a Kalman filter\n"
273 <<
"with constant velocity modelization (see -K option)\n";
276 std::cout <<
"Servo with target motion compensation using a Kalman filter\n"
277 <<
"with constant acceleration modelization (see -K option)\n";
280 std::cout <<
"-------------------------------------------------------" << std::endl ;
281 std::cout << std::endl ;
285 std::cout <<
"Click on the dot..." << std::endl;
316 std::cout << std::endl ;
317 task.addFeature(p,pd) ;
320 task.setLambda(lambda) ;
333 unsigned int nsignal = 2;
337 unsigned int state_size = 0;
344 sigma_state.
resize(state_size*nsignal);
345 sigma_state = 0.00001;
346 sigma_measure = 0.05;
348 kalman.
initFilter(nsignal, sigma_state, sigma_measure, rho, dummy);
352 case K_ACCELERATION: {
356 sigma_state.
resize(state_size*nsignal);
357 sigma_state = 0.00001;
358 sigma_measure = 0.05;
359 double dt = 1./opt_cam_frequency;
360 kalman.
initFilter(nsignal, sigma_state, sigma_measure, rho, dt );
371 double t_0, t_1, Tv, Tv_0, Tv_1;
389 std::cout <<
"\nHit CTRL-C to stop the loop...\n" << std::flush;
393 Tv = (double)(t_0 - t_1) / 1000.0;
427 v1 = task.computeControlLaw() ;
442 dedt_mes = (err_0 - err_1)/(Tv_1) - task.J1*vm_0;
460 for (
unsigned int i=0; i < nsignal; i++) {
461 dedt_filt[i] = kalman.
Xest[i*state_size];
467 vpMatrix J1p = task.getTaskJacobianPseudoInverse();
468 v2 = - J1p*dedt_filt;
492 flog << v[0] <<
" " << v[1] <<
" " << v[2] <<
" "
493 << v[3] <<
" " << v[4] <<
" " << v[5] <<
" ";
498 flog << task.error[0] <<
" " << task.error[1] <<
" ";
505 flog << dedt_mes[0] <<
" " << dedt_mes[1] <<
" ";
508 flog << dedt_filt[0] <<
" " << dedt_filt[1] <<
" ";
545 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()
static void display(vpServo &s, const vpCameraParameters &cam, vpImage< unsigned char > &I, vpColor currentColor=vpColor::green, vpColor desiredColor=vpColor::red, unsigned int thickness=1)
unsigned int getWidth() const
void initFilter(unsigned int nsignal, vpColVector &sigma_state, vpColVector &sigma_measure, double rho, double dt)
void initFromConstant(double lambda)
void filter(vpColVector &z)
void setVelocity(const vpRobot::vpControlFrameType frame, const vpColVector &velocity)
Define the X11 console to display images.
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
Initialize the velocity controller.
static void display(const vpImage< unsigned char > &I)
virtual void displayCross(const vpImagePoint &ip, unsigned int size, const vpColor &color, unsigned int thickness=1)=0
Generic class defining intrinsic camera parameters.
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)
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)
Class required to compute the visual servoing control law.
void initStandard(double en_zero, double en_infini, double pente_en_zero)
void setGraphics(const bool activate)
static const vpColor blue
void resize(const unsigned int i, const bool flagNullify=true)