~robot3d-team/robot3d/trunk

« back to all changes in this revision

Viewing changes to src/srActuator/multiActuator.cpp

  • 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
/*
 
2
 * Robot3D Physical realistic 3D simulator for robots
 
3
 *
 
4
 * @license GNU Lesser General Public License
 
5
 *
 
6
 * @author Lutz Winkler
 
7
 * @author Anne C. van Rossum
 
8
 */
 
9
#include <srActuator/multiActuator.h>
 
10
 
 
11
namespace srCore {
 
12
 
 
13
 
 
14
MultiActuator::MultiActuator(dtCore::RefPtr<ActuatorBase> firstElement, const std::string name) :
 
15
        ActuatorBase(name, "MultiActuator")
 
16
 
 
17
{
 
18
        myActuators.push_back(firstElement);
 
19
 
 
20
        // add parameters of the first element to our parameter list
 
21
        myParameters = firstElement->getParameterList();
 
22
 
 
23
 
 
24
}
 
25
 
 
26
MultiActuator::~MultiActuator() {
 
27
        // TODO Auto-generated destructor stub
 
28
}
 
29
 
 
30
 
 
31
 
 
32
//! add actuator to container
 
33
void MultiActuator::addActuator(dtCore::RefPtr<ActuatorBase> actuator) {
 
34
 
 
35
        myActuators.push_back(actuator);
 
36
 
 
37
};
 
38
 
 
39
void MultiActuator::registerActuator() {
 
40
 
 
41
        for (unsigned int i=0; i < getNumActuators(); i++) {
 
42
                ActuatorBase::jointActuatorMap.insert(std::pair<dJointID, ActuatorBase*>(this->getHinge(i), this));
 
43
 
 
44
        }
 
45
 
 
46
}
 
47
 
 
48
//! Sets ode parameters for the actuators in the list. For more Information, see www.ode.org/ode-latest-user-guide.org.
 
49
inline void MultiActuator::setODEParameter(int parameter, float value) {
 
50
 
 
51
        for (unsigned int i=0; i<myActuators.size(); i++)
 
52
                myActuators[i]->setODEParameter(parameter, value);
 
53
 
 
54
};
 
55
 
 
56
float MultiActuator::getODEParameter(int parameter) {
 
57
 
 
58
        return myActuators[0]->getODEParameter(parameter);
 
59
 
 
60
 
 
61
};
 
62
 
 
63
 
 
64
void MultiActuator::setParameter(const std::string &name, ParameterReturnValue  parameter) {
 
65
 
 
66
        for (unsigned int i=0; i<myActuators.size(); i++)
 
67
                myActuators[i]->setParameter(name, parameter);
 
68
 
 
69
}
 
70
 
 
71
void MultiActuator::getParameter(const std::string &name, ParameterReturnValue  parameter) {
 
72
 
 
73
        myActuators[0]->getParameter(name, parameter);
 
74
 
 
75
};
 
76
 
 
77
//returns the jointID of the hinge.
 
78
inline dJointID MultiActuator::getHinge() {
 
79
 
 
80
        printf("Warning: This is a meta actuator. To get a hinge, use the getActuators function. Returning hinge of the first actuator \n");
 
81
        return myActuators[0]->getHinge();
 
82
 
 
83
};
 
84
 
 
85
unsigned int MultiActuator::getNumActuators() {
 
86
 
 
87
        return myActuators.size();
 
88
 
 
89
}
 
90
 
 
91
dJointID MultiActuator::getHinge(unsigned int index) {
 
92
 
 
93
        printf("Warning: This is a meta actuator. To get a hinge, use the getActuators function. Returning hinge of the first actuator \n");
 
94
        return ((index < myActuators.size()) ? myActuators[index]->getHinge() : NULL);
 
95
 
 
96
};
 
97
//! Setting a velocity.
 
98
/*! Motor tries to reach this velocity as fast as possible, but is constrained
 
99
 * by maxTorque
 
100
 */
 
101
void MultiActuator::setVel(float v, float deltaTime) {
 
102
 
 
103
        for (unsigned int i=0; i<myActuators.size(); i++)
 
104
                myActuators[i]->setVel(v, deltaTime);
 
105
 
 
106
}
 
107
 
 
108
//! Setting a torque directly to a joint, can't be greater than maxTorque.
 
109
void MultiActuator::setTorque(float torque, float deltaTime) {
 
110
 
 
111
        for (unsigned int i=0; i<myActuators.size(); i++)
 
112
                myActuators[i]->setTorque(torque, deltaTime);
 
113
 
 
114
}
 
115
 
 
116
//! Returns the current velocity of the joint.
 
117
float MultiActuator::getVel(float deltaTime) {return myActuators[0]->getVel(deltaTime);};
 
118
 
 
119
//! Returns the current position of the joint.
 
120
float MultiActuator::getPos() {return myActuators[0]->getPos();};
 
121
 
 
122
//! activate/deactivate the actuator
 
123
void MultiActuator::setActive(bool activate) {
 
124
 
 
125
        for (unsigned int i=0; i<myActuators.size(); i++)
 
126
                myActuators[i]->setActive(active);
 
127
 
 
128
};
 
129
 
 
130
//! will be called in the TickLocal function of the robotActorBase class
 
131
void MultiActuator::update(float deltaSimTime) {
 
132
 
 
133
        for (unsigned int i=0; i<myActuators.size(); i++)
 
134
                myActuators[i]->update(deltaSimTime);
 
135
 
 
136
};
 
137
 
 
138
 
 
139
}