~robot3d-team/robot3d/trunk

« back to all changes in this revision

Viewing changes to inc/srCore/actuator/actuatorBase.h

  • Committer: Anne van Rossum
  • Date: 2010-08-10 15:58:55 UTC
  • Revision ID: anne@gamix-20100810155855-kve7x2vwouagdij9
Initial import

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
//! Actuator base class.
 
2
 
 
3
/*!
 
4
 *
 
5
 * This is a basic actuator class. Actuators are joints, created by the Open Dynamics Engine (ODE) which connects two bodies
 
6
 *
 
7
 * @author Lutz Winkler
 
8
 *
 
9
 */
 
10
 
 
11
//TODO:         Include an AMotor joint to simulate friction of the actuator
 
12
 
 
13
/* TODO:        What are the basic properties each actuator has in common --> adopt the interface accordingly
 
14
 *                      Torque the motor can apply to the joint,
 
15
 *                      Max Velocity the joint can rotate/move
 
16
 *                      (Friction of the motor)
 
17
 *                      Holding Torque of the motor
 
18
 *                      Position / Velocity / Acceleration
 
19
 */
 
20
 
 
21
/* TODO:        providing internal functions, such as joint distance to body 1 and 2, (kinematic) energy of the system,
 
22
 *              oscillating movements of the bodies to provide a measurement of the stability of the simulation. These
 
23
 *              functions should be private and a friend class which is determing the stability of the simulation is its
 
24
 *              friend.
 
25
 */
 
26
 
 
27
// TODO:        Sound should be handled by the actuator classes and therefore an interface needs to be defined here.
 
28
 
 
29
#ifndef ACTUATOR_H_
 
30
#define ACTUATOR_H_
 
31
 
 
32
#include <srCore/robot/objectBase.h>
 
33
 
 
34
#include <dtCore/dt.h>
 
35
#include <dtCore/object.h>
 
36
#include <dtCore/globals.h>
 
37
#include <dtCore/transform.h>
 
38
#include <dtGame/gameactor.h>
 
39
#include <dtCore/refptr.h>
 
40
 
 
41
 
 
42
#include <osg/Node>
 
43
#include <osgDB/ReadFile>
 
44
 
 
45
#include <ode/ode.h>
 
46
 
 
47
#include <map>
 
48
 
 
49
namespace srCore {
 
50
 
 
51
 
 
52
 
 
53
 
 
54
class ActuatorBase : public ObjectBase
 
55
{
 
56
 
 
57
public:
 
58
 
 
59
        static std::map< dJointID, ActuatorBase*> jointActuatorMap;
 
60
 
 
61
 
 
62
//      static inline void registerActuator(ActuatorBase* actuator) {
 
63
//
 
64
//              jointActuatorMap.insert(std::pair<ActuatorBase*, dJointID>(actuator, actuator->getHinge()));
 
65
//
 
66
//
 
67
//      };
 
68
 
 
69
        //! Constructor
 
70
        ActuatorBase(const std::string name,  const std::string type) :
 
71
                ObjectBase(),
 
72
                velocity (0),
 
73
                name (name),
 
74
                type (type)
 
75
                {};
 
76
 
 
77
        /**
 
78
          * \brief  Initializes the actuator
 
79
          *
 
80
          *
 
81
          * \param              bodyI                                           First Body
 
82
          * \param                      bodyII                                          Second Body
 
83
          * \param                      anchorX, anchorY, anchorZ       position of the joint
 
84
          * \param                      axisX, axisY, axisZ                     orientation of the joint
 
85
          *
 
86
          *
 
87
          */
 
88
        virtual void init(dtCore::RefPtr<BodyBase> myBody1, dtCore::RefPtr<BodyBase> myBody2,
 
89
                        float anchorX, float anchorY, float anchorZ,
 
90
                        float axisX, float axisY, float axisZ) {};
 
91
 
 
92
 
 
93
 
 
94
        virtual void registerActuator() = 0;
 
95
 
 
96
        //returns the jointID of the hinge.
 
97
        virtual dJointID getHinge() = 0;
 
98
 
 
99
        // Maximum torque that can be applied by the motor.
 
100
        //virtual void setMaxTorque(float torque) = 0;
 
101
 
 
102
        // Maximum torque that the motor can stand(then switched off) to hold its position
 
103
        //virtual void setHoldingTorque(float torque) = 0;
 
104
 
 
105
        // Torque, that applies against the velocity vector, to slow down the joint.
 
106
        //virtual void setBrakeTorque(float torque) = 0;
 
107
 
 
108
        // Maximum speed the joint can reach.
 
109
        //virtual void setMaxSpeed(float v_max) = 0;
 
110
 
 
111
        //! Setting a torque directly to a joint, can't be greater than maxTorque.
 
112
        virtual void setTorque(float torque, float deltaTime) = 0;
 
113
 
 
114
        //! Setting a velocity.
 
115
        /*! Motor tries to reach this velocity as fast as possible, but is constrained
 
116
         * by maxTorque
 
117
         */
 
118
        virtual void setVel(float v, float deltaTime) = 0;
 
119
 
 
120
        //! Returns the current velocity of the joint.
 
121
        virtual float getVel(float deltaTime) {return velocity;};
 
122
 
 
123
        //! Returns the current position of the joint.
 
124
        virtual float getPos() = 0;
 
125
 
 
126
        //! Sets ode parameters for the joint. For more Information, see www.ode.org/ode-latest-user-guide.org.
 
127
        virtual void setODEParameter(int parameter, float value) = 0;
 
128
        virtual float getODEParameter(int parameter) = 0;
 
129
 
 
130
        //! activate/deactivate the actuator
 
131
        virtual void setActive(bool activate) {}
 
132
 
 
133
        //! will be called in the TickLocal function of the robotActorBase class
 
134
        virtual void update(float deltaSimTme) {}
 
135
 
 
136
        //! returns the name of the actuator
 
137
        inline std::string getName() const {return name;}
 
138
 
 
139
        //!returns the type of the class
 
140
        inline std::string getType() const {return type;}
 
141
 
 
142
protected:
 
143
        virtual ~ActuatorBase() {};
 
144
 
 
145
        float velocity;
 
146
 
 
147
private:
 
148
 
 
149
        const std::string name;
 
150
        const std::string type;
 
151
 
 
152
 
 
153
/*
 
154
        void setVel(float v,float deltatime);
 
155
        void setParam(int parameter, float value);
 
156
*/
 
157
 
 
158
};
 
159
 
 
160
typedef std::map< dJointID, ActuatorBase*> map_type;
 
161
typedef map_type::value_type pair_type;
 
162
 
 
163
}
 
164
 
 
165
 
 
166
 
 
167
#endif /*ACTUATOR_H_*/