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 "phycylinder.h"
35 #include <QVector>
36 
37 namespace farsa {
38  class PhyObject;
39  class PhyJoint;
40  class PhyCylinder;
41  class PhyFixed;
42  class PhyHinge;
43 
55  class FARSA_WSIM_API PhyMarXbot : public WObject {
56  Q_OBJECT
57  public:
58  // Robot dimensions. Measures and masses in MKS
59 
60  // --- chassis containing the battery
61  static const real basex;
62  static const real basey;
63  static const real basez;
64  static const real basem;
65 
66  // --- cylinder body supporting infrared and other modules and turrets
67  static const real bodyr;
68  static const real bodyh;
69  static const real bodym;
70 
71  // --- inner part of the continous tracks (where the rubber tracks move on)
72  static const real axledistance;
73  static const real trackradius;
74  static const real trackheight;
75  static const real trackm;
76 
77  // --- the height of the treads on tracks and wheels
78  static const real treaddepth;
79 
80  // --- external wheels (the radius is excluding the tread height)
81  static const real wheelr;
82  static const real wheelh;
83  static const real wheelm;
84 
85  // --- height of the turret
86  static const real turreth;
87  static const real turretm;
88 
89  // --- dimensions of the attachment device
90  static const real attachdevr;
91  static const real attachdevx;
92  static const real attachdevy;
93  static const real attachdevz;
94  static const real attachdevm;
95 
96  public:
100  PhyMarXbot( World* world, QString name, const wMatrix& tm = wMatrix::identity() );
103  virtual ~PhyMarXbot();
106  return wheelsCtrl;
107  }
110  return attachdevCtrl;
111  }
114  return proximityIR;
115  }
118  return groundBottomIR;
119  }
122  return groundAroundIR;
123  }
126  return tractionSensor;
127  }
132  virtual void preUpdate();
137  virtual void postUpdate();
139  void setProximityIRSensorsGraphicalProperties(bool drawSensor, bool drawRay = false, bool drawRealRay = false);
141  void setGroundBottomIRSensorsGraphicalProperties(bool drawSensor, bool drawRay = false, bool drawRealRay = false);
143  void setGroundAroundIRSensorsGraphicalProperties(bool drawSensor, bool drawRay = false, bool drawRealRay = false);
144 
152  void setDrawFrontMarker(bool drawMarker);
153 
161  bool getDrawFrontMarker() const;
162 
171  void enableAttachmentDevice(bool enable);
172 
178  bool attachmentDeviceEnabled() const
179  {
180  return (attachdev != NULL);
181  }
182 
190  void resetAttachmentDevice();
191 
198  PhyObject* base()
199  {
200  return basev;
201  }
202 
209  PhyObject* turret()
210  {
211  return turretv;
212  }
213 
221  PhyObject* attachmentDevice()
222  {
223  return attachdev;
224  }
225 
232  PhyHinge* attachmentDeviceJoint()
233  {
234  return attachdevjoint;
235  }
236 
243  void doKinematicSimulation(bool k);
244 
246  bool isKinematic() const
247  {
248  return kinematicSimulation;
249  }
250 
263  void setLedColors(QList<QColor> c);
264 
270  QList<QColor> ledColors() const;
271 
279  const QList<PhyCylinder::SegmentColor>& segmentsColor() const;
280 
281  public slots:
282 
283  protected slots:
293  void setLeftWheelDesideredVelocity(real velocity);
294 
304  void setRightWheelDesideredVelocity(real velocity);
305 
306  protected:
308  virtual void changedMatrix();
309 
310  private:
312  PhyObject* basev;
314  QVector<PhyObject*> wheels;
316  QVector<wMatrix> wheelstm;
318  QVector<PhyJoint*> wheelJoints;
320  WheelMotorController* wheelsCtrl;
323  PhyCylinder* turretv;
325  wMatrix turrettm;
327  PhyFixed* forcesensor;
330  PhyObject* attachdev;
332  wMatrix attachdevtm;
334  PhyHinge* attachdevjoint;
340  SimulatedIRGroundSensorController* groundBottomIR;
342  SimulatedIRGroundSensorController* groundAroundIR;
344  TractionSensorController* tractionSensor;
346  bool kinematicSimulation;
348  real leftWheelVelocity;
350  real rightWheelVelocity;
351 
358  GraphicalWObject* frontMarker;
359 
366  QList<QColor> ledColorsv;
367 
368 
375  mutable QList<PhyCylinder::SegmentColor> uniformColor;
376  };
377 
378  namespace previous {
382  class FARSA_WSIM_API PhyMarXbot : public WObject {
383  Q_OBJECT
384  public:
385  // Robot dimensions. Measures and masses in MKS
386 
387  // --- chassis containing the battery
388  static const real basex;
389  static const real basey;
390  static const real basez;
391  static const real basem;
392 
393  // --- cylinder body supporting infrared and other modules and turrets
394  static const real bodyr;
395  static const real bodyh;
396  static const real bodym;
397 
398  // --- inner part of the continous tracks (where the rubber tracks move on)
399  static const real axledistance;
400  static const real trackradius;
401  static const real trackheight;
402  static const real trackm;
403 
404  // --- the height of the treads on tracks and wheels
405  static const real treaddepth;
406 
407  // --- external wheels (the radius is excluding the tread height)
408  static const real wheelr;
409  static const real wheelh;
410  static const real wheelm;
411 
412  // --- height of the attachment ring
413  static const real attachringh;
414  static const real attachringm;
415 
416  // --- module with 12 RGB LEDs
417  static const real ledsh;
418  static const real ledsradius;
419  static const real ledsm;
420 
421  public:
425  PhyMarXbot( World* world, QString name, const wMatrix& tm = wMatrix::identity() );
428  virtual ~PhyMarXbot();
431  return wheelsCtrl;
432  };
435  return proximityIR;
436  }
439  return groundBottomIR;
440  }
443  return groundAroundIR;
444  }
447  return tractionSensor;
448  }
453  virtual void preUpdate();
458  virtual void postUpdate();
460  void setProximityIRSensorsGraphicalProperties(bool drawSensor, bool drawRay = false, bool drawRealRay = false);
462  void setGroundBottomIRSensorsGraphicalProperties(bool drawSensor, bool drawRay = false, bool drawRealRay = false);
464  void setGroundAroundIRSensorsGraphicalProperties(bool drawSensor, bool drawRay = false, bool drawRealRay = false);
465 
466 
473  void doKinematicSimulation(bool k);
474 
477  bool isKinematic() const
478  {
479  return kinematicSimulation;
480  }
481  public slots:
482 
483  protected slots:
493  void setLeftWheelDesideredVelocity(real velocity);
494 
504  void setRightWheelDesideredVelocity(real velocity);
505 
506  protected:
508  virtual void changedMatrix();
509 
510  private:
512  PhyObject* base;
514  QVector<PhyObject*> wheels;
516  QVector<wMatrix> wheelstm;
518  QVector<PhyJoint*> wheelJoints;
520  WheelMotorController* wheelsCtrl;
522  PhyObject* attachring;
524  wMatrix attachringtm;
526  PhyFixed* forcesensor;
530  SimulatedIRGroundSensorController* groundBottomIR;
532  SimulatedIRGroundSensorController* groundAroundIR;
534  TractionSensorController* tractionSensor;
536  bool kinematicSimulation;
538  real leftWheelVelocity;
540  real rightWheelVelocity;
541  };
542  }
543 } // end namespace farsa
544 
545 #endif