53 #include <visp3/core/vpConfig.h> 54 #include <visp3/core/vpDebug.h> 57 #ifdef VISP_HAVE_COIN3D_AND_GUI 58 #include <visp3/core/vpImage.h> 59 #include <visp3/core/vpCameraParameters.h> 60 #include <visp3/core/vpTime.h> 61 #include <visp3/ar/vpSimulator.h> 62 #include <visp3/core/vpMath.h> 63 #include <visp3/core/vpHomogeneousMatrix.h> 64 #include <visp3/visual_features/vpFeatureEllipse.h> 65 #include <visp3/core/vpCircle.h> 66 #include <visp3/vs/vpServo.h> 67 #include <visp3/robot/vpSimulatorCamera.h> 68 #include <visp3/visual_features/vpFeatureBuilder.h> 69 #include <visp3/io/vpParseArgv.h> 70 #include <visp3/core/vpIoTools.h> 72 #define GETOPTARGS "cdi:h" 84 void usage(
const char *name,
const char *badparam, std::string ipath)
87 Simulation Servo Circle\n\ 90 %s [-i <input image path>] [-d] [-h]\n", name);
95 -i <input image path> %s\n\ 96 Set image input path.\n\ 97 From this path read \"ViSP-images/iv/4points.iv\"\n\ 99 Setting the VISP_INPUT_IMAGE_PATH environment\n\ 100 variable produces the same behaviour than using\n\ 104 Disable the image display. This can be useful \n\ 105 for automatic tests using crontab under Unix or \n\ 106 using the task manager under Windows.\n\ 109 Print the help.\n\n",
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)
182 unsigned int pos = 2 ;
188 float sampling_time = 0.040f;
197 if (pos==1) cMod[2][3] = 0.32 ;
221 std::cout << std::endl ;
232 unsigned int iter=0 ;
234 unsigned int itermax ;
235 if (pos==2) itermax = 75 ;
else itermax = 100 ;
236 while(iter++ < itermax)
240 if (iter==1) std::cout <<
"get the robot position" << std::endl;
242 if (iter==1) std::cout <<
"new circle position" << std::endl;
249 if (iter==1) std::cout <<
"compute the control law" << std::endl;
252 std::cout <<
"Task rank: " << task.
getTaskRank() <<std::endl ;
253 std::cout <<
"send the camera velocity to the controller" << std::endl;
261 char name[FILENAME_MAX] ;
262 sprintf(name,
"/tmp/image.%04d.external.png",it) ;
263 std::cout <<
"Save " << name << std::endl ;
265 sprintf(name,
"/tmp/image.%04u.internal.png",iter) ;
266 std::cout <<
"Save " << name << std::endl ;
287 main(
int argc,
const char ** argv)
290 std::string env_ipath;
291 std::string opt_ipath;
293 std::string filename;
294 bool opt_display =
true;
300 if (! env_ipath.empty())
304 if (getOptions(argc, argv, opt_ipath, opt_display) ==
false) {
309 if (!opt_ipath.empty())
314 if (!opt_ipath.empty() && !env_ipath.empty()) {
315 if (ipath != env_ipath) {
316 std::cout << std::endl
317 <<
"WARNING: " << std::endl;
318 std::cout <<
" Since -i <visp image path=" << ipath <<
"> " 319 <<
" is different from VISP_INPUT_IMAGE_PATH=" << env_ipath << std::endl
320 <<
" we skip the environment variable." << std::endl;
325 if (opt_ipath.empty() && env_ipath.empty()){
326 usage(argv[0], NULL, ipath);
327 std::cerr << std::endl
328 <<
"ERROR:" << std::endl;
329 std::cerr <<
" Use -i <visp image path> option or set VISP_INPUT_IMAGE_PATH " 331 <<
" environment variable to specify the location of the " << std::endl
332 <<
" image path where test images are located." << std::endl << std::endl;
351 simu.
load(filename.c_str(),fMo) ;
362 std::cout <<
"Catch an exception: " << e << std::endl;
371 {
vpTRACE(
"You should install Coin3D and SoQT or SoWin or SoXt") ;
void setPosition(const vpHomogeneousMatrix &wMc)
virtual void initInternalViewer(const unsigned int nlig, const unsigned int ncol)
initialize the camera view
VISP_EXPORT int wait(double t0, double t)
unsigned int getTaskRank() const
void setVelocity(const vpRobot::vpControlFrameType frame, const vpColVector &vel)
void write(const char *fileName)
void setMaxTranslationVelocity(const double maxVt)
void setCameraPosition(vpHomogeneousMatrix &cMf)
set the camera position (from an homogeneous matrix)
Implementation of an homogeneous matrix and operations on such kind of matrices.
Class that defines the simplest robot: a free flying camera.
Implementation of a simulator based on Coin3d (www.coin3d.org).
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 addAbsoluteFrame(float zoom=1)
Add the representation of the absolute frame.
void track(const vpHomogeneousMatrix &cMo)
vpHomogeneousMatrix inverse() const
vpHomogeneousMatrix getPosition() const
virtual void mainLoop()
activate the mainloop
VISP_EXPORT double measureTimeMs()
static bool parse(int *argcPtr, const char **argv, vpArgvInfo *argTable, int flags)
virtual void setSamplingTime(const double &delta_t)
void initApplication(void *(*start_routine)(void *))
begin the main program
vpColVector computeControlLaw()
void setInternalCameraParameters(vpCameraParameters &cam)
set internal camera parameters
Generic class defining intrinsic camera parameters.
void load(const char *file_name)
load an iv file
void setInteractionMatrixType(const vpServoIteractionMatrixType &interactionMatrixType, const vpServoInversionType &interactionMatrixInversion=PSEUDO_INVERSE)
static double rad(double deg)
void initMainApplication()
perform some initialization in the main program thread
Implementation of column vector and the associated operations.
Implementation of a pose vector and operations on poses.
void print(const vpServo::vpServoPrintType display_level=ALL, std::ostream &os=std::cout)
Class that defines 2D ellipse visual feature.
static void create(vpFeaturePoint &s, const vpCameraParameters &cam, const vpDot &d)
Class that defines what is a circle.
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 setWorldCoordinates(const vpColVector &oP)