50 #include <visp3/core/vpConfig.h> 51 #include <visp3/core/vpDebug.h> 53 #ifdef VISP_HAVE_COIN3D_AND_GUI 55 #include <visp3/ar/vpSimulator.h> 56 #include <visp3/core/vpCameraParameters.h> 57 #include <visp3/core/vpHomogeneousMatrix.h> 58 #include <visp3/core/vpImage.h> 59 #include <visp3/core/vpIoTools.h> 60 #include <visp3/core/vpMath.h> 61 #include <visp3/core/vpTime.h> 62 #include <visp3/io/vpParseArgv.h> 63 #include <visp3/robot/vpSimulatorCamera.h> 64 #include <visp3/visual_features/vpFeatureBuilder.h> 65 #include <visp3/visual_features/vpFeaturePointPolar.h> 66 #include <visp3/vs/vpServo.h> 68 #define GETOPTARGS "di:h" 80 void usage(
const char *name,
const char *badparam, std::string ipath)
83 Simulation Servo 4points.\n\ 86 %s [-i <input image path>] [-d] [-h]\n", name);
90 -i <input image path> %s\n\ 91 Set image input path.\n\ 92 From this path read \"iv/4points.iv\"\n\ 94 Setting the VISP_INPUT_IMAGE_PATH environment\n\ 95 variable produces the same behaviour than using\n\ 99 Disable the image display. This can be useful \n\ 100 for automatic tests using crontab under Unix or \n\ 101 using the task manager under Windows.\n\ 104 Print the help.\n\n", ipath.c_str());
107 fprintf(stdout,
"\nERROR: Bad parameter [%s]\n", badparam);
125 bool getOptions(
int argc,
const char **argv, std::string &ipath,
bool &display)
139 usage(argv[0], NULL, ipath);
144 usage(argv[0], optarg, ipath);
150 if ((c == 1) || (c == -1)) {
152 usage(argv[0], NULL, ipath);
153 std::cerr <<
"ERROR: " << std::endl;
154 std::cerr <<
" Bad argument " << optarg << std::endl << std::endl;
161 static void *mainLoop(
void *_simu)
169 float sampling_time = 0.040f;
205 for (
int i = 0; i < 4; i++) {
212 for (
int i = 0; i < 4; i++)
218 std::cout <<
"s: \n";
219 for (
int i = 0; i < 4; i++) {
220 printf(
"[%d] rho %f theta %f Z %f\n", i, p[i].get_rho(), p[i].get_theta(), p[i].get_Z());
239 for (
int i = 0; i < 4; i++) {
247 std::cout <<
"s*: \n";
248 for (
int i = 0; i < 4; i++) {
249 printf(
"[%d] rho %f theta %f Z %f\n", i, pd[i].get_rho(), pd[i].get_theta(), pd[i].get_Z());
269 for (
int i = 0; i < 4; i++)
280 unsigned int iter = 0;
282 while (iter++ < 200) {
290 for (
int i = 0; i < 4; i++) {
301 char name[FILENAME_MAX];
302 sprintf(name,
"/tmp/image.%04u.external.png", iter);
303 std::cout << name << std::endl;
305 sprintf(name,
"/tmp/image.%04u.internal.png", iter);
314 std::cout <<
"cMo:\n" << cMo << std::endl;
316 std::cout <<
"final pose:\n" << pose.t() << std::endl;
324 int main(
int argc,
const char **argv)
327 std::string env_ipath;
328 std::string opt_ipath;
330 std::string filename;
331 bool opt_display =
true;
338 if (!env_ipath.empty())
342 if (getOptions(argc, argv, opt_ipath, opt_display) ==
false) {
347 if (!opt_ipath.empty())
352 if (!opt_ipath.empty() && !env_ipath.empty()) {
353 if (ipath != env_ipath) {
354 std::cout << std::endl <<
"WARNING: " << std::endl;
355 std::cout <<
" Since -i <visp image path=" << ipath <<
"> " 356 <<
" is different from VISP_IMAGE_PATH=" << env_ipath << std::endl
357 <<
" we skip the environment variable." << std::endl;
362 if (opt_ipath.empty() && env_ipath.empty()) {
363 usage(argv[0], NULL, ipath);
364 std::cerr << std::endl <<
"ERROR:" << std::endl;
365 std::cerr <<
" Use -i <visp image path> option or set VISP_INPUT_IMAGE_PATH " << std::endl
366 <<
" environment variable to specify the location of the " << std::endl
367 <<
" image path where test images are located." << std::endl
386 simu.
load(filename.c_str());
396 std::cout <<
"Catch an exception: " << e << std::endl;
404 std::cout <<
"You do not have Coin3D and SoQT or SoWin or SoXt functionalities enabled..." << std::endl;
405 std::cout <<
"Tip:" << std::endl;
406 std::cout <<
"- Install Coin3D and SoQT or SoWin or SoXt, configure ViSP again using cmake and build again this example" << std::endl;
void setPosition(const vpHomogeneousMatrix &wMc)
Implementation of a matrix and operations on matrices.
VISP_EXPORT int wait(double t0, double t)
void setWorldCoordinates(double oX, double oY, double oZ)
void setVelocity(const vpRobot::vpControlFrameType frame, const vpColVector &vel)
void write(const char *fileName)
void setExternalCameraParameters(vpCameraParameters &cam)
set external camera parameters
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.
void addFeature(vpBasicFeature &s, vpBasicFeature &s_star, unsigned int select=vpBasicFeature::FEATURE_ALL)
Implementation of a simulator based on Coin3d (www.coin3d.org).
void setZoomFactor(float zoom)
set the size of the camera/frame
void set_eJe(const vpMatrix &eJe_)
void closeMainApplication()
error that can be emited by ViSP classes.
void track(const vpHomogeneousMatrix &cMo)
vpHomogeneousMatrix inverse() const
vpHomogeneousMatrix getPosition() const
virtual void mainLoop()
activate the mainloop
Class that defines 2D image point visual feature with polar coordinates described in ...
VISP_EXPORT double measureTimeMs()
static bool parse(int *argcPtr, const char **argv, vpArgvInfo *argTable, int flags)
Class that defines a 3D point in the object frame and allows forward projection of a 3D point in the ...
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)
void setInternalCameraParameters(vpCameraParameters &cam)
set internal camera parameters
Generic class defining intrinsic camera parameters.
virtual void initInternalViewer(unsigned int nlig, unsigned int ncol)
initialize the camera view
void changeFrame(const vpHomogeneousMatrix &cMo, vpColVector &cP) const
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.
void set_cVe(const vpVelocityTwistMatrix &cVe_)
Implementation of a pose vector and operations on poses.
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 get_eJe(vpMatrix &eJe)
void initExternalViewer(unsigned int nlig, unsigned int ncol)
initialize the external view
void setServo(const vpServoType &servo_type)
void setMaxTranslationVelocity(double maxVt)