Rigid Body Dynamics Library
TorqueMuscleFittingToolkit.h
Go to the documentation of this file.
1#ifndef TORQUEMUSCLEFITTINGTOOLKIT_H_
2#define TORQUEMUSCLEFITTINGTOOLKIT_H_
3
4
5#include <vector>
6#include <rbdl/rbdl_math.h>
7#include "IpTNLP.hpp"
9
10namespace RigidBodyDynamics {
11 namespace Addons {
12 namespace Muscle{
13
14
16 public:
17
18
162 Millard2016TorqueMuscle const &tqMcl,
163 RigidBodyDynamics::Math::VectorNd const &jointAngle,
164 RigidBodyDynamics::Math::VectorNd const &jointAngularVelocity,
165 RigidBodyDynamics::Math::VectorNd const &jointTorque,
166 double activationUpperBound,
167 double passiveTorqueAngleMultiplierUpperBound,
168 TorqueMuscleParameterFittingData &parametersOfBestFit,
169 bool verbose=false);
170
171
172};
173
174
175
176
177//A class that defines the virtual functions needed
178//to use Ipopt to solve the problem
179class FitTorqueMuscleParameters : public Ipopt::TNLP{
180 public:
182 const RigidBodyDynamics::Math::VectorNd &jointAngle,
183 const RigidBodyDynamics::Math::VectorNd &jointAngularVelocity,
184 const RigidBodyDynamics::Math::VectorNd &jointTorque,
185 double maxActivation,
186 double maxPassiveTorqueAngleMultiplier,
187 double taLambda,
188 double tvLambda,
190
191
192 //Manditory functions of the TNLP interface
193 virtual bool get_nlp_info(Ipopt::Index &n,
194 Ipopt::Index &m,
195 Ipopt::Index &nnz_jac_g,
196 Ipopt::Index &nnz_h_lag,
197 Ipopt::TNLP::IndexStyleEnum &index_style);
198
199
200 virtual bool get_bounds_info(Ipopt::Index n,
201 Ipopt::Number *x_l,
202 Ipopt::Number *x_u,
203 Ipopt::Index m,
204 Ipopt::Number *g_l,
205 Ipopt::Number *g_u);
206
207
208 virtual bool get_starting_point(Ipopt::Index n,
209 bool init_x,
210 Ipopt::Number *x,
211 bool init_z,
212 Ipopt::Number *z_L,
213 Ipopt::Number *z_U,
214 Ipopt::Index m,
215 bool init_lambda,
216 Ipopt::Number *lambda);
217
218 virtual bool eval_f(Ipopt::Index n,
219 const Ipopt::Number *x,
220 bool new_x,
221 Ipopt::Number &obj_value);
222
223 virtual bool eval_grad_f(Ipopt::Index n,
224 const Ipopt::Number *x,
225 bool new_x,
226 Ipopt::Number *grad_f);
227
228 virtual bool eval_g(Ipopt::Index n,
229 const Ipopt::Number *x,
230 bool new_x,
231 Ipopt::Index m,
232 Ipopt::Number *g);
233
234 virtual bool eval_jac_g(Ipopt::Index n,
235 const Ipopt::Number *x,
236 bool new_x,
237 Ipopt::Index m,
238 Ipopt::Index nele_jac,
239 Ipopt::Index *iRow,
240 Ipopt::Index *jCol,
241 Ipopt::Number *values);
242
243 virtual void finalize_solution(
244 Ipopt::SolverReturn status,
245 Ipopt::Index n,
246 const Ipopt::Number *x,
247 const Ipopt::Number *z_L,
248 const Ipopt::Number *z_U,
249 Ipopt::Index m,
250 const Ipopt::Number *g,
251 const Ipopt::Number *lambda,
252 Ipopt:: Number obj_value,
253 const Ipopt::IpoptData *ip_data,
254 Ipopt::IpoptCalculatedQuantities *ip_cq);
255
256 //Optional functions
257 virtual bool eval_h(Ipopt::Index n,
258 const Ipopt::Number *x,
259 bool new_x,
260 Ipopt::Number obj_factor,
261 Ipopt::Index m,
262 const Ipopt::Number *lambda,
263 bool new_lambda,
264 Ipopt::Index nele_hess,
265 Ipopt::Index *iRow,
266 Ipopt::Index *jCol,
267 Ipopt::Number *values);
268
276
277 void updOptimizationVariables(const Ipopt::Number *x);
278 private:
279 unsigned int mN, mM;
280
283 double mMaxTp;
284 double mTauIso;
285
287 double mOmegaMax;
288 double mTaLambda;
289 double mTvLambda;
290
291
297
298
304
305
311
312
315 double mTpLambda;
318
319 unsigned int mIndexTaAngleScale;
321 unsigned int mIndexTpLambda;
322 unsigned int mIndexTpOffset;
323 unsigned int mIndexTauScaling;
324
331
332
336
340 double mObjValue;
345};
346
347
348
349
350 }
351 }
352}
353
354#endif
355
virtual bool get_starting_point(Ipopt::Index n, bool init_x, Ipopt::Number *x, bool init_z, Ipopt::Number *z_L, Ipopt::Number *z_U, Ipopt::Index m, bool init_lambda, Ipopt::Number *lambda)
virtual bool eval_g(Ipopt::Index n, const Ipopt::Number *x, bool new_x, Ipopt::Index m, Ipopt::Number *g)
virtual bool eval_f(Ipopt::Index n, const Ipopt::Number *x, bool new_x, Ipopt::Number &obj_value)
virtual bool get_nlp_info(Ipopt::Index &n, Ipopt::Index &m, Ipopt::Index &nnz_jac_g, Ipopt::Index &nnz_h_lag, Ipopt::TNLP::IndexStyleEnum &index_style)
FitTorqueMuscleParameters(const RigidBodyDynamics::Math::VectorNd &jointAngle, const RigidBodyDynamics::Math::VectorNd &jointAngularVelocity, const RigidBodyDynamics::Math::VectorNd &jointTorque, double maxActivation, double maxPassiveTorqueAngleMultiplier, double taLambda, double tvLambda, Millard2016TorqueMuscle &tqMcl)
RigidBodyDynamics::Math::VectorNd & getConstraintError()
virtual bool eval_jac_g(Ipopt::Index n, const Ipopt::Number *x, bool new_x, Ipopt::Index m, Ipopt::Index nele_jac, Ipopt::Index *iRow, Ipopt::Index *jCol, Ipopt::Number *values)
virtual bool eval_grad_f(Ipopt::Index n, const Ipopt::Number *x, bool new_x, Ipopt::Number *grad_f)
virtual bool eval_h(Ipopt::Index n, const Ipopt::Number *x, bool new_x, Ipopt::Number obj_factor, Ipopt::Index m, const Ipopt::Number *lambda, bool new_lambda, Ipopt::Index nele_hess, Ipopt::Index *iRow, Ipopt::Index *jCol, Ipopt::Number *values)
virtual bool get_bounds_info(Ipopt::Index n, Ipopt::Number *x_l, Ipopt::Number *x_u, Ipopt::Index m, Ipopt::Number *g_l, Ipopt::Number *g_u)
virtual void finalize_solution(Ipopt::SolverReturn status, Ipopt::Index n, const Ipopt::Number *x, const Ipopt::Number *z_L, const Ipopt::Number *z_U, Ipopt::Index m, const Ipopt::Number *g, const Ipopt::Number *lambda, Ipopt::Number obj_value, const Ipopt::IpoptData *ip_data, Ipopt::IpoptCalculatedQuantities *ip_cq)
This class implements a rigid-tendon muscle-torque-generator (MTG) for a growing list of joints and t...
static void fitTorqueMuscleParameters(Millard2016TorqueMuscle const &tqMcl, RigidBodyDynamics::Math::VectorNd const &jointAngle, RigidBodyDynamics::Math::VectorNd const &jointAngularVelocity, RigidBodyDynamics::Math::VectorNd const &jointTorque, double activationUpperBound, double passiveTorqueAngleMultiplierUpperBound, TorqueMuscleParameterFittingData &parametersOfBestFit, bool verbose=false)
This function will adjust the parameters of the muscle-torque-generator (MTG) so that the MTG is stro...