Skip to content

Cannot reproduce the forward dynamics results output from CMC tool. #4237

@Nino-LFC

Description

@Nino-LFC

Description

Dear opensim developer,
I hope you're enjoying a nice day today!
I have encountered an issue where the joint position results from the forward dynamics simulated inside CMC differ from the joint position results from running a standalone Forward Dynamics simulation using the control signals computed by CMC.

My workflow

  1. Provide a desired joint trajectory (q_desired.sto) to CMC.
  2. CMC produces states (CMC_states.sto) and controls (CMC_controls.xml), and also stores a forward-simulated trajectory during its internal integration (CMC_q.sto).
  3. Then run a standalone Forward Dynamics in OpenSim using CMC_states.sto as the initial state and CMC_controls.xml as the controls, producing q_fd.sto.

OpenSim version: 4.5

I have confirmed the following:

  • No reserve actuators are used.
  • Integrator type is the same (Runge–Kutta–Merson).
  • Min/max step sizes and tolerances are configured to be the same in both setup files.

Observations

CMC_q.sto matches well with q_desired.sto, as expected. However, unexpectedly, CMC_q.sto and q_fd.sto do not match; after some time the trajectories clearly diverge.

The blue line as shown in the figure below represent the joint position trajectory stored in the forward dynamics results of CMC and the red line represents the joint position trajectory results of the standalone forward dynamics.

Image

Other tries

Experiment1

The results described above are run CMC with GUI, I also tried to compile the source codes in C++ and run the experiments by setting the integration step size to be fixed by putting the code below

std::cout << "set the integrator to be fixed step size." << std::endl;
const double fixedDt = 0.001;
manager.setIntegratorFixedStepSize(fixedDt);

before calling manager.integrate() in CMCTool.cpp and ForwardTool.cpp to make sure the integrator to use the fixed step size, however, divergence also happens.

Experiment2

I also tried specifying the use_specified_dt to be true in the forward dynamics set_up file, no matter how I debugged and changed the states file and controls file according to the forum discussion, if this flag is set to be true, it will only integrate one step.

Questions

  1. Will the divergence be unavoidable in my experiments, if so, which could be the biggest factor resulting in this divergence?
  2. I compared the initial states used in both cases and only observed a very small difference in the initial joint velocity, on the order of 1e-8, which may be caused by some dynamics projection function in the first step of forward dynamics. But due to the error is so small, so maybe the difference in initial states would not contribute too much to the divergence?
  3. Is there any difference between the control signals used in CMC's forward dynamics and the standalone forward dynamics? I think in CMC, the control signals will be hold in the time interval of cmc look_ahead window, however, I am not sure whether in the standalone forward dynamics which used the control signals defined by ControllinearNode, will the control signals be interpolated when it uses Runger-Kutta-Merson methon when calling neural exciations at t0+h/2 or t0+h/3.

If you have any guidance on what mechanisms in CMC commonly lead to this kind of mismatch—or what settings/logs you would recommend to verify equivalence between the two forward simulations—I would greatly appreciate it.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions