Skip to content

Commit 62206e7

Browse files
committed
Add test case for ActivationCoordinateActuator.
1 parent a97c772 commit 62206e7

File tree

2 files changed

+59
-2
lines changed

2 files changed

+59
-2
lines changed

OpenSim/Actuators/ActivationCoordinateActuator.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,14 @@ class OSIMACTUATORS_API ActivationCoordinateActuator
6161
constructProperties();
6262
}
6363

64+
/// Provide the coordinate name.
65+
explicit ActivationCoordinateActuator(const std::string& coordinateName)
66+
: ActivationCoordinateActuator() {
67+
if (!coordinateName.empty()) {
68+
set_coordinate(coordinateName);
69+
}
70+
}
71+
6472
/// The lower bound on activation is getMinControl() and the upper bound is
6573
/// getMaxControl().
6674
/// Whether these bounds are enforced is determined by the solver used.

OpenSim/Actuators/Test/testActuators.cpp

Lines changed: 51 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@
2828
// 3. testClutchedPathSpring()
2929
// 4. testMcKibbenActuator()
3030
// 5. testActuatorsCombination()
31-
//
31+
// 6. testActivationCoordinateActuator()
32+
//
3233
// Add tests here as Actuators are added to OpenSim
3334
//
3435
//=============================================================================
@@ -55,6 +56,7 @@ void testBodyActuator();
5556
void testClutchedPathSpring();
5657
void testMcKibbenActuator();
5758
void testActuatorsCombination();
59+
void testActivationCoordinateActuator();
5860

5961

6062
int main()
@@ -81,6 +83,10 @@ int main()
8183
catch (const std::exception& e) {
8284
cout << e.what() << endl; failures.push_back("testActuatorsCombination");
8385
}
86+
try { testActivationCoordinateActuator(); }
87+
catch (const std::exception& e) {
88+
cout << e.what() << endl; failures.push_back("testActivationCoordinateActuator");
89+
}
8490
if (!failures.empty()) {
8591
cout << "Done, with failure(s): " << failures << endl;
8692
return 1;
@@ -709,7 +715,7 @@ void testBodyActuator()
709715
//==================================================================================
710716
/**
711717
* This test verifies if using a BodyActuator generates equivalent result in the body
712-
* acceleration compared to when using a combination of PointActuaor, TorqueActuaor
718+
* acceleration compared to when using a combination of PointActuaor, TorqueActuator
713719
* and BodyActuator.
714720
* It therefore also verifies model consistency when user defines and uses a
715721
* combination of these 3 actuators.
@@ -918,3 +924,46 @@ void testActuatorsCombination()
918924
std::cout << " ********** Test Actuator Combination time = ********** " <<
919925
1.e3*(std::clock() - startTime) / CLOCKS_PER_SEC << "ms\n" << endl;
920926
}
927+
928+
// Test de/serialization and numerical integration of
929+
// ActivationCoordinateActautor.
930+
void testActivationCoordinateActuator() {
931+
Model model;
932+
auto* body = new Body("body", 1, SimTK::Vec3(0), SimTK::Inertia(0));
933+
auto* joint = new PinJoint("joint", *body, model.getGround());
934+
joint->updCoordinate().setName("coord");
935+
model.addBody(body);
936+
model.addJoint(joint);
937+
auto* aca = new ActivationCoordinateActuator("coord");
938+
aca->setName("aca");
939+
const double a0 = 0.7;
940+
const double tau = 0.20;
941+
aca->set_default_activation(a0);
942+
aca->set_activation_time_constant(tau);
943+
model.addForce(aca);
944+
model.finalizeFromProperties();
945+
model.finalizeConnections();
946+
model.print("Model_ActivationCoordinateActuator.osim");
947+
948+
Model modelDeserialized("Model_ActivationCoordinateActuator.osim");
949+
ASSERT(model == modelDeserialized);
950+
951+
auto* controller = new PrescribedController();
952+
controller->addActuator(*aca);
953+
const double x = 0.15;
954+
controller->prescribeControlForActuator("aca", new Constant(x));
955+
model.addController(controller);
956+
957+
auto state = model.initSystem();
958+
959+
Manager manager(model);
960+
manager.initialize(state);
961+
const double tf = 0.10;
962+
state = manager.integrate(tf);
963+
964+
const double expectedFinalActivation =
965+
(a0 - x) * exp(-tf / tau) + x;
966+
const double foundFinalActivation =
967+
aca->getStateVariableValue(state, "activation");
968+
ASSERT_EQUAL(expectedFinalActivation, foundFinalActivation, 1e-4);
969+
}

0 commit comments

Comments
 (0)