-
Notifications
You must be signed in to change notification settings - Fork 437
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Unable to read LaserScan message from /scan #85
Comments
I'm not seeing any data on the /scan topic either. @sgawalsh - do you see anything when you run 'ros2 topic echo /scan' |
I remember testing that at the time, and as I recall the LaserScan message was displayed as expected when running |
@sgawalsh
I've attached reference about QoS Settings. |
My issue is this one: This means a change is needed in the turtlebot3 model files to match the new argument style. |
What should be the quality of service to listen to |
I'm haiving the same issue - |
docs for and for setting QoS: ROS2 docs: QoSProfile import rclpy
from rclpy.node import Node
from rclpy.qos import ReliabilityPolicy, QoSProfile
from std_msgs.msg import String
from sensor_msgs.msg import LaserScan
class MinimalSubscriber(Node):
def __init__(self):
super().__init__('minimal_subscriber')
self.subscription = self.create_subscription(
LaserScan,
'scan',
self.listener_callback,
QoSProfile(depth=10, reliability=ReliabilityPolicy.BEST_EFFORT))
self.subscription # prevent unused variable warning
def listener_callback(self, msg):
dist_back = format(msg.ranges[180], '.2f')
dist_left = format(msg.ranges[90], '.2f')
dist_right = format(msg.ranges[270], '.2f')
dist_head = format(msg.ranges[0], '.2f')
self.get_logger().info(f'{dist_back} {dist_left} {dist_right} {dist_head}')
def main(args=None):
rclpy.init(args=args)
ef main(args=None):
rclpy.init(args=args)
minimal_subscriber = MinimalSubscriber()
rclpy.spin(minimal_subscriber)
# Destroy the node explicitly
# (optional - otherwise it will be done automatically
# when the garbage collector destroys the node object)
minimal_subscriber.destroy_node()
rclpy.shutdown()
if __name__ == '__main__':
main() I did not test it thoroughly, but the code snippet at least shows how to set You should get:
|
I had a very similar issue. @goekce's solution of setting the QoSProfile's reliability to best effort, i.e. reliability=ReliabilityPolicy.BEST_EFFORT, fixed things for me. |
I found a more typing-friendly solution than the long option in my last post:
Here is a minimal example using import rclpy
from rclpy.node import Node
from rclpy.qos import qos_profile_sensor_data
from sensor_msgs.msg import LaserScan
class Tb3(Node):
def __init__(self):
super().__init__('tb3')
self.scan_sub = self.create_subscription(
LaserScan,
'scan',
self.scan_callback, # function to run upon message arrival
qos_profile_sensor_data) # allows packet loss
def scan_callback(self, msg):
print(msg.ranges[0])
def main(args=None):
rclpy.init(args=args)
tb3 = Tb3()
rclpy.spin(tb3) # execute tb3 node
# blocks until the executor cannot work
tb3.destroy_node()
rclpy.shutdown()
if __name__ == '__main__':
main() The output should be similar to:
Other examples are in https://github.com/ROBOTIS-GIT/turtlebot3/tree/ros2/turtlebot3_example/turtlebot3_example |
I used this tutorial to set up my workspace and am trying to implement a q-learning environment using ROS2. I have written a simple subscriber to the /scan topic which has publisher /turtlebot3_laserscan, but do not get any results when running the script alongside the
ros2 launch turtlebot3_gazebo turtlebot3_world.launch.py
command.scanSub.py
However, when I run my own simple publisher to publish custom scan messages, the messages are recieved.
testPub.py
The
ros2 node info /turtlebot3_laserscan
command gives the message type of /scan as sensor_msgs/msg/LaserScan which I believe is the type I am using on the custom subscriber and publisher.My environment is
The text was updated successfully, but these errors were encountered: