初始化:RMUL 2027 哨兵导航仿真工程

- Gazebo Sim (Jetty 10.6) + ROS 2 Lyrical + Nav2 全栈
- 整车模型:URDF/SDF + 减面网格(SolidWorks 装配体实测尺寸)
- 场地:RMUL 2027 官方包(2D 栅格地图 + 3D 场地模型),放在 field/
- sentry_nav C++ 包:self_filter 点云自滤 / patrol 航点巡逻
- 文档:README(含本机开发环境实测)、MID-360 接入说明

已排除:build/ install/ log/ 缓存目录,以及 115 MB 的原始高模
(仿真实际用的是 meshes/base.stl 减面版,约 25.7 万面)
This commit is contained in:
mzx committed 2026-11-14 21:18:04 +08:00
1 parent ed31ccc39f
commit f7412ec369
142 files changed
+58958 -2

No files matched your search

+69
View File
@@ -0,0 +1,69 @@
#!/usr/bin/env python3
"""演示脚本:驱动哨兵前进+转向,并打印雷达/里程计/AMCL 的真实数据。"""
import math
import time
import rclpy
from geometry_msgs.msg import Twist
from nav_msgs.msg import Odometry
from rclpy.node import Node
from sensor_msgs.msg import LaserScan
from tf2_ros import Buffer, TransformListener
rclpy.init()
node = Node('demo_driver')
pub = node.create_publisher(Twist, '/cmd_vel', 10)
data = {'odom': None, 'scan': None}
node.create_subscription(Odometry, '/odom', lambda m: data.__setitem__('odom', m), 10)
node.create_subscription(LaserScan, '/scan', lambda m: data.__setitem__('scan', m), 10)
tf = Buffer()
TransformListener(tf, node)
def spin(sec):
t0 = time.time()
while time.time() - t0 < sec:
rclpy.spin_once(node, timeout_sec=0.1)
def drive(lin, ang, sec, label):
msg = Twist()
msg.linear.x = lin
msg.angular.z = ang
t0 = time.time()
while time.time() - t0 < sec:
pub.publish(msg)
rclpy.spin_once(node, timeout_sec=0.05)
pub.publish(Twist())
p = data['odom'].pose.pose.position if data['odom'] else None
yaw = 0.0
if data['odom']:
q = data['odom'].pose.pose.orientation
yaw = math.degrees(2 * math.atan2(q.z, q.w))
print(f' {label}: odom=({p.x:+.3f}, {p.y:+.3f}) 航向={yaw:+.1f}°' if p else f' {label}: 无 odom')
spin(3)
if data['scan']:
finite = [r for r in data['scan'].ranges if r == r and r != float('inf')]
print(f'[雷达] frame={data["scan"].header.frame_id} 线数={len(data["scan"].ranges)} '
f'有效点={len(finite)} 最近={min(finite):.2f}m 最远={max(finite):.2f}m')
else:
print('[雷达] 无数据')
print('[驱动]')
drive(0.5, 0.0, 3.0, '前进 0.5 m/s × 3s')
drive(0.0, 0.8, 1.5, '原地转 0.8 rad/s × 1.5s')
drive(0.3, 0.0, 2.0, '再前进 0.3 m/s × 2s')
for i in range(20):
spin(0.2)
try:
tr = tf.lookup_transform('map', 'base_link', rclpy.time.Time())
p = tr.transform.translation
print(f'[AMCL] TF map->base_link: x={p.x:.3f} y={p.y:.3f}')
except Exception as exc: # noqa: BLE001
print(f'[AMCL] 查不到 TF: {exc}')
node.destroy_node()
rclpy.shutdown()