Robot Simulator of the Robotics Group for Self-Organization of Control  0.8.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
contactsensor.h
Go to the documentation of this file.
1 /***************************************************************************
2  * Copyright (C) 2005-2012 LpzRobots development team *
3  * Georg Martius <georg dot martius at web dot de> *
4  * Frank Guettler <guettler at informatik dot uni-leipzig dot de *
5  * Frank Hesse <frank at nld dot ds dot mpg dot de> *
6  * Ralf Der <ralfder at mis dot mpg dot de> *
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 *
20  * Free Software Foundation, Inc., *
21  * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
22  * *
23  ***************************************************************************/
24 #ifndef __CONTACTSENSOR_H
25 #define __CONTACTSENSOR_H
26 
27 #include <ode_robots/color.h>
28 #include <ode_robots/physicalsensor.h>
29 
30 namespace lpzrobots {
31 
32  class Sphere;
33  class Transform;
34 
35  /** Class for a contact sensor.
36  The sensor is on if a collision occurs and stores the penetration depth
37  (as a crude measure for the colission force). It can be either attached to
38  an existing primitive (e.g. a leg) or create its own sensor object. The latter
39  is recommended if you want very localized force sensors.
40  The information of a collision comes to the sensor via the
41  collision callback of the substance used for the primitive.
42  The sensor returns the maximum forces since the last sense() call.
43  */
44  class ContactSensor : public PhysicalSensor{
45  public:
46 
47  /**
48  @param binary if true then the sensor is 0 or 1 (for contact), no force value returned
49  @param forcescale scale of the measured collision force (default: 1)
50  @param size size of little sphere representing the sensor (if it has an own body) (default: 0.05)
51  @param createSphere if true then a little sphere is created otherwise the reference body is directly used
52  @param colorObject if true then the object (sphere or reference) is colored according to contact state
53  @param contactColor color if contact sensor values is 1. In between it is blend with original color.
54  If a channel is negative: use original color and invert those channels that are negative.
55  (default: (-1,-1,-1) : invert all channels)
56  */
57  ContactSensor(bool binary=true, double forcescale = 1, double radius = 0.05,
58  bool createSphere = false, bool colorObject = true,
59  Color contactColor = Color(-1,-1,-1));
60 
61  virtual ~ContactSensor();
62 
63  /** returns the sensor value in the range >=0;
64  0 means nothing no contact
65  >0 means contact with another object: size is the force in arbitrary unit
66  @see characteritic()
67  */
68  virtual double get();
69 
70  // ---- Sensor interface -----
71  virtual void init(Primitive* own, Joint* joint = 0) override;
72 
73  virtual int getSensorNumber() const { return 1; }
74 
75  virtual bool sense(const GlobalData& globaldata) override;
76 
77  virtual int get(sensor* sensors, int length) const override;
78 
79  virtual std::list<sensor> getList() const override;
80 
81  virtual void update() override ;
82 
83  // set measued depth (used internally) and the time (old measures are ignored)
84  virtual void setDepth(float depth, long int time);
85 
87 
88  protected:
89  bool binary; ///< if contact sensor is a switch
90  double forcescale;
91  double detection; ///< currently detected value
92  double value; ///< actual sensor value
93  double lastvalue; ///< last value
94  double size; ///< size of graphical sensor
95  long int lasttimeasked; // used to make sense return the same number if called two times in one timestep
96 
97  Primitive* reference; ///< primitive to which the sensor is bound
100 
106  };
107 
108 }
109 
110 #endif
double forcescale
Definition: contactsensor.h:90
bool binary
if contact sensor is a switch
Definition: contactsensor.h:89
virtual void setDepth(float depth, long int time)
Definition: contactsensor.cpp:121
bool colorObject
Definition: contactsensor.h:102
Sphere * sensorBody
Definition: contactsensor.h:98
Color origColor
Definition: contactsensor.h:103
Definition: joint.h:41
double sensor
Definition: types.h:29
Sphere primitive.
Definition: primitive.h:289
bool createSphere
Definition: contactsensor.h:101
Transform * transform
Definition: contactsensor.h:99
Primitive * reference
primitive to which the sensor is bound
Definition: contactsensor.h:97
double lastvalue
last value
Definition: contactsensor.h:93
double detection
currently detected value
Definition: contactsensor.h:91
long int lasttimeasked
Definition: contactsensor.h:95
virtual int getSensorNumber() const
returns the number of sensors values produced by this sensor
Definition: contactsensor.h:73
Interface class for primitives represented in the physical and graphical world.
Definition: primitive.h:80
virtual void init(Primitive *own, Joint *joint=0) override
initialises sensor with a body of robot and optionally with a joint.
Definition: contactsensor.cpp:89
Data structure holding all essential global information.
Definition: globaldata.h:57
ContactSensor(bool binary=true, double forcescale=1, double radius=0.05, bool createSphere=false, bool colorObject=true, Color contactColor=Color(-1,-1,-1))
Definition: contactsensor.cpp:61
Definition: color.h:32
Transform * getTransformObject()
Definition: contactsensor.cpp:153
virtual std::list< sensor > getList() const override
returns a list of sensor values (usually in the range [-1,1] ) This function should be overloaded...
Definition: contactsensor.cpp:145
virtual ~ContactSensor()
Definition: contactsensor.cpp:79
Class for a contact sensor.
Definition: contactsensor.h:44
virtual bool sense(const GlobalData &globaldata) override
performs sense action
Definition: contactsensor.cpp:130
bool initialised
Definition: contactsensor.h:105
Abstract class for sensors that have a physical representation.
Definition: physicalsensor.h:35
Primitive for transforming a geom (primitive without body) in respect to a body (primitive with body)...
Definition: primitive.h:410
virtual void update() override
to update any visual appearance
Definition: contactsensor.cpp:162
double value
actual sensor value
Definition: contactsensor.h:92
Color touchColor
Definition: contactsensor.h:104
double size
size of graphical sensor
Definition: contactsensor.h:94