Skip to content

Commit

Permalink
Add support for individual resets
Browse files Browse the repository at this point in the history
Signed-off-by: Arjo Chakravarty <arjoc@intrinsic.ai>
  • Loading branch information
arjo129 committed Jan 8, 2025
1 parent 35eca3e commit 15fa867
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 1 deletion.
4 changes: 4 additions & 0 deletions include/gz/sim/Server.hh
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,10 @@ namespace gz

/// \brief Reset all runners in this simulation
public: void ResetAll();
/// \brief Reset a specific runner in this server
/// \param[in] runnerId - The runner which you want to reset
/// \ return False if the runner does not exist, true otherwise.
public: bool Reset(const std::size_t _runnerId);

/// \brief Private data
private: std::unique_ptr<ServerPrivate> dataPtr;
Expand Down
4 changes: 3 additions & 1 deletion python/src/gz/sim/Server.cc
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,9 @@ void defineSimServer(pybind11::object module)
pybind11::overload_cast<>(&gz::sim::Server::Running, pybind11::const_),
"Get whether the server is running.")
.def("reset_all", &gz::sim::Server::ResetAll,
"Resets all simulation runners under this server.");
"Resets all simulation runners under this server.")
.def("reset", &gz::sim::Server::Reset,
"Resets a specific simulation runner under this server.");
}
} // namespace python
} // namespace sim
Expand Down
11 changes: 11 additions & 0 deletions src/Server.cc
Original file line number Diff line number Diff line change
Expand Up @@ -496,6 +496,17 @@ void Server::ResetAll()
}
}

//////////////////////////////////////////////////
bool Server::Reset(const std::size_t _runnerId)
{
if (_runnerId >= this->dataPtr->simRunners.size())
{
return false;
}
this->dataPtr->simRunners[_runnerId]->Reset(true, false, false);
return true;
}

//////////////////////////////////////////////////
void Server::Stop()
{
Expand Down

0 comments on commit 15fa867

Please sign in to comment.