Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove kinematics_for_external_loads property #2770

Merged
merged 22 commits into from
Sep 1, 2020
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
111520b
Remove kinematics_for_external_loads property from ExternalLoads obje…
aymanhab May 13, 2020
8260d39
Update externalForces file to latest format and remove reference to e…
aymanhab May 19, 2020
8ba06c4
Fix IAA to handle externalForce.expressedInBody being "ground" which …
aymanhab May 20, 2020
0917baa
Remove kinematics_for_external_loads property from ExternalLoads obje…
aymanhab May 13, 2020
134a5b8
Update externalForces file to latest format and remove reference to e…
aymanhab May 19, 2020
5b81e09
Fix IAA to handle externalForce.expressedInBody being "ground" which …
aymanhab May 20, 2020
40d8f85
Merge branch 'remove_kin_external_loads' of https://github.com/opensi…
aymanhab Jun 11, 2020
25918ab
Merge branch 'master' of github.com:opensim-org/opensim-core into rem…
chrisdembia Jun 12, 2020
9ddd2d8
Remove kinematics_for_external_loads property from ExternalLoads obje…
aymanhab May 13, 2020
ed63930
Update externalForces file to latest format and remove reference to e…
aymanhab May 19, 2020
f4f1639
Fix IAA to handle externalForce.expressedInBody being "ground" which …
aymanhab May 20, 2020
2fc1a97
Merge branch 'remove_kin_external_loads' of https://github.com/opensi…
aymanhab Jun 15, 2020
fcfae60
Use log methods instead of cout
aymanhab Jun 16, 2020
ac99fcf
Port bugfix to IAA from already reviewed PR 2691
aymanhab Jun 16, 2020
035f90f
Fix comment
aymanhab Jun 16, 2020
f4b25fa
log_warn instead of cout
aymanhab Jun 16, 2020
7504d7a
Merge branch 'master' into remove_kin_external_loads
aymanhab Aug 21, 2020
33355c1
Update standard for SO test case to account for removal of Kinematics…
aymanhab Aug 27, 2020
cfc2fd6
Update std for InducedAcceleration test case
aymanhab Aug 27, 2020
d79e572
Fix testCMCWithControlConstraintsGait2354 by updating standard and us…
aymanhab Aug 28, 2020
0f787f2
Fix indentation that failed ci build on linux
aymanhab Aug 28, 2020
dce7562
Undo XMLDocument version upgrade to keep backward compatibility of Mo…
aymanhab Aug 31, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
113 changes: 30 additions & 83 deletions Applications/Analyze/test/externalForces.xml
Original file line number Diff line number Diff line change
@@ -1,91 +1,38 @@
<?xml version="1.0" encoding="UTF-8" ?>
<OpenSimDocument Version="20201">
<ExternalLoads name="">
<OpenSimDocument Version="40000">
<ExternalLoads name="default">
<objects>
<PrescribedForce name="RightForce">
<ExternalForce name="RightForce">
<!--Name of the body the force is applied to.-->
<body>calcn_r</body>
<!--Flag indicating whether the point (specified in pointFunctions) is in
global frame-->
<pointIsGlobal>false</pointIsGlobal>
<!--Flag indicating whether the quantities (specified in
force/torqueFunctions) is in global frame-->
<forceIsGlobal>true</forceIsGlobal>
<!--Three functions describing the force to be applied.-->
<FunctionSet name="forceFunctions">
<objects>
<NaturalCubicSpline name="ground_force_vx" />
<NaturalCubicSpline name="ground_force_vy" />
<NaturalCubicSpline name="ground_force_vz" />
</objects>
<groups />
</FunctionSet>
<!--Three functions describing the location at which the force is applied-->
<FunctionSet name="pointFunctions">
<objects>
<NaturalCubicSpline name="ground_force_px" />
<NaturalCubicSpline name="ground_force_py" />
<NaturalCubicSpline name="ground_force_pz" />
</objects>
<groups />
</FunctionSet>
<!--Three functions describing the torque the PrescribedForce applies-->
<FunctionSet name="torqueFunctions">
<objects>
<NaturalCubicSpline name="ground_torque_x" />
<NaturalCubicSpline name="ground_torque_y" />
<NaturalCubicSpline name="ground_torque_z" />
</objects>
<groups />
</FunctionSet>
</PrescribedForce>
<PrescribedForce name="LeftForce">
<applied_to_body>calcn_r</applied_to_body>
<!--Name of the body the force is expressed in (default is ground).-->
<force_expressed_in_body>ground</force_expressed_in_body>
<!--Name of the body the point is expressed in (default is ground).-->
<point_expressed_in_body>ground</point_expressed_in_body>
<!--Identifier (string) to locate the force to be applied in the data source.-->
<force_identifier>ground_force_v</force_identifier>
<!--Identifier (string) to locate the point to be applied in the data source.-->
<point_identifier>ground_force_p</point_identifier>
<!--Identifier (string) to locate the torque to be applied in the data source.-->
<torque_identifier>ground_torque_</torque_identifier>
</ExternalForce>
<ExternalForce name="LeftForce">
<!--Name of the body the force is applied to.-->
<body>calcn_l</body>
<!--Flag indicating whether the point (specified in pointFunctions) is in
global frame-->
<pointIsGlobal>false</pointIsGlobal>
<!--Flag indicating whether the quantities (specified in
force/torqueFunctions) is in global frame-->
<forceIsGlobal>true</forceIsGlobal>
<!--Three functions describing the force to be applied.-->
<FunctionSet name="forceFunctions">
<objects>
<NaturalCubicSpline name="l_ground_force_vx" />
<NaturalCubicSpline name="l_ground_force_vy" />
<NaturalCubicSpline name="l_ground_force_vz" />
</objects>
<groups />
</FunctionSet>
<!--Three functions describing the location at which the force is applied-->
<FunctionSet name="pointFunctions">
<objects>
<NaturalCubicSpline name="l_ground_force_px" />
<NaturalCubicSpline name="l_ground_force_py" />
<NaturalCubicSpline name="l_ground_force_pz" />
</objects>
<groups />
</FunctionSet>
<!--Three functions describing the torque the PrescribedForce applies-->
<FunctionSet name="torqueFunctions">
<objects>
<NaturalCubicSpline name="l_ground_torque_x" />
<NaturalCubicSpline name="l_ground_torque_y" />
<NaturalCubicSpline name="l_ground_torque_z" />
</objects>
<groups />
</FunctionSet>
</PrescribedForce>
<applied_to_body>calcn_l</applied_to_body>
<!--Name of the body the force is expressed in (default is ground).-->
<force_expressed_in_body>ground</force_expressed_in_body>
<!--Name of the body the point is expressed in (default is ground).-->
<point_expressed_in_body>ground</point_expressed_in_body>
<!--Identifier (string) to locate the force to be applied in the data source.-->
<force_identifier>l_ground_force_v</force_identifier>
<!--Identifier (string) to locate the point to be applied in the data source.-->
<point_identifier>l_ground_force_p</point_identifier>
<!--Identifier (string) to locate the torque to be applied in the data source.-->
<torque_identifier>l_ground_torque_</torque_identifier>
</ExternalForce>
</objects>
<!--Storage file (.sto) containing the Forces, Torques and locations of
the external loads.-->
<groups />
<!--Storage file (.sto) containing (3) components of force and/or torque and point of application.Note: this file overrides the data source specified by the individual external forces if specified.-->
<datafile>subject01_walk1_grf.mot</datafile>
<!--Motion file (.mot) or storage file (.sto) containing the model
kinematics corresponding to the external loads.-->
<external_loads_model_kinematics_file>subject01_walk1_ik.mot</external_loads_model_kinematics_file>
<!--Low-pass cut-off frequency for filtering the model kinematics
corresponding to the external loads. A negative value results in no
filtering. The default value is -1.0, so no filtering.-->
<lowpass_cutoff_frequency_for_load_kinematics>6</lowpass_cutoff_frequency_for_load_kinematics>
</ExternalLoads>
</OpenSimDocument>
9 changes: 6 additions & 3 deletions OpenSim/Analyses/InducedAccelerations.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -970,16 +970,19 @@ Array<bool> InducedAccelerations::applyContactConstraintAccordingToExternalForce
}

int expressedInBodyIndex = _model->getBodySet().getIndex(exf->getPointExpressedInBodyName());
if(expressedInBodyIndex < 0){
if (expressedInBodyIndex < 0 &&
exf->getPointExpressedInBodyName() != "ground") {
log_warn("ExternalForce point_expressed_in_body '{}' not found.",
exf->getPointExpressedInBodyName());
}

const Body &appliedToBody = _model->getBodySet().get(appliedToBodyIndex);
const Body &expressedInBody = _model->getBodySet().get(expressedInBodyIndex);
const Frame* expressedInBody =
_model->findComponent<Frame>(
exf->getPointExpressedInBodyName());

_model->getMultibodySystem().realize(s, SimTK::Stage::Velocity);
point = expressedInBody.findStationLocationInAnotherFrame(s, point, appliedToBody);
point = expressedInBody->findStationLocationInAnotherFrame(s, point, appliedToBody);
}

_constraintSet.get(i).setContactPointForInducedAccelerations(s, point);
Expand Down
5 changes: 3 additions & 2 deletions OpenSim/Common/XMLDocument.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,9 @@ using namespace std;
// 30515 for WrapObject color, display_preference, VisibleObject -> Appearance
// 30516 for GeometryPath default_color -> Appearance
// 30517 for removal of _connectee_name suffix to shorten XML for socket, input
// 40000 for OpenSim 4.0 release
const int XMLDocument::LatestVersion = 40000;
// 40000 for OpenSim 4.0 release 40000
// 40200 for ExternalLoads retire kinematics for external loads options
const int XMLDocument::LatestVersion = 40200;
//=============================================================================
// DESTRUCTOR AND CONSTRUCTOR(S)
//=============================================================================
Expand Down
53 changes: 0 additions & 53 deletions OpenSim/Simulation/Model/AbstractTool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -584,59 +584,6 @@ bool AbstractTool::createExternalLoads( const string& aExternalLoadsFileName,
throw(ex);
}

string loadKinematicsFileName =
externalLoads->getExternalLoadsModelKinematicsFileName();

const Storage *loadKinematicsForPointTransformation = nullptr;

IO::TrimLeadingWhitespace(loadKinematicsFileName);
Storage *temp = NULL;
// fine if there are no kinematics as long as it was not assigned
if (!(loadKinematicsFileName == "") && !(loadKinematicsFileName == "Unassigned")) {
if (IO::FileExists(loadKinematicsFileName)) {
temp = new Storage(loadKinematicsFileName);
}
else {
// attempt to find the file local to the external loads XML file
std::string savedCwd = IO::getCwd();
IO::chDir(IO::getParentDirectory(aExternalLoadsFileName));
if (IO::FileExists(loadKinematicsFileName)) {
temp = new Storage(loadKinematicsFileName);
IO::chDir(savedCwd);
}
else {
IO::chDir(savedCwd);
throw Exception("AbstractTool: could not find external loads kinematics file '"
+ loadKinematicsFileName + "'.");
}
}
// if loading the data, do whatever filtering operations are also specified
if (temp && externalLoads->getLowpassCutoffFrequencyForLoadKinematics() >= 0) {
log_info("Low-pass filtering coordinates data with a cutoff frequency of {}.",
_externalLoads.getLowpassCutoffFrequencyForLoadKinematics());
temp->pad(temp->getSize() / 2);
temp->lowpassIIR(externalLoads->getLowpassCutoffFrequencyForLoadKinematics());
}
loadKinematicsForPointTransformation = temp;
}

// if load kinematics for performing re-expressing the point of application is provided
// then perform the transformations
if(loadKinematicsForPointTransformation){
SimTK::State& s = copyModel.initSystem();

// Form complete storage so that the kinematics match the state labels/ordering
Storage *qStore=NULL;
Storage *uStore=NULL;
copyModel.getSimbodyEngine().formCompleteStorages(s,
*loadKinematicsForPointTransformation,
qStore, uStore);

externalLoads->transformPointsExpressedInGroundToAppliedBodies(*qStore, _ti, _tf);
delete qStore;
delete uStore;
}

//Now add the ExternalLoads (transformed or not) to the Model to be analyzed
ExternalLoads* exLoadsClone = externalLoads->clone();
aModel.addModelComponent(exLoadsClone);
Expand Down
50 changes: 21 additions & 29 deletions OpenSim/Simulation/Model/ExternalLoads.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,18 +49,14 @@ ExternalLoads::~ExternalLoads()
* Default constructor.
*/
ExternalLoads::ExternalLoads():
_dataFileName(_dataFileNameProp.getValueStr()),
_externalLoadsModelKinematicsFileName(_externalLoadsModelKinematicsFileNameProp.getValueStr()),
_lowpassCutoffFrequencyForLoadKinematics(_lowpassCutoffFrequencyForLoadKinematicsProp.getValueDbl())
_dataFileName(_dataFileNameProp.getValueStr())
{
setNull();
}

ExternalLoads::ExternalLoads(const std::string &fileName, bool updateFromXMLNode) :
Super(fileName, false),
_dataFileName(_dataFileNameProp.getValueStr()),
_externalLoadsModelKinematicsFileName(_externalLoadsModelKinematicsFileNameProp.getValueStr()),
_lowpassCutoffFrequencyForLoadKinematics(_lowpassCutoffFrequencyForLoadKinematicsProp.getValueDbl()),
_loadedFromFile(fileName)
{
setNull();
Expand All @@ -78,9 +74,7 @@ ExternalLoads::ExternalLoads(const std::string &fileName, bool updateFromXMLNode
*/
ExternalLoads::ExternalLoads(const ExternalLoads &otherExternalLoads) :
ModelComponentSet<ExternalForce>(otherExternalLoads),
_dataFileName(_dataFileNameProp.getValueStr()),
_externalLoadsModelKinematicsFileName(_externalLoadsModelKinematicsFileNameProp.getValueStr()),
_lowpassCutoffFrequencyForLoadKinematics(_lowpassCutoffFrequencyForLoadKinematicsProp.getValueDbl())
_dataFileName(_dataFileNameProp.getValueStr())
{
setNull();

Expand Down Expand Up @@ -115,8 +109,6 @@ void ExternalLoads::copyData(const ExternalLoads &aAbsExternalLoads)
{
// ACTUATORS
_dataFileName = aAbsExternalLoads._dataFileName;
_externalLoadsModelKinematicsFileName = aAbsExternalLoads._externalLoadsModelKinematicsFileName;
_lowpassCutoffFrequencyForLoadKinematics = aAbsExternalLoads._lowpassCutoffFrequencyForLoadKinematics;
_storages = aAbsExternalLoads._storages;
_loadedFromFile = aAbsExternalLoads._loadedFromFile;
}
Expand All @@ -134,23 +126,6 @@ void ExternalLoads::setupSerializedMembers()
"Note: this file overrides the data source specified by the individual external forces if specified.";
_dataFileNameProp.setComment(comment);
_propertySet.append(&_dataFileNameProp);

_externalLoadsModelKinematicsFileName="";
comment = "The option is deprecated and unnecessary to apply external loads. "
"A motion file (.mot) or storage file (.sto) containing the model kinematics "
"used to transform a point expressed in ground to the body of force application."
"If the point is not expressed in ground, the point is not transformed";
_externalLoadsModelKinematicsFileNameProp.setComment(comment);
_externalLoadsModelKinematicsFileNameProp.setName("external_loads_model_kinematics_file");
_propertySet.append( &_externalLoadsModelKinematicsFileNameProp );

_lowpassCutoffFrequencyForLoadKinematics=-1.0;
comment = "Optional low-pass cut-off frequency for filtering the model kinematics corresponding "
"used to transform the point of application. A negative value results in no filtering. "
"The default value is -1.0, so no filtering.";
_lowpassCutoffFrequencyForLoadKinematicsProp.setComment(comment);
_lowpassCutoffFrequencyForLoadKinematicsProp.setName("lowpass_cutoff_frequency_for_load_kinematics");
_propertySet.append( &_lowpassCutoffFrequencyForLoadKinematicsProp );
}


Expand Down Expand Up @@ -438,11 +413,13 @@ void ExternalLoads::updateFromXMLNode(SimTK::Xml::Element& aNode, int versionNum
if (kinFileNode != aNode.element_end()){
SimTK::String transcoded = kinFileNode->getValueAs<SimTK::String>();
if (transcoded.length()>0)
_externalLoadsModelKinematicsFileName =transcoded;
std::cout << "Warn: external_loads_model_kinematics_file option is not supported anymore"
<< " result could change, please inspect and update accordingly" << std::endl;
}
SimTK::Xml::element_iterator kinFilterNode = aNode.element_begin("lowpass_cutoff_frequency_for_load_kinematics");
if (kinFilterNode != aNode.element_end()){
_lowpassCutoffFrequencyForLoadKinematics = kinFilterNode->getValueAs<double>();
// This is now unnecessary since we dropped supoprt for external_loads_model_kinematics_file
// _lowpassCutoffFrequencyForLoadKinematics = kinFilterNode->getValueAs<double>();
}
bool changeWorkingDir = false;
std::string savedCwd;
Expand Down Expand Up @@ -507,6 +484,21 @@ void ExternalLoads::updateFromXMLNode(SimTK::Xml::Element& aNode, int versionNum
delete dataSource;
}
else
if (documentVersion < 40200) {
// Warn on depreacted external_loads_kinematics_specification
SimTK::Xml::element_iterator kinFileNode =
aNode.element_begin("external_loads_model_kinematics_file");
if (kinFileNode != aNode.element_end()) {
SimTK::String transcoded =
kinFileNode->getValueAs<SimTK::String>();
if (transcoded.length() > 0)
std::cout << "Warn: external_loads_model_kinematics_file "
"option is not supported anymore"
<< " result could change, please inspect and "
"update accordingly"
<< std::endl;
}
}
// Call base class now assuming _node has been corrected for current version
ModelComponentSet<ExternalForce>::updateFromXMLNode(aNode, versionNumber);
}
Expand Down
14 changes: 0 additions & 14 deletions OpenSim/Simulation/Model/ExternalLoads.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,15 +70,6 @@ OpenSim_DECLARE_CONCRETE_OBJECT(ExternalLoads,
* external forces identify which subsets of the data they will access.*/
PropertyStr _dataFileNameProp;
std::string &_dataFileName;
/** Name of the file containing the model kinematics corresponding to the
external loads. */
PropertyStr _externalLoadsModelKinematicsFileNameProp;
std::string &_externalLoadsModelKinematicsFileName;
/** Low-pass cut-off frequency for filtering the model kinematics corresponding
to the external loads. A negative value results in no filtering.
The default value is -1.0, so no filtering. */
PropertyDbl _lowpassCutoffFrequencyForLoadKinematicsProp;
double &_lowpassCutoffFrequencyForLoadKinematics;

private:
/* If point of applications for external forces must be re-expressed
Expand Down Expand Up @@ -120,11 +111,6 @@ OpenSim_DECLARE_CONCRETE_OBJECT(ExternalLoads,
const std::string& getDataFileName() const { return _dataFileName;};
void setDataFileName(const std::string& aNewFile) { _dataFileName = aNewFile; };

const std::string &getExternalLoadsModelKinematicsFileName() const { return _externalLoadsModelKinematicsFileName; }
void setExternalLoadsModelKinematicsFileName(const std::string &aFileName) { _externalLoadsModelKinematicsFileName = aFileName; }
double getLowpassCutoffFrequencyForLoadKinematics() const { return _lowpassCutoffFrequencyForLoadKinematics; }
void setLowpassCutoffFrequencyForLoadKinematics(double aLowpassCutoffFrequency) { _lowpassCutoffFrequencyForLoadKinematics = aLowpassCutoffFrequency; }

void transformPointsExpressedInGroundToAppliedBodies(const Storage &kinematics, double startTime = -SimTK::Infinity, double endTime = SimTK::Infinity);
ExternalForce* transformPointExpressedInGroundToAppliedBody(const ExternalForce &exForce, const Storage &kinematics, double startTime, double endTime);

Expand Down
Loading