Visual Servoing Platform version 3.6.0
Loading...
Searching...
No Matches
vpRobotWireFrameSimulator.h
1/****************************************************************************
2 *
3 * ViSP, open source Visual Servoing Platform software.
4 * Copyright (C) 2005 - 2023 by Inria. All rights reserved.
5 *
6 * This software is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 * See the file LICENSE.txt at the root directory of this source
11 * distribution for additional information about the GNU GPL.
12 *
13 * For using ViSP with software that can not be combined with the GNU
14 * GPL, please contact Inria about acquiring a ViSP Professional
15 * Edition License.
16 *
17 * See https://visp.inria.fr for more information.
18 *
19 * This software was developed at:
20 * Inria Rennes - Bretagne Atlantique
21 * Campus Universitaire de Beaulieu
22 * 35042 Rennes Cedex
23 * France
24 *
25 * If you have questions regarding the use of this file, please contact
26 * Inria at visp@inria.fr
27 *
28 * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
29 * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
30 *
31 * Description:
32 * Basic class used to make robot simulators.
33 *
34*****************************************************************************/
35
36#ifndef vpRobotWireFrameSimulator_HH
37#define vpRobotWireFrameSimulator_HH
38
44#include <visp3/core/vpConfig.h>
45
46#if defined(VISP_HAVE_MODULE_GUI) && ((defined(_WIN32) && !defined(WINRT_8_0)) || defined(VISP_HAVE_PTHREAD))
47
48#include <cmath> // std::fabs
49#include <limits> // numeric_limits
50#if defined(_WIN32)
51// Include WinSock2.h before windows.h to ensure that winsock.h is not
52// included by windows.h since winsock.h and winsock2.h are incompatible
53#include <WinSock2.h>
54#include <windows.h>
55#elif defined(VISP_HAVE_PTHREAD)
56#include <pthread.h>
57#endif
58
59#include <visp3/core/vpMutex.h>
60#include <visp3/gui/vpDisplayD3D.h>
61#include <visp3/gui/vpDisplayGDI.h>
62#include <visp3/gui/vpDisplayGTK.h>
63#include <visp3/gui/vpDisplayOpenCV.h>
64#include <visp3/gui/vpDisplayX.h>
65#include <visp3/robot/vpRobot.h>
66#include <visp3/robot/vpRobotSimulator.h>
67#include <visp3/robot/vpWireFrameSimulator.h>
68
87{
88public:
90
91 typedef enum { MODEL_3D, MODEL_DH } vpDisplayRobotType;
92
93protected:
95 double tcur;
97 double tprev;
98
100 Bound_scene *robotArms;
101
103 unsigned int size_fMi;
111
118
119#if defined(_WIN32)
120 HANDLE hThread;
121#elif defined(VISP_HAVE_PTHREAD)
122 pthread_t thread;
123 pthread_attr_t attr;
124#endif
125
136
138
144 unsigned int jointLimitArt;
147
150
151#if defined(VISP_HAVE_X11)
153#elif defined(VISP_HAVE_GDI)
154 vpDisplayGDI display;
155#elif defined(HAVE_OPENCV_HIGHGUI)
156 vpDisplayOpenCV display;
157#elif defined(VISP_HAVE_D3D9)
158 vpDisplayD3D display;
159#elif defined(VISP_HAVE_GTK)
160 vpDisplayGTK display;
161#endif
162
164
171
175
177
178public:
180 explicit vpRobotWireFrameSimulator(bool display);
182
191 {
192 // if(px_ext != 1 && py_ext != 1)
193 // we assume px_ext and py_ext > 0
194 if ((std::fabs(px_ext - 1.) > vpMath::maximum(px_ext, 1.) * std::numeric_limits<double>::epsilon()) &&
195 (std::fabs(py_ext - 1) > vpMath::maximum(py_ext, 1.) * std::numeric_limits<double>::epsilon()))
196 return vpCameraParameters(px_ext, py_ext, I.getWidth() / 2, I.getHeight() / 2);
197 else {
198 unsigned int size = vpMath::minimum(I.getWidth(), I.getHeight()) / 2;
199 return vpCameraParameters(size, size, I.getWidth() / 2, I.getHeight() / 2);
200 }
201 }
213
214 void getInternalView(vpImage<vpRGBa> &I);
215 void getInternalView(vpImage<unsigned char> &I);
216
223 vpHomogeneousMatrix get_fMo() const { return fMo; }
224
225 /* Display functions */
226 void initScene(const vpSceneObject &obj, const vpSceneDesiredObject &desiredObject);
227 void initScene(const char *obj, const char *desiredObject);
228 void initScene(const vpSceneObject &obj);
229 void initScene(const char *obj);
230
236 void setCameraColor(const vpColor &col) { camColor = col; }
237
247 inline void setConstantSamplingTimeMode(const bool _constantSamplingTimeMode)
248 {
249 constantSamplingTimeMode = _constantSamplingTimeMode;
250 }
251
258 void setCurrentViewColor(const vpColor &col) { curColor = col; }
259
266 void setDesiredViewColor(const vpColor &col) { desColor = col; }
267
277
285 inline void setDisplayRobotType(const vpDisplayRobotType dispType) { displayType = dispType; }
299 void setGraphicsThickness(unsigned int thickness) { this->thickness_ = thickness; }
300
311 inline void setSamplingTime(const double &delta_t)
312 {
313 if (delta_t < static_cast<float>(vpTime::getMinTimeForUsleepCall() * 1e-3)) {
314 this->delta_t_ = static_cast<float>(vpTime::getMinTimeForUsleepCall() * 1e-3);
315 } else {
316 this->delta_t_ = delta_t;
317 }
318 }
320 void setSingularityManagement(bool sm) { singularityManagement = sm; }
321
325 void setVerbose(bool verbose) { this->verbose_ = verbose; }
326
332 void set_fMo(const vpHomogeneousMatrix &fMo_) { this->fMo = fMo_; }
334
335protected:
342#if defined(_WIN32)
343 static DWORD WINAPI launcher(LPVOID lpParam)
344 {
345 (static_cast<vpRobotWireFrameSimulator *>(lpParam))->updateArticularPosition();
346 return 0;
347 }
348#elif defined(VISP_HAVE_PTHREAD)
349 static void *launcher(void *arg)
350 {
351 (reinterpret_cast<vpRobotWireFrameSimulator *>(arg))->updateArticularPosition();
352 // pthread_exit((void*) 0);
353 return NULL;
354 }
355#endif
356
357 /* Robot functions */
358 void init() { ; }
361 virtual void updateArticularPosition() = 0;
363 virtual int isInJointLimit() = 0;
366 virtual void computeArticularVelocity() = 0;
367
368 /* Display functions */
369 void initDisplay() { ; }
370 virtual void initArms() = 0;
371
373 {
374 m_mutex_artCoord.lock();
375 vpColVector artCoordTmp(6);
376 artCoordTmp = artCoord;
377 m_mutex_artCoord.unlock();
378 return artCoordTmp;
379 }
380 void set_artCoord(const vpColVector &coord)
381 {
382 m_mutex_artCoord.lock();
383 artCoord = coord;
384 m_mutex_artCoord.unlock();
385 }
386
388 {
389 m_mutex_artVel.lock();
390 vpColVector artVelTmp(artVel);
391 m_mutex_artVel.unlock();
392 return artVelTmp;
393 }
394 void set_artVel(const vpColVector &vel)
395 {
396 m_mutex_artVel.lock();
397 artVel = vel;
398 m_mutex_artVel.unlock();
399 }
400
402 {
403 m_mutex_velocity.lock();
404 vpColVector velocityTmp = velocity;
405 m_mutex_velocity.unlock();
406 return velocityTmp;
407 }
408 void set_velocity(const vpColVector &vel)
409 {
410 m_mutex_velocity.lock();
411 velocity = vel;
412 m_mutex_velocity.unlock();
413 }
414
415 void set_displayBusy(const bool &status)
416 {
417 m_mutex_display.lock();
418 displayBusy = status;
419 m_mutex_display.unlock();
420 }
422 {
423 m_mutex_display.lock();
424 bool status = displayBusy;
425 if (!displayBusy)
426 displayBusy = true;
427 m_mutex_display.unlock();
428 return status;
429 }
430
433 virtual void get_fMi(vpHomogeneousMatrix *fMit) = 0;
435};
436
437#endif
438#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:152
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:132
Implementation of an homogeneous matrix and operations on such kind of matrices.
Definition of the vpImage class member functions.
Definition vpImage.h:135
unsigned int getWidth() const
Definition vpImage.h:242
unsigned int getHeight() const
Definition vpImage.h:184
static Type maximum(const Type &a, const Type &b)
Definition vpMath.h:172
static Type minimum(const Type &a, const Type &b)
Definition vpMath.h:180
void unlock()
Definition vpMutex.h:106
void lock()
Definition vpMutex.h:90
This class aims to be a basis used to create all the robot simulators.
This class aims to be a basis used to create all the simulators of robots.
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)
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
static void * launcher(void *arg)
void setDesiredCameraPosition(const vpHomogeneousMatrix &cdMo_)
virtual void get_fMi(vpHomogeneousMatrix *fMit)=0
void set_fMo(const vpHomogeneousMatrix &fMo_)
void setSamplingTime(const double &delta_t)
void setExternalCameraPosition(const vpHomogeneousMatrix &camMf_)
void set_artVel(const vpColVector &vel)
Implementation of a wire frame simulator. Compared to the vpSimulator class, it does not require thir...
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()