Subscriber only receives data from connected publisher after 'ros2 topic echo <name_of_topic>'
Environment:
- ROS Galactic, built from source using instructions similar to https://docs.ros.org/en/galactic/Inst... (stopped after the 'Install dependencies using rosdep' sections, i.e. did NOT install additional DDS implementations)
- Lubuntu 20.04
- Additional repos of interest, also built from source:
- https://github.com/ros-perception/ima..., 'ros2' branch
- https://github.com/klintan/ros2_usb_c..., 'foxy-devel' branch
I have a couple of nodes, one of which publishes sensor_msgs::msg::Image data on a topic /smart_home/scc_image, the other subscribes to the data on this topic.
The publisher node is started with a custom launch file, which instantiates a node from the aforementioned ros2_usb_camera package (the topic remapping moves 'image' to 'scc_image', and 'sh_common_py' is a custom module):
from launch import LaunchDescription
from launch.actions import DeclareLaunchArgument, LogInfo, Shutdown
from launch.substitutions import LaunchConfiguration
from launch_ros.actions import Node
from ament_index_python.packages import get_package_share_directory
from os.path import join as ojoin
import sh_common_py
def generate_launch_description():
cfg = ojoin(
get_package_share_directory("sh_scc_image_stream"),
"config",
"params.yaml"
)
desc = LaunchDescription()
desc.add_action(DeclareLaunchArgument(
"camera_calibration_file",
default_value=""
))
desc.add_action(DeclareLaunchArgument(
"camera_id",
default_value="0"
))
desc.add_action(Node(
package="usb_camera_driver",
executable="usb_camera_driver_node",
name="sh_scc_image_stream",
namespace="/smart_home",
remappings=[("image", sh_common_py.topics.SCC_CAMERA_IMAGE)],
parameters=[
cfg,
{"camera_calibration_file": LaunchConfiguration("camera_calibration_file")},
{"camera_id": LaunchConfiguration("camera_id")},
],
on_exit=Shutdown(),
))
desc.add_action(LogInfo(msg=LaunchConfiguration("camera_calibration_file")))
desc.add_action(LogInfo(msg=LaunchConfiguration("camera_id")))
return desc
And this references a simple configuration file:
/smart_home:
sh_scc_image_stream:
ros__parameters:
frame_id: "sh_scc_image_stream_camera"
image_width: 3840
image_height: 2160
fps: 30.0
camera_id: 0
The subscriber node is from a custom package. The header declares the subscription as:
image_transport::Subscriber cap_image_raw_sub;
And is initialized in the source as:
cap_image_raw_sub = image_transport::create_subscription(
this,
::sh::names::topics::SCC_CAMERA_IMAGE,
std::bind(
&sh::ColorPeaksCalculatorNode::cap_image_raw_callback,
this,
std::placeholders::_1
),
"raw",
rmw_qos_profile_sensor_data
);
Where sh::ColorPeaksCalculatorNode::cap_image_raw_callback has the following signature:
void sh::ColorPeaksCalculatorNode::cap_image_raw_callback(const sensor_msgs::msg::Image::ConstSharedPtr& msg);
Running the full system, I can see that these two nodes connect to the same topic:
$ ros2 topic info /smart_home/scc_image --verbose
Type: sensor_msgs/msg/Image
Publisher count: 1
Node name: sh_scc_image_stream
Node namespace: /smart_home
Topic type: sensor_msgs/msg/Image
Endpoint type: PUBLISHER
GID: 56.8b.10.01.47.47.5d.07.f0.e5.e7.23.00.00.15.03.00.00.00.00.00.00.00.00
QoS profile:
Reliability: BEST_EFFORT
Durability: VOLATILE
Lifespan: 9223372036854775807 nanoseconds
Deadline: 9223372036854775807 nanoseconds
Liveliness: AUTOMATIC
Liveliness lease duration: 9223372036854775807 nanoseconds
Subscription count: 1
Node name: sh_color_peaks_calculator
Node namespace: /smart_home
Topic type: sensor_msgs/msg/Image
Endpoint type: SUBSCRIPTION
GID: 66.4f.10.01.3d.3e.6d.25.6a.9f.f5.fd.00.00.1a.04.00.00.00.00.00.00.00.00
QoS profile:
Reliability: BEST_EFFORT
Durability: VOLATILE
Lifespan: 9223372036854775807 nanoseconds
Deadline: 9223372036854775807 nanoseconds
Liveliness: AUTOMATIC
Liveliness lease duration: 9223372036854775807 nanoseconds
However, the subscriber node is not behaving like it is receiving data. But as soon as I run ros2 topic echo /smart_home/scc_image, both this and the subscriber node start receiving data. When I terminate the echo command, the subscriber node continues to receive data as expected. Output I receive with ros2 topic echo /smart_home ...