Last active
February 20, 2023 21:40
-
-
Save atotto/c47bc69a48ed38e86947b5506b8e0e61 to your computer and use it in GitHub Desktop.
Publishing Sensor Streams Over ROS (python)
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
#!/usr/bin/env python | |
import rospy | |
from sensor_msgs.msg import LaserScan | |
rospy.init_node('laser_scan_publisher') | |
scan_pub = rospy.Publisher('scan', LaserScan, queue_size=50) | |
num_readings = 100 | |
laser_frequency = 40 | |
count = 0 | |
r = rospy.Rate(1.0) | |
while not rospy.is_shutdown(): | |
current_time = rospy.Time.now() | |
scan = LaserScan() | |
scan.header.stamp = current_time | |
scan.header.frame_id = 'laser_frame' | |
scan.angle_min = -1.57 | |
scan.angle_max = 1.57 | |
scan.angle_increment = 3.14 / num_readings | |
scan.time_increment = (1.0 / laser_frequency) / (num_readings) | |
scan.range_min = 0.0 | |
scan.range_max = 100.0 | |
scan.ranges = [] | |
scan.intensities = [] | |
for i in range(0, num_readings): | |
scan.ranges.append(1.0 * count) # fake data | |
scan.intensities.append(1) # fake data | |
scan_pub.publish(scan) | |
count += 1 | |
r.sleep() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
see http://wiki.ros.org/navigation/Tutorials/RobotSetup/Sensors
terminal1:
terminal2:
terminal3:
terminal4: