wheeledexperimenthelper.h
1 /********************************************************************************
2  * FARSA Experimentes Library *
3  * Copyright (C) 2007-2012 *
4  * Gianluca Massera <emmegian@yahoo.it> *
5  * Stefano Nolfi <stefano.nolfi@istc.cnr.it> *
6  * Tomassino Ferrauto <tomassino.ferrauto@istc.cnr.it> *
7  * *
8  * This program is free software; you can redistribute it and/or modify *
9  * it under the terms of the GNU General Public License as published by *
10  * the Free Software Foundation; either version 2 of the License, or *
11  * (at your option) any later version. *
12  * *
13  * This program is distributed in the hope that it will be useful, *
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
16  * GNU General Public License for more details. *
17  * *
18  * You should have received a copy of the GNU General Public License *
19  * along with this program; if not, write to the Free Software *
20  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA *
21  ********************************************************************************/
22 
23 #ifndef WHEELEDEXPERIMENTHELPER_H
24 #define WHEELEDEXPERIMENTHELPER_H
25 
26 #include "experimentsconfig.h"
27 #include "parametersettable.h"
28 #include "resourcesuser.h"
29 #include "world.h"
30 #include "wvector.h"
31 #include "phyobject.h"
32 #include "phybox.h"
33 #include "phycylinder.h"
34 #include "physphere.h"
35 #include <QVector>
36 
37 namespace farsa {
38 
39 class Arena;
40 class RobotOnPlane;
41 class WheeledRobot2DWrapper;
42 
51 class FARSA_EXPERIMENTS_API PhyObject2DWrapper
52 {
53 public:
57  enum Type {
58  Plane = 0,
59  Wall,
60  Box,
61  RectangularTargetArea,
62  Cylinder,
63  SmallCylinder,
64  BigCylinder,
65  CircularTargetArea,
66  LightBulb,
67  WheeledRobot,
68  NumberOfDifferentTypes
69  };
70 
76  {
77  public:
82  minAngle(0.0),
83  maxAngle(0.0),
84  color()
85  {
86  }
87 
95  AngularRangeAndColor(double mn, double mx, QColor c) :
96  minAngle(mn),
97  maxAngle(mx),
98  color(c)
99  {
100  }
101 
105  double minAngle;
106 
110  double maxAngle;
111 
115  QColor color;
116  };
117 
118 public:
127  virtual WObject* wObject();
128 
135  virtual const WObject* wObject() const;
136 
145  virtual PhyObject* phyObject() = 0;
146 
154  virtual const PhyObject* phyObject() const = 0;
155 
162  virtual Type type() const = 0;
163 
172  virtual void setStatic(bool s);
173 
182  bool getStatic() const;
183 
196  virtual void setKinematic(bool b, bool c = false);
197 
205  bool getKinematic() const;
206 
213  void setPosition(wVector pos);
214 
222  virtual void setPosition(real x, real y) = 0;
223 
229  wVector position() const;
230 
255  virtual void computeLinearViewFieldOccupiedRange(const wMatrix& mtr, QVector<AngularRangeAndColor>& rangesAndColors, double& distance, double maxDistance) const = 0;
256 
271  virtual bool computeDistanceAndOrientationFromRobot(const WheeledRobot2DWrapper& robot, double& distance, double& angle) const = 0;
272 
278  void setTexture(QString textureName);
279 
285  QString texture() const;
286 
292  void setColor(QColor color);
293 
299  QColor color() const;
300 
308  void setUseColorTextureOfOwner(bool b);
309 
317  bool useColorTextureOfOwner() const;
318 
325  {
326  m_previousMatrix = wObject()->matrix();
327  }
328 
334  const wMatrix& previousMatrix() const
335  {
336  return m_previousMatrix;
337  }
338 
339 protected:
345  PhyObject2DWrapper(Arena* arena);
346 
350  virtual ~PhyObject2DWrapper();
351 
355  Arena *const m_arena;
356 
357 private:
364  wMatrix m_previousMatrix;
365 
372 
378  PhyObject2DWrapper& operator=(const PhyObject2DWrapper&);
379 
384  friend class Arena;
385 };
386 
390 class FARSA_EXPERIMENTS_API Box2DWrapper : public PhyObject2DWrapper
391 {
392 public:
400  virtual PhyBox* phyObject();
401 
407  virtual const PhyBox* phyObject() const;
408 
414  virtual Type type() const;
415 
422  virtual void setStatic(bool s);
423 
434  virtual void setKinematic(bool b, bool c = false);
435 
443  virtual void setPosition(real x, real y);
444 
471  virtual void computeLinearViewFieldOccupiedRange(const wMatrix& cameraMtr, QVector<AngularRangeAndColor>& rangesAndColors, double& distance, double maxDistance) const;
472 
487  virtual bool computeDistanceAndOrientationFromRobot(const WheeledRobot2DWrapper& robot, double& distance, double& angle) const;
488 
497  const wVector& vertex(int i) const
498  {
499  return m_vertexes[i];
500  }
501 
509  const wVector& centerOnPlane() const
510  {
511  return m_centerOnPlane;
512  }
513 
519  real width() const
520  {
521  return m_box->sideX();
522  }
523 
529  real depth() const
530  {
531  return m_box->sideY();
532  }
533 
534 protected:
545  Box2DWrapper(Arena* arena, PhyBox* box, Type type);
546 
550  ~Box2DWrapper();
551 
552 private:
556  PhyBox* const m_box;
557 
564  QVector<wVector> m_vertexes;
565 
571  wVector m_centerOnPlane;
572 
580  const Type m_type;
581 
586  friend class Arena;
587 };
588 
592 class FARSA_EXPERIMENTS_API Cylinder2DWrapper : public PhyObject2DWrapper
593 {
594 public:
602  virtual PhyCylinder* phyObject();
603 
609  virtual const PhyCylinder* phyObject() const;
610 
618  virtual void setStatic(bool s);
619 
631  virtual void setKinematic(bool b, bool c = false);
632 
638  virtual Type type() const;
639 
646  virtual void setPosition(real x, real y);
647 
674  virtual void computeLinearViewFieldOccupiedRange(const wMatrix& cameraMtr, QVector<AngularRangeAndColor>& rangesAndColors, double& distance, double maxDistance) const;
675 
690  virtual bool computeDistanceAndOrientationFromRobot(const WheeledRobot2DWrapper& robot, double& distance, double& angle) const;
691 
697  real radius() const
698  {
699  return m_cylinder->radius();
700  }
701 
702 protected:
713  Cylinder2DWrapper(Arena* arena, PhyCylinder* cylinder, Type type);
714 
719 
720 private:
724  PhyCylinder* const m_cylinder;
725 
733  const Type m_type;
734 
739  friend class Arena;
740 };
741 
749 class FARSA_EXPERIMENTS_API Sphere2DWrapper : public PhyObject2DWrapper
750 {
751 public:
759  virtual PhySphere* phyObject();
760 
766  virtual const PhySphere* phyObject() const;
767 
774  virtual void setStatic(bool s);
775 
786  virtual void setKinematic(bool b, bool c = false);
787 
793  virtual Type type() const;
794 
801  virtual void setPosition(real x, real y);
802 
829  virtual void computeLinearViewFieldOccupiedRange(const wMatrix& cameraMtr, QVector<AngularRangeAndColor>& rangesAndColors, double& distance, double maxDistance) const;
830 
845  virtual bool computeDistanceAndOrientationFromRobot(const WheeledRobot2DWrapper& robot, double& distance, double& angle) const;
846 
852  real radius() const
853  {
854  return m_sphere->radius();
855  }
856 
857 protected:
866  Sphere2DWrapper(Arena* arena, PhySphere* sphere, Type type);
867 
871  ~Sphere2DWrapper();
872 
873 private:
877  PhySphere* const m_sphere;
878 
884  const Type m_type;
885 
890  friend class Arena;
891 };
892 
896 class FARSA_EXPERIMENTS_API WheeledRobot2DWrapper : public PhyObject2DWrapper
897 {
898 public:
899 
907  RobotOnPlane* robotOnPlane();
908 
915  const RobotOnPlane* robotOnPlane() const;
916 
924  virtual WObject* wObject();
925 
931  virtual const WObject* wObject() const;
932 
939  virtual PhyObject* phyObject();
940 
947  virtual const PhyObject* phyObject() const;
948 
954  virtual Type type() const;
955 
962  virtual void setPosition(real x, real y);
963 
990  virtual void computeLinearViewFieldOccupiedRange(const wMatrix& cameraMtr, QVector<AngularRangeAndColor>& rangesAndColors, double& distance, double maxDistance) const;
991 
1006  virtual bool computeDistanceAndOrientationFromRobot(const WheeledRobot2DWrapper& robot, double& distance, double& angle) const;
1007 
1013  double getHeight() const
1014  {
1015  return m_height;
1016  }
1017 
1023  double getRadius() const
1024  {
1025  return m_radius;
1026  }
1027 
1028 protected:
1037  WheeledRobot2DWrapper(Arena* arena, RobotOnPlane* robot, double height, double radius);
1038 
1043 
1044 private:
1048  RobotOnPlane* const m_robot;
1049 
1053  const double m_height;
1054 
1058  const double m_radius;
1059 
1064  friend class Arena;
1065 };
1066 
1067 
1079 wVector FARSA_EXPERIMENTS_API positionOnPlane(const Box2DWrapper* plane, real x, real y);
1080 
1096 void FARSA_EXPERIMENTS_API orientationOnPlane(const Box2DWrapper* plane, real angle, wMatrix& mtr);
1097 
1109 real FARSA_EXPERIMENTS_API angleBetweenXAxes(const wMatrix& mtr1, const wMatrix& mtr2);
1110 
1111 } // end namespace farsa
1112 
1113 #endif
const wVector & vertex(int i) const
Returns the coordinates of the i-th vertex of the box on the plane in the global frame of reference...
AngularRangeAndColor(double mn, double mx, QColor c)
Constructor.
real radius() const
Returns the radius of this sphere.
The subclass of PhyObject2DWrapper wrapping a box.
double getRadius() const
Returns the radius of the robot.
real radius() const
Returns the radius of this cylinder.
void storePreviousMatrix()
Stores the current matrix in the previousMatrix.
The subclass of PhyObject2DWrapper wrapping a wheeled robot.
real width() const
Returns the width of the box.
The base class for robots that move on a plane.
Definition: robots.h:108
real depth() const
Returns the depth of the box.
The class modelling an arena.
Definition: arena.h:50
This file contains the common type defitions used on the whole framework.
The subclass of PhyObject2DWrapper wrapping a cylinder.
A class wrapping a PhyObject to add methods suitable for wheeled robots simulations.
const wMatrix & previousMatrix() const
Returns the transformation matrix of the previous time-step.
const wVector & centerOnPlane() const
Returns the coordinates of the center of the box on the plane in the global frame of reference...
The structure with angular range and color used by the computeLinearViewFieldOccupiedRange() function...
float real
Type
The possible type of wrapped objects.
double getHeight() const
Returns the height of the robot.
The subclass of PhyObject2DWrapper wrapping a sphere.
Arena *const m_arena
The pointer to the arena in which this object lives.