Cannot connect to gazebo API topics if i run a gazebo server using roslaunch.

asked 2018-11-07 05:26:03 -0500

Solrac3589 gravatar image

updated 2018-11-07 06:29:31 -0500

Hello everybody. I have been stucked for a day on that and i do not find the solution to this problem.

I am just trying to do a mix between the clone simulation tutorial ( ) and a empty_world.launch simulation.

First of all, I am using ROS Kinetic and Gazebo 7.0

in clone.cpp I have commented the server run lines:

std::thread serverThread(RunServer);



Instead of running like this way the server, i just added the cpp code inside a launch copy of empty_world. adding the following line:

  <node name="clone_node" pkg="ros_trial" type="cloner" output="screen" />

(just to be clear, CMakeLists.txt and package.xml are correctly configured

When I do a roslaunch, everyting seems to work, but the api message /gazebo/server/control is not published.

I have check if the channel exists with gz topic -l (and exists) but if i do gz topic -e /gazebo/server/control nothing appears.

The reason why i want to do this is because I want to clone a simulation several time and run them simoultaneously in order to reduce training time. The simulation which i want to run uses gazebo_msgs topics like gazebo_msgs::SpawnModel which does not exists woithout ROS (and I did not found any substitute).

I do not know if I have been clear, (sorry if not!) in which case just ask me. Any help will be appreciated.


EDIT: I add the code to be more clear.


#include <cstdlib>

#include <iostream>
#include <memory>
#include <thread>
#include <gazebo/gazebo.hh>
#include <gazebo/msgs/msgs.hh>
#include <gazebo/transport/transport.hh>

#include <fstream>
#include <string>

#include <ros/ros.h>
#include <ros/package.h>
#include <geometry_msgs/Quaternion.h>
#include <geometry_msgs/PoseArray.h>
#include <geometry_msgs/Inertia.h>
#include <std_srvs/Empty.h>
#include <std_srvs/Trigger.h>

#include <urdf/model.h>
#include <urdf_parser/urdf_parser.h>
#include <collada_urdf/collada_urdf.h>

#include <gazebo_msgs/SpawnModel.h>
#include <gazebo_msgs/DeleteModel.h>
#include <gazebo_msgs/SetModelState.h>
#include <gazebo_msgs/GetModelState.h>

#include <actionlib/server/simple_action_server.h>

std::mutex feedback_mutex__;
std::vector<std::shared_ptr<std::thread>> clone_thread_ptr_vector__;
std::vector<char*> __environments;
void OnWorldModify(ConstWorldModifyPtr &_msg)
    std::cout << "inside on world modify function" << std::endl;
  if (_msg->has_cloned() && _msg->cloned() && _msg->has_cloned_uri())
    std::cout << "World cloned. You can connect a client by typing\n"
              << "\tGAZEBO_MASTER_URI=" << _msg->cloned_uri()
              << " gzclient" << std::endl;
    char uri = *_msg->cloned_uri().c_str();
      std::cout << "ERROR 1" << std::endl;

void RunServer()
  // Initialize gazebo server.
    std::cout << "inside run server function" << std::endl;
  std::unique_ptr<gazebo::Server> server(new gazebo::Server());
    if (!server->ParseArgs(0, NULL))

    // Initialize the informational logger. This will log warnings, and errors.
    gzLogInit("server-", "gzserver.log");

  catch(gazebo::common::Exception &_e)
      std::cout << "ERROR 2" << std::endl;

int port_ = 11346;
char* __master = getenv("ROS_MASTER_URI");

void GenerateClone(gazebo::transport::PublisherPtr serverControlPub )
  std::cout << "inside GenerateClone" << std::endl;
  gazebo::msgs::ServerControl msg;

  std::cout ...
edit retag flag offensive close merge delete


I am not going to post this as a solution, because it is not, but I am working through a workaround (if somebody has this problem). I am adapting the code to work only with the API topics from Gazebo (non-ROS ones). Disabling the gzserver generation from the launcher and generating it in the code.

Solrac3589 gravatar image Solrac3589  ( 2018-11-08 02:11:37 -0500 )edit