ROS node from Gazebo plugin is not showing in the rosnode list
I want to publish some topics from a Gazebo model plugin to the ROS topic, so I use the C++ ROS node initiation code from some example that I now only copy-paste to all plugins I need.
// Initialize ros, if it has not already been initialized.
std::string node_name = std::string("my_node_name");
if (!ros::isInitialized()) {
int argc = 0;
char **argv = nullptr;
ros::init(argc, argv, node_name. ros::init_options::NoSigintHandler);
}
// Create ROS node.
this->rosNode.reset(new ros::NodeHandle(node_name));
topic_name = "/my_topic";
this->rosPublisher = this->rosNode->advertise<std_msgs::Float64>(topic_name, 1);
The /my_topic
topic is registered (I can see it in the rostopic list
), I publish to the topic messages on every update (I debugged that the code is being executed, so the messages are being send in the plugin) but when I use rostopic echo /my_node
nothing is being printed.
Also using rosnode list
shows me no /my_node_name
node. I'm thinking the node either isn't created at all, or shuts down. I don't know. How can I check for that, or launch the node correctly, or what else could be going wrong?