mujoco_mpc
mujoco_mpc copied to clipboard
Proposal: ComposeOverrideModel() in Task to allow programmingly constructed model building using mjSpec API
Hi MuJoCo team & everyone,
-
Given the current state that, MjMPC could not be easily updated to using the latest mujoco + menagerie repos, largely due to manually crafted XML patches for tasks, it would be nice to allow custom model building per task using mjSpec API
-
An example implementation for that could be as follows: In
Taskclass:
// Compose & configue override model
UniqueMjModel ComposeOverrideModel() {
mjModel* model = ConstructModel();
model_programmingly_built_ = static_cast<bool>(model);
if (model) {
ConfigureModel(model);
return {model, mj_deleteModel};
}
return {nullptr, nullptr};
}
// Programmingly construct model
virtual mjModel* ConstructModel() {
// Construct model from either or both of pre-created XML & mjSpec API
return nullptr;
}
// Customizingly configure model options (timestep, gravity, etc.)
virtual void ConfigureModel(mjModel* model) {
}
agent.h:
// Currently selected task on GUI
Task* GuiTask() const { return tasks_[gui_task_id].get(); }
app.cc:
mjModel* LoadModel(const mjpc::Agent* agent, mj::Simulate& sim) {
// Set sim.agent's [model_override_] from task, but only if not already provided
if (nullptr == sim.agent->GetOverrideModel()) {
sim.agent->OverrideModel(sim.agent->GuiTask()->ComposeOverrideModel());
}
// Then load the model
mjpc::Agent::LoadModelResult load_model = sim.agent->LoadModel();
...
}
Would love to hear your thoughts! Thanks