mit-biomimetics / Cheetah-Software

MIT License
2.62k stars 929 forks source link

Can the full state of the simulator be saved/loaded? #30

Open bayerj opened 4 years ago

bayerj commented 4 years ago

Assume I am running a simulation. Is it possible to "save" the full state of the simulation, continue with it, and then "load" the previous state to return back to it?

Saving is fine if it happens in memory, but writing it to disk would be preferable.

qiayuanl commented 4 years ago

Yes, and it's easy to implement. Class DynamicsSimulator provided

  void setState(const FBModelState<T> &state) {
    _state = state;
    _model.setState(state);  // force recalculate dynamics
  }

  const FBModelState<T> &getState() const { return _state; }

You can record the state in Class Simulation which contained a DynamicsSimulator member by using getState and return back by setState. You can have a look the rm_suspension which using the same floating base dynamics and program architecture. It computes all states of the robot in simulation time and record, before replays the states.