~robot3d-team/robot3d/trunk

« back to all changes in this revision

Viewing changes to inc/srCore/actuator/hingeActuator.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
//! Basic hinge class.
 
2
 
 
3
/*!
 
4
 *
 
5
 * This class simulates a hinge joint. Can be used for all rotatorial joints with just one axis.
 
6
 * For example, for hinges or wheels, what are fixed.
 
7
 *
 
8
 * @author Lutz Winkler
 
9
 *
 
10
 */
 
11
 
 
12
#ifndef HINGEACTOR_H_
 
13
#define HINGEACTOR_H_
 
14
 
 
15
#include <dtCore/dt.h>
 
16
#include <dtCore/object.h>
 
17
#include <dtCore/globals.h>
 
18
#include <dtCore/transform.h>
 
19
#include <dtGame/gameactor.h>
 
20
#include <dtCore/refptr.h>
 
21
 
 
22
 
 
23
#include <osg/Node>
 
24
#include <osgDB/ReadFile>
 
25
 
 
26
#include <ode/ode.h>
 
27
 
 
28
#include <srCore/actuator/actuatorBase.h>
 
29
 
 
30
namespace srCore {
 
31
 
 
32
class HingeActuator : public ActuatorBase
 
33
{
 
34
public:
 
35
        //! Constructor
 
36
        HingeActuator(const std::string name,  const std::string type);
 
37
        virtual ~HingeActuator();
 
38
 
 
39
        void registerActuator();
 
40
 
 
41
        /**
 
42
         * \brief  Initializes the Hinge
 
43
         *
 
44
         *      Needs to be called before using the hinge.
 
45
         *
 
46
         * \param               bodyI                                           First Body
 
47
         * \param                       bodyII                                          Second Body
 
48
         * \param                       anchorX, anchorY, anchorZ       position of the joint
 
49
         * \param                       axisX, axisY, axisZ                     orientation of the joint
 
50
         *
 
51
         *
 
52
         */
 
53
        void init(dtCore::RefPtr<BodyBase> myBody1, dtCore::RefPtr<BodyBase> myBody2,
 
54
                        float anchorX, float anchorY, float anchorZ,
 
55
                        float axisX, float axisY, float axisZ);
 
56
 
 
57
        /**
 
58
         * \brief  Writes the parameter value in parameter
 
59
         *
 
60
         *              The available parameters can be retrieved by calling getParameterList()
 
61
         *              See also: ObjectBase::getParameter()
 
62
         *
 
63
         *
 
64
         */
 
65
        virtual void getParameter(const std::string &name, ParameterReturnValue  parameter);
 
66
 
 
67
        /**
 
68
         * \brief  Sets a parameter
 
69
         *
 
70
         *              See also getParameter()
 
71
         *
 
72
         */
 
73
        virtual void setParameter(const std::string &name, ParameterReturnValue  parameter);
 
74
 
 
75
        //todo: one time there should not be the need anymore to access the joint directly:
 
76
        //! returns the jointID of the hinge. Will become obsolete.
 
77
        dJointID getHinge();
 
78
 
 
79
        void gotoAngle(float angle);
 
80
 
 
81
        //! Maximum torque that can be applied by the motor.
 
82
        void setMaxTorque(float torque);
 
83
 
 
84
        //! Maximum torque that the motor can stand(then switched off) to hold its position
 
85
        void setHoldingTorque(float torque);
 
86
 
 
87
        //! Torque, that applies against the velocity vector, to slow down the joint.
 
88
        void setBrakeTorque(float torque);
 
89
 
 
90
        //! Maximum speed the joint can reach.
 
91
        void setMaxVelocity(float v_max);
 
92
 
 
93
        //! Setting a torque directly to a joint, can't be greater than maxTorque.
 
94
        void setTorque(float torque, float deltaTime);
 
95
 
 
96
        //! Setting a velocity.
 
97
        /*! Motor tries to reach this velocity as fast as possible, but is constrained
 
98
         * by maxTorque
 
99
         */
 
100
        void setVel(float v, float deltaTime);
 
101
 
 
102
        //! Returns the current velocity of the joint.
 
103
        float getVel(float deltaTime);
 
104
 
 
105
        //! Returns the current position of the joint.
 
106
        float getPos();
 
107
 
 
108
        //! Returns the time derivate of the hinge position
 
109
        float getAngleRate();
 
110
 
 
111
        //! Sets ode parameters for the joint. For more Information, see www.ode.org/ode-latest-user-guide.org.
 
112
        void setODEParameter(int parameter, float value);
 
113
 
 
114
        float getODEParameter(int parameter);
 
115
 
 
116
        //! when the joint will be created in such a way that the actuator already has a position different when zero.
 
117
        void setZeroAngle(float angle);
 
118
 
 
119
        //! will be called in the TickLocal function of the robotActorBase class
 
120
        virtual void update(float deltaSimTme);
 
121
 
 
122
protected:
 
123
 
 
124
        double calculateTorqueToStop(float deltaTime);
 
125
        dJointID joint, motor;
 
126
        float distToBody1;
 
127
        float distToBody2;
 
128
 
 
129
private:
 
130
        float maxTorque;                                                        // maximum torque the motor can apply
 
131
 
 
132
        float maxHoldingTorque;                                         // holding torque, when actor isn't moving
 
133
        float maxBrakeTorque;                                           // torque that will apply then actor is moving, but motor is off
 
134
        float maxVelocity;                                                      // maximum angular velocity the joint can reach
 
135
        bool isAtConstraint;                                            // joint reached a constraint.
 
136
 
 
137
        float paramAngle, paramVelocity, paramFMax, paramDesiredVelocity, paramLoStop, paramHiStop, paramDesiredAngle;
 
138
 
 
139
        float zeroAngle;                                                        // when joint will be created in such a way that the actuator already has a position different when zero.
 
140
 
 
141
 
 
142
};
 
143
}
 
144
 
 
145
#endif /*HINGEACTOR_H_*/