[英]Is there any way to get roscore string using python script in raspberry pi?
I'm using Raspberry Pi for LaserScanner(Motor + Rangefinder/Hokuyo).我将 Raspberry Pi 用于 LaserScanner(电机 + 测距仪/Hokuyo)。
For the case of Rangefinder, I open 3 command window,对于测距仪的情况,我打开 3 命令 window,
#1: roscore #1:罗斯科
#2: rosrun urg_node urg_node _serial_port:=/dev/ttyACM0 #2: rosrun urg_node urg_node _serial_port:=/dev/ttyACM0
#3: sh /home/pi/hokuyo/lidarDemo.sh /home/pi/Desktop/Demo/Data lidar.txt #3: sh /home/pi/hokuyo/lidarDemo.sh /home/pi/Desktop/Demo/Data lidar.txt
where lidarDemo.sh:其中lidarDemo.sh:
if [$# -ne 2 ]
then
echo '2 inputs'
exit 1
fi
rostopic echo /scan|tee $1/$2
Then lidar.txt is saved until I close the terminal#3.然后保存lidar.txt,直到我关闭终端#3。
lidar.txt:激光雷达.txt:
header: header:
seq: 16828序列号:16828
stamp:邮票:
secs: 1594386688秒:1594386688
nsecs: 380816175纳秒:380816175
frame_id: "laser" frame_id:“激光”
angle_min: -2.35619449615角度最小值:-2.35619449615
angle_max: 2.35619449615最大角度:2.35619449615
angle_increment: 0.00436332309619角度增量:0.00436332309619
time_increment: 1.73611151695e-05时间增量:1.73611151695e-05
scan_time: 0.0250000003725扫描时间:0.0250000003725
range_min: 0.0230000000447 range_min: 0.0230000000447
range_max: 60.0最大范围:60.0
ranges: [3.888000011444092, 3.888000011444092, 3.888000011444092, ...范围:[3.888000011444092, 3.888000011444092, 3.888000011444092, ...
intensities: [2673.0, 2663.0, 2652.0, 2673.0...强度:[2673.0, 2663.0, 2652.0, 2673.0 ...
header: header:
seq: 16828序列号:16828
stamp:邮票:
... ...
Now, Can I get those strings of lidar.txt by using python script in real-time?现在,我可以通过实时使用 python 脚本来获取这些lidar.txt 字符串吗?
For example, test.py:例如,test.py:
while(True):
str = getRoscore()
print(str)
Assuming you want to get realtime lidar data in python;假设您想在 python 中获取实时激光雷达数据; you can write a python script which has a subscriber to /scan topic where you can process your data in real-time something similar to this,
您可以编写一个 python 脚本,该脚本有一个订阅者 /scan 主题,您可以在其中实时处理类似于此的数据,
import rospy
from sensor_msgs.msg import LaserScan
lidar_message = None
def lidar_callback(data):
rospy.loginfo(rospy.get_caller_id() + " %s", data)
lidar_message = data
##Execute necessary processing here..
if __name__ == '__main__':
rospy.init_node('lidar_node', anonymous=True)
rospy.Subscriber("/scan", LaserScan, lidar_callback)
##Execute rest of the logic here...
rospy.spin()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.