Visual Servoing Platform version 3.7.0
Loading...
Searching...
No Matches
vpRobotWireFrameSimulator.h
1/*
2 * ViSP, open source Visual Servoing Platform software.
3 * Copyright (C) 2005 - 2025 by Inria. All rights reserved.
4 *
5 * This software is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 * See the file LICENSE.txt at the root directory of this source
10 * distribution for additional information about the GNU GPL.
11 *
12 * For using ViSP with software that can not be combined with the GNU
13 * GPL, please contact Inria about acquiring a ViSP Professional
14 * Edition License.
15 *
16 * See https://visp.inria.fr for more information.
17 *
18 * This software was developed at:
19 * Inria Rennes - Bretagne Atlantique
20 * Campus Universitaire de Beaulieu
21 * 35042 Rennes Cedex
22 * France
23 *
24 * If you have questions regarding the use of this file, please contact
25 * Inria at visp@inria.fr
26 *
27 * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
28 * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
29 *
30 * Description:
31 * Basic class used to make robot simulators.
32 */
33
38
39#ifndef VP_ROBOT_WIREFRAME_SIMULATOR_H
40#define VP_ROBOT_WIREFRAME_SIMULATOR_H
41
42#include <visp3/core/vpConfig.h>
43
44#if defined(VISP_HAVE_MODULE_GUI) && defined(VISP_HAVE_THREADS)
45
46#include <cmath> // std::fabs
47#include <limits> // numeric_limits
48
49#include <thread>
50#include <mutex>
51
52#include <visp3/gui/vpDisplayD3D.h>
53#include <visp3/gui/vpDisplayGDI.h>
54#include <visp3/gui/vpDisplayGTK.h>
55#include <visp3/gui/vpDisplayOpenCV.h>
56#include <visp3/gui/vpDisplayX.h>
57#include <visp3/robot/vpRobot.h>
58#include <visp3/robot/vpRobotSimulator.h>
59#include <visp3/robot/vpWireFrameSimulator.h>
60
80{
81public:
83
84 typedef enum { MODEL_3D, MODEL_DH } vpDisplayRobotType;
85
86protected:
88 double tcur;
90 double tprev;
91
93 Bound_scene *robotArms;
94
96 unsigned int size_fMi;
104
111
112 std::thread *m_thread;
113
114 std::mutex m_mutex_fMi;
115 std::mutex m_mutex_eMc;
116 std::mutex m_mutex_artVel;
119 std::mutex m_mutex_display;
121 std::mutex m_mutex_frame;
123 std::mutex m_mutex_scene;
124
126
132 unsigned int jointLimitArt;
135
138
139#if defined(VISP_HAVE_X11)
141#elif defined(VISP_HAVE_GDI)
143#elif defined(HAVE_OPENCV_HIGHGUI)
145#elif defined(VISP_HAVE_D3D9)
147#elif defined(VISP_HAVE_GTK)
149#endif
150
152
159
163
164public:
166 VP_EXPLICIT vpRobotWireFrameSimulator(bool display);
167
170
176 {
177 // if(px_ext != 1 && py_ext != 1)
178 // we assume px_ext and py_ext > 0
179 if ((std::fabs(px_ext - 1.) > vpMath::maximum(px_ext, 1.) * std::numeric_limits<double>::epsilon()) &&
180 (std::fabs(py_ext - 1) > vpMath::maximum(py_ext, 1.) * std::numeric_limits<double>::epsilon()))
181 return vpCameraParameters(px_ext, py_ext, I.getWidth() / 2, I.getHeight() / 2);
182 else {
183 unsigned int size = vpMath::minimum(I.getWidth(), I.getHeight()) / 2;
184 return vpCameraParameters(size, size, I.getWidth() / 2, I.getHeight() / 2);
185 }
186 }
187
198
199 void getInternalView(vpImage<vpRGBa> &I);
200 void getInternalView(vpImage<unsigned char> &I);
201
208 vpHomogeneousMatrix get_fMo() const { return fMo; }
209
210 /* Display functions */
211 void initScene(const vpSceneObject &obj, const vpSceneDesiredObject &desiredObject);
212 void initScene(const char *obj, const char *desiredObject);
213 void initScene(const vpSceneObject &obj);
214 void initScene(const char *obj);
215
221 void setCameraColor(const vpColor &col) { camColor = col; }
222
232 inline void setConstantSamplingTimeMode(const bool _constantSamplingTimeMode)
233 {
234 constantSamplingTimeMode = _constantSamplingTimeMode;
235 }
236
243 void setCurrentViewColor(const vpColor &col) { curColor = col; }
244
251 void setDesiredViewColor(const vpColor &col) { desColor = col; }
252
262
270 inline void setDisplayRobotType(const vpDisplayRobotType dispType) { displayType = dispType; }
281
284 void setGraphicsThickness(unsigned int thickness) { this->thickness_ = thickness; }
285
295 inline void setSamplingTime(const double &delta_t) VP_OVERRIDE
296 {
297 if (delta_t < (vpTime::getMinTimeForUsleepCall() * 1e-3)) {
298 this->delta_t_ = (vpTime::getMinTimeForUsleepCall() * 1e-3);
299 }
300 else {
301 this->delta_t_ = delta_t;
302 }
303 }
304
308
312 void setVerbose(bool verbose) { this->verbose_ = verbose; }
313
319 void set_fMo(const vpHomogeneousMatrix &fMo_) { this->fMo = fMo_; }
321
322protected:
326
329 static void launcher(vpRobotWireFrameSimulator &simulator)
330 {
331 simulator.updateArticularPosition();
332 }
333
338 virtual void updateArticularPosition() = 0;
340 virtual int isInJointLimit() = 0;
343 virtual void computeArticularVelocity() = 0;
344
345 /* Display functions */
346 void initDisplay() { }
347 virtual void initArms() = 0;
348
350 {
351 m_mutex_artCoord.lock();
352 vpColVector artCoordTmp(6);
353 artCoordTmp = artCoord;
354 m_mutex_artCoord.unlock();
355 return artCoordTmp;
356 }
357 void set_artCoord(const vpColVector &coord)
358 {
359 m_mutex_artCoord.lock();
360 artCoord = coord;
361 m_mutex_artCoord.unlock();
362 }
363
365 {
366 m_mutex_artVel.lock();
367 vpColVector artVelTmp(artVel);
368 m_mutex_artVel.unlock();
369 return artVelTmp;
370 }
371 void set_artVel(const vpColVector &vel)
372 {
373 m_mutex_artVel.lock();
374 artVel = vel;
375 m_mutex_artVel.unlock();
376 }
377
379 {
380 m_mutex_velocity.lock();
381 vpColVector velocityTmp = velocity;
382 m_mutex_velocity.unlock();
383 return velocityTmp;
384 }
385 void set_velocity(const vpColVector &vel)
386 {
387 m_mutex_velocity.lock();
388 velocity = vel;
389 m_mutex_velocity.unlock();
390 }
391
392 void set_displayBusy(const bool &status)
393 {
394 m_mutex_display.lock();
395 displayBusy = status;
396 m_mutex_display.unlock();
397 }
399 {
400 m_mutex_display.lock();
401 bool status = displayBusy;
402 if (!displayBusy)
403 displayBusy = true;
404 m_mutex_display.unlock();
405 return status;
406 }
407
410 virtual void get_fMi(vpHomogeneousMatrix *fMit) = 0;
412};
413END_VISP_NAMESPACE
414#endif
415#endif
Generic class defining intrinsic camera parameters.
Implementation of column vector and the associated operations.
Class to define RGB colors available for display functionalities.
Definition vpColor.h:157
Display for windows using Direct3D 3rd party. Thus to enable this class Direct3D should be installed....
Display for windows using GDI (available on any windows 32 platform).
The vpDisplayGTK allows to display image using the GTK 3rd party library. Thus to enable this class G...
The vpDisplayOpenCV allows to display image using the OpenCV library. Thus to enable this class OpenC...
Use the X11 console to display images on unix-like OS. Thus to enable this class X11 should be instal...
Definition vpDisplayX.h:135
Implementation of an homogeneous matrix and operations on such kind of matrices.
Definition of the vpImage class member functions.
Definition vpImage.h:131
static Type maximum(const Type &a, const Type &b)
Definition vpMath.h:257
static Type minimum(const Type &a, const Type &b)
Definition vpMath.h:265
void setSamplingTime(const double &delta_t) VP_OVERRIDE
virtual void computeArticularVelocity()=0
void setDisplayRobotType(const vpDisplayRobotType dispType)
virtual int isInJointLimit()=0
void setGraphicsThickness(unsigned int thickness)
void set_velocity(const vpColVector &vel)
void setCurrentViewColor(const vpColor &col)
static void launcher(vpRobotWireFrameSimulator &simulator)
void set_displayBusy(const bool &status)
void setDesiredViewColor(const vpColor &col)
vpHomogeneousMatrix getExternalCameraPosition() const
vpHomogeneousMatrix get_fMo() const
void setConstantSamplingTimeMode(const bool _constantSamplingTimeMode)
void set_artCoord(const vpColVector &coord)
void setCameraColor(const vpColor &col)
virtual void initArms()=0
vpCameraParameters getExternalCameraParameters() const
virtual void updateArticularPosition()=0
void setDesiredCameraPosition(const vpHomogeneousMatrix &cdMo_)
virtual void get_fMi(vpHomogeneousMatrix *fMit)=0
void set_fMo(const vpHomogeneousMatrix &fMo_)
void setExternalCameraPosition(const vpHomogeneousMatrix &camMf_)
void set_artVel(const vpColVector &vel)
bool verbose_
Definition vpRobot.h:115
vpHomogeneousMatrix getExternalCameraPosition() const
void initScene(const vpSceneObject &obj, const vpSceneDesiredObject &desiredObject)
vpHomogeneousMatrix get_cMo() const
vpHomogeneousMatrix fMo
void setExternalCameraPosition(const vpHomogeneousMatrix &cam_Mf)
void setDesiredCameraPosition(const vpHomogeneousMatrix &cdMo_)
VISP_EXPORT double getMinTimeForUsleepCall()