ViSP  2.10.0
vpRobotWireFrameSimulator.cpp
1 /****************************************************************************
2  *
3  * $Id: vpRobotWireFrameSimulator.cpp 3530 2012-01-03 10:52:12Z fspindle $
4  *
5  * This file is part of the ViSP software.
6  * Copyright (C) 2005 - 2014 by INRIA. All rights reserved.
7  *
8  * This software is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU General Public License
10  * ("GPL") version 2 as published by the Free Software Foundation.
11  * See the file LICENSE.txt at the root directory of this source
12  * distribution for additional information about the GNU GPL.
13  *
14  * For using ViSP with software that can not be combined with the GNU
15  * GPL, please contact INRIA about acquiring a ViSP Professional
16  * Edition License.
17  *
18  * See http://www.irisa.fr/lagadic/visp/visp.html for more information.
19  *
20  * This software was developed at:
21  * INRIA Rennes - Bretagne Atlantique
22  * Campus Universitaire de Beaulieu
23  * 35042 Rennes Cedex
24  * France
25  * http://www.irisa.fr/lagadic
26  *
27  * If you have questions regarding the use of this file, please contact
28  * INRIA at visp@inria.fr
29  *
30  * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
31  * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
32  *
33  *
34  * Description:
35  * Basic class used to make robot simulators.
36  *
37  * Authors:
38  * Nicolas Melchior
39  *
40  *****************************************************************************/
41 
42 #include <visp/vpConfig.h>
43 
44 
45 
46 #if defined(_WIN32) || defined(VISP_HAVE_PTHREAD)
47 #include <visp/vpRobotWireFrameSimulator.h>
48 #include <visp/vpSimulatorViper850.h>
49 
55  I(), tcur(0), tprev(0), robotArms(NULL), size_fMi(8), fMi(NULL), artCoord(), artVel(), velocity(),
56 #if defined(_WIN32)
57 #elif defined(VISP_HAVE_PTHREAD)
58  thread(), attr(),
59 #endif
60  mutex_fMi(), mutex_artVel(), mutex_artCoord(), mutex_velocity(), mutex_display(),
61  displayBusy(false), robotStop(false), jointLimit(false), jointLimitArt(false), singularityManagement(true),
62  cameraParam(),
63 #if defined(VISP_HAVE_DISPLAY)
64  display(),
65 #endif
66  displayType(MODEL_3D), displayAllowed(true), constantSamplingTimeMode(false),
67  setVelocityCalled(false), verbose_(false)
68 {
69  setSamplingTime(0.010);
70  velocity.resize(6);
71  I.resize(480,640);
72  I = 255;
73 #if defined(VISP_HAVE_DISPLAY)
74  display.init(I, 0, 0,"The External view");
75 #endif
76 
77  //pid_t pid = getpid();
78  // setpriority (PRIO_PROCESS, pid, 19);
79 }
80 
87  I(), tcur(0), tprev(0), robotArms(NULL), size_fMi(8), fMi(NULL), artCoord(), artVel(), velocity(),
88 #if defined(_WIN32)
89 #elif defined(VISP_HAVE_PTHREAD)
90  thread(), attr(),
91 #endif
92  /* thread(), attr(), */ mutex_fMi(), mutex_artVel(), mutex_artCoord(), mutex_velocity(), mutex_display(),
93  displayBusy(false), robotStop(false), jointLimit(false), jointLimitArt(false), singularityManagement(true),
94  cameraParam(),
95 #if defined(VISP_HAVE_DISPLAY)
96  display(),
97 #endif
98  displayType(MODEL_3D), displayAllowed(do_display), constantSamplingTimeMode(false),
99  setVelocityCalled(false), verbose_(false)
100 {
101  setSamplingTime(0.010);
102  velocity.resize(6);
103  I.resize(480,640);
104  I = 255;
105 
106 #if defined(VISP_HAVE_DISPLAY)
107  if (do_display)
108  this->display.init(I, 0, 0,"The External view");
109 #endif
110 
111  //pid_t pid = getpid();
112  // setpriority (PRIO_PROCESS, pid, 19);
113 }
114 
115 
116 
121 {
122 }
123 
133 void
135 {
136  if(displayCamera){
137  free_Bound_scene (&(this->camera));
138  }
139  vpWireFrameSimulator::initScene(obj, desired_object);
140  if(displayCamera){
141  free_Bound_scene (&(this->camera));
142  }
143  displayCamera = false;
144 }
145 
156 void
157 vpRobotWireFrameSimulator::initScene(const char* obj, const char* desired_object)
158 {
159  if(displayCamera){
160  free_Bound_scene (&(this->camera));
161  }
162  vpWireFrameSimulator::initScene(obj, desired_object);
163  if(displayCamera){
164  free_Bound_scene (&(this->camera));
165  }
166  displayCamera = false;
167 }
168 
177 void
179 {
180  if(displayCamera){
181  free_Bound_scene (&(this->camera));
182  }
184  if(displayCamera){
185  free_Bound_scene (&(this->camera));
186  }
187  displayCamera = false;
188 }
189 
198 void
200 {
201  if(displayCamera){
202  free_Bound_scene (&(this->camera));
203  }
205  if(displayCamera){
206  free_Bound_scene (&(this->camera));
207  }
208  displayCamera = false;
209 }
210 
220 void
222 {
223 
224  if (!sceneInitialized)
225  throw;
226 
227  double u;
228  double v;
229  //if(px_int != 1 && py_int != 1)
230  // we assume px_int and py_int > 0
231  if( (std::fabs(px_int-1.) > vpMath::maximum(px_int,1.)*std::numeric_limits<double>::epsilon())
232  && (std::fabs(py_int-1) > vpMath::maximum(py_int,1.)*std::numeric_limits<double>::epsilon()))
233  {
234  u = (double)I_.getWidth()/(2*px_int);
235  v = (double)I_.getHeight()/(2*py_int);
236  }
237  else
238  {
239  u = (double)I_.getWidth()/(vpMath::minimum(I_.getWidth(),I_.getHeight()));
240  v = (double)I_.getHeight()/(vpMath::minimum(I_.getWidth(),I_.getHeight()));
241  }
242 
243  float o44c[4][4],o44cd[4][4],x,y,z;
244  Matrix id = IDENTITY_MATRIX;
245 
247  get_fMi(fMit);
248  this->cMo = fMit[size_fMi-1].inverse()*fMo;
249  this->cMo = rotz*cMo;
250 
251  vp2jlc_matrix(cMo.inverse(),o44c);
252  vp2jlc_matrix(cdMo.inverse(),o44cd);
253 
254  while (get_displayBusy()) vpTime::wait(2);
255 
256  add_vwstack ("start","cop", o44c[3][0],o44c[3][1],o44c[3][2]);
257  x = o44c[2][0] + o44c[3][0];
258  y = o44c[2][1] + o44c[3][1];
259  z = o44c[2][2] + o44c[3][2];
260  add_vwstack ("start","vrp", x,y,z);
261  add_vwstack ("start","vpn", o44c[2][0],o44c[2][1],o44c[2][2]);
262  add_vwstack ("start","vup", o44c[1][0],o44c[1][1],o44c[1][2]);
263  add_vwstack ("start","window", -u, u, -v, v);
264  if (displayObject)
265  display_scene(id,this->scene,I_, curColor);
266 
267  add_vwstack ("start","cop", o44cd[3][0],o44cd[3][1],o44cd[3][2]);
268  x = o44cd[2][0] + o44cd[3][0];
269  y = o44cd[2][1] + o44cd[3][1];
270  z = o44cd[2][2] + o44cd[3][2];
271  add_vwstack ("start","vrp", x,y,z);
272  add_vwstack ("start","vpn", o44cd[2][0],o44cd[2][1],o44cd[2][2]);
273  add_vwstack ("start","vup", o44cd[1][0],o44cd[1][1],o44cd[1][2]);
274  add_vwstack ("start","window", -u, u, -v, v);
276  {
278  else display_scene(id,desiredScene,I_, desColor);
279  }
280  delete[] fMit;
281  set_displayBusy(false);
282 }
283 
293 void
295 {
296 
297  if (!sceneInitialized)
298  throw;
299 
300  double u;
301  double v;
302  //if(px_int != 1 && py_int != 1)
303  // we assume px_int and py_int > 0
304  if( (std::fabs(px_int-1.) > vpMath::maximum(px_int,1.)*std::numeric_limits<double>::epsilon())
305  && (std::fabs(py_int-1) > vpMath::maximum(py_int,1.)*std::numeric_limits<double>::epsilon()))
306  {
307  u = (double)I.getWidth()/(2*px_int);
308  v = (double)I.getHeight()/(2*py_int);
309  }
310  else
311  {
312  u = (double)I_.getWidth()/(vpMath::minimum(I_.getWidth(),I_.getHeight()));
313  v = (double)I_.getHeight()/(vpMath::minimum(I_.getWidth(),I_.getHeight()));
314  }
315 
316  float o44c[4][4],o44cd[4][4],x,y,z;
317  Matrix id = IDENTITY_MATRIX;
318 
320  get_fMi(fMit);
321  this->cMo = fMit[size_fMi-1].inverse()*fMo;
322  this->cMo = rotz*cMo;
323 
324  vp2jlc_matrix(cMo.inverse(),o44c);
325  vp2jlc_matrix(cdMo.inverse(),o44cd);
326 
327  while (get_displayBusy()) vpTime::wait(2);
328 
329  add_vwstack ("start","cop", o44c[3][0],o44c[3][1],o44c[3][2]);
330  x = o44c[2][0] + o44c[3][0];
331  y = o44c[2][1] + o44c[3][1];
332  z = o44c[2][2] + o44c[3][2];
333  add_vwstack ("start","vrp", x,y,z);
334  add_vwstack ("start","vpn", o44c[2][0],o44c[2][1],o44c[2][2]);
335  add_vwstack ("start","vup", o44c[1][0],o44c[1][1],o44c[1][2]);
336  add_vwstack ("start","window", -u, u, -v, v);
337  if (displayObject)
338  {
339  display_scene(id,this->scene,I_, curColor);
340  }
341 
342  add_vwstack ("start","cop", o44cd[3][0],o44cd[3][1],o44cd[3][2]);
343  x = o44cd[2][0] + o44cd[3][0];
344  y = o44cd[2][1] + o44cd[3][1];
345  z = o44cd[2][2] + o44cd[3][2];
346  add_vwstack ("start","vrp", x,y,z);
347  add_vwstack ("start","vpn", o44cd[2][0],o44cd[2][1],o44cd[2][2]);
348  add_vwstack ("start","vup", o44cd[1][0],o44cd[1][1],o44cd[1][2]);
349  add_vwstack ("start","window", -u, u, -v, v);
351  {
353  else display_scene(id,desiredScene,I_, desColor);
354  }
355  delete[] fMit;
356  set_displayBusy(false);
357 }
358 
366 {
367  vpHomogeneousMatrix cMoTemp;
369  get_fMi(fMit);
370  cMoTemp = fMit[size_fMi-1].inverse()*fMo;
371  delete[] fMit;
372  return cMoTemp;
373 }
374 
375 #endif
virtual void get_fMi(vpHomogeneousMatrix *fMit)=0
void initScene(const vpSceneObject &obj, const vpSceneDesiredObject &desiredObject)
unsigned int getWidth() const
Definition: vpImage.h:161
The class provides a data structure for the homogeneous matrices as well as a set of operations on th...
A cylindrical tool is attached to the camera.
vpHomogeneousMatrix cdMo
static int wait(double t0, double t)
Definition: vpTime.cpp:149
vpHomogeneousMatrix fMo
static const vpColor red
Definition: vpColor.h:167
static Type maximum(const Type &a, const Type &b)
Definition: vpMath.h:137
This class aims to be a basis used to create all the robot simulators.
void set_displayBusy(const bool &status)
void setSamplingTime(const double &delta_t)
void getInternalView(vpImage< vpRGBa > &I)
void initScene(const vpSceneObject &obj, const vpSceneDesiredObject &desiredObject)
void resize(const unsigned int h, const unsigned int w)
set the size of the image without initializing it.
Definition: vpImage.h:536
vpHomogeneousMatrix cMo
static Type minimum(const Type &a, const Type &b)
Definition: vpMath.h:148
Implementation of a wire frame simulator. Compared to the vpSimulator class, it does not require thir...
vpSceneDesiredObject desiredObject
void display_scene(Matrix mat, Bound_scene &sc, const vpImage< vpRGBa > &I, const vpColor &color)
vpHomogeneousMatrix inverse() const
vpHomogeneousMatrix rotz
unsigned int getHeight() const
Definition: vpImage.h:152
void init(vpImage< unsigned char > &I, int winx=-1, int winy=-1, const char *title=NULL)
Definition: vpDisplayX.cpp:194
void resize(const unsigned int i, const bool flagNullify=true)
Definition: vpColVector.h:98