55 #include <visp/vpConfig.h>
56 #include <visp/vpDebug.h>
59 #ifdef VISP_HAVE_COIN_AND_GUI
61 #include <visp/vpImage.h>
62 #include <visp/vpCameraParameters.h>
63 #include <visp/vpTime.h>
64 #include <visp/vpSimulator.h>
65 #include <visp/vpMath.h>
66 #include <visp/vpHomogeneousMatrix.h>
67 #include <visp/vpFeaturePoint.h>
68 #include <visp/vpServo.h>
69 #include <visp/vpRobotCamera.h>
70 #include <visp/vpFeatureBuilder.h>
71 #include <visp/vpParseArgv.h>
72 #include <visp/vpIoTools.h>
74 #define GETOPTARGS "di:h"
86 void usage(
const char *name,
const char *badparam, std::string ipath)
89 Simulation Servo 4points.\n\
92 %s [-i <input image path>] [-d] [-h]\n", name);
96 -i <input image path> %s\n\
97 Set image input path.\n\
98 From this path read \"ViSP-images/iv/4points.iv\"\n\
100 Setting the VISP_INPUT_IMAGE_PATH environment\n\
101 variable produces the same behaviour than using\n\
105 Disable the image display. This can be useful \n\
106 for automatic tests using crontab under Unix or \n\
107 using the task manager under Windows.\n\
110 Print the help.\n\n", ipath.c_str());
113 fprintf(stdout,
"\nERROR: Bad parameter [%s]\n", badparam);
131 bool getOptions(
int argc,
const char **argv, std::string &ipath,
bool &display)
138 case 'i': ipath = optarg;
break;
139 case 'd': display =
false;
break;
140 case 'h': usage(argv[0], NULL, ipath);
return false;
break;
143 usage(argv[0], optarg, ipath);
return false;
break;
147 if ((c == 1) || (c == -1)) {
149 usage(argv[0], NULL, ipath);
150 std::cerr <<
"ERROR: " << std::endl;
151 std::cerr <<
" Bad argument " << optarg << std::endl << std::endl;
159 void *mainLoop (
void *_simu)
167 float sampling_time = 0.040f;
170 std::cout << std::endl ;
171 std::cout <<
"-------------------------------------------------------" << std::endl ;
172 std::cout <<
" Test program for vpServo " <<std::endl ;
173 std::cout <<
" Eye-in-hand task control, articular velocities are computed" << std::endl ;
174 std::cout <<
" Simulation " << std::endl ;
175 std::cout <<
" task : servo 4 points " << std::endl ;
176 std::cout <<
"-------------------------------------------------------" << std::endl ;
177 std::cout << std::endl ;
207 for (
int i = 0 ; i < 4 ; i++)
208 point[i].track(cMo) ;
212 for (
int i = 0 ; i < 4 ; i++)
240 for (
int i = 0 ; i < 4 ; i++)
246 std::cout <<
"Display task information" << std::endl;
251 unsigned int iter=0 ;
253 while(iter++ < 100) {
262 for (
int i = 0 ; i < 4 ; i++)
264 point[i].
track(cMo) ;
275 char name[FILENAME_MAX];
276 sprintf(name,
"/tmp/image.%04d.external.png",iter) ;
277 std::cout << name << std::endl ;
279 sprintf(name,
"/tmp/image.%04d.internal.png",iter) ;
285 std::cout <<
"\nDisplay task information" << std::endl;
295 int main(
int argc,
const char ** argv)
298 std::string env_ipath;
299 std::string opt_ipath;
301 std::string filename;
302 std::string username;
303 bool opt_display =
true;
309 if (! env_ipath.empty())
313 if (getOptions(argc, argv, opt_ipath, opt_display) ==
false) {
318 if (!opt_ipath.empty())
323 if (!opt_ipath.empty() && !env_ipath.empty()) {
324 if (ipath != env_ipath) {
325 std::cout << std::endl
326 <<
"WARNING: " << std::endl;
327 std::cout <<
" Since -i <visp image path=" << ipath <<
"> "
328 <<
" is different from VISP_IMAGE_PATH=" << env_ipath << std::endl
329 <<
" we skip the environment variable." << std::endl;
334 if (opt_ipath.empty() && env_ipath.empty()){
335 usage(argv[0], NULL, ipath);
336 std::cerr << std::endl
337 <<
"ERROR:" << std::endl;
338 std::cerr <<
" Use -i <visp image path> option or set VISP_INPUT_IMAGE_PATH "
340 <<
" environment variable to specify the location of the " << std::endl
341 <<
" image path where test images are located." << std::endl << std::endl;
358 simu.
load(filename.c_str()) ;
369 std::cout <<
"Catch an exception: " << e << std::endl;
377 {
vpTRACE(
"You should install Coin3D and SoQT or SoWin or SoXt") ;
Definition of the vpMatrix class.
virtual void initInternalViewer(const unsigned int nlig, const unsigned int ncol)
initialize the camera view
void write(const char *fileName)
void setExternalCameraParameters(vpCameraParameters &cam)
set external camera parameters
void setMaxTranslationVelocity(const double maxVt)
void setCameraPosition(vpHomogeneousMatrix &cMf)
set the camera position (from an homogeneous matrix)
The class provides a data structure for the homogeneous matrices as well as a set of operations on th...
void setPosition(const vpHomogeneousMatrix &cMw)
Implementation of a simulator based on Coin3d (www.coin3d.org).
void set_eJe(const vpMatrix &eJe_)
void closeMainApplication()
void addFeature(vpBasicFeature &s, vpBasicFeature &s_star, const unsigned int select=vpBasicFeature::FEATURE_ALL)
error that can be emited by ViSP classes.
void track(const vpHomogeneousMatrix &cMo)
Class that defines a 2D point visual feature which is composed by two parameters that are the cartes...
static double measureTimeMs()
virtual void mainLoop()
activate the mainloop
static int wait(double t0, double t)
static bool parse(int *argcPtr, const char **argv, vpArgvInfo *argTable, int flags)
Class that defines what is a point.
virtual void setSamplingTime(const double &delta_t)
void initApplication(void *(*start_routine)(void *))
begin the main program
vpColVector computeControlLaw()
void getCameraPosition(vpHomogeneousMatrix &_cMf)
get the camera position (from an homogeneous matrix)
Class that defines the simplest robot: a free flying camera.
void setInternalCameraParameters(vpCameraParameters &cam)
set internal camera parameters
Generic class defining intrinsic camera parameters.
void load(const char *file_name)
load an iv file
Class that consider the particular case of twist transformation matrix that allows to transform a vel...
void setInteractionMatrixType(const vpServoIteractionMatrixType &interactionMatrixType, const vpServoInversionType &interactionMatrixInversion=PSEUDO_INVERSE)
static double rad(double deg)
void buildFrom(const double x, const double y, const double Z)
void getPosition(vpHomogeneousMatrix &cMw) const
void initMainApplication()
perform some initialization in the main program thread
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 set_cVe(const vpVelocityTwistMatrix &cVe_)
The pose is a complete representation of every rigid motion in the euclidian space.
void print(const vpServo::vpServoPrintType display_level=ALL, std::ostream &os=std::cout)
static void create(vpFeaturePoint &s, const vpCameraParameters &cam, const vpDot &d)
void initExternalViewer(const unsigned int nlig, const unsigned int ncol)
initialize the external view
void setServo(const vpServoType &servo_type)
void setZoomFactor(const float zoom)
set the size of the camera/frame
void setVelocity(const vpRobot::vpControlFrameType frame, const vpColVector &v)
void setWorldCoordinates(const double ox, const double oy, const double oz)
Set the point world coordinates. We mean here the coordinates of the point in the object frame...