67 #include <visp/vpTime.h>
68 #include <visp/vpConfig.h>
69 #include <visp/vpDebug.h>
72 #if ( defined (VISP_HAVE_BICLOPS) && (defined (VISP_HAVE_DC1394_2) || defined(VISP_HAVE_DIRECTSHOW)) )
74 #ifdef VISP_HAVE_PTHREAD
78 #include <visp/vp1394TwoGrabber.h>
80 #include <visp/vpDirectShowGrabber.h>
81 #include <visp/vpImage.h>
82 #include <visp/vpDisplay.h>
83 #include <visp/vpDisplayX.h>
84 #include <visp/vpDisplayGTK.h>
85 #include <visp/vpDisplayGDI.h>
87 #include <visp/vpMath.h>
88 #include <visp/vpHomogeneousMatrix.h>
89 #include <visp/vpFeaturePoint.h>
90 #include <visp/vpPoint.h>
91 #include <visp/vpServo.h>
92 #include <visp/vpFeatureBuilder.h>
93 #include <visp/vpRobotBiclops.h>
94 #include <visp/vpIoTools.h>
95 #include <visp/vpParseArgv.h>
96 #include <visp/vpServoDisplay.h>
97 #include <visp/vpDot.h>
100 #include <visp/vpException.h>
101 #include <visp/vpMatrixException.h>
104 #ifdef VISP_HAVE_PTHREAD
105 pthread_mutex_t mutexEndLoop = PTHREAD_MUTEX_INITIALIZER;
108 void signalCtrC(
int )
110 #ifdef VISP_HAVE_PTHREAD
111 pthread_mutex_unlock( &mutexEndLoop );
119 #define GETOPTARGS "c:d:h"
132 void usage(
const char *name,
const char *badparam, std::string& conf, std::string& debugdir, std::string& user)
135 Example of eye-in-hand control law. We control here a real robot, the biclops\n\
136 robot (pan-tilt head provided by Traclabs). The velocity is\n\
137 computed in articular. The visual feature is the center of gravity of a\n\
141 %s [-c <Biclops configuration file>] [-d <debug file directory>] [-h]\n", name);
145 -c <Biclops configuration file> %s\n\
146 Sets the biclops robot configuration file.\n\n\
147 -d <debug file directory> %s\n\
148 Sets the debug file directory.\n\
149 From this directory, creates the\"%s\"\n\
150 subdirectory depending on the username, where\n\
151 it writes biclops.txt file.\n", conf.c_str(), debugdir.c_str(), user.c_str());
154 fprintf(stderr,
"ERROR: \n" );
155 fprintf(stderr,
"\nBad parameter [%s]\n", badparam);
171 bool getOptions(
int argc,
const char **argv, std::string& conf, std::string &debugdir, std::string& user)
178 case 'c': conf = optarg;
break;
179 case 'd': debugdir = optarg;
break;
180 case 'h': usage(argv[0], NULL, conf, debugdir, user);
return false;
break;
183 usage(argv[0], optarg, conf, debugdir, user);
return false;
break;
187 if ((c == 1) || (c == -1)) {
189 usage(argv[0], NULL, conf, debugdir, user);
190 std::cerr <<
"ERROR: " << std::endl;
191 std::cerr <<
" Bad argument " << optarg << std::endl << std::endl;
201 main(
int argc,
const char ** argv)
203 std::cout << std::endl ;
204 std::cout <<
"-------------------------------------------------------" << std::endl ;
205 std::cout <<
" Test program for vpServo " <<std::endl ;
206 std::cout <<
" Eye-in-hand task control, velocity computed in the camera frame" << std::endl ;
207 std::cout <<
" Simulation " << std::endl ;
208 std::cout <<
" task : servo a point " << std::endl ;
209 std::cout <<
"-------------------------------------------------------" << std::endl ;
210 std::cout << std::endl ;
214 #ifdef VISP_HAVE_PTHREAD
215 pthread_mutex_lock( &mutexEndLoop );
217 signal( SIGINT,&signalCtrC );
220 std::string opt_conf =
"/usr/share/BiclopsDefault.cfg";
222 std::string username;
223 std::string debugdir;
224 std::string opt_debugdir;
228 opt_debugdir =
"/tmp";
230 opt_debugdir =
"C:/temp";
237 if (getOptions(argc, argv, opt_conf, opt_debugdir , username) ==
false) {
242 if (!opt_debugdir.empty())
243 debugdir = opt_debugdir;
246 std::string dirname = debugdir +
"/" + username;
255 usage(argv[0], NULL, opt_conf, debugdir, username);
256 std::cerr << std::endl
257 <<
"ERROR:" << std::endl;
258 std::cerr <<
" Cannot create " << dirname << std::endl;
259 std::cerr <<
" Check your -d " << debugdir <<
" option " << std::endl;
265 char *filename =
new char[FILENAME_MAX];
266 sprintf(filename,
"%s/biclops.txt", debugdir.c_str());
267 FILE *fd = fopen(filename,
"w");
280 #if defined VISP_HAVE_DC1394_2
284 #elif defined VISP_HAVE_DIRECTSHOW
301 #if defined VISP_HAVE_X11
302 vpDisplayX display(I, 100, 100,
"Display X...") ;
303 #elif defined VISP_HAVE_GTK
326 std::cout <<
"Click on a dot to initialize the tracking..." << std::endl;
356 vpTRACE(
"Set the position of the camera in the end-effector frame ") ;
362 std::cout << cVe <<std::endl ;
365 std::cout <<
"Click in the image to start the servoing..." << std::endl;
384 unsigned int iter=0 ;
386 #ifdef VISP_HAVE_PTHREAD
387 while( 0 != pthread_mutex_trylock( &mutexEndLoop ) )
392 std::cout <<
"---------------------------------------------" << iter <<std::endl ;
417 std::cout <<
"v: " << v.
t() ;
420 std::cout <<
"|| s - s* || = " << ( task.
getError() ).sumSquare() << std::endl;
424 s_minus_sStar = task.
s - task.
sStar;
425 fprintf(fd,
"%f %f %f %f %f\n",
427 s_minus_sStar[0], s_minus_sStar[1],
432 std::cout <<
"Display task information " << std::endl;
447 vpERROR_TRACE(
"You don't have a biclops head connected to your computer or 1394 framegrabbing capabilities...");