Skip to content

Commit

Permalink
fix bug with Actuation analysis leading to extra columns in output (#…
Browse files Browse the repository at this point in the history
…2980)

* fix bug with Actuation analysis that has extra columns in output when acutators are disabled. also add a test

* add Actuation analysis to PlotterTool.xml test file

Co-authored-by: carmichaelong <[email protected]>
  • Loading branch information
carmichaelong and carmichaelong authored Apr 8, 2021
1 parent fe4a2fe commit a2d3446
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 1 deletion.
12 changes: 12 additions & 0 deletions Applications/Analyze/test/PlotterTool.xml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,18 @@
<!--Flag indicating whether moments should be computed.-->
<compute_moments>false</compute_moments>
</MuscleAnalysis>
<Actuation name="Actuation">
<!--Flag (true or false) specifying whether on. True by default.-->
<on>true</on>
<!--Start time.-->
<start_time>-Inf</start_time>
<!--End time.-->
<end_time>Inf</end_time>
<!--Specifies how often to store results during a simulation. More specifically, the interval (a positive integer) specifies how many successful integration steps should be taken before results are recorded again.-->
<step_interval>1</step_interval>
<!--Flag (true or false) indicating whether the results are in degrees or not.-->
<in_degrees>true</in_degrees>
</Actuation>
</objects>
<groups />
</AnalysisSet>
Expand Down
28 changes: 28 additions & 0 deletions Applications/Analyze/test/testAnalyzeTool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ using namespace OpenSim;
using namespace std;

void testTutorialOne();
void testActuationAnalysisWithDisabledForce();

// Test different default activations are respected when activation
// states are not provided.
Expand Down Expand Up @@ -70,6 +71,12 @@ int main()
failures.push_back("testTugOfWar with activation state provided");
}

try { testActuationAnalysisWithDisabledForce(); }
catch (const std::exception& e) {
cout << e.what() << endl;
failures.push_back("testActuationAnalysisWithDisabledForce");
}

if (!failures.empty()) {
cout << "Done, with failure(s): " << failures << endl;
return 1;
Expand Down Expand Up @@ -227,3 +234,24 @@ void testTugOfWar(const string& dataFileName, const double& defaultAct) {
"Force trajectory has unexplained discontinuity.");
}
}

void testActuationAnalysisWithDisabledForce() {
AnalyzeTool analyze("PlotterTool.xml");
Model& model = analyze.getModel();
auto& muscle = model.updMuscles()[0];
muscle.set_appliesForce(false);

std::string resultsDir = "testPlotterToolWithDisabledForce";
analyze.setResultsDir(resultsDir);
analyze.run();

// Reading a file with mismatched nColumns header and actual number of
// data columns will throw.
TimeSeriesTable_<double> act_force_table(
resultsDir + "/BothLegs_Actuation_force.sto");

// Let's also check that the number of columns is correct (i.e.,
// (number of muscles in the model) - 1).
ASSERT_EQUAL(model.getMuscles().getSize() - 1,
(int)act_force_table.getNumColumns());
}
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ request related to the change, then we may provide the commit.
This is not a comprehensive list of changes but rather a hand-curated collection of the more notable ones. For a comprehensive history, see the [OpenSim Core GitHub repo](https://github.com/opensim-org/opensim-core).
v4.3
====
- Fixed a bug with Actuation analysis that would lead to extra columns in the output when an actuator is disabled (Issue #2977).

v4.2
====
Expand Down
2 changes: 1 addition & 1 deletion OpenSim/Analyses/Actuation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -416,7 +416,7 @@ begin(const SimTK::State& s)
if (!proceed()) return(0);

// NUMBER OF ACTUATORS
int na = _model->getActuators().getSize();
int na = getNumEnabledActuators();
_na = na;
// WORK ARRAY
if (_fsp != NULL) delete[] _fsp;
Expand Down

0 comments on commit a2d3446

Please sign in to comment.