Visual Servoing Platform version 3.7.0
Loading...
Searching...
No Matches
vpRobotWireFrameSimulator.cpp
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
34#include <visp3/core/vpConfig.h>
35
36#if defined(VISP_HAVE_MODULE_GUI) && defined(VISP_HAVE_THREADS)
37#include <visp3/robot/vpRobotWireFrameSimulator.h>
38#include <visp3/robot/vpSimulatorViper850.h>
39
40#include "../wireframe-simulator/vpBound.h"
41#include "../wireframe-simulator/vpScene.h"
42#include "../wireframe-simulator/vpVwstack.h"
43
49 : vpWireFrameSimulator(), vpRobotSimulator(), I(), tcur(0), tprev(0), robotArms(nullptr), size_fMi(8), fMi(nullptr),
52 m_mutex_scene(), displayBusy(false), robotStop(false), jointLimit(false), jointLimitArt(false),
54#if defined(VISP_HAVE_DISPLAY)
55 display(),
56#endif
58{
59 setSamplingTime(0.010);
60 velocity.resize(6);
61 I.resize(480, 640);
62 I = vpRGBa(255);
63#if defined(VISP_HAVE_DISPLAY)
64 display.init(I, 0, 0, "The External view");
65#endif
66}
67
73 : vpWireFrameSimulator(), vpRobotSimulator(), I(), tcur(0), tprev(0), robotArms(nullptr), size_fMi(8), fMi(nullptr),
76 displayBusy(false), robotStop(false), jointLimit(false), jointLimitArt(false), singularityManagement(true),
78#if defined(VISP_HAVE_DISPLAY)
79 display(),
80#endif
82{
83 setSamplingTime(0.010);
84 velocity.resize(6);
85 I.resize(480, 640);
86 I = vpRGBa(255);
87
88#if defined(VISP_HAVE_DISPLAY)
89 if (do_display)
90 this->display.init(I, 0, 0, "The External view");
91#endif
92}
93
109{
110 m_mutex_scene.lock();
111 if (displayCamera) {
112 free_Bound_scene(&(this->camera));
113 }
114 vpWireFrameSimulator::initScene(obj, desired_object);
115 if (displayCamera) {
116 free_Bound_scene(&(this->camera));
117 }
118 displayCamera = false;
119 m_mutex_scene.unlock();
120}
121
133void vpRobotWireFrameSimulator::initScene(const char *obj, const char *desired_object)
134{
135 if (displayCamera) {
136 free_Bound_scene(&(this->camera));
137 }
138 vpWireFrameSimulator::initScene(obj, desired_object);
139 if (displayCamera) {
140 free_Bound_scene(&(this->camera));
141 }
142 displayCamera = false;
143}
144
158{
159 if (displayCamera) {
160 free_Bound_scene(&(this->camera));
161 }
163 if (displayCamera) {
164 free_Bound_scene(&(this->camera));
165 }
166 displayCamera = false;
167}
168
180{
181 if (displayCamera) {
182 free_Bound_scene(&(this->camera));
183 }
185 if (displayCamera) {
186 free_Bound_scene(&(this->camera));
187 }
188 displayCamera = false;
189}
190
203{
204
205 if (!sceneInitialized)
206 throw;
207
208 double u;
209 double v;
210 // if(px_int != 1 && py_int != 1)
211 // we assume px_int and py_int > 0
212 if ((std::fabs(px_int - 1.) > vpMath::maximum(px_int, 1.) * std::numeric_limits<double>::epsilon()) &&
213 (std::fabs(py_int - 1) > vpMath::maximum(py_int, 1.) * std::numeric_limits<double>::epsilon())) {
214 u = static_cast<double>(I_.getWidth()) / (2 * px_int);
215 v = static_cast<double>(I_.getHeight()) / (2 * py_int);
216 }
217 else {
218 u = static_cast<double>(I_.getWidth()) / (vpMath::minimum(I_.getWidth(), I_.getHeight()));
219 v = static_cast<double>(I_.getHeight()) / (vpMath::minimum(I_.getWidth(), I_.getHeight()));
220 }
221
222 float o44c[4][4], o44cd[4][4], x, y, z;
223 Matrix id = IDENTITY_MATRIX;
224
226 get_fMi(fMit);
227 this->cMo = fMit[size_fMi - 1].inverse() * fMo;
228 this->cMo = rotz * cMo;
229
230 vp2jlc_matrix(cMo.inverse(), o44c);
231 vp2jlc_matrix(cdMo.inverse(), o44cd);
232
233 while (get_displayBusy())
234 vpTime::wait(2);
235
236 add_vwstack("start", "cop", o44c[3][0], o44c[3][1], o44c[3][2]);
237 x = o44c[2][0] + o44c[3][0];
238 y = o44c[2][1] + o44c[3][1];
239 z = o44c[2][2] + o44c[3][2];
240 add_vwstack("start", "vrp", x, y, z);
241 add_vwstack("start", "vpn", o44c[2][0], o44c[2][1], o44c[2][2]);
242 add_vwstack("start", "vup", o44c[1][0], o44c[1][1], o44c[1][2]);
243 add_vwstack("start", "window", -u, u, -v, v);
244 if (displayObject)
245 display_scene(id, this->scene, I_, curColor);
246
247 add_vwstack("start", "cop", o44cd[3][0], o44cd[3][1], o44cd[3][2]);
248 x = o44cd[2][0] + o44cd[3][0];
249 y = o44cd[2][1] + o44cd[3][1];
250 z = o44cd[2][2] + o44cd[3][2];
251 add_vwstack("start", "vrp", x, y, z);
252 add_vwstack("start", "vpn", o44cd[2][0], o44cd[2][1], o44cd[2][2]);
253 add_vwstack("start", "vup", o44cd[1][0], o44cd[1][1], o44cd[1][2]);
254 add_vwstack("start", "window", -u, u, -v, v);
256 if (desiredObject == D_TOOL)
258 else
260 }
261 delete[] fMit;
262 set_displayBusy(false);
263}
264
277{
278
279 if (!sceneInitialized)
280 throw;
281
282 double u;
283 double v;
284 // if(px_int != 1 && py_int != 1)
285 // we assume px_int and py_int > 0
286 if ((std::fabs(px_int - 1.) > vpMath::maximum(px_int, 1.) * std::numeric_limits<double>::epsilon()) &&
287 (std::fabs(py_int - 1) > vpMath::maximum(py_int, 1.) * std::numeric_limits<double>::epsilon())) {
288 u = static_cast<double>(I.getWidth()) / (2 * px_int);
289 v = static_cast<double>(I.getHeight()) / (2 * py_int);
290 }
291 else {
292 u = static_cast<double>(I_.getWidth()) / (vpMath::minimum(I_.getWidth(), I_.getHeight()));
293 v = static_cast<double>(I_.getHeight()) / (vpMath::minimum(I_.getWidth(), I_.getHeight()));
294 }
295
296 float o44c[4][4], o44cd[4][4], x, y, z;
297 Matrix id = IDENTITY_MATRIX;
298
300 get_fMi(fMit);
301 this->cMo = fMit[size_fMi - 1].inverse() * fMo;
302 this->cMo = rotz * cMo;
303
304 vp2jlc_matrix(cMo.inverse(), o44c);
305 vp2jlc_matrix(cdMo.inverse(), o44cd);
306
307 while (get_displayBusy())
308 vpTime::wait(2);
309
310 add_vwstack("start", "cop", o44c[3][0], o44c[3][1], o44c[3][2]);
311 x = o44c[2][0] + o44c[3][0];
312 y = o44c[2][1] + o44c[3][1];
313 z = o44c[2][2] + o44c[3][2];
314 add_vwstack("start", "vrp", x, y, z);
315 add_vwstack("start", "vpn", o44c[2][0], o44c[2][1], o44c[2][2]);
316 add_vwstack("start", "vup", o44c[1][0], o44c[1][1], o44c[1][2]);
317 add_vwstack("start", "window", -u, u, -v, v);
318 if (displayObject) {
319 display_scene(id, this->scene, I_, curColor);
320 }
321
322 add_vwstack("start", "cop", o44cd[3][0], o44cd[3][1], o44cd[3][2]);
323 x = o44cd[2][0] + o44cd[3][0];
324 y = o44cd[2][1] + o44cd[3][1];
325 z = o44cd[2][2] + o44cd[3][2];
326 add_vwstack("start", "vrp", x, y, z);
327 add_vwstack("start", "vpn", o44cd[2][0], o44cd[2][1], o44cd[2][2]);
328 add_vwstack("start", "vup", o44cd[1][0], o44cd[1][1], o44cd[1][2]);
329 add_vwstack("start", "window", -u, u, -v, v);
331 if (desiredObject == D_TOOL)
333 else
335 }
336 delete[] fMit;
337 set_displayBusy(false);
338}
339
346{
347 vpHomogeneousMatrix cMoTemp;
349 get_fMi(fMit);
350 cMoTemp = fMit[size_fMi - 1].inverse() * fMo;
351 delete[] fMit;
352 return cMoTemp;
353}
354END_VISP_NAMESPACE
355#elif !defined(VISP_BUILD_SHARED_LIBS)
356// Work around to avoid warning:
357// libvisp_robot.a(vpRobotWireFrameSimulator.cpp.o) has no symbols
358void dummy_vpRobotWireFrameSimulator() { }
359#endif
static const vpColor red
Definition vpColor.h:198
Implementation of an homogeneous matrix and operations on such kind of matrices.
vpHomogeneousMatrix inverse() const
Definition of the vpImage class member functions.
Definition vpImage.h:131
unsigned int getWidth() const
Definition vpImage.h:242
unsigned int getHeight() const
Definition vpImage.h:181
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
void initScene(const vpSceneObject &obj, const vpSceneDesiredObject &desiredObject)
void set_displayBusy(const bool &status)
void getInternalView(vpImage< vpRGBa > &I)
virtual void get_fMi(vpHomogeneousMatrix *fMit)=0
vpSceneDesiredObject desiredObject
@ D_TOOL
A cylindrical tool is attached to the camera.
void initScene(const vpSceneObject &obj, const vpSceneDesiredObject &desiredObject)
void display_scene(Matrix mat, Bound_scene &sc, const vpImage< vpRGBa > &I, const vpColor &color)
vpHomogeneousMatrix fMo
vpHomogeneousMatrix cMo
vpHomogeneousMatrix rotz
vpHomogeneousMatrix cdMo
VISP_EXPORT int wait(double t0, double t)