44#include <visp3/core/vpConfig.h>
45#include <visp3/core/vpDebug.h>
47#ifdef VISP_HAVE_COIN3D_AND_GUI
49#include <visp3/ar/vpSimulator.h>
50#include <visp3/core/vpCameraParameters.h>
51#include <visp3/core/vpHomogeneousMatrix.h>
52#include <visp3/core/vpImage.h>
53#include <visp3/core/vpIoTools.h>
54#include <visp3/core/vpMath.h>
55#include <visp3/core/vpTime.h>
56#include <visp3/io/vpParseArgv.h>
57#include <visp3/robot/vpSimulatorCamera.h>
58#include <visp3/visual_features/vpFeatureBuilder.h>
59#include <visp3/visual_features/vpFeaturePointPolar.h>
60#include <visp3/vs/vpServo.h>
62#define GETOPTARGS "di:h"
65#ifdef ENABLE_VISP_NAMESPACE
78void usage(
const char *name,
const char *badparam, std::string ipath)
81Simulation Servo 4points.\n\
84 %s [-i <input image path>] [-d] [-h]\n",
89 -i <input image path> %s\n\
90 Set image input path.\n\
91 From this path read \"iv/4points.iv\"\n\
93 Setting the VISP_INPUT_IMAGE_PATH environment\n\
94 variable produces the same behaviour than using\n\
98 Disable the image display. This can be useful \n\
99 for automatic tests using crontab under Unix or \n\
100 using the task manager under Windows.\n\
103 Print the help.\n\n",
107 fprintf(stdout,
"\nERROR: Bad parameter [%s]\n", badparam);
125bool getOptions(
int argc,
const char **argv, std::string &ipath,
bool &display)
139 usage(argv[0],
nullptr, ipath);
143 usage(argv[0], optarg, ipath);
148 if ((c == 1) || (c == -1)) {
150 usage(argv[0],
nullptr, ipath);
151 std::cerr <<
"ERROR: " << std::endl;
152 std::cerr <<
" Bad argument " << optarg << std::endl << std::endl;
159static void *mainLoop(
void *_simu)
167 float sampling_time = 0.040f;
169 robot.setMaxTranslationVelocity(4.);
184 wMc = wMo *
cMo.inverse();
185 robot.setPosition(wMc);
189 wMc = wMo *
cMo.inverse();
190 robot.setPosition(wMc);
203 for (
int i = 0;
i < 4;
i++) {
210 for (
int i = 0;
i < 4;
i++)
216 std::cout <<
"s: \n";
217 for (
int i = 0;
i < 4;
i++) {
218 printf(
"[%d] rho %f theta %f Z %f\n", i, p[i].get_rho(), p[i].get_theta(), p[i].get_Z());
237 for (
int i = 0;
i < 4;
i++) {
245 std::cout <<
"s*: \n";
246 for (
int i = 0;
i < 4;
i++) {
247 printf(
"[%d] rho %f theta %f Z %f\n", i, pd[i].get_rho(), pd[i].get_theta(), pd[i].get_Z());
267 for (
int i = 0;
i < 4;
i++)
268 task.addFeature(p[i], pd[i]);
278 unsigned int iter = 0;
280 while (iter++ < 200) {
286 wMc = robot.getPosition();
288 for (
int i = 0;
i < 4;
i++) {
299 char name[FILENAME_MAX];
300 snprintf(name, FILENAME_MAX,
"/tmp/image.%04u.external.png", iter);
301 std::cout << name << std::endl;
303 snprintf(name, FILENAME_MAX,
"/tmp/image.%04u.internal.png", iter);
312 std::cout <<
"cMo:\n" <<
cMo << std::endl;
314 std::cout <<
"final pose:\n" << pose.t() << std::endl;
322int main(
int argc,
const char **argv)
325 std::string env_ipath;
326 std::string opt_ipath;
329 bool opt_display =
true;
336 if (!env_ipath.empty())
340 if (getOptions(argc, argv, opt_ipath, opt_display) ==
false) {
345 if (!opt_ipath.empty())
350 if (!opt_ipath.empty() && !env_ipath.empty()) {
351 if (ipath != env_ipath) {
352 std::cout << std::endl <<
"WARNING: " << std::endl;
353 std::cout <<
" Since -i <visp image path=" << ipath <<
"> "
354 <<
" is different from VISP_IMAGE_PATH=" << env_ipath << std::endl
355 <<
" we skip the environment variable." << std::endl;
360 if (opt_ipath.empty() && env_ipath.empty()) {
361 usage(argv[0],
nullptr, ipath);
362 std::cerr << std::endl <<
"ERROR:" << std::endl;
363 std::cerr <<
" Use -i <visp image path> option or set VISP_INPUT_IMAGE_PATH " << std::endl
364 <<
" environment variable to specify the location of the " << std::endl
365 <<
" image path where test images are located." << std::endl
395 std::cout <<
"Catch an exception: " <<
e << std::endl;
403 std::cout <<
"You do not have Coin3D and SoQT or SoWin or SoXt functionalities enabled..." << std::endl;
404 std::cout <<
"Tip:" << std::endl;
406 <<
"- Install Coin3D and SoQT or SoWin or SoXt, configure ViSP again using cmake and build again this example"
Generic class defining intrinsic camera parameters.
Implementation of column vector and the associated operations.
error that can be emitted by ViSP classes.
static void create(vpFeaturePoint &s, const vpCameraParameters &cam, const vpDot &d)
Class that defines 2D image point visual feature with polar coordinates described in corke09a.
void track(const vpHomogeneousMatrix &cMo)
Implementation of an homogeneous matrix and operations on such kind of matrices.
vpHomogeneousMatrix inverse() const
static double rad(double deg)
Implementation of a matrix and operations on matrices.
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 ...
void changeFrame(const vpHomogeneousMatrix &cMo, vpColVector &cP) const VP_OVERRIDE
void setWorldCoordinates(double oX, double oY, double oZ)
Implementation of a pose vector and operations on poses.
virtual void setSamplingTime(const double &delta_t)
Class that defines the simplest robot: a free flying camera.
Implementation of a simulator based on Coin3d (www.coin3d.org).
void load(const char *file_name)
load an iv file
void setInternalCameraParameters(vpCameraParameters &cam)
set internal camera parameters
virtual void mainLoop()
activate the mainloop
void setExternalCameraParameters(vpCameraParameters &cam)
set external camera parameters
void initMainApplication()
perform some initialization in the main program thread
void initApplication(void *(*start_routine)(void *))
begin the main program
void getCameraPosition(vpHomogeneousMatrix &_cMf)
get the camera position (from an homogeneous matrix)
void setZoomFactor(float zoom)
set the size of the camera/frame
void setCameraPosition(vpHomogeneousMatrix &cMf)
set the camera position (from an homogeneous matrix)
void initExternalViewer(unsigned int nlig, unsigned int ncol)
initialize the external view
void write(const char *fileName)
virtual void initInternalViewer(unsigned int nlig, unsigned int ncol)
initialize the camera view
void closeMainApplication()
VISP_EXPORT double measureTimeMs()
VISP_EXPORT int wait(double t0, double t)