46#include <visp3/core/vpConfig.h>
47#include <visp3/core/vpDebug.h>
49#ifdef VISP_HAVE_COIN3D_AND_GUI
50#include <visp3/ar/vpSimulator.h>
51#include <visp3/core/vpCameraParameters.h>
52#include <visp3/core/vpCircle.h>
53#include <visp3/core/vpHomogeneousMatrix.h>
54#include <visp3/core/vpImage.h>
55#include <visp3/core/vpIoTools.h>
56#include <visp3/core/vpMath.h>
57#include <visp3/core/vpTime.h>
58#include <visp3/io/vpParseArgv.h>
59#include <visp3/robot/vpSimulatorCamera.h>
60#include <visp3/visual_features/vpFeatureBuilder.h>
61#include <visp3/visual_features/vpFeatureEllipse.h>
62#include <visp3/vs/vpServo.h>
64#define GETOPTARGS "cdi:hs"
66#ifdef ENABLE_VISP_NAMESPACE
81void usage(
const char *name,
const char *badparam, std::string ipath)
84Simulation Servo Circle\n\
87 %s [-i <input image path>] [-d] [-s] [-h]\n",
92 -i <input image path> %s\n\
93 Set image input path.\n\
94 From this path read \"iv/4points.iv\"\n\
96 Setting the VISP_INPUT_IMAGE_PATH environment\n\
97 variable produces the same behaviour than using\n\
101 Disable the image display. This can be useful \n\
102 for automatic tests using crontab under Unix or \n\
103 using the task manager under Windows.\n\
109 Print the help.\n\n",
113 fprintf(stdout,
"\nERROR: Bad parameter [%s]\n", badparam);
130bool getOptions(
int argc,
const char **argv, std::string &ipath,
bool &display,
bool &save)
147 usage(argv[0],
nullptr, ipath);
151 usage(argv[0], optarg, ipath);
156 if ((c == 1) || (c == -1)) {
158 usage(argv[0],
nullptr, ipath);
159 std::cerr <<
"ERROR: " << std::endl;
160 std::cerr <<
" Bad argument " << optarg << std::endl << std::endl;
167static void *mainLoop(
void *_simu)
190 unsigned int pos = 2;
195 float sampling_time = 0.040f;
197 robot.setMaxTranslationVelocity(4.);
200 wMc = wMo *
cMo.inverse();
201 robot.setPosition(wMc);
229 std::cout << std::endl;
230 task.addFeature(p, pd);
240 unsigned int iter = 0;
242 unsigned int itermax;
247 while (iter++ < itermax) {
251 std::cout <<
"get the robot position" << std::endl;
252 wMc = robot.getPosition();
254 std::cout <<
"new circle position" << std::endl;
262 std::cout <<
"compute the control law" << std::endl;
265 std::cout <<
"Task rank: " <<
task.getTaskRank() << std::endl;
266 std::cout <<
"send the camera velocity to the controller" << std::endl;
275 std::cout <<
"Save " <<
filename << std::endl;
276 simu->
write(filename);
278 std::cout <<
"Save " <<
filename << std::endl;
279 simu->
write(filename);
294int main(
int argc,
const char **argv)
297 std::string env_ipath;
298 std::string opt_ipath;
301 bool opt_display =
true;
308 if (!env_ipath.empty())
312 if (getOptions(argc, argv, opt_ipath, opt_display, opt_save) ==
false) {
317 if (!opt_ipath.empty())
322 if (!opt_ipath.empty() && !env_ipath.empty()) {
323 if (ipath != env_ipath) {
324 std::cout << std::endl <<
"WARNING: " << std::endl;
325 std::cout <<
" Since -i <visp image path=" << ipath <<
"> "
326 <<
" is different from VISP_INPUT_IMAGE_PATH=" << env_ipath << std::endl
327 <<
" we skip the environment variable." << std::endl;
332 if (opt_ipath.empty() && env_ipath.empty()) {
333 usage(argv[0],
nullptr, ipath);
334 std::cerr << std::endl <<
"ERROR:" << std::endl;
335 std::cerr <<
" Use -i <visp image path> option or set VISP_INPUT_IMAGE_PATH " << std::endl
336 <<
" environment variable to specify the location of the " << std::endl
337 <<
" image path where test images are located." << std::endl
368 std::cout <<
"Catch an exception: " <<
e << std::endl;
376 std::cout <<
"You do not have Coin3D and SoQT or SoWin or SoXt functionalities enabled..." << std::endl;
377 std::cout <<
"Tip:" << std::endl;
379 <<
"- Install Coin3D and SoQT or SoWin or SoXt, configure ViSP again using cmake and build again this example"
Generic class defining intrinsic camera parameters.
Class that defines a 3D circle in the object frame and allows forward projection of a 3D circle in th...
void setWorldCoordinates(const vpColVector &oP) VP_OVERRIDE
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 ellipse visual feature.
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)
static bool parse(int *argcPtr, const char **argv, vpArgvInfo *argTable, int flags)
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 initMainApplication()
perform some initialization in the main program thread
void initApplication(void *(*start_routine)(void *))
begin the main program
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()
void addAbsoluteFrame(float zoom=1)
Add the representation of the absolute frame.
VISP_EXPORT double measureTimeMs()
VISP_EXPORT int wait(double t0, double t)