Skip to content

Commit

Permalink
Return a zero moment if a path does not depend on a coordinate
Browse files Browse the repository at this point in the history
  • Loading branch information
nickbianco committed Sep 25, 2023
1 parent 885fd34 commit dde9b2d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
11 changes: 8 additions & 3 deletions OpenSim/Simulation/Model/FunctionBasedPath.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -125,9 +125,14 @@ double FunctionBasedPath::getLength(const SimTK::State& s) const
double FunctionBasedPath::computeMomentArm(const SimTK::State& s,
const Coordinate& coord) const
{
computeMomentArms(s);
return getCacheVariableValue<SimTK::Vector>(s, MOMENT_ARMS_NAME)
.get(_coordinateIndices.at(coord.getAbsolutePathString()));
if (_coordinateIndices.find(coord.getAbsolutePathString()) !=
_coordinateIndices.end()) {
computeMomentArms(s);
return getCacheVariableValue<SimTK::Vector>(s, MOMENT_ARMS_NAME)
.get(_coordinateIndices.at(coord.getAbsolutePathString()));
} else {
return 0.0;
}
}

double FunctionBasedPath::getLengtheningSpeed(const SimTK::State& s) const
Expand Down
4 changes: 4 additions & 0 deletions OpenSim/Simulation/Model/FunctionBasedPath.h
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,10 @@ OpenSim_DECLARE_CONCRETE_OBJECT(FunctionBasedPath, AbstractPath);
// ABSTRACT PATH INTERFACE
double getLength(const SimTK::State& s) const override;
double getLengtheningSpeed(const SimTK::State& s) const override;
/// @note This must check if the path is dependent on the provided
/// coordinate, which requires a search through the list of coordinates.
/// To retreive the moment arms directly from the cache variable, use
/// `getMomentArms()`.
double computeMomentArm(const SimTK::State& s,
const Coordinate& coord) const override;
void addInEquivalentForces(const SimTK::State& state,
Expand Down

0 comments on commit dde9b2d

Please sign in to comment.