48 #include <visp3/core/vpConfig.h>
49 #include <visp3/core/vpDebug.h>
51 #ifdef VISP_HAVE_COIN3D_AND_GUI
53 #include <visp3/ar/vpSimulator.h>
54 #include <visp3/core/vpCameraParameters.h>
55 #include <visp3/core/vpHomogeneousMatrix.h>
56 #include <visp3/core/vpImage.h>
57 #include <visp3/core/vpIoTools.h>
58 #include <visp3/core/vpMath.h>
59 #include <visp3/core/vpTime.h>
60 #include <visp3/io/vpParseArgv.h>
61 #include <visp3/robot/vpSimulatorCamera.h>
62 #include <visp3/visual_features/vpFeatureBuilder.h>
63 #include <visp3/visual_features/vpFeaturePoint.h>
64 #include <visp3/vs/vpServo.h>
66 #define GETOPTARGS "di:h"
69 #ifdef ENABLE_VISP_NAMESPACE
82 void usage(
const char *name,
const char *badparam, std::string ipath)
85 Simulation Servo 4points.\n\
88 %s [-i <input image path>] [-d] [-h]\n",
93 -i <input image path> %s\n\
94 Set image input path.\n\
95 From this path read \"iv/4points.iv\"\n\
97 Setting the VISP_INPUT_IMAGE_PATH environment\n\
98 variable produces the same behaviour than using\n\
102 Disable the image display. This can be useful \n\
103 for automatic tests using crontab under Unix or \n\
104 using the task manager under Windows.\n\
107 Print the help.\n\n",
111 fprintf(stdout,
"\nERROR: Bad parameter [%s]\n", badparam);
129 bool getOptions(
int argc,
const char **argv, std::string &ipath,
bool &display)
143 usage(argv[0],
nullptr, ipath);
148 usage(argv[0], optarg, ipath);
154 if ((c == 1) || (c == -1)) {
156 usage(argv[0],
nullptr, ipath);
157 std::cerr <<
"ERROR: " << std::endl;
158 std::cerr <<
" Bad argument " << optarg << std::endl << std::endl;
165 static void *mainLoop(
void *_simu)
173 float sampling_time = 0.040f;
174 robot.setSamplingTime(sampling_time);
176 std::cout << std::endl;
177 std::cout <<
"-------------------------------------------------------" << std::endl;
178 std::cout <<
" Test program for vpServo " << std::endl;
179 std::cout <<
" Eye-in-hand task control, articular velocities are computed" << std::endl;
180 std::cout <<
" Simulation " << std::endl;
181 std::cout <<
" task : servo 4 points " << std::endl;
182 std::cout <<
"-------------------------------------------------------" << std::endl;
183 std::cout << std::endl;
199 robot.setPosition(wMc);
204 robot.setPosition(wMc);
218 for (
int i = 0; i < 4; i++)
223 for (
int i = 0; i < 4; i++)
251 for (
int i = 0; i < 4; i++)
257 std::cout <<
"Display task information" << std::endl;
262 unsigned int iter = 0;
264 while (iter++ < 100) {
272 wMc = robot.getPosition();
274 for (
int i = 0; i < 4; i++) {
285 char name[FILENAME_MAX];
286 snprintf(name, FILENAME_MAX,
"/tmp/image.%04u.external.png", iter);
287 std::cout << name << std::endl;
289 snprintf(name, FILENAME_MAX,
"/tmp/image.%04u.internal.png", iter);
295 std::cout <<
"\nDisplay task information" << std::endl;
304 int main(
int argc,
const char **argv)
307 std::string env_ipath;
308 std::string opt_ipath;
310 std::string filename;
311 bool opt_display =
true;
318 if (!env_ipath.empty())
322 if (getOptions(argc, argv, opt_ipath, opt_display) ==
false) {
327 if (!opt_ipath.empty())
332 if (!opt_ipath.empty() && !env_ipath.empty()) {
333 if (ipath != env_ipath) {
334 std::cout << std::endl <<
"WARNING: " << std::endl;
335 std::cout <<
" Since -i <visp image path=" << ipath <<
"> "
336 <<
" is different from VISP_IMAGE_PATH=" << env_ipath << std::endl
337 <<
" we skip the environment variable." << std::endl;
342 if (opt_ipath.empty() && env_ipath.empty()) {
343 usage(argv[0],
nullptr, ipath);
344 std::cerr << std::endl <<
"ERROR:" << std::endl;
345 std::cerr <<
" Use -i <visp image path> option or set VISP_INPUT_IMAGE_PATH " << std::endl
346 <<
" environment variable to specify the location of the " << std::endl
347 <<
" image path where test images are located." << std::endl
366 simu.
load(filename.c_str());
377 std::cout <<
"Catch an exception: " << e << std::endl;
385 std::cout <<
"You do not have Coin3D and SoQT or SoWin or SoXt functionalities enabled..." << std::endl;
386 std::cout <<
"Tip:" << std::endl;
388 <<
"- 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 vpImagePoint &t)
Class that defines a 2D point visual feature which is composed by two parameters that are the cartes...
vpFeaturePoint & buildFrom(const double &x, const double &y, const double &Z)
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 setWorldCoordinates(double oX, double oY, double oZ)
Implementation of a pose vector and operations on poses.
void get_eJe(vpMatrix &eJe) VP_OVERRIDE
void setVelocity(const vpRobot::vpControlFrameType frame, const vpColVector &vel) VP_OVERRIDE
void setMaxTranslationVelocity(double maxVt)
void setInteractionMatrixType(const vpServoIteractionMatrixType &interactionMatrixType, const vpServoInversionType &interactionMatrixInversion=PSEUDO_INVERSE)
void addFeature(vpBasicFeature &s_cur, vpBasicFeature &s_star, unsigned int select=vpBasicFeature::FEATURE_ALL)
void set_cVe(const vpVelocityTwistMatrix &cVe_)
void print(const vpServo::vpServoPrintType display_level=ALL, std::ostream &os=std::cout)
void set_eJe(const vpMatrix &eJe_)
void setServo(const vpServoType &servo_type)
vpColVector computeControlLaw()
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
virtual void initInternalViewer(unsigned int nlig, unsigned int ncol)
initialize the camera view
void closeMainApplication()
VISP_EXPORT int wait(double t0, double t)
VISP_EXPORT double measureTimeMs()