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 
189  void resetAttachmentDevice();
190 
197  PhyObject* base()
198  {
199  return basev;
200  }
201 
208  PhyObject* turret()
209  {
210  return turretv;
211  }
212 
220  PhyObject* attachmentDevice()
221  {
222  return attachdev;
223  }
224 
231  PhyHinge* attachmentDeviceJoint()
232  {
233  return attachdevjoint;
234  }
235 
242  void doKinematicSimulation(bool k);
243 
245  bool isKinematic() const
246  {
247  return kinematicSimulation;
248  }
249  public slots:
250 
251  protected slots:
261  void setLeftWheelDesideredVelocity(real velocity);
262 
272  void setRightWheelDesideredVelocity(real velocity);
273 
274  protected:
276  virtual void changedMatrix();
277 
278  private:
280  PhyObject* basev;
282  QVector<PhyObject*> wheels;
284  QVector<wMatrix> wheelstm;
286  QVector<PhyJoint*> wheelJoints;
288  WheelMotorController* wheelsCtrl;
291  PhyObject* turretv;
293  wMatrix turrettm;
295  PhyFixed* forcesensor;
298  PhyObject* attachdev;
300  wMatrix attachdevtm;
302  PhyHinge* attachdevjoint;
308  SimulatedIRGroundSensorController* groundBottomIR;
310  SimulatedIRGroundSensorController* groundAroundIR;
312  TractionSensorController* tractionSensor;
314  bool kinematicSimulation;
316  real leftWheelVelocity;
318  real rightWheelVelocity;
319 
326  GraphicalWObject* frontMarker;
327  };
328 
329  namespace previous {
333  class FARSA_WSIM_API PhyMarXbot : public WObject {
334  Q_OBJECT
335  public:
336  // Robot dimensions. Measures and masses in MKS
337 
338  // --- chassis containing the battery
339  static const real basex;
340  static const real basey;
341  static const real basez;
342  static const real basem;
343 
344  // --- cylinder body supporting infrared and other modules and turrets
345  static const real bodyr;
346  static const real bodyh;
347  static const real bodym;
348 
349  // --- inner part of the continous tracks (where the rubber tracks move on)
350  static const real axledistance;
351  static const real trackradius;
352  static const real trackheight;
353  static const real trackm;
354 
355  // --- the height of the treads on tracks and wheels
356  static const real treaddepth;
357 
358  // --- external wheels (the radius is excluding the tread height)
359  static const real wheelr;
360  static const real wheelh;
361  static const real wheelm;
362 
363  // --- height of the attachment ring
364  static const real attachringh;
365  static const real attachringm;
366 
367  // --- module with 12 RGB LEDs
368  static const real ledsh;
369  static const real ledsradius;
370  static const real ledsm;
371 
372  public:
376  PhyMarXbot( World* world, QString name, const wMatrix& tm = wMatrix::identity() );
379  virtual ~PhyMarXbot();
382  return wheelsCtrl;
383  };
386  return proximityIR;
387  }
390  return groundBottomIR;
391  }
394  return groundAroundIR;
395  }
398  return tractionSensor;
399  }
404  virtual void preUpdate();
409  virtual void postUpdate();
411  void setProximityIRSensorsGraphicalProperties(bool drawSensor, bool drawRay = false, bool drawRealRay = false);
413  void setGroundBottomIRSensorsGraphicalProperties(bool drawSensor, bool drawRay = false, bool drawRealRay = false);
415  void setGroundAroundIRSensorsGraphicalProperties(bool drawSensor, bool drawRay = false, bool drawRealRay = false);
416 
417 
424  void doKinematicSimulation(bool k);
425 
428  bool isKinematic() const
429  {
430  return kinematicSimulation;
431  }
432  public slots:
433 
434  protected slots:
444  void setLeftWheelDesideredVelocity(real velocity);
445 
455  void setRightWheelDesideredVelocity(real velocity);
456 
457  protected:
459  virtual void changedMatrix();
460 
461  private:
463  PhyObject* base;
465  QVector<PhyObject*> wheels;
467  QVector<wMatrix> wheelstm;
469  QVector<PhyJoint*> wheelJoints;
471  WheelMotorController* wheelsCtrl;
473  PhyObject* attachring;
475  wMatrix attachringtm;
477  PhyFixed* forcesensor;
481  SimulatedIRGroundSensorController* groundBottomIR;
483  SimulatedIRGroundSensorController* groundAroundIR;
485  TractionSensorController* tractionSensor;
487  bool kinematicSimulation;
489  real leftWheelVelocity;
491  real rightWheelVelocity;
492  };
493  }
494 } // end namespace farsa
495 
496 #endif