Last active
May 29, 2023 19:10
-
-
Save rfzeg/b392c7d7a3495b04ef218724e73b2df1 to your computer and use it in GitHub Desktop.
ROS2: Retrieve the total number of laser rays using the python interpreter (adjust topic name if neccesary)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import rclpy | |
from sensor_msgs.msg import LaserScan | |
from rclpy.qos import ReliabilityPolicy, QoSProfile | |
def scan_callback(msg): | |
global g_node | |
g_node.get_logger().info('Number of rays: "%d"' % len(msg.ranges)) | |
g_node.get_logger().info('Angle of first ray: "%.2f"' % msg.angle_min) | |
g_node.get_logger().info('Angle of last ray: "%.2f"' % msg.angle_max) | |
g_node.get_logger().info('Total angular area of coverage: "%.2f"' % (msg.angle_max-msg.angle_min)) | |
g_node = None | |
global g_node | |
rclpy.init() | |
qos_policy = rclpy.qos.QoSProfile(reliability=rclpy.qos.ReliabilityPolicy.BEST_EFFORT,history=rclpy.qos.HistoryPolicy.KEEP_LAST,depth=1) | |
g_node = rclpy.create_node('minimal_subscriber') | |
subscription = g_node.create_subscription(LaserScan, '/scan', scan_callback, qos_profile=qos_policy) | |
if rclpy.ok(): | |
rclpy.spin_once(g_node) | |
#g_node.destroy_node() | |
#rclpy.shutdown() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
ROS1 version: