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...");
Definition of the vpMatrix class.
static void display(vpServo &s, const vpCameraParameters &cam, vpImage< unsigned char > &I, vpColor currentColor=vpColor::green, vpColor desiredColor=vpColor::red, unsigned int thickness=1)
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).
Define the X11 console to display images.
void addFeature(vpBasicFeature &s, vpBasicFeature &s_star, const unsigned int select=vpBasicFeature::FEATURE_ALL)
create a new ste of two visual features
void setLambda(double _lambda)
set the gain lambda
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)
void set_cVe(vpVelocityTwistMatrix &_cVe)
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)
void get_cVe(vpVelocityTwistMatrix &cVe)
void kill()
destruction (memory deallocation if required)
Initialize the velocity controller.
vpColVector getError() const
vpColVector computeControlLaw()
compute the desired control law
static void display(const vpImage< unsigned char > &I)
void set_eJe(vpMatrix &_eJe)
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)
Set the type of the interaction matrix (current, mean, desired, user).
void buildFrom(const double x, const double y, const double Z)
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 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)
Class required to compute the visual servoing control law descbribed in and .
void setVelocity(const vpRobot::vpControlFrameType frame, const vpColVector &v)
void initTracking(const vpImage< unsigned char > &I)
void setServo(vpServoType _servo_type)
Choice of the visual servoing control law.