Doesn't get robots /scan events

asked 2019-03-20 14:53:02 -0500

moni213 gravatar image

updated 2019-03-21 14:44:41 -0500

allenh1 gravatar image

I'm trying to get robot /scan events notification. This works for me:

// Subscribe to the simulated robot's laser scan topic
laserSub = nh.subscribe("/scan", 1, &MyObject::scanCallback, this);

But when I change the topic to my_robot_name/scan, it doesn't work: I don't get any robot scan notification to my callback.

// Subscribe to the simulated robot's laser scan topic
laserSub = nh.subscribe(my_robot_name + "/scan", 1, &MyObject::scanCallback, this);

I run "rostopic info my_robot_name/scan", and it looks that no publisher to my_robot_name/scan at all.

How can I solve this? Thanks in advance.

Launch file:

<?xml version="1.0"?>
    <param name="/use_sim_time" value="true" />  
    <arg name="robot_name" default="robot1"/>

    <!-- Launch the turtle bot world -->
    <include file="$(find turtlebot_gazebo)/launch/turtlebot_world.launch">      
        <arg name="world_file" value="$(find turtlebot_gazebo)/worlds/"/>

    <!-- Launch stopper node -->
    <node name="stopper" pkg="stopper" type="stopper" output="screen" args="$(arg robot_name)">
    <remap from="/scan" to="$(arg robot_name)/scan"/>
    <remap from="/cmd_vel_mux/input/teleop" to="$(arg robot_name)/cmd_vel_mux/input/teleop"/>
edit retag flag offensive close merge delete


We're gonna need a bit more info. What node is publishing the /scan topic?

allenh1 gravatar image allenh1  ( 2019-03-20 15:36:54 -0500 )edit

I'm running the gazebo, so /laserscan_nodelet_manager should publish the messages to my node the subscriber to its events. When my subscriber topic is just "/scan", everything works well. However, when I changed the topic to be my_robot_name + "scan", I have no publisher but just my subscriber as previous. Thank you.

moni213 gravatar image moni213  ( 2019-03-20 15:48:05 -0500 )edit

@moni213 the reason you don't have the topic is because you changed your subscriber's target to be "my_robot_name + 'scan'", as opposed to the publisher's topic name. You likely need to add a <remap from=”scan” to=”$(arg scan_topic)”/> to your <node/> section of the launch file you are using (feel free to update your question with aforementioned launch file for me to be more specific).

allenh1 gravatar image allenh1  ( 2019-03-20 16:02:11 -0500 )edit

@allenh1 I tried to use "remap", as you suggested but it still doesn't work. I still have no publisher to "my_robot_name/scan" but only to "/scan". Subscriber I have in both cases. Here is my updated launch file and my definitions: link text. Do you know what the problem is? Thank you

moni213 gravatar image moni213  ( 2019-03-20 21:08:16 -0500 )edit

@moni213 please update your question with a copy and paste of the files instead of using a link to a paste bin. This will keep the question self-contained should that link go bad.

jayess gravatar image jayess  ( 2019-03-21 03:39:58 -0500 )edit