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
angularmotor.h
Go to the documentation of this file.
1 /***************************************************************************
2  * Copyright (C) 2005-2011 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 __ANGULARMOTOR_H
25 #define __ANGULARMOTOR_H
26 
27 #include <list>
28 #include "joint.h"
29 #include "motor.h"
30 #include "sensor.h"
31 
32 namespace lpzrobots {
33 
34  /** Abstract angular motor class. This is a wrapper for ODE's AMotor.
35  */
36  class AngularMotor : virtual public Sensor, virtual public Motor {
37  public:
38  /// creates a AMotor attached to the same bodies as the given joint.
40 
41  // destroys the AMotor
42  virtual ~AngularMotor ();
43 
44  /// returns the number of Axis of this Motor
45  virtual int getNumberOfAxes() const= 0;
46 
47  // --- Sensor interface ---
48  virtual void init(Primitive* own, Joint* joint = 0) override ;
49 
50  virtual bool sense(const GlobalData& globaldata) override { return true;};
51  virtual int getSensorNumber() const override {
52  return getNumberOfAxes();
53  }
54  virtual std::list<sensor> getList() const override { return getListOfArray();};
55  virtual int get(sensor* sensors, int length) const override;
56 
57  // --- Motor interface ---
58  virtual int getMotorNumber() const override { return getNumberOfAxes();};
59 
60  virtual bool act(GlobalData& globaldata) override {
61  return true;
62  };
63 
64  /** sends the action commands to the motor.
65  It returns the number of used values. (should be equal to
66  getMotorNumber)
67  */
68  virtual int set(const motor* values, int length) override;
69 
70  // --- old interface
71 
72  /** sets the desired speed of the motor at the given axis.
73  @param velocity Desired motor velocity (this will be an angular or linear velocity).
74  */
75  virtual void set(int axisNumber, double velocity) = 0;
76  /** returns the speed (PositionRate) at the given axis, or zero if the axis is out of range*/
77  virtual double get(int axisNumber) const = 0;
78 
79  /** sets the maximal force the motor has
80  */
81  virtual void setPower(double power) = 0;
82 
83  /// return the maximal force
84  virtual double getPower();
85 
86  /// returns the joint to which this motor is attached
87  virtual Joint* getJoint() { return joint; };
88 
89  //sets the parameter for a motor
90  virtual void setParam(int parameter, double value);
91 
92  /// return the ODE joint parameter (see ODE manual)
93  virtual double getParam(int parameter);
94 
95  /// sets factor for velocity
96  virtual void setVelovityFactor(double factor);
97 
98  /// retuns factor for velocity
99  virtual double getVelovityFactor(double factor);
100 
101  protected:
102  dJointID motor;
107  };
108 
109 
110  /// Angular motor for OneAxisJoints
112  public:
113  /** Constuct a motor attached to a OneAxisJoint. It will its axis of course.
114  @param power The maximum force or torque that the motor will use to achieve the desired velocity.
115  This must always be greater than or equal to zero.
116  Setting this to zero (the default value) turns off the motor.
117  */
119  virtual ~AngularMotor1Axis() {}
120 
121  virtual void init(Primitive* own, Joint* joint = 0) override ;
122 
123  virtual int getNumberOfAxes() const override { return 1; };
124 
125  /** sets the desired speed of the motor at the given axis.
126  @param axisNumber is ignored because have only one axis
127  @param velocity Desired motor velocity (this will be an angular or linear velocity).
128  */
129  virtual void set(int axisNumber, double velocity);
130  /** returns the speed (PositionRate) at the given axis, or zero if the axis is out of range
131  @param axisNumber is ignored because have only one axis
132  */
133  virtual double get(int axisNumber) const override ;
134 
135  virtual void setPower(double power);
136  protected:
137  double power;
138  };
139 
140  /// Angular motor for TwoAxisJoints
142  public:
143  /** Constuct a motor attached to a TwoAxisJoint. It will its two axis of course.
144  @param power The maximum force or torque that the motor will use to achieve the desired velocity.
145  This must always be greater than or equal to zero.
146  Setting this to zero (the default value) turns off the motor.
147  */
149  virtual ~AngularMotor2Axis() {}
150 
151  virtual void init(Primitive* own, Joint* joint = 0) override ;
152 
153  /// returns the number of Axis of this Motor
154  virtual int getNumberOfAxes() const override { return 2; };
155 
156  /** sets the desired speed of the motor at the given axis.
157  @param axisNumber either 0 or 1
158  @param velocity Desired motor velocity (this will be an angular or linear velocity).
159  */
160  virtual void set(int axisNumber, double velocity);
161  virtual double get(int axisNumber) const override ;
162 
163  virtual void setPower(double power);
164  virtual void setPower(double power1, double power2);
165 
166  /// return the maximal force
167  virtual double getPower2();
168  protected:
169  double power1;
170  double power2;
171  };
172 
173 
174  /// Angular motor for Ball Joints with Euler control
176  public:
177  /** Constuct a motor attached to a BallJoint.
178  @param axis1 axis relative to body 1
179  @param axis3 axis relative to body 2 (must be perpendicular to axis1
180  (the axis 2 is calculated automatically)
181  @param power The maximum force or torque that the motor will use to achieve the desired velocity.
182  This must always be greater than or equal to zero.
183  Setting this to zero (the default value) turns off the motor.
184  */
186  const Axis& axis1, const Axis& axis3, double power);
187 
188  virtual void init(Primitive* own, Joint* joint = 0) override ;
189 
190  /// returns the number of Axis of this Motor
191  virtual int getNumberOfAxes() const override { return 3; };
192 
193  /** sets the desired speed of the motor at the given axis.
194  @param axisNumber either 0 or 1
195  @param velocity Desired motor velocity (this will be an angular or linear velocity).
196  */
197  virtual void set(int axisNumber, double velocity);
198  /** returns the speed (PositionRate) at the given axis, or zero if the axis is out of range*/
199  virtual double get(int axisNumber) const override ;
200 
201  /** sets the maximal force the motor has
202  */
203  virtual void setPower(double power);
204  protected:
207  double power;
208  };
209 
210  /// Angular motor for arbitrary Joints with custom axis (up to 3)
212  public:
213  /** Constuct a motor attached to any Joint (not Sliders!).
214  The axis have to be provided by the user.
215  @param axis list of axis vector and power If empty then it motor is disabled.
216  Power is the maximum force or torque that the motor will use to achieve the desired velocity.
217  This must always be greater than or equal to zero.
218  Setting this to zero (the default value) turns off the motor.
219  */
221  std::list<std::pair<double, Axis > > axis);
222 
223  virtual ~AngularMotorNAxis() {}
224 
225  virtual void init(Primitive* own, Joint* joint = 0) override ;
226 
227  /// returns the number of Axis of this Motor
228  virtual int getNumberOfAxes() const override ;
229 
230  /** sets the desired speed of the motor at the given axis.
231  @param velocity Desired motor velocity (this will be an angular or linear velocity).
232  */
233  virtual void set(int axisNumber, double velocity);
234  /** returns the speed (PositionRate) at the given axis, or zero if the axis is out of range
235  The problem is, that we don't have actual information available.
236  So we return the last set position!.
237  */
238  virtual double get(int axisNumber) const override ;
239 
240  virtual void setPower(double power);
241  protected:
242  std::list<std::pair<double, Axis > > axis;
243  };
244 
245 
246 
247 }
248 #endif
virtual ~AngularMotor1Axis()
Definition: angularmotor.h:119
Joint * joint
Definition: angularmotor.h:105
double power
Definition: angularmotor.h:137
virtual ~AngularMotor2Axis()
Definition: angularmotor.h:149
virtual void set(int axisNumber, double velocity)
sets the desired speed of the motor at the given axis.
Definition: angularmotor.cpp:400
virtual void setPower(double power)
sets the maximal force the motor has
Definition: angularmotor.cpp:230
Data structure for accessing the ODE.
Definition: odehandle.h:44
virtual void init(Primitive *own, Joint *joint=0) override
initialises motor with body of robot
Definition: angularmotor.cpp:258
virtual void setPower(double power)
sets the maximal force the motor has
Definition: angularmotor.cpp:163
virtual int set(const motor *values, int length) override
sends the action commands to the motor.
Definition: angularmotor.cpp:67
Definition: axis.h:36
double power(void *c, double x)
returns x the power c (as a double)
Definition: controller_misc.cpp:17
virtual void setPower(double power)
sets the maximal force the motor has
Definition: angularmotor.cpp:347
virtual ~AngularMotor()
Definition: angularmotor.cpp:44
virtual void init(Primitive *own, Joint *joint=0) override
initialises motor with body of robot
Definition: angularmotor.cpp:179
virtual void init(Primitive *own, Joint *joint=0) override
initialises motor with body of robot
Definition: angularmotor.cpp:128
Angular motor for TwoAxisJoints.
Definition: angularmotor.h:141
virtual double getParam(int parameter)
return the ODE joint parameter (see ODE manual)
Definition: angularmotor.cpp:97
virtual int getNumberOfAxes() const override
returns the number of Axis of this Motor
Definition: angularmotor.cpp:299
AngularMotor(const OdeHandle &odeHandle, Joint *joint)
creates a AMotor attached to the same bodies as the given joint.
Definition: angularmotor.cpp:38
Definition: joint.h:41
Axis axis3
Definition: angularmotor.h:206
virtual void setVelovityFactor(double factor)
sets factor for velocity
Definition: angularmotor.cpp:107
virtual double getPower()
return the maximal force
Definition: angularmotor.cpp:102
double power1
Definition: angularmotor.h:169
double sensor
Definition: types.h:29
virtual Joint * getJoint()
returns the joint to which this motor is attached
Definition: angularmotor.h:87
bool initialized
Definition: angularmotor.h:106
Definition: joint.h:108
AngularMotor2Axis(const OdeHandle &odeHandle, TwoAxisJoint *joint, double power1, double power2)
Constuct a motor attached to a TwoAxisJoint.
Definition: angularmotor.cpp:174
double power
Definition: angularmotor.h:207
dJointID motor
Definition: angularmotor.h:102
AngularMotor1Axis(const OdeHandle &odeHandle, OneAxisJoint *joint, double power)
Constuct a motor attached to a OneAxisJoint.
Definition: angularmotor.cpp:124
virtual void setPower(double power)
sets the maximal force the motor has
Definition: angularmotor.cpp:435
Abstract class for sensors that can be plugged into a robot.
Definition: sensor.h:43
virtual void init(Primitive *own, Joint *joint=0) override
initialises motor with body of robot
Definition: angularmotor.cpp:379
Angular motor for arbitrary Joints with custom axis (up to 3)
Definition: angularmotor.h:211
Angular motor for Ball Joints with Euler control.
Definition: angularmotor.h:175
virtual bool sense(const GlobalData &globaldata) override
performs sense action
Definition: angularmotor.h:50
virtual void setParam(int parameter, double value)
sets the parameters of the motor
Definition: angularmotor.cpp:90
Abstact base class for attachable motors.
Definition: motor.h:35
Interface class for primitives represented in the physical and graphical world.
Definition: primitive.h:80
Definition: joint.h:128
Abstract angular motor class.
Definition: angularmotor.h:36
double velocityFactor
Definition: angularmotor.h:104
Data structure holding all essential global information.
Definition: globaldata.h:57
virtual int getNumberOfAxes() const override
returns the number of Axis of this Motor
Definition: angularmotor.h:191
Definition: joint.h:277
virtual void set(int axisNumber, double velocity)
sets the desired speed of the motor at the given axis.
Definition: angularmotor.cpp:308
virtual double getPower2()
return the maximal force
Definition: angularmotor.cpp:240
std::list< std::pair< double, Axis > > axis
Definition: angularmotor.h:242
virtual bool act(GlobalData &globaldata) override
performs the actions, This is usually called in doInternalStuff() from the robot
Definition: angularmotor.h:60
virtual void setPower(double power)=0
sets the maximal force the motor has
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: angularmotor.h:54
virtual void set(int axisNumber, double velocity)
sets the desired speed of the motor at the given axis.
Definition: angularmotor.cpp:201
virtual void set(int axisNumber, double velocity)
sets the desired speed of the motor at the given axis.
Definition: angularmotor.cpp:146
double motor
Definition: types.h:30
virtual int getMotorNumber() const override
return the dimensionality of this motor
Definition: angularmotor.h:58
virtual int getNumberOfAxes() const override
returns the number of Axis of this Motor
Definition: angularmotor.h:154
virtual int getNumberOfAxes() const override
returns the number of Axis of this Motor
Definition: angularmotor.h:123
Axis axis1
Definition: angularmotor.h:205
virtual void init(Primitive *own, Joint *joint=0) override
initialises motor with body of robot
Definition: angularmotor.cpp:48
virtual double getVelovityFactor(double factor)
retuns factor for velocity
Definition: angularmotor.cpp:112
OdeHandle odeHandle
Definition: angularmotor.h:103
virtual ~AngularMotorNAxis()
Definition: angularmotor.h:223
AngularMotor3AxisEuler(const OdeHandle &odeHandle, BallJoint *joint, const Axis &axis1, const Axis &axis3, double power)
Constuct a motor attached to a BallJoint.
Definition: angularmotor.cpp:374
AngularMotorNAxis(const OdeHandle &odeHandle, Joint *joint, std::list< std::pair< double, Axis > > axis)
Constuct a motor attached to any Joint (not Sliders!).
Definition: angularmotor.cpp:253
virtual int getSensorNumber() const override
returns the number of sensors values produced by this sensor
Definition: angularmotor.h:51
virtual int getNumberOfAxes() const =0
returns the number of Axis of this Motor
Angular motor for OneAxisJoints.
Definition: angularmotor.h:111
std::list< sensor > getListOfArray() const
helper function for performance implementation of list<> get() based on array-get ...
Definition: sensor.h:99
double power2
Definition: angularmotor.h:170