From 15fa86727f197bd3591524453a19b01a47732b72 Mon Sep 17 00:00:00 2001 From: Arjo Chakravarty Date: Wed, 8 Jan 2025 20:01:28 +0800 Subject: [PATCH] Add support for individual resets Signed-off-by: Arjo Chakravarty --- include/gz/sim/Server.hh | 4 ++++ python/src/gz/sim/Server.cc | 4 +++- src/Server.cc | 11 +++++++++++ 3 files changed, 18 insertions(+), 1 deletion(-) diff --git a/include/gz/sim/Server.hh b/include/gz/sim/Server.hh index ae49bd59f6..9867ca68d7 100644 --- a/include/gz/sim/Server.hh +++ b/include/gz/sim/Server.hh @@ -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 dataPtr; diff --git a/python/src/gz/sim/Server.cc b/python/src/gz/sim/Server.cc index 7ece7ec090..b5688ece9b 100644 --- a/python/src/gz/sim/Server.cc +++ b/python/src/gz/sim/Server.cc @@ -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 diff --git a/src/Server.cc b/src/Server.cc index 602eb1e569..25497fa960 100644 --- a/src/Server.cc +++ b/src/Server.cc @@ -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() {