Closed A-Artemis closed 8 months ago
:
Initialization (init):
self.state = self.model.initSystem()
lines in your __init__
. The reason you need both is to ensure your model initializes correctly. Removing either of them leads to an error. So, you're on the right track here.Reset (reset):
reset
function looks well-handled. You reset your environment's internal state, and it's essential to set the integrator accuracy after setting the integrator method and before initializing it, as you mentioned. This order ensures the settings take effect as intended.Step (step):
step
function, you seem to be handling the actions, integration, and calculations correctly. The sequence you've described seems logical.Manager and Integration Settings:
setIntegratorMethod
function lets you pick one. Your use of setIntegratorMinimumStepSize
to break down the integration into smaller steps can significantly speed up your simulation, but its accuracy depends on the specific dynamics of your system.Minimum Steps of an Integrator:
Accuracy vs. Speed:
To find the sweet spot for your simulation, you might need to experiment with different settings, observing how they affect your simulation's behavior and accuracy. The OpenSim documentation and input from the community can provide valuable guidance.
In summary, you're tackling the complexities of simulation setup and integration methods, which can be quite involved. Keep experimenting and seeking advice from experts in the field to fine-tune your environment for the best results.
Hi @A-Artemis, much of the functionality you're tyring to implement is already available in the classes SimTK::Integrator
and SimTK::TimeStepper
classes which are managed by OpenSim::Manager
. It would likely be more straightforward to use these classes, unless you have a specific reason for needing a custom implementation.
Hey @nickbianco I have been looking at the documentation here https://simtk.org/api_docs/opensim/api_docs/classOpenSim_1_1Manager.html but I am still struggling with it, could you please provide me with an example or editing the integrator and setting custom timesteps?
EDIT: Additionally, is there any difference between using model.realizeDynamics()
vs model.realizeAcceleration()
? with models using either muscle forces or actuators?
Here's a simple example in Python: https://github.com/opensim-org/opensim-core/blob/26b7b9b125c041cef83d6e28bcbfc541218d6e14/Bindings/Python/examples/build_simple_arm_model.py#L161.
To update the SimTK::Integrator
, you can do the following:
integrator = manager.getIntegrator()
You can refer to Simbody's documentation for the integrator settings.
EDIT: Additionally, is there any difference between using model.realizeDynamics() vs model.realizeAcceleration()? with models using either muscle forces or actuators?
It depends. If you only need force information, then realizing to SimTK::Stage::Dynamics
might be fine. But if you're unsure, realize to SimTK::Stage::Acceleration
. Usually Simbody will throw an Exception if you try to compute something that requires a stage you haven't realized to yet.
Hi, I am building an environment for OpenAI stable-baselines3 in Python 3.11.4, but I am unsure how to correctly handle the init, reset, and step of Opensim (using 4.4.1).
My
__init__()
ismy
reset()
:And my
step()
I have noticed that the order of which functions are called is important. In the
reset()
I need to set the integrator accuracy (or the minimum step size) AFTER setting the integrator method and before the initialize, otherwise the values wont take.In the
__init__
I have twoself.state = self.model.initSystem()
but I seem to need both for my model to launch, I encounter this error when removing either:Am I correctly setting up and resetting the environment? Is there a specific order that must be carried out?
For the
Manager
, what are the differences between the methods in terms of accuracy/speed/functionality. And what is the minimum steps an integrator can do? If I have:Will it integrate in 10 steps of size 0.001? This shows a massive speed up in the simulation, but does it remain accurate?