robopeak / rplidar_ros

BSD 2-Clause "Simplified" License
453 stars 370 forks source link

Read LaserScan msg #81

Closed ShettyHarapanahalli closed 5 years ago

ShettyHarapanahalli commented 6 years ago

Hi,

I am trying to read the Laser Scan messages from the program, but fails to print the message. Below is mt code used -
`#! /usr/bin/env python

import rospy from sensor_msgs.msg import LaserScan

def callback(msg):

values at 0 degree

print(msg.ranges[0])
# values at 90 degree
print msg.ranges[360]
# values at 180 degree
print msg.ranges[719]

rospy.init_node('lidar') sub = rospy.Subscriber('sensor_msgs/LaserScan', LaserScan, callback) rospy.spin()`

command rosnode list indicates gives the below list of nodes - /lidar /record_1542883733941723041 /rosout /rplidarNode

rqt_graph command indicates that the lidar node is not Rx the Scan messages.

What am i missing something to read the LaserScan messages.

ShettyHarapanahalli commented 6 years ago

Well my ROS topic was scan and i was not using it correctly. Update the below line and it worked - sub = rospy.Subscriber('scan', LaserScan, callback)