任务执行
This commit is contained in:
@@ -0,0 +1,67 @@
|
||||
#!/usr/bin/env python3
|
||||
"""修复激光雷达时间戳偏移的修正器 v5"""
|
||||
import os, sys, rclpy
|
||||
from rclpy.node import Node
|
||||
from sensor_msgs.msg import LaserScan
|
||||
from builtin_interfaces.msg import Time
|
||||
|
||||
LOCKFILE = "/tmp/scan_fixer.lock"
|
||||
|
||||
if os.path.exists(LOCKFILE):
|
||||
with open(LOCKFILE) as f:
|
||||
old_pid = int(f.read().strip())
|
||||
try:
|
||||
os.kill(old_pid, 0)
|
||||
print(f"Another fixer running PID {old_pid}, exit.", file=sys.stderr)
|
||||
sys.exit(1)
|
||||
except (OSError, ProcessLookupError):
|
||||
print(f"Stale lock removed (PID {old_pid} dead)", file=sys.stderr)
|
||||
|
||||
with open(LOCKFILE, "w") as f:
|
||||
f.write(str(os.getpid()))
|
||||
|
||||
def main():
|
||||
rclpy.init(args=sys.argv[1:])
|
||||
node = Node('scan_timestamp_fixer')
|
||||
offset = 2.0
|
||||
pub = node.create_publisher(LaserScan, '/scan_corrected', 10)
|
||||
count = [0]
|
||||
|
||||
def cb(msg: LaserScan):
|
||||
count[0] += 1
|
||||
s, ns = msg.header.stamp.sec, msg.header.stamp.nanosec
|
||||
s2 = s - int(offset)
|
||||
ns2 = ns - int((offset % 1) * 1e9)
|
||||
if ns2 < 0:
|
||||
ns2 += 1000000000
|
||||
s2 -= 1
|
||||
out = LaserScan()
|
||||
out.header.frame_id = msg.header.frame_id
|
||||
out.header.stamp = Time(sec=s2, nanosec=ns2)
|
||||
out.angle_min = msg.angle_min
|
||||
out.angle_max = msg.angle_max
|
||||
out.angle_increment = msg.angle_increment
|
||||
out.time_increment = msg.time_increment
|
||||
out.scan_time = msg.scan_time
|
||||
out.range_min = msg.range_min
|
||||
out.range_max = msg.range_max
|
||||
out.ranges = msg.ranges
|
||||
out.intensities = msg.intensities
|
||||
pub.publish(out)
|
||||
if count[0] % 200 == 0:
|
||||
node.get_logger().info(f'#{count[0]} /scan={s} -> /scan_corrected={s2}')
|
||||
|
||||
node.create_subscription(LaserScan, '/scan', cb, 10)
|
||||
node.get_logger().info(f'Fixer PID={os.getpid()}, offset={offset}s')
|
||||
|
||||
try:
|
||||
while rclpy.ok():
|
||||
rclpy.spin_once(node, timeout_sec=0.5)
|
||||
finally:
|
||||
node.destroy_node()
|
||||
rclpy.shutdown()
|
||||
if os.path.exists(LOCKFILE):
|
||||
os.unlink(LOCKFILE)
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
@@ -0,0 +1,17 @@
|
||||
#!/bin/bash
|
||||
source /opt/ros/humble/setup.bash
|
||||
source /home/elephant/agv_pro_ros2/install/setup.bash
|
||||
export ROS_DOMAIN_ID=1
|
||||
cd /home/elephant/agv_pro_ros2
|
||||
nohup ros2 daemon start >/dev/null 2>&1 &
|
||||
sleep 5
|
||||
nohup ros2 launch agv_pro_bringup agv_pro_bringup.launch.py port_name:=/dev/agvpro_controller > /tmp/ros2_bringup.log 2>&1 &
|
||||
sleep 8
|
||||
nohup python3 /home/elephant/work/scan_fixer/fix_scan_timestamp.py > /tmp/scan_fixer.log 2>&1 &
|
||||
sleep 5
|
||||
nohup ros2 launch agv_pro_navigation2 navigation2_active.launch.py autostart:=True > /tmp/ros2_nav2.log 2>&1 &
|
||||
sleep 15
|
||||
cd /home/elephant/work/agv_app && nohup python3 app.py > /tmp/agv_flask.log 2>&1 &
|
||||
sleep 5
|
||||
echo "ALL_STARTED"
|
||||
ps aux | grep -E 'lslidar|agv_pro_node|nav2_container|scan_timestamp_fixer|ros2-daemon|app.py' | grep -v grep
|
||||
Reference in New Issue
Block a user