# Subscriber isn't reading anything from LaserScan topic

**URL:** <https://get-help.theconstruct.ai/t/subscriber-isnt-reading-anything-from-laserscan-topic/38201>\
**Category:** ROS Basics In 5 Days (Python)\
**Tags:** quiz\
**Created:** [September 23, 2025, 1:15pm UTC](https://get-help.theconstruct.ai/t/subscriber-isnt-reading-anything-from-laserscan-topic/38201 "2025-09-23T13:15:19Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![kc2023](https://get-help.theconstruct.ai/user_avatar/get-help.theconstruct.ai/kc2023/32/10078_2.png) [@kc2023](https://get-help.theconstruct.ai/u/kc2023)\
**Post date:** [September 23, 2025, 1:15pm UTC](https://get-help.theconstruct.ai/t/subscriber-isnt-reading-anything-from-laserscan-topic/38201/1 "2025-09-23T13:15:19Z")

</div>

Hi, I’m a little confused as to where I’m going wrong with the Topics Quiz.

I’ve only gotten the robot to move and turn left for now, but I think I’m not actually using the data from the subscriber? When I do rostopic echo /kobuki/laser/scan, nothing is returned.

Can someone check my code and see where I’m going wrong or what I’ve misunderstood about the quiz? My launcher is defined correctly.

```auto
#! /usr/bin/env python

import rospy
from geometry_msgs.msg import Twist
from sensor_msgs.msg import LaserScan

rospy.init_node('tp')
pub = rospy.Publisher('/cmd_vel', Twist, queue_size=1)                                           
rate = rospy.Rate(2)
move = Twist()

#function that recieves parameter msg and prints data in msg
def callback(msg):
    a = msg.ranges[360]
    print(a)
    if a > 1 :
        move.linear.x = 0.5
        move.angular.z = 0
    elif a < 1:
        move.angular.z = 0.5
        move.linear.x = 0

#sub object listens to topic and calls callback every time it reads
sub = rospy.Subscriber('/kobuki/laser/scan', LaserScan, callback)

while not rospy.is_shutdown():
  # Publish the message
  pub.publish(move)
  # Make sure the publish rate maintains at 2 Hz
  rate.sleep()

```

Thank you!

---

<div class="post-metadata">

**Author:** ![duckfrost2](https://get-help.theconstruct.ai/user_avatar/get-help.theconstruct.ai/duckfrost2/32/9365_2.png) [@duckfrost2](https://get-help.theconstruct.ai/u/duckfrost2)\
**Post date:** [September 24, 2025, 7:55am UTC](https://get-help.theconstruct.ai/t/subscriber-isnt-reading-anything-from-laserscan-topic/38201/2 "2025-09-24T07:55:03Z")

</div>

Hi,

Try it with “rospy.spin()” instead of the while loop first.

Also , everytime you have ssieus with topics, check with the rostopic echo /topic, that the messages are arriving, then try it in the python script, just in case the robot for some reason is not publishing or you are subscribed to the wrong topic

---

<div class="post-metadata">

**Author:** ![kc2023](https://get-help.theconstruct.ai/user_avatar/get-help.theconstruct.ai/kc2023/32/10078_2.png) [@kc2023](https://get-help.theconstruct.ai/u/kc2023)\
**Post date:** [September 25, 2025, 8:00am UTC](https://get-help.theconstruct.ai/t/subscriber-isnt-reading-anything-from-laserscan-topic/38201/3 "2025-09-25T08:00:51Z")

</div>

rospy.spin() fixed my issue. thanks!

---

<div class="post-metadata">

**Author:** ![system](https://get-help.theconstruct.ai/uploads/default/original/2X/9/9d3ce8305cc0d0d9b6e07d15767a6f245c526f1b.jpeg) [@system](https://get-help.theconstruct.ai/u/system)\
**Post date:** [September 30, 2025, 8:01am UTC](https://get-help.theconstruct.ai/t/subscriber-isnt-reading-anything-from-laserscan-topic/38201/4 "2025-09-30T08:01:01Z")

</div>

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.
