MocoExtendProblem: Interface Between OpenSim and MATLAB for Rapidly Developing Direct Collocation Goals in Moco 1.1.0
add custom Moco goals to existing matlab scripts
MocoActivationSquaredGoal.h
Go to the documentation of this file.
1#ifndef OPENSIM_MOCOACTIVATIONSQUAREDGOAL_H
2#define OPENSIM_MOCOACTIVATIONSQUAREDGOAL_H
3/* -------------------------------------------------------------------------- *
4 * OpenSim: MocoActivationSquaredGoal.h *
5 * -------------------------------------------------------------------------- */
6
7#include <OpenSim/Moco/osimMoco.h>
9
10namespace OpenSim {
11
32
33public:
36
37 MocoActivationSquaredGoal() { constructProperties(); }
38
41 MocoActivationSquaredGoal(std::string name) : MocoGoal(std::move(name)) {
42 constructProperties();
43 }
44
48 MocoActivationSquaredGoal(std::string name, double weight)
49 : MocoGoal(std::move(name), weight) {
50 constructProperties();
51 }
53
56 void setDivideByDisplacement(bool tf) { set_divide_by_displacement(tf); }
57
60 bool getDivideByDisplacement() const { return get_divide_by_displacement(); }
61
64 void setEndPointGoal(double end_point_goal) { set_end_point_goal(end_point_goal); }
65
68 double getEndPointGoal() const { return get_end_point_goal(); }
69
70protected:
73
74 Mode getDefaultModeImpl() const override { return Mode::Cost; }
75
77 bool getSupportsEndpointConstraintImpl() const override { return true; }
78
80 void initializeOnModelImpl(const Model&) const override;
81
86 const IntegrandInput& input, double& integrand) const override;
87
92 const GoalInput& input, SimTK::Vector& cost) const override;
94
95private:
98 OpenSim_DECLARE_PROPERTY(divide_by_displacement, bool,
99 "Divide by the model's displacement over the phase (default: "
100 "false)");
101
103 "The exponent applied to the output value in the integrand. "
104 "The output can take on negative values in the integrand when the "
105 "exponent is set to 1 (the default value). When the exponent is "
106 "set to a value greater than 1, the absolute value function is "
107 "applied to the output (before the exponent is applied), meaning "
108 "that odd numbered exponents (greater than 1) do not take on "
109 "negative values.");
110
111 OpenSim_DECLARE_PROPERTY(end_point_goal, double,
112 "Target value for end-point goal (default: 0)");
114
117
121 mutable std::function<double(const double&)> m_power_function;
123 mutable std::vector<int> m_act_indices;
125};
126
127} // namespace OpenSim
128
129#endif // OPENSIM_MOCOACTIVATIONSQUAREDGOAL_H
#define OSIMMOCOACTIVATIONSQUAREDGOAL_API
Definition osimMocoActivationSquaredGoalDLL.h:12
Goal that minimizes the squared sum of muscle activations.
Definition MocoActivationSquaredGoal.h:30
void initializeOnModelImpl(const Model &) const override
Initialize the goal with the model.
bool getDivideByDisplacement() const
Get whether the sum is divided by displacement.
Definition MocoActivationSquaredGoal.h:60
OpenSim_DECLARE_PROPERTY(divide_by_displacement, bool, "Divide by the model's displacement over the phase (default: " "false)")
MocoActivationSquaredGoal(std::string name, double weight)
Constructor with name and weight.
Definition MocoActivationSquaredGoal.h:48
void setDivideByDisplacement(bool tf)
Set whether to divide the sum of squared activations by displacement.
Definition MocoActivationSquaredGoal.h:56
OpenSim_DECLARE_CONCRETE_OBJECT(MocoActivationSquaredGoal, MocoGoal)
void calcIntegrandImpl(const IntegrandInput &input, double &integrand) const override
Calculate the integrand value for the cost function.
void calcGoalImpl(const GoalInput &input, SimTK::Vector &cost) const override
Calculate the goal value.
MocoActivationSquaredGoal(std::string name)
Constructor with name.
Definition MocoActivationSquaredGoal.h:41
OpenSim_DECLARE_PROPERTY(exponent, int, "The exponent applied to the output value in the integrand. " "The output can take on negative values in the integrand when the " "exponent is set to 1 (the default value). When the exponent is " "set to a value greater than 1, the absolute value function is " "applied to the output (before the exponent is applied), meaning " "that odd numbered exponents (greater than 1) do not take on " "negative values.")
bool getSupportsEndpointConstraintImpl() const override
Whether this goal supports endpoint constraint mode.
Definition MocoActivationSquaredGoal.h:77
MocoActivationSquaredGoal()
Default constructor.
Definition MocoActivationSquaredGoal.h:37
void setEndPointGoal(double end_point_goal)
Set the target value when using this goal as an endpoint constraint.
Definition MocoActivationSquaredGoal.h:64
OpenSim_DECLARE_PROPERTY(end_point_goal, double, "Target value for end-point goal (default: 0)")
double getEndPointGoal() const
Get the endpoint constraint target value.
Definition MocoActivationSquaredGoal.h:68
void constructProperties()
Initialize the goal's properties.
Mode getDefaultModeImpl() const override
Get the default mode for this goal.
Definition MocoActivationSquaredGoal.h:74
Definition MocoActivationGoal.h:14