pygazebo icon indicating copy to clipboard operation
pygazebo copied to clipboard

Cannot get LaserScanStamped range values

Open pirobot opened this issue 7 years ago • 0 comments

I am using the develop branch and I'm trying to get the range values from a laser scanner sensor in Gazebo 2.3. The laser is defined in my model SDF using the libgazebo_ros_laser.so plugin and the scan appears fine in the Gazebo GUI as well as in the Topic Visualization.

When I run the following code, the range array always appears empty (prints out as []) whereas I expected to see the actual ranges. The header and scan fields of the message print fine so I know the callback is receiving the messages.

Here now is the code:

import trollius
from trollius import From

import pygazebo
import pygazebo.msg.laserscan_stamped_pb2

@trollius.coroutine
def publish_loop():
    manager = yield From(pygazebo.connect()) 

    def callback_lidar(data):
        message = pygazebo.msg.laserscan_stamped_pb2.LaserScanStamped.FromString(data)
        print message.scan.ranges

    subscriber = manager.subscribe('/gazebo/default/person_walking_lidar/lidar_link/laser/scan',
                     'gazebo.msgs.LaserScanStamped',
                     callback_lidar)

    yield From(subscriber.wait_for_connection())
    while(True):
        yield From(trollius.sleep(0.1))
        print('wait...')
    print(dir(manager))

import logging

logging.basicConfig()

loop = trollius.get_event_loop()
loop.run_until_complete(publish_loop())

pirobot avatar Jan 05 '18 21:01 pirobot