phykhepera.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 PHYKHEPERA_H
23 #define PHYKHEPERA_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 <QVector>
32 
33 namespace farsa {
34  class PhyObject;
35  class PhyJoint;
36  class PhyCylinder;
37 
44  class FARSA_WSIM_API PhyKhepera : public WObject {
45  Q_OBJECT
46 
47  public:
51  static const real bodydistancefromground;
52 
56  static const real bodyr;
57 
61  static const real bodyh;
62 
66  static const real bodym;
67 
71  static const real wheelr;
72 
76  static const real wheelh;
77 
81  static const real wheelm;
82 
86  static const real axletrack;
87 
94  static const real passivewheelr;
95 
102  static const real passivewheelm;
103 
104  public:
112  PhyKhepera(World* world, QString name, const wMatrix& transformation = wMatrix::identity());
113 
117  virtual ~PhyKhepera();
118 
124  WheelMotorController* wheelsController()
125  {
126  return m_wheelsCtrl;
127  }
128 
134  IRSensorController* proximityIRSensorController()
135  {
136  return m_proximityIR;
137  }
138 
145  virtual void preUpdate();
146 
153  virtual void postUpdate();
154 
165  void setProximityIRSensorsGraphicalProperties(bool drawSensor, bool drawRay = false, bool drawRealRay = false);
166 
175  void doKinematicSimulation(bool k);
176 
182  bool isKinematic() const
183  {
184  return m_kinematicSimulation;
185  }
186 
187  protected slots:
197  void setLeftWheelDesideredVelocity(real velocity);
198 
208  void setRightWheelDesideredVelocity(real velocity);
209 
210  protected:
217  virtual void changedMatrix();
218 
219  private:
223  PhyObject* m_body;
224 
229  wMatrix m_bodyTransformation;
230 
235  wMatrix m_bodyInvTransformation;
236 
243  QVector<PhyObject*> m_wheels;
244 
252  QVector<wMatrix> m_wheelsTransformation;
253 
260  QVector<PhyJoint*> m_wheelJoints;
261 
267  WheelMotorController* m_wheelsCtrl;
268 
273 
277  bool m_kinematicSimulation;
278 
282  real m_leftWheelVelocity;
283 
287  real m_rightWheelVelocity;
288  };
289 } // end namespace farsa
290 
291 #endif