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>
79 #include <visp/vpDirectShowGrabber.h>
80 #include <visp/vpImage.h>
81 #include <visp/vpDisplay.h>
82 #include <visp/vpDisplayX.h>
83 #include <visp/vpDisplayGTK.h>
84 #include <visp/vpDisplayGDI.h>
86 #include <visp/vpMath.h>
87 #include <visp/vpHomogeneousMatrix.h>
88 #include <visp/vpFeaturePoint.h>
89 #include <visp/vpPoint.h>
90 #include <visp/vpServo.h>
91 #include <visp/vpFeatureBuilder.h>
92 #include <visp/vpRobotBiclops.h>
93 #include <visp/vpIoTools.h>
94 #include <visp/vpParseArgv.h>
95 #include <visp/vpServoDisplay.h>
96 #include <visp/vpDot.h>
99 #include <visp/vpException.h>
100 #include <visp/vpMatrixException.h>
103 #ifdef VISP_HAVE_PTHREAD
104 pthread_mutex_t mutexEndLoop = PTHREAD_MUTEX_INITIALIZER;
107 void signalCtrC(
int )
109 #ifdef VISP_HAVE_PTHREAD
110 pthread_mutex_unlock( &mutexEndLoop );
118 #define GETOPTARGS "c:d:h"
131 void usage(
const char *name,
const char *badparam, std::string& conf, std::string& debugdir, std::string& user)
134 Example of eye-in-hand control law. We control here a real robot, the biclops\n\
135 robot (pan-tilt head provided by Traclabs). The velocity is\n\
136 computed in articular. The visual feature is the center of gravity of a\n\
140 %s [-c <Biclops configuration file>] [-d <debug file directory>] [-h]\n", name);
144 -c <Biclops configuration file> %s\n\
145 Sets the biclops robot configuration file.\n\n\
146 -d <debug file directory> %s\n\
147 Sets the debug file directory.\n\
148 From this directory, creates the\"%s\"\n\
149 subdirectory depending on the username, where\n\
150 it writes biclops.txt file.\n", conf.c_str(), debugdir.c_str(), user.c_str());
153 fprintf(stderr,
"ERROR: \n" );
154 fprintf(stderr,
"\nBad parameter [%s]\n", badparam);
170 bool getOptions(
int argc,
const char **argv, std::string& conf, std::string &debugdir, std::string& user)
177 case 'c': conf = optarg;
break;
178 case 'd': debugdir = optarg;
break;
179 case 'h': usage(argv[0], NULL, conf, debugdir, user);
return false;
break;
182 usage(argv[0], optarg, conf, debugdir, user);
return false;
break;
186 if ((c == 1) || (c == -1)) {
188 usage(argv[0], NULL, conf, debugdir, user);
189 std::cerr <<
"ERROR: " << std::endl;
190 std::cerr <<
" Bad argument " << optarg << std::endl << std::endl;
200 main(
int argc,
const char ** argv)
202 std::cout << std::endl ;
203 std::cout <<
"-------------------------------------------------------" << std::endl ;
204 std::cout <<
" Test program for vpServo " <<std::endl ;
205 std::cout <<
" Eye-in-hand task control, velocity computed in the camera frame" << std::endl ;
206 std::cout <<
" Simulation " << std::endl ;
207 std::cout <<
" task : servo a point " << std::endl ;
208 std::cout <<
"-------------------------------------------------------" << std::endl ;
209 std::cout << std::endl ;
213 #ifdef VISP_HAVE_PTHREAD
214 pthread_mutex_lock( &mutexEndLoop );
216 signal( SIGINT,&signalCtrC );
219 std::string opt_conf =
"/usr/share/BiclopsDefault.cfg";
221 std::string username;
222 std::string debugdir;
223 std::string opt_debugdir;
226 #if !defined(_WIN32) && (defined(__unix__) || defined(__unix) || (defined(__APPLE__) && defined(__MACH__))) // UNIX
227 opt_debugdir =
"/tmp";
228 #elif defined(_WIN32)
229 opt_debugdir =
"C:/temp";
236 if (getOptions(argc, argv, opt_conf, opt_debugdir , username) ==
false) {
241 if (!opt_debugdir.empty())
242 debugdir = opt_debugdir;
245 std::string dirname = debugdir +
"/" + username;
254 usage(argv[0], NULL, opt_conf, debugdir, username);
255 std::cerr << std::endl
256 <<
"ERROR:" << std::endl;
257 std::cerr <<
" Cannot create " << dirname << std::endl;
258 std::cerr <<
" Check your -d " << debugdir <<
" option " << std::endl;
264 char *filename =
new char[FILENAME_MAX];
265 sprintf(filename,
"%s/biclops.txt", debugdir.c_str());
266 FILE *fd = fopen(filename,
"w");
279 #if defined VISP_HAVE_DC1394_2
281 #elif defined VISP_HAVE_DIRECTSHOW
298 #if defined VISP_HAVE_X11
299 vpDisplayX display(I, 100, 100,
"Display X...") ;
300 #elif defined VISP_HAVE_GTK
302 #elif defined(_WIN32)
322 std::cout <<
"Click on a dot to initialize the tracking..." << std::endl;
352 vpTRACE(
"Set the position of the camera in the end-effector frame ") ;
358 std::cout << cVe <<std::endl ;
361 std::cout <<
"Click in the image to start the servoing..." << std::endl;
380 unsigned int iter=0 ;
382 #ifdef VISP_HAVE_PTHREAD
383 while( 0 != pthread_mutex_trylock( &mutexEndLoop ) )
388 std::cout <<
"---------------------------------------------" << iter <<std::endl ;
413 std::cout <<
"v: " << v.
t() ;
416 std::cout <<
"|| s - s* || = " << ( task.
getError() ).sumSquare() << std::endl;
420 s_minus_sStar = task.
s - task.
sStar;
421 fprintf(fd,
"%f %f %f %f %f\n",
423 s_minus_sStar[0], s_minus_sStar[1],
428 std::cout <<
"Display task information " << std::endl;
443 vpERROR_TRACE(
"You don't have a biclops head connected to your computer or 1394 framegrabbing capabilities...");
Definition of the vpMatrix class.
The class provides a data structure for the homogeneous matrices as well as a set of operations on th...
void setPosition(const vpHomogeneousMatrix &cMw)
Display for windows using GDI (available on any windows 32 platform).
void set_eJe(const vpMatrix &eJe_)
Define the X11 console to display images.
void addFeature(vpBasicFeature &s, vpBasicFeature &s_star, const unsigned int select=vpBasicFeature::FEATURE_ALL)
Initialize the position controller.
void track(const vpImage< unsigned char > &I)
Class that defines a 2D point visual feature which is composed by two parameters that are the cartes...
class for windows direct show devices
static int wait(double t0, double t)
static void flush(const vpImage< unsigned char > &I)
static bool parse(int *argcPtr, const char **argv, vpArgvInfo *argTable, int flags)
virtual vpRobotStateType setRobotState(const vpRobot::vpRobotStateType newState)
Initialize the velocity controller.
vpColVector getError() const
vpColVector computeControlLaw()
static void display(const vpImage< unsigned char > &I)
vpRowVector t() const
transpose of Vector
void acquire(vpImage< unsigned char > &I)
Generic class defining intrinsic camera parameters.
The vpDisplayGTK allows to display image using the GTK+ library version 1.2.
Class that consider the particular case of twist transformation matrix that allows to transform a vel...
Interface for the biclops, pan, tilt head control.
void setInteractionMatrixType(const vpServoIteractionMatrixType &interactionMatrixType, const vpServoInversionType &interactionMatrixInversion=PSEUDO_INVERSE)
void buildFrom(const double x, const double y, const double Z)
void get_cVe(vpVelocityTwistMatrix &cVe) const
Class that provides a data structure for the column vectors as well as a set of operations on these v...
void get_eJe(vpMatrix &eJe)
void setGraphics(const bool activate)
void set_cVe(const vpVelocityTwistMatrix &cVe_)
void print(const vpServo::vpServoPrintType display_level=ALL, std::ostream &os=std::cout)
This tracker is meant to track a dot (connected pixels with same gray level) on a vpImage...
Class for firewire ieee1394 video devices using libdc1394-2.x api.
virtual bool getClick(bool blocking=true)=0
void set_Z(const double Z)
static void create(vpFeaturePoint &s, const vpCameraParameters &cam, const vpDot &d)
void setServo(const vpServoType &servo_type)
void setVelocity(const vpRobot::vpControlFrameType frame, const vpColVector &v)
void initTracking(const vpImage< unsigned char > &I)
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)