-
Notifications
You must be signed in to change notification settings - Fork 327
/
Copy pathTaskSpaceCoordinateTask.h
254 lines (227 loc) · 9.88 KB
/
TaskSpaceCoordinateTask.h
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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
#ifndef OPENSIM_TASK_SPACE_COORDINATE_TASK_H_
#define OPENSIM_TASK_SPACE_COORDINATE_TASK_H_
/* -------------------------------------------------------------------------- *
* OpenSim: TaskSpaceCoordinateTask.h *
* -------------------------------------------------------------------------- *
* Developed by CFD Research Corporation for a project sponsored by the US *
* Army Medical Research and Materiel Command under Contract No. *
* W81XWH-22-C-0020. Any views, opinions and/or findings expressed in this *
* material are those of the author(s) and should not be construed as an *
* official Department of the Army position, policy or decision unless so *
* designated by other documentation. *
* *
* Please refer to the following publication for mathematical details, and *
* cite this paper if you use this code in your own work: *
* *
* Pickle and Sundararajan. "Predictive simulation of human movement in *
* OpenSim using floating-base task space control". *
* *
* Copyright (c) 2023 CFD Research Corporation and the Authors *
* *
* Author(s): Aravind Sundararajan, Nathan Pickle, Garrett Tuer *
* *
* Licensed under the Apache License, Version 2.0 (the "License"); you may *
* not use this file except in compliance with the License. You may obtain a *
* copy of the License at http://www.apache.org/licenses/LICENSE-2.0 *
* *
* Unless required by applicable law or agreed to in writing, software *
* distributed under the License is distributed on an "AS IS" BASIS, *
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. *
* See the License for the specific language governing permissions and *
* limitations under the License. *
* -------------------------------------------------------------------------- */
//============================================================================
// INCLUDE
//============================================================================
#include "osimToolsDLL.h"
#include "OpenSim/Simulation/osimSimulation.h"
#include "OpenSim/Common/PropertyDbl.h"
#include "TaskSpaceTask.h"
namespace OpenSim {
class Coordinate;
//=============================================================================
//=============================================================================
/**
* A class for specifying the tracking task for a joint.
*/
class OSIMTOOLS_API CoordinateTask : public TaskSpaceTask {
OpenSim_DECLARE_CONCRETE_OBJECT(CoordinateTask, TaskSpaceTask);
//==========================================================================
// DATA
//==========================================================================
public:
OpenSim_DECLARE_PROPERTY(coordinate, std::string,
"Name of coordinate with respect to which a tracking objective is "
"specified. ");
OpenSim_DECLARE_PROPERTY(limit_avoidance, bool,
"Boolean to indicate whether this coordinate should be used for "
"limit avoidance (true) or coordinate space control (false).");
protected:
// Work Variables
const OpenSim::Coordinate* _q;
mutable int _mbti;
//==========================================================================
// METHODS
//==========================================================================
//--------------------------------------------------------------------------
// CONSTRUCTION
//--------------------------------------------------------------------------
public:
/**
* Construct a task for a specified generalized coordinate.
*
* @param aQID ID of the generalized coordinate to be tracked.
* @todo Instead of an integer id, the name of the coordinate
* should be used.
*/
CoordinateTask(const std::string& aCoordinateName = "",
bool limit_avoidance = false);
/**
* Copy constructor.
*
* @param aTask Joint task to be copied.
*/
CoordinateTask(const CoordinateTask& aTask);
/**
* Destructor.
*/
virtual ~CoordinateTask();
//--------------------------------------------------------------------------
// GET AND SET
//--------------------------------------------------------------------------
/**
* @brief Set the limit avoidance flag
*
* @param b flag to set
*/
void setLimitAvoidance(const bool b) { set_limit_avoidance(b); }
//--------------------------------------------------------------------------
// COMPUTATIONS
//--------------------------------------------------------------------------
/**
* Compute the position and velocity errors.
* This method assumes the states have been set for the model.
*
* @param aT Current time in real time units.
* @see Model::set()
* @see Model::setStates()
*/
void computeErrors(const SimTK::State& s, double aT) override;
/**
* Compute the desired accelerations.
* This method assumes that the states have been set for the model.
*
* @param aT Time at which the desired accelerations are to be computed in
* real time units.
* @see Model::set()
* @see Model::setStates()
*/
void computeDesiredAccelerations(const SimTK::State& s, double aT) override;
/**
* Compute the desired accelerations.
* This method assumes that the states have been set for the model.
*
* @param aTI Initial time of the controlled interval in real time units.
* @param aTF Final time of the controlled interval in real time units.
* @see Model::set()
* @see Model::setStates()
*/
void computeDesiredAccelerations(
const SimTK::State& s, double aTI, double aTF) override;
/**
* Compute the acceleration of the appropriate generalized coordinate.
* For the computed accelerations to be correct,
* Model::computeAccelerations() must have already been called.
*
* For joints (i.e., generalized coordinates), the acceleration is
* not computed. It has already been computed and is simply retrieved
* from the model.
*
* @see Model::computeAccelerations()
* @see suTrackObject::getAcceleration()
*/
void computeAccelerations(const SimTK::State& s) override;
/**
* @brief Compute the Jacobian, since the task is already in coordinate
* space, the jacobian is nu x 1 identity with 1 in the column of the
* specified coordinate. When considering joint limit avoidance, the
* expression for J is based on the potential field expression.
* @param s current state
* @return SimTK::Matrix Jacobian
* @see CoordinateTask::computeJointLimitMatrix(const SimTK::State& s)
*
*/
void computeJacobian(const SimTK::State& s) override;
/**
* @brief Compute the Jacobian bias term for the tracked point given the
* current state of the model.
*
* @param s current state
* @return SimTK::Vector bias term
* @see CoordinateTask::computeJointLimitBias(const SimTK::State& s)
*/
void computeBias(const SimTK::State& s) override;
/**
* @brief Update internal storage of task dynamics.
*
* @param s current state
*/
// void update(const SimTK::State& s) override;
/**
* Compute the joint limit matrix, which is used in the potential field
* expression for the Jacobian.
*
* @see CoordinateTask::computeJointLimitMatrix(const SimTK::State& s)
*/
double computeJointLimitMatrix(const SimTK::State& s);
//--------------------------------------------------------------------------
// XML
//--------------------------------------------------------------------------
/**
* Update this object based on its XML node.
*
* @param aDeep If true, update this object and all its child objects
* (that is, member variables that are Object's); if false, update only
* the member variables that are not Object's.
*/
void updateFromXMLNode(
SimTK::Xml::Element& aNode, int versionNumber = -1) override;
#ifndef SWIG
/**
* Assignment operator.
*
* @param aTask Object to be copied.
* @return Reference to the altered object.
*/
CoordinateTask& operator=(const CoordinateTask& aTask);
#endif
private:
/**
* Set NULL values for all member variables.
*/
void setNull();
/**
* @brief Set up serialized member variables.
*
* @param aCoordinateName Name of the coordinate to be tracked.
*/
void setupProperties();
/**
* @brief Copy data members from one CoordinateTask to another.
*
* @param aTask CoordinateTask to be copied.
*/
void copyData(const CoordinateTask& aTask);
/**
* @brief Update the work variables based on the current model.
* This method is called by setModel() and setCoordinateName().
*/
void updateWorkVariables();
//--------------------------------------------------------------------------
// OPERATORS
//--------------------------------------------------------------------------
//==========================================================================
}; // END of class CoordinateTask
//==========================================================================
}; // namespace OpenSim
#endif // OPENSIM_TASK_SPACE_COORDINATE_TASK_H_