I am working on a reinforcement learning environment for a robot using gz-sim8
, and I am trying to implement the reset functionality. I would like to call my resets with a ResetSim()
function, as seen here. I am currently trying to call a reset similar to the GUI's reset button with the gz.msgs.WorldControl
service call to /world/<world_name>/control
. Seeing the reset button work in my gui when I run gz sim empty.world
makes me believe I can reset the simulation with service calls, as seen with my code:
void TrainSimulator::ResetSim(){
gz::transport::Node node;
// Create a message to reset the world
gz::msgs::WorldControl req;
req.mutable_reset()->set_all(true); // Reset everything
gz::msgs::Boolean rep;
std::string service = "/world/empty/control";
bool result = false;
unsigned int timeout = 5000; // Timeout in milliseconds
// Request reset through the transport node
bool success = node.Request(service, req, timeout, rep, result);
if (!success || !result || !rep.data()) {
std::cerr << "Failed to reset the world using transport service." << std::endl;
} else {
std::cout << "World reset successfully through transport service." << std::endl;
}
}
Unfortunately, I get a warning in terminal that prints 3 times:
[Wrn] [SystemManager.cc:185] In-memory without ISystemReset detected: []
Systems created without plugins that do not implement Reset will not be reloaded. Reset may not work correctly
Then I get a Segmentation fault (Core dumped)
. I have 3 plugins loaded by my gz::sim::Server
object, and I wonder if I have to remember to implement an ISystemReset
for each...would It just be like the ISystemConfigure
call I created?
Alternatives
I have tried resetting my simulation by resetting the robot's pose by setting gz::sim::components::WorldPoseCmd
to an initial pose, setting the JointPositionReset
, JointVelocityReset
, JointForceCmd
components to zero, and setting the AngularAcceleration
, LinearAcceleration
components of the model to zero. Calling this implementation of ResetSim()
would make my sdf model move in erratic ways, so I tried setting AngularVelocityCmd
and LinearVelocityCmd
to zero to keep the robot from moving randomly, but the robot would just freeze in mid air while the simulation would run.
I am wondering what I would need to do to be able to reset my robot properly, similar to how pybullet has its restoreState()
function where you can reset the world to a state that you save.