phymarxbot.h
1 /********************************************************************************
2  * WorldSim -- library for robot simulations *
3  * Copyright (C) 2012-2013 *
4  * Gianluca Massera <emmegian@yahoo.it> *
5  * Fabrizio Papi <erkito87@gmail.com> *
6  * *
7  * This program is free software; you can redistribute it and/or modify *
8  * it under the terms of the GNU General Public License as published by *
9  * the Free Software Foundation; either version 2 of the License, or *
10  * (at your option) any later version. *
11  * *
12  * This program is distributed in the hope that it will be useful, *
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
15  * GNU General Public License for more details. *
16  * *
17  * You should have received a copy of the GNU General Public License *
18  * along with this program; if not, write to the Free Software *
19  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA *
20  ********************************************************************************/
21 
22 #ifndef PHYMARXBOT_H
23 #define PHYMARXBOT_H
24 
25 #include "worldsimconfig.h"
26 #include "wvector.h"
27 #include "wmatrix.h"
28 #include "world.h"
29 #include "motorcontrollers.h"
30 #include "sensorcontrollers.h"
31 #include "graphicalwobject.h"
32 #include "phyhinge.h"
33 #include "phyfixed.h"
34 #include <QVector>
35 
36 namespace farsa {
37  class PhyObject;
38  class PhyJoint;
39  class PhyCylinder;
40  class PhyFixed;
41  class PhyHinge;
42 
54  class FARSA_WSIM_API PhyMarXbot : public WObject {
55  Q_OBJECT
56  public:
57  // Robot dimensions. Measures and masses in MKS
58 
59  // --- chassis containing the battery
60  static const real basex;
61  static const real basey;
62  static const real basez;
63  static const real basem;
64 
65  // --- cylinder body supporting infrared and other modules and turrets
66  static const real bodyr;
67  static const real bodyh;
68  static const real bodym;
69 
70  // --- inner part of the continous tracks (where the rubber tracks move on)
71  static const real axledistance;
72  static const real trackradius;
73  static const real trackheight;
74  static const real trackm;
75 
76  // --- the height of the treads on tracks and wheels
77  static const real treaddepth;
78 
79  // --- external wheels (the radius is excluding the tread height)
80  static const real wheelr;
81  static const real wheelh;
82  static const real wheelm;
83 
84  // --- height of the turret
85  static const real turreth;
86  static const real turretm;
87 
88  // --- dimensions of the attachment device
89  static const real attachdevr;
90  static const real attachdevx;
91  static const real attachdevy;
92  static const real attachdevz;
93  static const real attachdevm;
94 
95  public:
99  PhyMarXbot( World* world, QString name, const wMatrix& tm = wMatrix::identity() );
102  virtual ~PhyMarXbot();
105  return wheelsCtrl;
106  }
109  return attachdevCtrl;
110  }
113  return proximityIR;
114  }
117  return groundBottomIR;
118  }
121  return groundAroundIR;
122  }
125  return tractionSensor;
126  }
131  virtual void preUpdate();
136  virtual void postUpdate();
138  void setProximityIRSensorsGraphicalProperties(bool drawSensor, bool drawRay = false, bool drawRealRay = false);
140  void setGroundBottomIRSensorsGraphicalProperties(bool drawSensor, bool drawRay = false, bool drawRealRay = false);
142  void setGroundAroundIRSensorsGraphicalProperties(bool drawSensor, bool drawRay = false, bool drawRealRay = false);
143 
151  void setDrawFrontMarker(bool drawMarker);
152 
160  bool getDrawFrontMarker() const;
161 
170  void enableAttachmentDevice(bool enable);
171 
177  bool attachmentDeviceEnabled() const
178  {
179  return (attachdev != NULL);
180  }
181 
188  PhyObject* base()
189  {
190  return basev;
191  }
192 
199  PhyObject* turret()
200  {
201  return turretv;
202  }
203 
211  PhyObject* attachmentDevice()
212  {
213  return attachdev;
214  }
215 
222  PhyHinge* attachmentDeviceJoint()
223  {
224  return attachdevjoint;
225  }
226 
233  void doKinematicSimulation(bool k);
234 
236  bool isKinematic() const
237  {
238  return kinematicSimulation;
239  }
240  public slots:
241 
242  protected slots:
252  void setLeftWheelDesideredVelocity(real velocity);
253 
263  void setRightWheelDesideredVelocity(real velocity);
264 
265  protected:
267  virtual void changedMatrix();
268 
269  private:
271  PhyObject* basev;
273  QVector<PhyObject*> wheels;
275  QVector<wMatrix> wheelstm;
277  QVector<PhyJoint*> wheelJoints;
279  WheelMotorController* wheelsCtrl;
282  PhyObject* turretv;
284  wMatrix turrettm;
286  PhyFixed* forcesensor;
289  PhyObject* attachdev;
291  wMatrix attachdevtm;
293  PhyHinge* attachdevjoint;
299  SimulatedIRGroundSensorController* groundBottomIR;
301  SimulatedIRGroundSensorController* groundAroundIR;
303  TractionSensorController* tractionSensor;
305  bool kinematicSimulation;
307  real leftWheelVelocity;
309  real rightWheelVelocity;
310 
317  GraphicalWObject* frontMarker;
318  };
319 
320  namespace previous {
324  class FARSA_WSIM_API PhyMarXbot : public WObject {
325  Q_OBJECT
326  public:
327  // Robot dimensions. Measures and masses in MKS
328 
329  // --- chassis containing the battery
330  static const real basex;
331  static const real basey;
332  static const real basez;
333  static const real basem;
334 
335  // --- cylinder body supporting infrared and other modules and turrets
336  static const real bodyr;
337  static const real bodyh;
338  static const real bodym;
339 
340  // --- inner part of the continous tracks (where the rubber tracks move on)
341  static const real axledistance;
342  static const real trackradius;
343  static const real trackheight;
344  static const real trackm;
345 
346  // --- the height of the treads on tracks and wheels
347  static const real treaddepth;
348 
349  // --- external wheels (the radius is excluding the tread height)
350  static const real wheelr;
351  static const real wheelh;
352  static const real wheelm;
353 
354  // --- height of the attachment ring
355  static const real attachringh;
356  static const real attachringm;
357 
358  // --- module with 12 RGB LEDs
359  static const real ledsh;
360  static const real ledsradius;
361  static const real ledsm;
362 
363  public:
367  PhyMarXbot( World* world, QString name, const wMatrix& tm = wMatrix::identity() );
370  virtual ~PhyMarXbot();
373  return wheelsCtrl;
374  };
377  return proximityIR;
378  }
381  return groundBottomIR;
382  }
385  return groundAroundIR;
386  }
389  return tractionSensor;
390  }
395  virtual void preUpdate();
400  virtual void postUpdate();
402  void setProximityIRSensorsGraphicalProperties(bool drawSensor, bool drawRay = false, bool drawRealRay = false);
404  void setGroundBottomIRSensorsGraphicalProperties(bool drawSensor, bool drawRay = false, bool drawRealRay = false);
406  void setGroundAroundIRSensorsGraphicalProperties(bool drawSensor, bool drawRay = false, bool drawRealRay = false);
407 
408 
415  void doKinematicSimulation(bool k);
416 
419  bool isKinematic() const
420  {
421  return kinematicSimulation;
422  }
423  public slots:
424 
425  protected slots:
435  void setLeftWheelDesideredVelocity(real velocity);
436 
446  void setRightWheelDesideredVelocity(real velocity);
447 
448  protected:
450  virtual void changedMatrix();
451 
452  private:
454  PhyObject* base;
456  QVector<PhyObject*> wheels;
458  QVector<wMatrix> wheelstm;
460  QVector<PhyJoint*> wheelJoints;
462  WheelMotorController* wheelsCtrl;
464  PhyObject* attachring;
466  wMatrix attachringtm;
468  PhyFixed* forcesensor;
472  SimulatedIRGroundSensorController* groundBottomIR;
474  SimulatedIRGroundSensorController* groundAroundIR;
476  TractionSensorController* tractionSensor;
478  bool kinematicSimulation;
480  real leftWheelVelocity;
482  real rightWheelVelocity;
483  };
484  }
485 } // end namespace farsa
486 
487 #endif