Skip to content

Commit a97c772

Browse files
committed
Add ActivationCoordinateActuator.h
1 parent 60dd70d commit a97c772

File tree

6 files changed

+114
-1
lines changed

6 files changed

+114
-1
lines changed

Bindings/OpenSimHeaders_actuators.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
#include <OpenSim/Actuators/osimActuatorsDLL.h>
77
#include <OpenSim/Actuators/CoordinateActuator.h>
8+
#include <OpenSim/Actuators/ActivationCoordinateActuator.h>
89
#include <OpenSim/Actuators/PointActuator.h>
910
#include <OpenSim/Actuators/TorqueActuator.h>
1011
#include <OpenSim/Actuators/BodyActuator.h>

Bindings/actuators.i

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
//osimActuators
22
%include <OpenSim/Actuators/osimActuatorsDLL.h>
33
%include <OpenSim/Actuators/CoordinateActuator.h>
4+
%include <OpenSim/Actuators/ActivationCoordinateActuator.h>
45
%include <OpenSim/Actuators/PointActuator.h>
56
%include <OpenSim/Actuators/TorqueActuator.h>
67
%include <OpenSim/Actuators/BodyActuator.h>

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ This is not a comprehensive list of changes but rather a hand-curated collection
88

99
v4.2
1010
====
11-
-
11+
- Add the ActivationCoordinateActuator component, which is a CoordinateActuator with simple activation dynamics.
1212

1313
v4.1
1414
====
Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
#ifndef OPENSIM_ACTIVATION_COORDINATE_ACTUATOR_H
2+
#define OPENSIM_ACTIVATION_COORDINATE_ACTUATOR_H
3+
/* -------------------------------------------------------------------------- *
4+
* OpenSim: ActivationCoordinateActuator.h *
5+
* -------------------------------------------------------------------------- *
6+
* The OpenSim API is a toolkit for musculoskeletal modeling and simulation. *
7+
* See http://opensim.stanford.edu and the NOTICE file for more information. *
8+
* OpenSim is developed at Stanford University and supported by the US *
9+
* National Institutes of Health (U54 GM072970, R24 HD065690) and by DARPA *
10+
* through the Warrior Web program. *
11+
* *
12+
* Copyright (c) 2005-2020 Stanford University and the Authors *
13+
* Author(s): Christopher Dembia *
14+
* *
15+
* Licensed under the Apache License, Version 2.0 (the "License"); you may *
16+
* not use this file except in compliance with the License. You may obtain a *
17+
* copy of the License at http://www.apache.org/licenses/LICENSE-2.0. *
18+
* *
19+
* Unless required by applicable law or agreed to in writing, software *
20+
* distributed under the License is distributed on an "AS IS" BASIS, *
21+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. *
22+
* See the License for the specific language governing permissions and *
23+
* limitations under the License. *
24+
* -------------------------------------------------------------------------- */
25+
26+
#include "osimActuatorsDLL.h"
27+
28+
#include "CoordinateActuator.h"
29+
30+
namespace OpenSim {
31+
32+
/// Similar to CoordinateActuator (simply produces a generalized force) but
33+
/// with first-order linear activation dynamics. This actuator has one state
34+
/// variable, `activation`, with \f$ \dot{a} = (x - a) / \tau \f$, where
35+
/// \f$ a \f$ is activation, \f$ x \f$ is excitation, and \f$ \tau \f$ is the
36+
/// activation time constant (there is no separate deactivation time constant).
37+
/// The statebounds_activation output is used in Moco to set default values for
38+
/// the activation state variable.
39+
/// <b>Default %Property Values</b>
40+
/// @verbatim
41+
/// activation_time_constant: 0.01
42+
/// default_activation: 0.5
43+
/// @endverbatim
44+
class OSIMACTUATORS_API ActivationCoordinateActuator
45+
: public CoordinateActuator {
46+
OpenSim_DECLARE_CONCRETE_OBJECT(ActivationCoordinateActuator,
47+
CoordinateActuator);
48+
public:
49+
OpenSim_DECLARE_PROPERTY(activation_time_constant, double,
50+
"Larger value means activation can change more rapidly "
51+
"(units: seconds; default: 0.01 seconds).");
52+
53+
OpenSim_DECLARE_PROPERTY(default_activation, double,
54+
"Value of activation in the default state returned by initSystem() "
55+
"(default: 0.5).");
56+
57+
OpenSim_DECLARE_OUTPUT(statebounds_activation, SimTK::Vec2,
58+
getBoundsActivation, SimTK::Stage::Model);
59+
60+
ActivationCoordinateActuator() {
61+
constructProperties();
62+
}
63+
64+
/// The lower bound on activation is getMinControl() and the upper bound is
65+
/// getMaxControl().
66+
/// Whether these bounds are enforced is determined by the solver used.
67+
SimTK::Vec2 getBoundsActivation(const SimTK::State&) const {
68+
return SimTK::Vec2(getMinControl(), getMaxControl());
69+
}
70+
71+
protected:
72+
void extendAddToSystem(SimTK::MultibodySystem& system) const override {
73+
Super::extendAddToSystem(system);
74+
addStateVariable("activation", SimTK::Stage::Dynamics);
75+
}
76+
77+
void extendInitStateFromProperties(SimTK::State& s) const override {
78+
Super::extendInitStateFromProperties(s);
79+
setStateVariableValue(s, "activation", get_default_activation());
80+
}
81+
82+
void extendSetPropertiesFromState(const SimTK::State& s) override {
83+
Super::extendSetPropertiesFromState(s);
84+
set_default_activation(getStateVariableValue(s, "activation"));
85+
}
86+
87+
void computeStateVariableDerivatives(const SimTK::State& s) const override {
88+
// No need to do clamping, etc; CoordinateActuator is bidirectional.
89+
const auto& tau = get_activation_time_constant();
90+
const auto& x = getControl(s);
91+
const auto& a = getStateVariableValue(s, "activation");
92+
const SimTK::Real adot = (x - a) / tau;
93+
setStateVariableDerivativeValue(s, "activation", adot);
94+
}
95+
96+
double computeActuation(const SimTK::State& s) const override {
97+
return getStateVariableValue(s, "activation") * getOptimalForce();
98+
}
99+
private:
100+
void constructProperties() {
101+
constructProperty_activation_time_constant(0.010);
102+
constructProperty_default_activation(0.5);
103+
}
104+
};
105+
106+
} // namespace OpenSim
107+
108+
#endif // OPENSIM_ACTIVATION_COORDINATE_ACTUATOR_H

OpenSim/Actuators/RegisterTypes_osimActuators.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
#include "RegisterTypes_osimActuators.h"
2828

2929
#include "CoordinateActuator.h"
30+
#include "ActivationCoordinateActuator.h"
3031
#include "PointActuator.h"
3132
#include "TorqueActuator.h"
3233
#include "BodyActuator.h"
@@ -78,6 +79,7 @@ OSIMACTUATORS_API void RegisterTypes_osimActuators()
7879
try {
7980

8081
Object::registerType( CoordinateActuator() );
82+
Object::registerType( ActivationCoordinateActuator() );
8183
Object::registerType( PointActuator() );
8284
Object::registerType( TorqueActuator() );
8385
Object::registerType( BodyActuator() );

OpenSim/Actuators/osimActuators.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
* -------------------------------------------------------------------------- */
2525

2626
#include "CoordinateActuator.h"
27+
#include "ActivationCoordinateActuator.h"
2728
#include "PointActuator.h"
2829
#include "TorqueActuator.h"
2930
#include "BodyActuator.h"

0 commit comments

Comments
 (0)