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

InducedAcceleration analyzes not properly working #3923

Open
carlosoleto opened this issue Oct 1, 2024 · 11 comments
Open

InducedAcceleration analyzes not properly working #3923

carlosoleto opened this issue Oct 1, 2024 · 11 comments
Assignees
Labels

Comments

@carlosoleto
Copy link

I experienced the same strange behavior loading a analyzes xml file in OpenSim GUI and OpenSim API (Python) trying to use the IAA.

As we load the XML file, the RollingOnSurfaceConstraint sockets are cleared. So the values for socket_rolling_body and socket_surface_body are blanked.

In the GUI, if you type the correct values and don't save the XML, the tool will run. In the script with OpenSim API, the tool wont run
with error message:

RuntimeError: std::exception in 'bool OpenSim::AnalyzeTool::run()': Failed to connect Socket 'rolling_body' of type PhysicalFrame (details: Connectee for Socket 'rolling_body' of type PhysicalFrame in RollingOnSurfaceConstraint at /constraintset/right_foot_contact_0 is unspecified. If this model was built programmatically, perhaps finalizeConnections() was not called before printing. Thrown at Component.h:3383 in finalizeConnection().). In Object 'right_foot_contact_0' of type RollingOnSurfaceConstraint. Thrown at Component.cpp:313 in finalizeConnections().

@nickbianco
Copy link
Member

@carlosoleto, thanks for reporting. I'm not sure why Sockets would be cleared when loading a model from XML. Or does this behavior only happen in the GUI?

If it's an API issue, could you post a minimum working example? If the issue is limited to the GUI, this issue might be better in https://github.com/opensim-org/opensim-gui.

@mrrezaie
Copy link
Contributor

Hi @nickbianco, based on this post, this issue exists in both API and GUI:
https://simtk.org/plugins/phpBB/viewtopicPhpbb.php?f=91&t=12364&p=0&start=0&view=&sid=f10362c5827b24924b17da442287e482
Thanks for your time and support.

@carlosoleto
Copy link
Author

@nickbianco , sorry for the delayed response.

As Mohammadreza Rezaie posted, We already did some tests and posted the findings in the OpenSim forum.

If it is not enough, I can provide further information.

Best regards.

@nickbianco
Copy link
Member

@carlosoleto, @mrrezaie, thank you for the detailed investigation. I'm not too familiar with how the IAA tool works, but I assume the bug is something like a missing finalizeConnections call when the RollingOnSurface constraint is added to the model.

As a workaround, could you try manually adding the constraint to the model before passing it to the tool? That way you should be able to guarantee that the model is constructed properly before the analysis is run.

@carlosoleto
Copy link
Author

Hello @nickbianco,

I think I already did it, but configuring the IAA component in the configuration file (XML). But I'm not too good at using the API for everything. Here what I tried:

analise3 = osim.AnalyzeTool('analise.xml')

iaa = analise3.getAnalysisSet().get(0)
CS = iaa.updPropertyByName('ConstraintSet')
CSo = CS.updValueAsObject()
CS_obj = CSo.updPropertyByIndex(1) # <objects>
constraintR = CS_obj.updValueAsObject(0) #<RollingOnSurface ... >
constraintL = CS_obj.updValueAsObject(1) #<RollingOnSurface ... >
propriedade = constraintR.updPropertyByName('socket_rolling_body')
osim.PropertyHelper.setValueString('/bodyset/calcn_r', propriedade)
propriedade = constraintR.updPropertyByName('socket_surface_body')
osim.PropertyHelper.setValueString('/ground', propriedade)

propriedade = constraintL.updPropertyByName('socket_rolling_body')
osim.PropertyHelper.setValueString('/bodyset/calcn_l', propriedade)
propriedade = constraintL.updPropertyByName('socket_surface_body')
osim.PropertyHelper.setValueString('/ground', propriedade)

analise3.verifyControlsStates() ## ok, i passes

analise3.run() # fails

When it runs, it fails in "finalizeConnections".

---------------------------------------------------------------------------
RuntimeError                              Traceback (most recent call last)
Input In [14], in <cell line: 1>()
----> 1 analise3.run()

File c:\Users\Carlo\.conda\envs\opensim44\lib\site-packages\opensim\tools.py:3902, in AnalyzeTool.run(self, *args)
   3901 def run(self, *args) -> "bool":
-> 3902     return _tools.AnalyzeTool_run(self, *args)

RuntimeError: std::exception in 'bool OpenSim::AnalyzeTool::run()': Failed to connect Socket 'rolling_body' of type PhysicalFrame (details: Connectee for Socket 'rolling_body' of type PhysicalFrame in RollingOnSurfaceConstraint at /constraintset/right_foot_contact is unspecified. If this model was built programmatically, perhaps finalizeConnections() was not called before printing.
	Thrown at Component.h:3383 in finalizeConnection().).
	In Object 'right_foot_contact' of type RollingOnSurfaceConstraint.
	Thrown at Component.cpp:313 in finalizeConnections().

I already change the model before running the analysis tool, because I need to remove the contact forces in my jump model. So, I could try adding the needed constraints. I remember trying to add the RollingConstraints but I couldn't manage with the available documentation.

Could you give some advice in adding the constraint using the API?

@nickbianco
Copy link
Member

nickbianco commented Oct 27, 2024

@carlosoleto it would look something like this:

# load your base model
model = osim.Model('/path/to/your/model.osim')
model.initSystem()

# add a RollingOnSurfaceConstraint()
constraint = osim.RollingOnSurfaceConstraint()
# add settings to configure the constraint here 
# ....
model.addConstraint(constraint)

# call "finalizeConnections" and save
model.finalizeConnections()
model.printToXML('/path/to/your/model_with_constraints.osim')

Then you should be able to use this model and exclude the RollingOnSurfaceConstraints from the IAA setup file. This way you can ensure that the model is constructed with the constraints properly before calling IAA.

@carlosoleto
Copy link
Author

Ok, I will try it, but I will cut the corner and add the Constraint directly to the .OSIM editing the XML. I will post it here.

Nevertheless, if it works, it will be great to speed things up in developing the analysis data. However, the issue regarding adding the .XML to the Analysis Tool and by no reason it cleares the Constraint information, will still remain.

@nickbianco
Copy link
Member

@carlosoleto, I agree that the issue still stands, but hopefully my suggestion above will be a usable workaround for your workflow in the meantime.

@carlosoleto
Copy link
Author

Hello @nickbianco , sorry for the delay.

I will attach the files used in the tests here. As I mentioned, I edited the files directly in Notepad++ to speed things up.

testIAA.zip

  • Test 1:
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import opensim as osim
# IAA config with constraints, model without
test01 = osim.AnalyzeTool('iaa.xml')

test01.run()
---------------------------------------------------------------------------
RuntimeError                              Traceback (most recent call last)
Input [In [14]](vscode-notebook-cell:?execution_count=14), in <cell line: 1>()
----> [1](vscode-notebook-cell:?execution_count=14&line=1) test01.run()

File c:\Users\Carlo\.conda\envs\opensim44\lib\site-packages\opensim\tools.py:3902, in AnalyzeTool.run(self, *args)
   [3901](file:///C:/Users/Carlo/.conda/envs/opensim44/lib/site-packages/opensim/tools.py:3901) def run(self, *args) -> "bool":
-> [3902](file:///C:/Users/Carlo/.conda/envs/opensim44/lib/site-packages/opensim/tools.py:3902)     return _tools.AnalyzeTool_run(self, *args)

RuntimeError: std::exception in 'bool OpenSim::AnalyzeTool::run()': Failed to connect Socket 'rolling_body' of type PhysicalFrame (details: Connectee for Socket 'rolling_body' of type PhysicalFrame in RollingOnSurfaceConstraint at /constraintset/right_foot_contact is unspecified. If this model was built programmatically, perhaps finalizeConnections() was not called before printing.
	Thrown at Component.h:3383 in finalizeConnection().).
	In Object 'right_foot_contact' of type RollingOnSurfaceConstraint.
	Thrown at Component.cpp:313 in finalizeConnections().
  • Test 2
# IAA config without constraints, model with constraints (enforced False)
test02 = osim.AnalyzeTool('iaaT1.xml')

test02.run()
---------------------------------------------------------------------------
RuntimeError                              Traceback (most recent call last)
Input [In [16]](vscode-notebook-cell:?execution_count=16), in <cell line: 1>()
----> [1](vscode-notebook-cell:?execution_count=16&line=1) test02.run()

File c:\Users\Carlo\.conda\envs\opensim44\lib\site-packages\opensim\tools.py:3902, in AnalyzeTool.run(self, *args)
   [3901](file:///C:/Users/Carlo/.conda/envs/opensim44/lib/site-packages/opensim/tools.py:3901) def run(self, *args) -> "bool":
-> [3902](file:///C:/Users/Carlo/.conda/envs/opensim44/lib/site-packages/opensim/tools.py:3902)     return _tools.AnalyzeTool_run(self, *args)

RuntimeError: std::exception in 'bool OpenSim::AnalyzeTool::run()': ArrayPtrs.get: Array index out of bounds.
  • Test3
# IAA config without constraints, model with constraints (enforced true)
test03 = osim.AnalyzeTool('iaaT2.xml')

test03.run()

---------------------------------------------------------------------------
RuntimeError                              Traceback (most recent call last)
Input [In [18]](vscode-notebook-cell:?execution_count=18), in <cell line: 1>()
----> [1](vscode-notebook-cell:?execution_count=18&line=1) test03.run()

File c:\Users\Carlo\.conda\envs\opensim44\lib\site-packages\opensim\tools.py:3902, in AnalyzeTool.run(self, *args)
   [3901](file:///C:/Users/Carlo/.conda/envs/opensim44/lib/site-packages/opensim/tools.py:3901) def run(self, *args) -> "bool":
-> [3902](file:///C:/Users/Carlo/.conda/envs/opensim44/lib/site-packages/opensim/tools.py:3902)     return _tools.AnalyzeTool_run(self, *args)

RuntimeError: std::exception in 'bool OpenSim::AnalyzeTool::run()': ArrayPtrs.get: Array index out of bounds.

To summarize, unfortunately, in all combinations tested, the error seems the same. The rolling surfaces definitions are cleared during "loading".

If I load the config file iaa.xml (Test 1) in the OpenSim GUI, and rewrite the terms in the tool ConstraintSet (not the model), I can run with good results (myIAA_InducedAccelerations_center_of_mass.sto).

Hope it helps.

And thanks for all the support.

Best regards.

@nickbianco
Copy link
Member

Hi @carlosoleto, the error seems different in Tests 2 and 3. Are you able to construct the model (i.e., model.initSystem()) with the RollingOnSurfaceConstraint manually added, outside of the IAA tool? Just trying to isolate potentially separate issues here.

@carlosoleto
Copy link
Author

Hello @nickbianco ,

Tests 2 and 3 used a model with the constraints already included. I just used the XML to speed things up. The models appear okay when loaded in OpenSim.

The path to the models is defined in the settings file for the analysis (.xml).

All the files in the tests are in the zip attached to the previous message.

@nickbianco nickbianco self-assigned this Nov 4, 2024
@nickbianco nickbianco added the bug label Nov 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants