diff --git a/hebiros_gazebo_plugin/include/hebiros_gazebo_plugin.h b/hebiros_gazebo_plugin/include/hebiros_gazebo_plugin.h index 538c89a..aa0296e 100644 --- a/hebiros_gazebo_plugin/include/hebiros_gazebo_plugin.h +++ b/hebiros_gazebo_plugin/include/hebiros_gazebo_plugin.h @@ -34,6 +34,7 @@ class HebirosGazeboPlugin: public ModelPlugin { private: physics::ModelPtr model; + bool first_sim_iteration{true}; event::ConnectionPtr update_connection; std::map> hebiros_groups; std::map> hebiros_joints; diff --git a/hebiros_gazebo_plugin/plugin/hebiros_gazebo_plugin.cpp b/hebiros_gazebo_plugin/plugin/hebiros_gazebo_plugin.cpp index 6e9f396..983374f 100644 --- a/hebiros_gazebo_plugin/plugin/hebiros_gazebo_plugin.cpp +++ b/hebiros_gazebo_plugin/plugin/hebiros_gazebo_plugin.cpp @@ -8,11 +8,6 @@ void HebirosGazeboPlugin::Load(physics::ModelPtr _model, sdf::ElementPtr _sdf) { char **argv = NULL; ros::init(argc, argv, "hebiros_gazebo_plugin_node"); - this->add_group_srv = - this->n->advertiseService( - "hebiros_gazebo_plugin/add_group", boost::bind( - &HebirosGazeboPlugin::SrvAddGroup, this, _1, _2)); - this->robot_namespace = ""; if (_sdf->HasElement("robotNamespace")) { this->robot_namespace = _sdf->GetElement("robotNamespace")->Get(); @@ -31,6 +26,15 @@ void HebirosGazeboPlugin::Load(physics::ModelPtr _model, sdf::ElementPtr _sdf) { //Update the joints at every simulation iteration void HebirosGazeboPlugin::OnUpdate(const common::UpdateInfo & _info) { + + if (this->first_sim_iteration) { + this->first_sim_iteration = false; + this->add_group_srv = + this->n->advertiseService( + "/hebiros_gazebo_plugin/add_group", boost::bind( + &HebirosGazeboPlugin::SrvAddGroup, this, _1, _2)); + } + ros::Time current_time = ros::Time::now(); for (auto group_pair : hebiros_groups) {