SITL Gazebo, Reset model using code
Hello, I am looking to reset the model position, I found that it is possible using the Edit panel in gazebo. I have tried to write several code to reset the mode automatically from the outside even being inspired by the source code of gazebo itself. However, the code I have written does not do anything. I do not know if you have an idea why it does not working. Should the code be implemented as a plugin?? or I missed something ?
/* C++ Standard library include */
# include <cstdlib>
# include <string>
# include <future>
# include <chrono>
# include <thread>
# include <vector>
/* locale defined include */
# include "gazebo.hh"
int main(int argc, char* argv[])
{
gazebo::transport::NodePtr node(new gazebo::transport::Node());
/* start resetting the world */
gazebo::transport::PublisherPtr reset_pub;
gazebo::transport::PublisherPtr userCmdPub;
node->Init("iris.world");
node->GetTopicNamespace();
// ~/world_control
reset_pub = node->Advertise<gazebo::msgs::WorldControl>("~/world_control");
userCmdPub = node->Advertise<gazebo::msgs::UserCmd>("~/user_cmd");
gazebo::msgs::WorldControl msg;
// w_ctrl.reset(); //->set_all(true); //I believe this is equal to indicating a world reset
msg.mutable_reset()->set_all(false);
msg.mutable_reset()->set_time_only(false);
msg.mutable_reset()->set_model_only(true);
gazebo::msgs::UserCmd userCmdMsg;
userCmdMsg.set_description("Reset models");
userCmdMsg.set_type(gazebo::msgs::UserCmd::WORLD_CONTROL);
userCmdMsg.mutable_world_control()->CopyFrom(msg);
userCmdPub->Publish(userCmdMsg);
reset_pub->Publish(msg);
}