~robot3d-team/robot3d/trunk

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
//! Basic hinge class.

/*!
 *
 * This class simulates a hinge joint. Can be used for all rotatorial joints with just one axis.
 * For example, for hinges or wheels, what are fixed.
 *
 * @author Lutz Winkler
 *
 */

#ifndef HINGEACTOR_H_
#define HINGEACTOR_H_

#include <dtCore/dt.h>
#include <dtCore/object.h>
#include <dtCore/globals.h>
#include <dtCore/transform.h>
#include <dtGame/gameactor.h>
#include <dtCore/refptr.h>


#include <osg/Node>
#include <osgDB/ReadFile>

#include <ode/ode.h>

#include <srCore/actuator/actuatorBase.h>

namespace srCore {

class HingeActuator : public ActuatorBase
{
public:
	//! Constructor
	HingeActuator(const std::string name,  const std::string type);
	virtual ~HingeActuator();

	void registerActuator();

	/**
	 * \brief  Initializes the Hinge
	 *
	 *	Needs to be called before using the hinge.
	 *
	 * \param     		bodyI   					First Body
	 * \param			bodyII 						Second Body
	 * \param			anchorX, anchorY, anchorZ	position of the joint
	 * \param			axisX, axisY, axisZ			orientation of the joint
	 *
	 *
	 */
	void init(dtCore::RefPtr<BodyBase> myBody1, dtCore::RefPtr<BodyBase> myBody2,
			float anchorX, float anchorY, float anchorZ,
			float axisX, float axisY, float axisZ);

	/**
	 * \brief  Writes the parameter value in parameter
	 *
	 *		The available parameters can be retrieved by calling getParameterList()
	 * 		See also: ObjectBase::getParameter()
	 *
	 *
	 */
	virtual void getParameter(const std::string &name, ParameterReturnValue  parameter);

	/**
	 * \brief  Sets a parameter
	 *
	 *		See also getParameter()
	 *
	 */
	virtual void setParameter(const std::string &name, ParameterReturnValue  parameter);

	//todo: one time there should not be the need anymore to access the joint directly:
	//! returns the jointID of the hinge. Will become obsolete.
	dJointID getHinge();

	void gotoAngle(float angle);

	//! Maximum torque that can be applied by the motor.
	void setMaxTorque(float torque);

	//! Maximum torque that the motor can stand(then switched off) to hold its position
	void setHoldingTorque(float torque);

	//! Torque, that applies against the velocity vector, to slow down the joint.
	void setBrakeTorque(float torque);

	//! Maximum speed the joint can reach.
	void setMaxVelocity(float v_max);

	//! Setting a torque directly to a joint, can't be greater than maxTorque.
	void setTorque(float torque, float deltaTime);

	//! Setting a velocity.
	/*! Motor tries to reach this velocity as fast as possible, but is constrained
	 * by maxTorque
	 */
	void setVel(float v, float deltaTime);

	//! Returns the current velocity of the joint.
	float getVel(float deltaTime);

	//! Returns the current position of the joint.
	float getPos();

	//! Returns the time derivate of the hinge position
	float getAngleRate();

	//! Sets ode parameters for the joint. For more Information, see www.ode.org/ode-latest-user-guide.org.
	void setODEParameter(int parameter, float value);

	float getODEParameter(int parameter);

	//! when the joint will be created in such a way that the actuator already has a position different when zero.
	void setZeroAngle(float angle);

	//! will be called in the TickLocal function of the robotActorBase class
	virtual void update(float deltaSimTme);

protected:

	double calculateTorqueToStop(float deltaTime);
	dJointID joint, motor;
	float distToBody1;
	float distToBody2;

private:
	float maxTorque;							// maximum torque the motor can apply

	float maxHoldingTorque;						// holding torque, when actor isn't moving
	float maxBrakeTorque;						// torque that will apply then actor is moving, but motor is off
	float maxVelocity;							// maximum angular velocity the joint can reach
	bool isAtConstraint;						// joint reached a constraint.

	float paramAngle, paramVelocity, paramFMax, paramDesiredVelocity, paramLoStop, paramHiStop, paramDesiredAngle;

	float zeroAngle;							// when joint will be created in such a way that the actuator already has a position different when zero.


};
}

#endif /*HINGEACTOR_H_*/