48 #include <visp3/core/vpConfig.h>
49 #include <visp3/core/vpDebug.h>
51 #ifdef VISP_HAVE_COIN3D_AND_GUI
52 #include <visp3/ar/vpSimulator.h>
53 #include <visp3/core/vpCameraParameters.h>
54 #include <visp3/core/vpCircle.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/vpFeatureEllipse.h>
64 #include <visp3/vs/vpServo.h>
66 #define GETOPTARGS "cdi:h"
78 void usage(
const char *name,
const char *badparam, std::string ipath)
81 Simulation Servo Circle\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);
125 bool getOptions(
int argc,
const char **argv, std::string &ipath,
bool &display)
139 usage(argv[0],
nullptr, ipath);
144 usage(argv[0], optarg, ipath);
150 if ((c == 1) || (c == -1)) {
152 usage(argv[0],
nullptr, ipath);
153 std::cerr <<
"ERROR: " << std::endl;
154 std::cerr <<
" Bad argument " << optarg << std::endl << std::endl;
161 static void *mainLoop(
void *_simu)
184 unsigned int pos = 2;
189 float sampling_time = 0.040f;
190 robot.setSamplingTime(sampling_time);
195 robot.setPosition(wMc);
223 std::cout << std::endl;
234 unsigned int iter = 0;
236 unsigned int itermax;
241 while (iter++ < itermax) {
245 std::cout <<
"get the robot position" << std::endl;
246 wMc = robot.getPosition();
248 std::cout <<
"new circle position" << std::endl;
256 std::cout <<
"compute the control law" << std::endl;
259 std::cout <<
"Task rank: " << task.
getTaskRank() << std::endl;
260 std::cout <<
"send the camera velocity to the controller" << std::endl;
267 char name[FILENAME_MAX];
268 snprintf(name, FILENAME_MAX,
"/tmp/image.%04d.external.png", it);
269 std::cout <<
"Save " << name << std::endl;
271 snprintf(name, FILENAME_MAX,
"/tmp/image.%04u.internal.png", iter);
272 std::cout <<
"Save " << name << std::endl;
289 int main(
int argc,
const char **argv)
292 std::string env_ipath;
293 std::string opt_ipath;
295 std::string filename;
296 bool opt_display =
true;
303 if (!env_ipath.empty())
307 if (getOptions(argc, argv, opt_ipath, opt_display) ==
false) {
312 if (!opt_ipath.empty())
317 if (!opt_ipath.empty() && !env_ipath.empty()) {
318 if (ipath != env_ipath) {
319 std::cout << std::endl <<
"WARNING: " << std::endl;
320 std::cout <<
" Since -i <visp image path=" << ipath <<
"> "
321 <<
" is different from VISP_INPUT_IMAGE_PATH=" << env_ipath << std::endl
322 <<
" we skip the environment variable." << std::endl;
327 if (opt_ipath.empty() && env_ipath.empty()) {
328 usage(argv[0],
nullptr, ipath);
329 std::cerr << std::endl <<
"ERROR:" << std::endl;
330 std::cerr <<
" Use -i <visp image path> option or set VISP_INPUT_IMAGE_PATH " << std::endl
331 <<
" environment variable to specify the location of the " << std::endl
332 <<
" image path where test images are located." << std::endl
353 simu.
load(filename.c_str(), fMo);
363 std::cout <<
"Catch an exception: " << e << std::endl;
371 std::cout <<
"You do not have Coin3D and SoQT or SoWin or SoXt functionalities enabled..." << std::endl;
372 std::cout <<
"Tip:" << std::endl;
374 <<
"- 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.
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)
unsigned int getTaskRank() const
void print(const vpServo::vpServoPrintType display_level=ALL, std::ostream &os=std::cout)
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 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.
void display(vpImage< unsigned char > &I, const std::string &title)
Display a gray-scale image.
VISP_EXPORT int wait(double t0, double t)
VISP_EXPORT double measureTimeMs()