Gazebo | Ignition | Community
Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Not receiving messages in ros2 while subscribing to topic from Gazebo 11 plugin demo world

Problem

Starting a demo world in Gazebo 11 by using

gazebo --verbose /opt/ros/foxy/share/gazebo_plugins/worlds/gazebo_ros_depth_camera_demo.world

causes all topics to appear as expected when checking with ros2 command line tools. Even when echoing the topics I can see the messages containing actual, seemingly plausible data.

When using a custom written script (C++, see below) to subscribe to the topics, only some of the topics published by the demo worlds are actually received. The subscription process works correctly, at least the subscriber count of each topic increases when starting the script. But receiving a message/invoking the callback function works only on few topics.

Specifically the topics /demo_cam/mycamera/depth_cam_info_demo and /demo_cam/mycamera/raw_cam_info_demo, both of type sensor_msgs/msg/CameraInfo, show different behaviour. Subscription to both works, but only ever the depth_cam.. topic triggers callbacks (regardless of which subscriber in the code is set to it, even both at the same time work).

I encountered this problem while running a custom .sdf model that publishes a pointcloud2 by using the libgazebo_ros_ray_sensor.so plugin. Using the cli tool the messages appear to be plausible and containing data. But when trying to visualize it in rviz2, it does not show, but also does not throw any errors (neither tf nor topic errors). Triggering the callback for this topic in a custom script does not work either.

Is it likely that these discrepancies between topics of the same type are caused by configurations on my system? Would Gazebo 11 from source be a better option? Any ideas how I could investigate this problem further, since I do not know if it is related to ros2, gazebo, or some middle ware communication? Thanks for any helpful tips.

Setup

  • Ubuntu 20.04
  • ros2 foxy installed as package ros-foxy-desktop
  • gazebo 11 installed as package ros-foxy-gazebo-ros-pkgs
  • script to test whether messages are received (compiled in a colcon workspace):

```

#include <functional>
#include <memory>
#include <string>
#include "rclcpp/rclcpp.hpp"
#include "std_msgs/msg/string.hpp"
#include "std_msgs/msg/float32.hpp"
#include "sensor_msgs/msg/point_cloud2.hpp"
#include "sensor_msgs/msg/camera_info.hpp"
#include "sensor_msgs/msg/image.hpp"
#include "nav_msgs/msg/odometry.hpp"
#include "gazebo_msgs/msg/contacts_state.hpp"

/*
working topics so far:
/odom - odometry (ackerman, diff drive)
/distance - float32 (ackerman)
/depth_cam_info_demo - sensor/CameraInfo (depth cam demo)
/points_demo - PointCloud2 (depth cam demo)

not working topics:
/bumper_demo - gazebo_msgs/contactsstate (bumper demo)
/pointcloud2 - pointcloud2 (sensor in sdf model)
/camera_info - sensor/CameraInfo (cam demo)
/image_raw - sensor/Image (cam demo)
/raw_cam_info_demo - sensor/CameraInfo (depth cam demo)
/image_demo - sensor/Image (depth cam demo)
/depth_demo - sensor/Image (depth cam demo)
*/

typedef sensor_msgs::msg::CameraInfo custom_type_one;
typedef sensor_msgs::msg::CameraInfo custom_type_two;
const std::string topic_one = "demo_cam/mycamera/depth_cam_info_demo";
const std::string topic_two = "demo_cam/mycamera/raw_cam_info_demo";
using std::placeholders::_1;

class ReBroadcaster : public rclcpp::Node
{
public:
ReBroadcaster() : Node("rebroadcaster"), count_(0)
{   
subscription_ = this->create_subscription<custom_type_one>(topic_one, 10, 
std::bind(&ReBroadcaster::topic_callback_one, this, _1));
subscription_two = this->create_subscription<custom_type_two>(topic_two, 10, 
std::bind(&ReBroadcaster::topic_callback_two, this, _1));
RCLCPP_INFO(this->get_logger(), "Constructed subscribers!");
}
private:
void topic_callback_one(const custom_type_one::SharedPtr msg) const
{
const custom_type_one::SharedPtr a = msg;  // just so there is no unused var warning
RCLCPP_INFO(this->get_logger(), "Got one!");
}
void topic_callback_two(const custom_type_one::SharedPtr msg) const
{
const custom_type_two::SharedPtr a = msg;  // just so there is no unused var warning
RCLCPP_INFO(this->get_logger(), "Got ---TWO!");
}
size_t count_;
rclcpp::Subscription<custom_type_one>::SharedPtr subscription_;
rclcpp::Subscription<custom_type_two>::SharedPtr subscription_two;
}; // end of class

int main(int argc, char * argv[])
{
rclcpp::init(argc, argv);
rclcpp::spin(std::make_shared<ReBroadcaster>());
rclcpp::shutdown();
return 0;
}

```

Not receiving messages in ros2 while subscribing to topic from Gazebo 11 plugin demo world

Problem

Starting a demo world in Gazebo 11 by using

gazebo --verbose /opt/ros/foxy/share/gazebo_plugins/worlds/gazebo_ros_depth_camera_demo.world

causes all topics to appear as expected when checking with ros2 command line tools. Even when echoing the topics I can see the messages containing actual, seemingly plausible data.

When However, when using a custom written script (C++, see below) to subscribe to the topics, only some of the topics published by the demo worlds are actually received. The subscription process works correctly, at least the subscriber count of each topic increases when starting the script. But receiving a message/invoking the callback function works only on few topics.

Specifically the topics /demo_cam/mycamera/depth_cam_info_demo and /demo_cam/mycamera/raw_cam_info_demo, both of type sensor_msgs/msg/CameraInfo, show different behaviour. Subscription to both works, but only ever the depth_cam.. topic triggers callbacks (regardless of which subscriber in the code is set to it, even both at the same time work).

I encountered this problem while running a custom .sdf model that publishes a pointcloud2 by using the libgazebo_ros_ray_sensor.so plugin. Using the cli tool the messages appear to be plausible and containing data. But when trying to visualize it in rviz2, it does not show, but also does not throw any errors (neither tf nor topic errors). Triggering the callback for this topic in a custom script does not work either.

Is it likely that these discrepancies between topics of the same type are caused by configurations on my system? Would Gazebo 11 from source be a better option? Any ideas how I could investigate this problem further, since I do not know if it is related to ros2, gazebo, or some middle ware communication? Thanks for any helpful tips.

Edit: Apparently another user experiences same symptoms with /imu messages published by a gazebo model and asked a question over at ros forum. But I am not sure whether these issues are caused by ros or gazebo.

Setup

  • Ubuntu 20.04
  • ros2 foxy installed as package ros-foxy-desktop
  • gazebo 11 installed as package ros-foxy-gazebo-ros-pkgs
  • script to test whether messages are received (compiled in a colcon workspace):

```

#include <functional>
#include <memory>
#include <string>
#include "rclcpp/rclcpp.hpp"
#include "std_msgs/msg/string.hpp"
#include "std_msgs/msg/float32.hpp"
#include "sensor_msgs/msg/point_cloud2.hpp"
#include "sensor_msgs/msg/camera_info.hpp"
#include "sensor_msgs/msg/image.hpp"
#include "nav_msgs/msg/odometry.hpp"
#include "gazebo_msgs/msg/contacts_state.hpp"

/*
working topics so far:
/odom - odometry (ackerman, diff drive)
/distance - float32 (ackerman)
/depth_cam_info_demo - sensor/CameraInfo (depth cam demo)
/points_demo - PointCloud2 (depth cam demo)

not working topics:
/bumper_demo - gazebo_msgs/contactsstate (bumper demo)
/pointcloud2 - pointcloud2 (sensor in sdf model)
/camera_info - sensor/CameraInfo (cam demo)
/image_raw - sensor/Image (cam demo)
/raw_cam_info_demo - sensor/CameraInfo (depth cam demo)
/image_demo - sensor/Image (depth cam demo)
/depth_demo - sensor/Image (depth cam demo)
*/

typedef sensor_msgs::msg::CameraInfo custom_type_one;
typedef sensor_msgs::msg::CameraInfo custom_type_two;
const std::string topic_one = "demo_cam/mycamera/depth_cam_info_demo";
const std::string topic_two = "demo_cam/mycamera/raw_cam_info_demo";
using std::placeholders::_1;

class ReBroadcaster : public rclcpp::Node
{
public:
ReBroadcaster() : Node("rebroadcaster"), count_(0)
{   
subscription_ = this->create_subscription<custom_type_one>(topic_one, 10, 
std::bind(&ReBroadcaster::topic_callback_one, this, _1));
subscription_two = this->create_subscription<custom_type_two>(topic_two, 10, 
std::bind(&ReBroadcaster::topic_callback_two, this, _1));
RCLCPP_INFO(this->get_logger(), "Constructed subscribers!");
}
private:
void topic_callback_one(const custom_type_one::SharedPtr msg) const
{
const custom_type_one::SharedPtr a = msg;  // just so there is no unused var warning
RCLCPP_INFO(this->get_logger(), "Got one!");
}
void topic_callback_two(const custom_type_one::SharedPtr msg) const
{
const custom_type_two::SharedPtr a = msg;  // just so there is no unused var warning
RCLCPP_INFO(this->get_logger(), "Got ---TWO!");
}
size_t count_;
rclcpp::Subscription<custom_type_one>::SharedPtr subscription_;
rclcpp::Subscription<custom_type_two>::SharedPtr subscription_two;
}; // end of class

int main(int argc, char * argv[])
{
rclcpp::init(argc, argv);
rclcpp::spin(std::make_shared<ReBroadcaster>());
rclcpp::shutdown();
return 0;
}

```