feat(sim): integrate Gazebo Classic with Point-LIO and SCAN navigation
Import the complete field and a simplified omnidirectional robot in sim_ws. Reuse original Point-LIO, SCAN and controller implementations with isolated simulation profiles, timed MID360/IMU data, readiness and command guards. Support known-corridor terrain paths, optional sensor stress profiles and separate physics/algorithm launch processes. Remove retired Fortress resources and operating instructions; add build, usage, scope and durable validation documentation. Validation: full build script; 8 adapter tests and 4 SCAN CTest targets; 8 continuous mild-noise routes; red/blue terrain 4 cases each; noise 9/9; visibility characterization 9/9; default sensors 16/16; loss-stop and post-build straight navigation. Real wheels/network remain unverified.
This commit is contained in:
@@ -0,0 +1,7 @@
|
||||
cmake_minimum_required(VERSION 3.8)
|
||||
project(br_sim_bringup)
|
||||
find_package(ament_cmake REQUIRED)
|
||||
install(DIRECTORY launch config DESTINATION share/${PROJECT_NAME}
|
||||
PATTERN "__pycache__" EXCLUDE)
|
||||
install(PROGRAMS scripts/scan_cloud_gate.py scripts/lio_navigation_adapter.py DESTINATION lib/${PROJECT_NAME})
|
||||
ament_package()
|
||||
@@ -0,0 +1,29 @@
|
||||
# Optional flat-ground LIO navigation profile. No real-vehicle files change.
|
||||
lio_navigation_adapter:
|
||||
ros__parameters:
|
||||
use_sim_time: true
|
||||
imu_position_base: [0.011, 0.02329, 0.25588]
|
||||
lidar_position_base: [0.0, 0.0, 0.30]
|
||||
ground_cutoff_z: 0.015
|
||||
|
||||
scan_planner_node:
|
||||
ros__parameters:
|
||||
manager.max_vel: 0.3
|
||||
optimization.max_vel: 0.3
|
||||
# Permit collision-checked replanning after a brief data hold near the goal.
|
||||
# Default legacy SCAN threshold stays at .20 m; finish_dist is still .06 m.
|
||||
manager.min_replan_distance: 0.04
|
||||
# MID360's -7 deg lower FOV sees the upper face of a nearby floor box.
|
||||
# Conservatively include returns up to z=.65 in the z=.15 flat driving
|
||||
# slice. This is map inflation, not fabricated low sensor returns.
|
||||
# Overhead-clearance and ramp planning require a different terrain profile.
|
||||
grid_map.obstacles_inflation_z_down: 0.50
|
||||
|
||||
closed_loop_controller:
|
||||
ros__parameters:
|
||||
max_vx: 0.3
|
||||
max_vy: 0.3
|
||||
# The original .10 rad finish tolerance ended rotations at excessive speed
|
||||
# in continuous tasks. Tighten only simulation; keep the .20 s stop budget.
|
||||
yaw_goal_tolerance: 0.02
|
||||
# Keep flat 9 cm margin and the existing 6 cm finish window.
|
||||
@@ -0,0 +1,58 @@
|
||||
# Independent low-speed terrain LIO profile. Flat profile is not included.
|
||||
lio_navigation_adapter:
|
||||
ros__parameters:
|
||||
use_sim_time: true
|
||||
imu_position_base: [0.011, 0.02329, 0.25588]
|
||||
lidar_position_base: [0.0, 0.0, 0.30]
|
||||
ground_cutoff_z: 0.015
|
||||
# Prior LIO slope max vertical error .038 m plus 2 cm allowance.
|
||||
# This intentionally cannot certify obstacles <= .10 m above known ground.
|
||||
surface_tolerance: 0.06
|
||||
traversable_planes: [-0.8, 2.7, 3.0, 4.0, -0.17057142857142857, 0.0, 0.46054285714285714,
|
||||
-0.8, 2.7, -4.0, -3.0, -0.17057142857142857, 0.0, 0.46054285714285714,
|
||||
-3.0, 3.0, -3.0, 3.0, 0.0, 0.0, 0.6,
|
||||
-1.8, -0.8, 3.0, 4.0, 0.0, 0.0, 0.6,
|
||||
-1.8, -0.8, -4.0, -3.0, 0.0, 0.0, 0.6,
|
||||
-7.0, 7.0, -8.0, 8.0, 0.0, 0.0, 0.0]
|
||||
required_planning_topic: /sim/navigation/terrain_planning_cloud
|
||||
# Baseline measured downstream age stays below .10 s. Revoke at .20 s
|
||||
# to leave enough braking time for the end-to-end .50 s loss-stop limit.
|
||||
required_planning_max_age: 0.20
|
||||
scan_planner_node:
|
||||
ros__parameters:
|
||||
manager.max_vel: 0.2
|
||||
optimization.max_vel: 0.2
|
||||
manager.min_replan_distance: 0.04
|
||||
grid_map.footprint_margin: 0.04
|
||||
# Half-size voxels reduce narrow-lane quantization without shrinking the
|
||||
# footprint or margin. A corridor-shaped window keeps memory near baseline.
|
||||
grid_map.resolution: 0.025
|
||||
grid_map.sliding_map_size_x: 10.0
|
||||
grid_map.sliding_map_size_y: 3.0
|
||||
grid_map.sliding_map_size_z: 2.0
|
||||
grid_map.local_update_range_x: 5.0
|
||||
grid_map.local_update_range_y: 1.5
|
||||
grid_map.local_update_range_z: 1.0
|
||||
# Do not project upper returns through the ramp into the driving slice.
|
||||
grid_map.obstacles_inflation_z_down: 0.05
|
||||
closed_loop_controller:
|
||||
ros__parameters:
|
||||
max_vx: 0.2
|
||||
max_vy: 0.2
|
||||
# Leave physical braking/transport budget at the unchanged 6 cm finish
|
||||
# distance. The real-vehicle 5 cm/s floor was too fast for this profile.
|
||||
goal_v_floor: 0.02
|
||||
goal_slow_gain: 0.3
|
||||
pos_deadband: 0.005
|
||||
step_blocker:
|
||||
ros__parameters:
|
||||
input_topic: /sim/navigation/planning_cloud
|
||||
output_topic: /sim/navigation/terrain_planning_cloud
|
||||
# 10 cm prior sampling is smaller than the 80 cm footprint; the existing
|
||||
# +15/-5 cm vertical inflation closes the vertical gaps. Keep wall height
|
||||
# 2 m while avoiding oversized DDS messages and lost freshness heartbeats.
|
||||
cell_size: 0.10
|
||||
# Certified corridor boundaries, not lidar returns or physical walls.
|
||||
# Without these prior planes, sparse/noisy upper returns allow a detour
|
||||
# off the side of the known ramp. Zero-width regions are vertical planes.
|
||||
regions: '-2.7,-1.8,3.0,4.0; -2.7,-1.8,-4.0,-3.0; -1.8,2.7,3.025,3.025; -1.8,2.7,4.0,4.0; -1.8,2.7,-3.025,-3.025; -1.8,2.7,-4.0,-4.0'
|
||||
@@ -0,0 +1,36 @@
|
||||
# Only simulation overrides. Original real-device configuration remains untouched.
|
||||
/**:
|
||||
ros__parameters:
|
||||
use_sim_time: true
|
||||
use_imu_as_input: false
|
||||
init_map_size: 500
|
||||
filter_size_surf: 0.15
|
||||
filter_size_map: 0.15
|
||||
runtime_pos_log_enable: false
|
||||
common.lid_topic: /sim/mid360/lidar
|
||||
common.imu_topic: /sim/mid360/imu
|
||||
common.time_diff_lidar_to_imu: 0.0
|
||||
preprocess.lidar_type: 1
|
||||
preprocess.scan_line: 4
|
||||
preprocess.blind: 0.55
|
||||
preprocess.blind_center_enable: true
|
||||
preprocess.blind_center: [0.0, 0.0, 0.0]
|
||||
mapping.imu_en: true
|
||||
mapping.extrinsic_est_en: false
|
||||
mapping.imu_time_inte: 0.005
|
||||
mapping.lidar_time_inte: 0.1
|
||||
# Gazebo's world has |g|=9.8; IMU reports SI specific force, not g units.
|
||||
mapping.acc_norm: 9.8
|
||||
mapping.satu_acc: 50.0
|
||||
mapping.satu_gyro: 35.0
|
||||
mapping.gravity: [0.0, 0.0, -9.8]
|
||||
mapping.gravity_init: [0.0, 0.0, -9.8]
|
||||
# Transform optical coordinates into the internally offset IMU frame.
|
||||
mapping.extrinsic_T: [-0.011, -0.02329, 0.04412]
|
||||
mapping.extrinsic_R: [1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 1.0]
|
||||
odometry.publish_odometry_without_downsample: true
|
||||
odometry.publish_frequency_hz: 100
|
||||
# Keep estimated TF isolated from the independent truth TF tree.
|
||||
publish.tf_send_en: false
|
||||
publish.path_en: true
|
||||
pcd_save.pcd_save_en: false
|
||||
@@ -0,0 +1,7 @@
|
||||
# Only the noise-free simulation terrain entry loads this optional override.
|
||||
# Retain the baseline residual variance; increasing its weight caused false
|
||||
# stationary velocity and was rejected by the unchanged startup gate.
|
||||
/**:
|
||||
ros__parameters:
|
||||
filter_size_surf: 0.10
|
||||
filter_size_map: 0.10
|
||||
@@ -0,0 +1,37 @@
|
||||
# These overrides describe the simplified simulated robot, not the real robot.
|
||||
scan_planner_node:
|
||||
ros__parameters:
|
||||
use_sim_time: true
|
||||
fsm.navi_mode: 1
|
||||
fsm.require_controller_feedback: true
|
||||
fsm.require_perception_ready: true
|
||||
grid_map.rectangle_footprint: true
|
||||
grid_map.footprint_length: 0.8
|
||||
grid_map.footprint_width: 0.8
|
||||
grid_map.footprint_margin: 0.09
|
||||
# Truth-mode heading hold: tighten to ~0.57 deg; keep the 9 cm margin.
|
||||
# The map also pads corners for this angle and covers full 5 cm voxels.
|
||||
grid_map.footprint_yaw_tolerance: 0.01
|
||||
grid_map.double_cylinder_offset: 0.0
|
||||
grid_map.ground_height: -0.1
|
||||
grid_map.body_height: 0.15
|
||||
grid_map.frame_id: world
|
||||
grid_map.sensor_type: lidar
|
||||
grid_map.cloud_is_world: true
|
||||
grid_map.need_extrinsic: false
|
||||
|
||||
closed_loop_controller:
|
||||
ros__parameters:
|
||||
use_sim_time: true
|
||||
require_trajectory_status: true
|
||||
require_locked_heading: true
|
||||
require_perception_ready: true
|
||||
allow_reverse: false
|
||||
# Stop inside the planner's 0.08 m goal window, allowing separate odom callbacks.
|
||||
finish_dist: 0.06
|
||||
|
||||
scan_cloud_gate:
|
||||
ros__parameters:
|
||||
use_sim_time: true
|
||||
# Flat-ground P4 only. Preserve the complete cloud on /cloud_registered.
|
||||
ground_cutoff_z: 0.015
|
||||
@@ -0,0 +1,42 @@
|
||||
# Explicit, optional terrain/reference-path mode. Base flat mode stays unchanged.
|
||||
scan_planner_node:
|
||||
ros__parameters:
|
||||
fsm.navi_mode: 3
|
||||
fsm.terrain_motion: true
|
||||
fsm.reference_path_min_distance: 0.05
|
||||
manager.max_vel: 0.3
|
||||
optimization.max_vel: 0.3
|
||||
# The ramp is only 1 m wide (0.975 m beside the 25 mm rail overhang).
|
||||
# Keep the 80 cm body; this optional low-speed truth profile uses 4 cm
|
||||
# explicit margin plus angular and voxel padding. Flat mode stays at 9 cm.
|
||||
grid_map.footprint_margin: 0.04
|
||||
|
||||
closed_loop_controller:
|
||||
ros__parameters:
|
||||
terrain_motion: true
|
||||
max_vx: 0.3
|
||||
max_vy: 0.3
|
||||
align_to_goal_yaw: false
|
||||
|
||||
scan_cloud_gate:
|
||||
ros__parameters:
|
||||
planning_cloud_topic: /sim/terrain_planning_cloud
|
||||
# Known walkable surfaces from the authoritative field model. Sensor cloud
|
||||
# /cloud_registered remains untouched. Format: xmin,xmax,ymin,ymax,mx,my,b;
|
||||
# z=mx*x+my*y+b. The .6 m landing is the highest original stair box.
|
||||
traversable_planes: [-0.8, 2.7, 3.0, 4.0, -0.17057142857142857, 0.0, 0.46054285714285714,
|
||||
-0.8, 2.7, -4.0, -3.0, -0.17057142857142857, 0.0, 0.46054285714285714,
|
||||
-3.0, 3.0, -3.0, 3.0, 0.0, 0.0, 0.6,
|
||||
-1.8, -0.8, 3.0, 4.0, 0.0, 0.0, 0.6,
|
||||
-1.8, -0.8, -4.0, -3.0, 0.0, 0.0, 0.6]
|
||||
|
||||
step_blocker:
|
||||
ros__parameters:
|
||||
use_sim_time: true
|
||||
input_topic: /cloud_registered_for_scan
|
||||
output_topic: /sim/terrain_planning_cloud
|
||||
# Explicit prior keepout layer, not simulated lidar returns.
|
||||
regions: '-2.7,-1.8,3.0,4.0; -2.7,-1.8,-4.0,-3.0'
|
||||
wall_height: 2.0
|
||||
z_min: 0.0
|
||||
cell_size: 0.05
|
||||
@@ -0,0 +1,38 @@
|
||||
"""Independent MID360-compatible sensors and optional Point-LIO evaluation; no SCAN."""
|
||||
import os
|
||||
from ament_index_python.packages import get_package_share_directory
|
||||
from launch import LaunchDescription
|
||||
from launch.actions import DeclareLaunchArgument,IncludeLaunchDescription,OpaqueFunction
|
||||
from launch.launch_description_sources import PythonLaunchDescriptionSource
|
||||
from launch.substitutions import LaunchConfiguration
|
||||
from launch_ros.actions import Node
|
||||
|
||||
|
||||
def generate_launch_description():
|
||||
own=get_package_share_directory('br_sim_bringup')
|
||||
def simulation(context):
|
||||
if LaunchConfiguration('start_sim').perform(context).lower()!='true':return []
|
||||
robot=get_package_share_directory('r2027_robot_description')
|
||||
return [IncludeLaunchDescription(PythonLaunchDescriptionSource(os.path.join(robot,'launch','robocon_robot.launch.py')),
|
||||
launch_arguments={'sensor_profile':LaunchConfiguration('sensor_profile'),'gui':LaunchConfiguration('gui'),'lidar':'true','sensor_model':'mid360','drive':'contact',
|
||||
'x':LaunchConfiguration('x'),'y':LaunchConfiguration('y'),'z':LaunchConfiguration('z'),'yaw':LaunchConfiguration('yaw')}.items())]
|
||||
def estimator(context):
|
||||
if LaunchConfiguration('with_lio').perform(context).lower()!='true':return []
|
||||
lio=get_package_share_directory('point_lio')
|
||||
return [Node(package='point_lio',executable='pointlio_mapping',name='point_lio_sim',
|
||||
namespace='sim/lio',output='screen',
|
||||
parameters=[os.path.join(lio,'config','mid360.yaml'),os.path.join(own,'config','point_lio_sim.yaml'),
|
||||
LaunchConfiguration('lio_profile')],
|
||||
# Three absolute publishers in the existing implementation need explicit remaps.
|
||||
remappings=[('/cloud_registered_full','/sim/lio/cloud_registered_full'),
|
||||
('/cloud_registered_full_lidar','/sim/lio/cloud_registered_full_lidar')])]
|
||||
return LaunchDescription([
|
||||
DeclareLaunchArgument('gui',default_value='true'),
|
||||
DeclareLaunchArgument('with_lio',default_value='false'),
|
||||
DeclareLaunchArgument('start_sim',default_value='true'),
|
||||
DeclareLaunchArgument('sensor_profile',default_value='ideal'),
|
||||
DeclareLaunchArgument('lio_profile',default_value=os.path.join(own,'config','point_lio_sim.yaml')),
|
||||
DeclareLaunchArgument('x',default_value='-4.5'),DeclareLaunchArgument('y',default_value='4.5'),
|
||||
DeclareLaunchArgument('z',default_value='0.17'),DeclareLaunchArgument('yaw',default_value='0.0'),
|
||||
OpaqueFunction(function=simulation),
|
||||
OpaqueFunction(function=estimator)])
|
||||
@@ -0,0 +1,36 @@
|
||||
"""Flat SCAN closed loop from Point-LIO only; truth remains an independent observer."""
|
||||
import os
|
||||
from ament_index_python.packages import get_package_share_directory
|
||||
from launch import LaunchDescription
|
||||
from launch.actions import DeclareLaunchArgument,IncludeLaunchDescription,OpaqueFunction
|
||||
from launch.launch_description_sources import PythonLaunchDescriptionSource
|
||||
from launch.substitutions import LaunchConfiguration
|
||||
from launch_ros.actions import Node
|
||||
|
||||
|
||||
def generate_launch_description():
|
||||
own=get_package_share_directory('br_sim_bringup');scan=get_package_share_directory('scan_planner')
|
||||
base=os.path.join(own,'config','scan_sim.yaml');profile=os.path.join(own,'config','lio_navigation.yaml')
|
||||
def bringup(context):
|
||||
pose=[float(LaunchConfiguration(k).perform(context)) for k in ('x','y','z','yaw')]
|
||||
return [
|
||||
IncludeLaunchDescription(PythonLaunchDescriptionSource(os.path.join(own,'launch','mid360_sim.launch.py')),
|
||||
launch_arguments={'gui':LaunchConfiguration('gui'),'with_lio':'true',
|
||||
'start_sim':LaunchConfiguration('start_sim'),'sensor_profile':LaunchConfiguration('sensor_profile'),
|
||||
**{k:LaunchConfiguration(k) for k in ('x','y','z','yaw')}}.items()),
|
||||
Node(package='br_sim_bringup',executable='lio_navigation_adapter.py',name='lio_navigation_adapter',
|
||||
output='screen',parameters=[profile,{'initial_base_pose':pose}]),
|
||||
Node(package='scan_planner',executable='scan_planner_node',name='scan_planner_node',output='screen',
|
||||
parameters=[os.path.join(scan,'config','planner_vehicle.yaml'),base,profile],
|
||||
remappings=[('body_pose','/sim/navigation/body_odom'),('sensor_pose','/sim/navigation/sensor_odom'),
|
||||
('cloud','/sim/navigation/planning_cloud')]),
|
||||
Node(package='scan_planner',executable='closed_loop_controller',name='closed_loop_controller',output='screen',
|
||||
parameters=[os.path.join(scan,'config','controllers_vehicle.yaml'),base,profile],
|
||||
remappings=[('body_pose','/sim/navigation/body_odom'),('cmd_vel','/cmd_vel')]),
|
||||
]
|
||||
return LaunchDescription([
|
||||
DeclareLaunchArgument('start_sim',default_value='true'),DeclareLaunchArgument('sensor_profile',default_value='ideal'),
|
||||
DeclareLaunchArgument('gui',default_value='true'),
|
||||
DeclareLaunchArgument('x',default_value='-4.5'),DeclareLaunchArgument('y',default_value='4.5'),
|
||||
DeclareLaunchArgument('z',default_value='0.15',description='Known settled base height in this flat profile'),
|
||||
DeclareLaunchArgument('yaw',default_value='0.0'),OpaqueFunction(function=bringup)])
|
||||
@@ -0,0 +1,18 @@
|
||||
"""Local rehearsal of two independent launch processes; use the same commands on two hosts."""
|
||||
from launch import LaunchDescription
|
||||
from launch.actions import DeclareLaunchArgument,ExecuteProcess,OpaqueFunction
|
||||
from launch.substitutions import LaunchConfiguration
|
||||
|
||||
|
||||
def generate_launch_description():
|
||||
def hosts(context):
|
||||
values={k:LaunchConfiguration(k).perform(context) for k in ('x','y','z','yaw','gui','sensor_profile','terrain')}
|
||||
terrain=values.pop('terrain').lower()=='true'
|
||||
args=[k+':='+v for k,v in values.items()]
|
||||
return [ExecuteProcess(cmd=['ros2','launch','r2027_robot_description','robocon_robot.launch.py',
|
||||
'lidar:=true','drive:=contact','sensor_model:=mid360']+args,output='screen'),
|
||||
ExecuteProcess(cmd=['ros2','launch','br_sim_bringup',
|
||||
'scan_lio_terrain.launch.py' if terrain else 'scan_lio.launch.py','start_sim:=false']+args,output='screen')]
|
||||
return LaunchDescription([DeclareLaunchArgument(k,default_value=v) for k,v in
|
||||
[('x','-4.5'),('y','4.5'),('z','0.15'),('yaw','0.0'),('gui','false'),('sensor_profile','ideal'),('terrain','false')]]+
|
||||
[OpaqueFunction(function=hosts)])
|
||||
@@ -0,0 +1,38 @@
|
||||
"""Explicit LIO terrain/reference-path profile; no truth navigation inputs."""
|
||||
import os
|
||||
from ament_index_python.packages import get_package_share_directory
|
||||
from launch import LaunchDescription
|
||||
from launch.actions import DeclareLaunchArgument,IncludeLaunchDescription,OpaqueFunction
|
||||
from launch.launch_description_sources import PythonLaunchDescriptionSource
|
||||
from launch.substitutions import LaunchConfiguration
|
||||
from launch_ros.actions import Node
|
||||
|
||||
|
||||
def generate_launch_description():
|
||||
own=get_package_share_directory('br_sim_bringup');scan=get_package_share_directory('scan_planner')
|
||||
base=os.path.join(own,'config','scan_sim.yaml');terrain=os.path.join(own,'config','terrain_sim.yaml')
|
||||
profile=os.path.join(own,'config','lio_terrain.yaml')
|
||||
def bringup(context):
|
||||
prior=[float(LaunchConfiguration(k).perform(context)) for k in ('x','y','z','yaw')]
|
||||
return [
|
||||
IncludeLaunchDescription(PythonLaunchDescriptionSource(os.path.join(own,'launch','mid360_sim.launch.py')),
|
||||
launch_arguments={'gui':LaunchConfiguration('gui'),'with_lio':'true',
|
||||
'start_sim':LaunchConfiguration('start_sim'),'sensor_profile':LaunchConfiguration('sensor_profile'),
|
||||
'lio_profile':os.path.join(own,'config','point_lio_terrain.yaml'),
|
||||
**{k:LaunchConfiguration(k) for k in ('x','y','z','yaw')}}.items()),
|
||||
Node(package='br_sim_bringup',executable='lio_navigation_adapter.py',name='lio_navigation_adapter',
|
||||
output='screen',parameters=[profile,{'initial_base_pose':prior}]),
|
||||
Node(package='step_blocker',executable='step_blocker',name='step_blocker',output='screen',parameters=[terrain,profile]),
|
||||
Node(package='scan_planner',executable='scan_planner_node',name='scan_planner_node',output='screen',
|
||||
parameters=[os.path.join(scan,'config','planner_vehicle.yaml'),base,terrain,profile],
|
||||
remappings=[('body_pose','/sim/navigation/body_odom'),('sensor_pose','/sim/navigation/sensor_odom'),
|
||||
('cloud','/sim/navigation/terrain_planning_cloud')]),
|
||||
Node(package='scan_planner',executable='closed_loop_controller',name='closed_loop_controller',output='screen',
|
||||
parameters=[os.path.join(scan,'config','controllers_vehicle.yaml'),base,terrain,profile],
|
||||
remappings=[('body_pose','/sim/navigation/body_odom'),('cmd_vel','/cmd_vel')]),
|
||||
]
|
||||
return LaunchDescription([
|
||||
DeclareLaunchArgument('start_sim',default_value='true'),DeclareLaunchArgument('sensor_profile',default_value='ideal'),
|
||||
DeclareLaunchArgument('gui',default_value='true'),DeclareLaunchArgument('x',default_value='3.5'),
|
||||
DeclareLaunchArgument('y',default_value='3.5125'),DeclareLaunchArgument('z',default_value='0.15'),
|
||||
DeclareLaunchArgument('yaw',default_value='0.0'),OpaqueFunction(function=bringup)])
|
||||
@@ -0,0 +1,45 @@
|
||||
"""One Classic server + generic 3D lidar + existing SCAN closed loop (truth mode)."""
|
||||
import os
|
||||
|
||||
from ament_index_python.packages import get_package_share_directory
|
||||
from launch import LaunchDescription
|
||||
from launch.actions import DeclareLaunchArgument, IncludeLaunchDescription, SetEnvironmentVariable
|
||||
from launch.launch_description_sources import PythonLaunchDescriptionSource
|
||||
from launch.substitutions import LaunchConfiguration
|
||||
from launch_ros.actions import Node
|
||||
|
||||
|
||||
def generate_launch_description():
|
||||
robot = get_package_share_directory('r2027_robot_description')
|
||||
scan = get_package_share_directory('scan_planner')
|
||||
own = get_package_share_directory('br_sim_bringup')
|
||||
overrides = os.path.join(own, 'config', 'scan_sim.yaml')
|
||||
return LaunchDescription([
|
||||
SetEnvironmentVariable('ROS_DOMAIN_ID', '77'),
|
||||
SetEnvironmentVariable('ROS_LOCALHOST_ONLY', '1'),
|
||||
DeclareLaunchArgument('gui', default_value='true'),
|
||||
DeclareLaunchArgument('paused', default_value='false'),
|
||||
DeclareLaunchArgument('x', default_value='-4.5'),
|
||||
DeclareLaunchArgument('y', default_value='4.5'),
|
||||
DeclareLaunchArgument('z', default_value='0.15'),
|
||||
DeclareLaunchArgument('yaw', default_value='0.0'),
|
||||
IncludeLaunchDescription(PythonLaunchDescriptionSource(
|
||||
os.path.join(robot, 'launch', 'robocon_robot.launch.py')),
|
||||
launch_arguments={'gui': LaunchConfiguration('gui'),
|
||||
'paused': LaunchConfiguration('paused'), 'lidar': 'true',
|
||||
'x': LaunchConfiguration('x'), 'y': LaunchConfiguration('y'),
|
||||
'z': LaunchConfiguration('z'), 'yaw': LaunchConfiguration('yaw')}.items()),
|
||||
Node(package='br_sim_bringup', executable='scan_cloud_gate.py',
|
||||
name='scan_cloud_gate', output='screen', parameters=[overrides]),
|
||||
Node(package='scan_planner', executable='scan_planner_node',
|
||||
name='scan_planner_node', output='screen',
|
||||
parameters=[os.path.join(scan, 'config', 'planner_vehicle.yaml'), overrides],
|
||||
remappings=[('body_pose', '/body_odom'),
|
||||
('sensor_pose', '/aft_mapped_to_init'),
|
||||
('cloud', '/cloud_registered_for_scan'),
|
||||
('move_base_simple/goal', '/move_base_simple/goal')]),
|
||||
Node(package='scan_planner', executable='closed_loop_controller',
|
||||
name='closed_loop_controller', output='screen',
|
||||
parameters=[os.path.join(scan, 'config', 'controllers_vehicle.yaml'), overrides],
|
||||
remappings=[('body_pose', '/body_odom'), ('cmd_vel', '/cmd_vel')]),
|
||||
])
|
||||
@@ -0,0 +1,34 @@
|
||||
"""Optional contact-force drive + existing SCAN 3D reference paths, truth mode."""
|
||||
import os
|
||||
from ament_index_python.packages import get_package_share_directory
|
||||
from launch import LaunchDescription
|
||||
from launch.actions import DeclareLaunchArgument,IncludeLaunchDescription,SetEnvironmentVariable
|
||||
from launch.launch_description_sources import PythonLaunchDescriptionSource
|
||||
from launch.substitutions import LaunchConfiguration
|
||||
from launch_ros.actions import Node
|
||||
|
||||
|
||||
def generate_launch_description():
|
||||
own=get_package_share_directory('br_sim_bringup')
|
||||
robot=get_package_share_directory('r2027_robot_description')
|
||||
scan=get_package_share_directory('scan_planner')
|
||||
base=os.path.join(own,'config','scan_sim.yaml')
|
||||
terrain=os.path.join(own,'config','terrain_sim.yaml')
|
||||
return LaunchDescription([
|
||||
SetEnvironmentVariable('ROS_DOMAIN_ID','77'),SetEnvironmentVariable('ROS_LOCALHOST_ONLY','1'),
|
||||
DeclareLaunchArgument('gui',default_value='true'),
|
||||
DeclareLaunchArgument('x',default_value='3.5'),DeclareLaunchArgument('y',default_value='3.5125'),
|
||||
DeclareLaunchArgument('z',default_value='0.15'),
|
||||
DeclareLaunchArgument('yaw',default_value='0.0'),
|
||||
IncludeLaunchDescription(PythonLaunchDescriptionSource(os.path.join(robot,'launch','robocon_robot.launch.py')),
|
||||
launch_arguments={'gui':LaunchConfiguration('gui'),'lidar':'true','drive':'contact',
|
||||
'x':LaunchConfiguration('x'),'y':LaunchConfiguration('y'),'z':LaunchConfiguration('z'),'yaw':LaunchConfiguration('yaw')}.items()),
|
||||
Node(package='br_sim_bringup',executable='scan_cloud_gate.py',name='scan_cloud_gate',parameters=[base,terrain]),
|
||||
Node(package='step_blocker',executable='step_blocker',name='step_blocker',parameters=[terrain]),
|
||||
Node(package='scan_planner',executable='scan_planner_node',name='scan_planner_node',output='screen',
|
||||
parameters=[os.path.join(scan,'config','planner_vehicle.yaml'),base,terrain],
|
||||
remappings=[('body_pose','/body_odom'),('sensor_pose','/aft_mapped_to_init'),('cloud','/sim/terrain_planning_cloud')]),
|
||||
Node(package='scan_planner',executable='closed_loop_controller',name='closed_loop_controller',output='screen',
|
||||
parameters=[os.path.join(scan,'config','controllers_vehicle.yaml'),base,terrain],
|
||||
remappings=[('body_pose','/body_odom'),('cmd_vel','/cmd_vel')]),
|
||||
])
|
||||
@@ -0,0 +1,24 @@
|
||||
<?xml version="1.0"?>
|
||||
<package format="3">
|
||||
<name>br_sim_bringup</name>
|
||||
<version>0.1.0</version>
|
||||
<description>Gazebo Classic integration of existing Point-LIO and SCAN, with isolated truth and estimation modes.</description>
|
||||
<maintainer email="[email protected]">kevin</maintainer>
|
||||
<license>Apache-2.0</license>
|
||||
<buildtool_depend>ament_cmake</buildtool_depend>
|
||||
<exec_depend>r2027_robot_description</exec_depend>
|
||||
<exec_depend>scan_planner</exec_depend>
|
||||
<exec_depend>step_blocker</exec_depend>
|
||||
<exec_depend>point_lio</exec_depend>
|
||||
<exec_depend>launch</exec_depend>
|
||||
<exec_depend>launch_ros</exec_depend>
|
||||
<exec_depend>ament_index_python</exec_depend>
|
||||
<exec_depend>rclpy</exec_depend>
|
||||
<exec_depend>sensor_msgs</exec_depend>
|
||||
<exec_depend>nav_msgs</exec_depend>
|
||||
<exec_depend>std_msgs</exec_depend>
|
||||
<exec_depend>geometry_msgs</exec_depend>
|
||||
<exec_depend>tf2_ros</exec_depend>
|
||||
<exec_depend>python3-numpy</exec_depend>
|
||||
<export><build_type>ament_cmake</build_type></export>
|
||||
</package>
|
||||
+231
@@ -0,0 +1,231 @@
|
||||
#!/usr/bin/python3
|
||||
"""Point-LIO -> SCAN, fixed known-start alignment; no truth/TF input or fallback."""
|
||||
from array import array
|
||||
from collections import deque
|
||||
import copy
|
||||
import json
|
||||
import math
|
||||
|
||||
import numpy as np
|
||||
import rclpy
|
||||
from rclpy.node import Node
|
||||
from rclpy.qos import QoSProfile,DurabilityPolicy,qos_profile_sensor_data
|
||||
from geometry_msgs.msg import TransformStamped
|
||||
from nav_msgs.msg import Odometry
|
||||
from sensor_msgs.msg import PointCloud2,PointField
|
||||
from std_msgs.msg import Bool,String
|
||||
from tf2_ros import TransformBroadcaster,StaticTransformBroadcaster
|
||||
|
||||
|
||||
def quaternion(values):
|
||||
q=np.asarray(values,dtype=float)
|
||||
if q.shape!=(4,) or not np.isfinite(q).all() or abs(np.linalg.norm(q)-1)>.001:
|
||||
raise ValueError('invalid unit quaternion')
|
||||
return q/np.linalg.norm(q)
|
||||
|
||||
|
||||
def multiply(a,b):
|
||||
return np.r_[a[3]*b[:3]+b[3]*a[:3]+np.cross(a[:3],b[:3]),a[3]*b[3]-np.dot(a[:3],b[:3])]
|
||||
|
||||
|
||||
def rotation(q):
|
||||
x,y,z,w=quaternion(q)
|
||||
return np.array([[1-2*(y*y+z*z),2*(x*y-z*w),2*(x*z+y*w)],
|
||||
[2*(x*y+z*w),1-2*(x*x+z*z),2*(y*z-x*w)],
|
||||
[2*(x*z-y*w),2*(y*z+x*w),1-2*(x*x+y*y)]])
|
||||
|
||||
|
||||
def skew(v):
|
||||
x,y,z=v
|
||||
return np.array([[0,-z,y],[z,0,-x],[-y,x,0]])
|
||||
|
||||
|
||||
class FixedAlignment:
|
||||
def __init__(self,prior_base,imu_position_base,position,orientation):
|
||||
self.imu_position_base=np.asarray(imu_position_base)
|
||||
yaw=prior_base[3];prior_q=np.array([0.,0.,math.sin(yaw/2),math.cos(yaw/2)])
|
||||
inverse=quaternion(orientation).copy();inverse[:3]*=-1
|
||||
self.q=quaternion(multiply(prior_q,inverse));self.R=rotation(self.q)
|
||||
self.t=np.array(prior_base[:3])+rotation(prior_q)@self.imu_position_base-self.R@position
|
||||
|
||||
def pose(self,position,orientation,offset_from_imu):
|
||||
q=quaternion(multiply(self.q,quaternion(orientation)))
|
||||
return self.R@position+self.t+rotation(q)@offset_from_imu,q
|
||||
|
||||
|
||||
def shifted_twist(linear,angular,offset_from_imu):
|
||||
# All three model axes are aligned; offset is from IMU to target origin.
|
||||
return np.asarray(linear)+np.cross(angular,offset_from_imu)
|
||||
|
||||
|
||||
def float_fields(msg,names,data=None):
|
||||
fields={f.name:f for f in msg.fields}
|
||||
if any(n not in fields or fields[n].datatype!=PointField.FLOAT32 or fields[n].count!=1 for n in names):
|
||||
raise ValueError('missing float32 point fields: '+','.join(names))
|
||||
if len(msg.data)<msg.row_step*msg.height:raise ValueError('truncated point data')
|
||||
return [np.ndarray((msg.height,msg.width),dtype=('>' if msg.is_bigendian else '<')+'f4',
|
||||
buffer=msg.data if data is None else data,offset=fields[n].offset,
|
||||
strides=(msg.row_step,msg.point_step)) for n in names]
|
||||
|
||||
|
||||
class LioNavigationAdapter(Node):
|
||||
def __init__(self):
|
||||
super().__init__('lio_navigation_adapter')
|
||||
self.prior=np.array(self.declare_parameter('initial_base_pose',[-4.5,4.5,.15,0.]).value)
|
||||
self.imu=np.array(self.declare_parameter('imu_position_base',[.011,.02329,.25588]).value)
|
||||
self.lidar=np.array(self.declare_parameter('lidar_position_base',[0.,0.,.30]).value)
|
||||
if self.prior.shape!=(4,) or self.imu.shape!=(3,) or self.lidar.shape!=(3,) or not all(np.isfinite(a).all() for a in (self.prior,self.imu,self.lidar)):
|
||||
raise ValueError('invalid prior or installation geometry')
|
||||
self.cutoff=float(self.declare_parameter('ground_cutoff_z',.015).value)
|
||||
if not math.isfinite(self.cutoff):raise ValueError('invalid ground cutoff')
|
||||
planes=list(self.declare_parameter('traversable_planes',[0.]*7).value)
|
||||
self.surface_tolerance=float(self.declare_parameter('surface_tolerance',.015).value)
|
||||
if len(planes)%7 or not all(math.isfinite(v) for v in planes) or not math.isfinite(self.surface_tolerance) or not 0<self.surface_tolerance<=.06:
|
||||
raise ValueError('invalid known traversable surfaces or tolerance')
|
||||
self.planes=[planes[i:i+7] for i in range(0,len(planes),7) if planes[i+1]>planes[i] and planes[i+3]>planes[i+2]]
|
||||
self.planning_topic=self.declare_parameter('required_planning_topic','').value
|
||||
self.planning_max_age=float(self.declare_parameter('required_planning_max_age',.3).value)
|
||||
if not math.isfinite(self.planning_max_age) or not 0<self.planning_max_age<=.3:
|
||||
raise ValueError('downstream planning maximum age must be in (0,0.3]')
|
||||
self.downstream_stamp=None
|
||||
self.alignment=None;self.fault='';self.window=deque();self.last=None
|
||||
self.odom_stamp=None;self.cloud_stamp=None;self.cloud_count=0;self.last_status=-1.
|
||||
self.anchor_stamp=None
|
||||
self.body_pub=self.create_publisher(Odometry,'/sim/navigation/body_odom',20)
|
||||
self.sensor_pub=self.create_publisher(Odometry,'/sim/navigation/sensor_odom',20)
|
||||
self.world_pub=self.create_publisher(PointCloud2,'/sim/navigation/cloud_registered',5)
|
||||
self.planning_pub=self.create_publisher(PointCloud2,'/sim/navigation/planning_cloud',5)
|
||||
self.ready_pub=self.create_publisher(Bool,'/planning/perception_ready',QoSProfile(depth=1,durability=DurabilityPolicy.TRANSIENT_LOCAL))
|
||||
self.status_pub=self.create_publisher(String,'/sim/navigation/status',QoSProfile(depth=1,durability=DurabilityPolicy.TRANSIENT_LOCAL))
|
||||
self.tf=TransformBroadcaster(self);self.static_tf=StaticTransformBroadcaster(self)
|
||||
self.create_subscription(Odometry,'/sim/lio/aft_mapped_to_init',self.on_odom,qos_profile_sensor_data)
|
||||
self.create_subscription(PointCloud2,'/sim/lio/cloud_registered_full_lidar',self.on_cloud,qos_profile_sensor_data)
|
||||
if self.planning_topic:
|
||||
if self.planning_topic in ('/sim/navigation/cloud_registered','/sim/navigation/planning_cloud'):
|
||||
raise ValueError('downstream gate must use a separate derived planning topic')
|
||||
self.create_subscription(PointCloud2,self.planning_topic,self.on_planning_cloud,qos_profile_sensor_data)
|
||||
self.create_timer(.05,self.health)
|
||||
|
||||
def on_planning_cloud(self,m):
|
||||
if m.header.frame_id=='world' and m.width*m.height>0:
|
||||
self.downstream_stamp=self.stamp(m)
|
||||
|
||||
@staticmethod
|
||||
def stamp(m):return m.header.stamp.sec+m.header.stamp.nanosec*1e-9
|
||||
|
||||
def now_s(self):return self.get_clock().now().nanoseconds*1e-9
|
||||
|
||||
def fresh(self,stamp,limit):return stamp is not None and 0<=self.now_s()-stamp<=limit
|
||||
|
||||
def reject(self,reason):
|
||||
if not self.fault:self.get_logger().error('Navigation latched stopped: '+reason)
|
||||
self.fault=reason
|
||||
|
||||
@staticmethod
|
||||
def transform(parent,child,stamp,position,orientation):
|
||||
tr=TransformStamped();tr.header.frame_id=parent;tr.child_frame_id=child;tr.header.stamp=stamp
|
||||
tr.transform.translation.x,tr.transform.translation.y,tr.transform.translation.z=map(float,position)
|
||||
tr.transform.rotation.x,tr.transform.rotation.y,tr.transform.rotation.z,tr.transform.rotation.w=map(float,orientation)
|
||||
return tr
|
||||
|
||||
def on_odom(self,m):
|
||||
if self.fault:return
|
||||
try:
|
||||
if m.header.frame_id!='camera_init' or m.child_frame_id!='body':raise ValueError('unexpected LIO odometry frames')
|
||||
p=m.pose.pose.position;q=m.pose.pose.orientation;v=m.twist.twist.linear;w=m.twist.twist.angular
|
||||
pos=np.array([p.x,p.y,p.z]);q=quaternion([q.x,q.y,q.z,q.w]);linear=np.array([v.x,v.y,v.z]);angular=np.array([w.x,w.y,w.z])
|
||||
if not all(np.isfinite(a).all() for a in (pos,linear,angular)):raise ValueError('nonfinite odometry')
|
||||
t=self.stamp(m)
|
||||
if not self.fresh(t,.2):return
|
||||
if self.last is not None:
|
||||
dt=t-self.last[0]
|
||||
if dt==0:return
|
||||
if dt<0:raise ValueError('LIO time moved backwards')
|
||||
if self.alignment and (dt>.5 or np.linalg.norm(pos-self.last[1])>.12+.7*dt or
|
||||
2*math.acos(min(1.,abs(np.dot(q,self.last[2]))))>.20+dt):
|
||||
raise ValueError('LIO gap or pose discontinuity; restart with a known start pose')
|
||||
self.last=(t,pos,q)
|
||||
if self.alignment is None:
|
||||
if np.linalg.norm(linear)>.02 or np.linalg.norm(angular)>.02:self.window.clear();return
|
||||
self.window.append((t,pos,q))
|
||||
while len(self.window)>1 and t-self.window[1][0]>1.:self.window.popleft()
|
||||
if len(self.window)<20 or t-self.window[0][0]<1.:return
|
||||
if max(np.linalg.norm(s[1]-pos) for s in self.window)>.02:return
|
||||
self.alignment=FixedAlignment(self.prior,self.imu,pos,q);self.anchor_stamp=t
|
||||
self.static_tf.sendTransform([
|
||||
self.transform('world','camera_init',m.header.stamp,self.alignment.t,self.alignment.q),
|
||||
self.transform('lio_imu','lio_base_link',m.header.stamp,-self.imu,[0.,0.,0.,1.]),
|
||||
self.transform('lio_base_link','lio_lidar',m.header.stamp,self.lidar,[0.,0.,0.,1.])])
|
||||
self.get_logger().info('Fixed known-start alignment locked; no truth input')
|
||||
for child,offset,pub in [('lio_base_link',-self.imu,self.body_pub),('lio_lidar',self.lidar-self.imu,self.sensor_pub)]:
|
||||
out=copy.deepcopy(m);out.header.frame_id='world';out.child_frame_id=child
|
||||
op,oq=self.alignment.pose(pos,q,offset)
|
||||
out.pose.pose.position.x,out.pose.pose.position.y,out.pose.pose.position.z=map(float,op)
|
||||
out.pose.pose.orientation.x,out.pose.pose.orientation.y,out.pose.pose.orientation.z,out.pose.pose.orientation.w=map(float,oq)
|
||||
ov=shifted_twist(linear,angular,offset)
|
||||
out.twist.twist.linear.x,out.twist.twist.linear.y,out.twist.twist.linear.z=map(float,ov)
|
||||
# Rotate pose covariance into world, then move the reference point.
|
||||
A=np.zeros((6,6));A[:3,:3]=self.alignment.R;A[3:,3:]=self.alignment.R
|
||||
J=np.eye(6);J[:3,3:]=-skew(rotation(oq)@offset)
|
||||
C=np.asarray(m.pose.covariance).reshape(6,6)
|
||||
out.pose.covariance=(J@A@C@A.T@J.T).ravel().tolist()
|
||||
J=np.eye(6);J[:3,3:]=-skew(offset)
|
||||
C=np.asarray(m.twist.covariance).reshape(6,6)
|
||||
out.twist.covariance=(J@C@J.T).ravel().tolist()
|
||||
pub.publish(out)
|
||||
self.tf.sendTransform(self.transform('camera_init','lio_imu',m.header.stamp,pos,q))
|
||||
self.odom_stamp=t
|
||||
except (ValueError,TypeError,KeyError) as exc:self.reject(str(exc))
|
||||
|
||||
def on_cloud(self,m):
|
||||
if self.fault or self.alignment is None:return
|
||||
try:
|
||||
t=self.stamp(m)
|
||||
if m.header.frame_id!='camera_init':raise ValueError('unexpected paired cloud frame')
|
||||
if not self.fresh(t,.25) or not self.fresh(self.odom_stamp,.2):return
|
||||
if self.cloud_stamp is not None and t<=self.cloud_stamp:return
|
||||
names=('x','y','z','lidar_x','lidar_y','lidar_z')
|
||||
values=float_fields(m,names)
|
||||
xyz=np.stack(values[:3],axis=-1)
|
||||
raw=np.stack(values[3:],axis=-1)
|
||||
if np.count_nonzero(np.isfinite(xyz).all(axis=-1))<100:return
|
||||
world=xyz@self.alignment.R.T+self.alignment.t
|
||||
data=bytearray(m.data)
|
||||
for i,v in enumerate(float_fields(m,names[:3],data)):v[:]=world[...,i]
|
||||
out=copy.deepcopy(m);out.header.frame_id='world';out.data=array('B',data)
|
||||
self.world_pub.publish(out)
|
||||
self_hit=(np.abs(raw[...,0])<=.42)&(np.abs(raw[...,1])<=.42)&(raw[...,2]>=-.47)&(raw[...,2]<=-.20)
|
||||
ground=world[...,2]<=self.cutoff
|
||||
for x0,x1,y0,y1,mx,my,b in self.planes:
|
||||
ground|=(world[...,0]>=x0)&(world[...,0]<=x1)&(world[...,1]>=y0)&(world[...,1]<=y1)&(
|
||||
np.abs(world[...,2]-(mx*world[...,0]+my*world[...,1]+b))<=self.surface_tolerance)
|
||||
for v in float_fields(m,names[:3],data):v[self_hit|ground]=np.nan
|
||||
out.data=array('B',data);out.is_dense=False;self.planning_pub.publish(out)
|
||||
self.cloud_stamp=t;self.cloud_count+=1
|
||||
except (ValueError,TypeError,KeyError) as exc:self.reject(str(exc))
|
||||
|
||||
def health(self):
|
||||
ready=not self.fault and self.alignment is not None and self.fresh(self.odom_stamp,.2) and self.fresh(self.cloud_stamp,.25)
|
||||
if self.planning_topic:ready=ready and self.fresh(self.downstream_stamp,self.planning_max_age)
|
||||
self.ready_pub.publish(Bool(data=bool(ready)))
|
||||
if self.now_s()-self.last_status<.5:return
|
||||
self.last_status=self.now_s()
|
||||
status=dict(phase='fault' if self.fault else ('initializing' if self.alignment is None else ('active' if ready else 'stale')),
|
||||
reason=self.fault,ready=bool(ready),stamp=self.now_s(),anchor_stamp=self.anchor_stamp,
|
||||
odom_stamp=self.odom_stamp,cloud_stamp=self.cloud_stamp,cloud_count=self.cloud_count,
|
||||
downstream_stamp=self.downstream_stamp,required_planning_topic=self.planning_topic,
|
||||
known_start_base=self.prior.tolist(),imu_position_base=self.imu.tolist())
|
||||
if self.alignment:status.update(rotation=self.alignment.R.tolist(),translation=self.alignment.t.tolist())
|
||||
self.status_pub.publish(String(data=json.dumps(status)))
|
||||
|
||||
|
||||
def main():
|
||||
rclpy.init();node=LioNavigationAdapter()
|
||||
try:rclpy.spin(node)
|
||||
except KeyboardInterrupt:pass
|
||||
finally:
|
||||
node.destroy_node()
|
||||
if rclpy.ok():rclpy.shutdown()
|
||||
|
||||
|
||||
if __name__=='__main__':main()
|
||||
+139
@@ -0,0 +1,139 @@
|
||||
#!/usr/bin/python3
|
||||
"""SCAN cloud/freshness gate with optional known surfaces; no invented returns or timing."""
|
||||
from array import array
|
||||
import copy
|
||||
import math
|
||||
from collections import OrderedDict
|
||||
|
||||
import numpy as np
|
||||
import rclpy
|
||||
from rclpy.node import Node
|
||||
from rclpy.qos import QoSProfile, DurabilityPolicy, qos_profile_sensor_data
|
||||
from nav_msgs.msg import Odometry
|
||||
from sensor_msgs.msg import PointCloud2, PointField
|
||||
from std_msgs.msg import Bool
|
||||
|
||||
|
||||
class ScanCloudGate(Node):
|
||||
def __init__(self):
|
||||
super().__init__('scan_cloud_gate')
|
||||
self.cutoff = float(self.declare_parameter('ground_cutoff_z', .015).value)
|
||||
if not math.isfinite(self.cutoff):
|
||||
raise ValueError('ground_cutoff_z must be finite')
|
||||
planes=list(self.declare_parameter('traversable_planes', [0.0]*7).value)
|
||||
if len(planes)%7 or not all(math.isfinite(v) for v in planes):
|
||||
raise ValueError('traversable_planes needs groups of xmin,xmax,ymin,ymax,mx,my,b')
|
||||
self.planes=[planes[i:i+7] for i in range(0,len(planes),7) if planes[i+1]>planes[i] and planes[i+3]>planes[i+2]]
|
||||
self.planning_topic=self.declare_parameter('planning_cloud_topic','').value
|
||||
self.stamps = {}
|
||||
self.raw = OrderedDict()
|
||||
self.world = OrderedDict()
|
||||
self.pub = self.create_publisher(PointCloud2, '/cloud_registered_for_scan', 5)
|
||||
self.ready_pub = self.create_publisher(Bool, '/planning/perception_ready',
|
||||
QoSProfile(depth=1, durability=DurabilityPolicy.TRANSIENT_LOCAL))
|
||||
self.create_subscription(PointCloud2, '/cloud_registered', self.on_cloud, 5)
|
||||
self.create_subscription(PointCloud2, '/lidar/points', self.on_raw, qos_profile_sensor_data)
|
||||
self.create_subscription(Odometry, '/body_odom', lambda m: self.on_odom('body', m), 10)
|
||||
self.create_subscription(Odometry, '/aft_mapped_to_init', lambda m: self.on_odom('sensor', m), 10)
|
||||
if self.planning_topic:
|
||||
self.create_subscription(PointCloud2,self.planning_topic,self.on_planning_cloud,qos_profile_sensor_data)
|
||||
self.create_timer(.05, self.publish_ready)
|
||||
|
||||
@staticmethod
|
||||
def stamp(m):
|
||||
return m.header.stamp.sec + m.header.stamp.nanosec * 1e-9
|
||||
|
||||
def on_odom(self, key, m):
|
||||
p, q = m.pose.pose.position, m.pose.pose.orientation
|
||||
child = 'base_link' if key == 'body' else 'lidar'
|
||||
if m.header.frame_id == 'world' and m.child_frame_id == child and all(
|
||||
math.isfinite(v) for v in (p.x, p.y, p.z, q.x, q.y, q.z, q.w)):
|
||||
self.stamps[key] = self.stamp(m)
|
||||
|
||||
def on_planning_cloud(self,m):
|
||||
if m.header.frame_id=='world' and m.width*m.height>0:
|
||||
self.stamps['planning']=self.stamp(m)
|
||||
|
||||
@staticmethod
|
||||
def key(m):
|
||||
return m.header.stamp.sec * 1_000_000_000 + m.header.stamp.nanosec
|
||||
|
||||
def on_raw(self, m):
|
||||
self.raw[self.key(m)] = m
|
||||
self.flush()
|
||||
|
||||
def on_cloud(self, m):
|
||||
self.world[self.key(m)] = m
|
||||
self.flush()
|
||||
|
||||
def flush(self):
|
||||
for key in list(self.world):
|
||||
if key in self.raw:
|
||||
self.publish_cloud(self.world.pop(key), self.raw.pop(key))
|
||||
for queue in (self.raw, self.world):
|
||||
while len(queue) > 20:
|
||||
queue.popitem(last=False)
|
||||
|
||||
@staticmethod
|
||||
def views(m, data):
|
||||
fields = {f.name: f for f in m.fields}
|
||||
if any(n not in fields or fields[n].datatype != PointField.FLOAT32
|
||||
or fields[n].count != 1 for n in ('x', 'y', 'z')):
|
||||
raise ValueError('Expected float32 XYZ from the simulated lidar')
|
||||
return [np.ndarray((m.height, m.width), dtype=('>' if m.is_bigendian else '<')+'f4',
|
||||
buffer=data, offset=fields[n].offset,
|
||||
strides=(m.row_step, m.point_step)) for n in ('x', 'y', 'z')]
|
||||
|
||||
def publish_cloud(self, m, raw):
|
||||
if (m.header.frame_id != 'world' or raw.header.frame_id != 'lidar' or
|
||||
m.width*m.height == 0 or
|
||||
(m.width, m.height, m.point_step, m.row_step, m.fields) !=
|
||||
(raw.width, raw.height, raw.point_step, raw.row_step, raw.fields)):
|
||||
return
|
||||
data = bytearray(m.data)
|
||||
xyz = self.views(m, data)
|
||||
rx, ry, rz = self.views(raw, raw.data)
|
||||
valid = np.isfinite(np.stack(xyz, axis=-1)).all(axis=-1)
|
||||
if np.count_nonzero(valid) < 100:
|
||||
return
|
||||
ground = valid & (xyz[2] <= self.cutoff)
|
||||
for x0,x1,y0,y1,mx,my,b in self.planes:
|
||||
surface_z=mx*xyz[0]+my*xyz[1]+b
|
||||
ground |= valid & (xyz[0]>=x0)&(xyz[0]<=x1)&(xyz[1]>=y0)&(xyz[1]<=y1)&(np.abs(xyz[2]-surface_z)<.015)
|
||||
# Exact same point indices and acquisition stamp; no latest-pose approximation.
|
||||
# Body envelope in lidar coordinates: mount z=.30, body z=[-.15,.08].
|
||||
# 2 cm numerical margin includes the fixed support wheels and roof returns.
|
||||
self_hit = ((np.abs(rx) <= .42) & (np.abs(ry) <= .42) &
|
||||
(rz >= -.47) & (rz <= -.20))
|
||||
for v in xyz:
|
||||
v[ground | self_hit] = np.nan
|
||||
out = copy.deepcopy(m)
|
||||
out.data = array('B', data)
|
||||
out.is_dense = False
|
||||
self.pub.publish(out)
|
||||
self.stamps['cloud'] = self.stamp(m)
|
||||
|
||||
def publish_ready(self):
|
||||
now = self.get_clock().now().nanoseconds * 1e-9
|
||||
ready = all(k in self.stamps and 0 <= now-self.stamps[k] <= limit
|
||||
for k, limit in (('body', .2), ('sensor', .2), ('cloud', .25)))
|
||||
if self.planning_topic:
|
||||
ready=ready and 'planning' in self.stamps and 0<=now-self.stamps['planning']<=.3
|
||||
self.ready_pub.publish(Bool(data=ready))
|
||||
|
||||
|
||||
def main():
|
||||
rclpy.init()
|
||||
node = ScanCloudGate()
|
||||
try:
|
||||
rclpy.spin(node)
|
||||
except KeyboardInterrupt:
|
||||
pass
|
||||
finally:
|
||||
node.destroy_node()
|
||||
if rclpy.ok():
|
||||
rclpy.shutdown()
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
@@ -0,0 +1,49 @@
|
||||
cmake_minimum_required(VERSION 3.8)
|
||||
project(r2027_robot_description)
|
||||
set(CMAKE_CXX_STANDARD 17)
|
||||
|
||||
find_package(ament_cmake REQUIRED)
|
||||
find_package(gazebo REQUIRED)
|
||||
find_package(gazebo_ros REQUIRED)
|
||||
find_package(rclcpp REQUIRED)
|
||||
find_package(nav_msgs REQUIRED)
|
||||
find_package(geometry_msgs REQUIRED)
|
||||
find_package(gazebo_msgs REQUIRED)
|
||||
find_package(tf2_ros REQUIRED)
|
||||
find_package(livox_ros_driver2 REQUIRED)
|
||||
find_package(sensor_msgs REQUIRED)
|
||||
find_package(std_msgs REQUIRED)
|
||||
|
||||
add_library(br_contact_drive SHARED src/contact_drive.cpp)
|
||||
target_include_directories(br_contact_drive PRIVATE ${GAZEBO_INCLUDE_DIRS})
|
||||
target_link_libraries(br_contact_drive ${GAZEBO_LIBRARIES})
|
||||
ament_target_dependencies(br_contact_drive gazebo_ros rclcpp nav_msgs geometry_msgs gazebo_msgs tf2_ros)
|
||||
install(TARGETS br_contact_drive LIBRARY DESTINATION lib)
|
||||
|
||||
add_library(br_mid360_sensor SHARED src/mid360_sensor.cpp)
|
||||
target_include_directories(br_mid360_sensor PRIVATE ${GAZEBO_INCLUDE_DIRS})
|
||||
target_link_libraries(br_mid360_sensor ${GAZEBO_LIBRARIES})
|
||||
ament_target_dependencies(br_mid360_sensor gazebo_ros rclcpp livox_ros_driver2 sensor_msgs std_msgs)
|
||||
install(TARGETS br_mid360_sensor LIBRARY DESTINATION lib)
|
||||
|
||||
add_library(br_mid360_imu SHARED src/mid360_imu.cpp)
|
||||
target_include_directories(br_mid360_imu PRIVATE ${GAZEBO_INCLUDE_DIRS})
|
||||
target_link_libraries(br_mid360_imu ${GAZEBO_LIBRARIES})
|
||||
ament_target_dependencies(br_mid360_imu gazebo_ros rclcpp sensor_msgs)
|
||||
install(TARGETS br_mid360_imu LIBRARY DESTINATION lib)
|
||||
|
||||
# SIM-P2-001: 只装本包自己的资源。
|
||||
# 外部 /home/kevin/r2027_gazebo_model/src/r2027_robot_description 只作**只读参考**,
|
||||
# 不复制它的 ros2_control 配置、controllers.yaml、rviz 配置和 launch 逻辑。
|
||||
install(DIRECTORY launch sdf config
|
||||
DESTINATION share/${PROJECT_NAME}
|
||||
PATTERN "__pycache__" EXCLUDE
|
||||
PATTERN "*.pyc" EXCLUDE)
|
||||
|
||||
install(PROGRAMS scripts/cmd_vel_timeout.py scripts/sim_data_adapter.py
|
||||
DESTINATION lib/${PROJECT_NAME})
|
||||
|
||||
install(FILES SOURCE_PROVENANCE.md
|
||||
DESTINATION share/${PROJECT_NAME})
|
||||
|
||||
ament_package()
|
||||
@@ -0,0 +1,122 @@
|
||||
# 来源说明(SIM-P2-001 / -R1)
|
||||
|
||||
## 1. 本包新增内容
|
||||
|
||||
| 文件 | 性质 | 说明 |
|
||||
|---|---|---|
|
||||
| `sdf/r2027_omni_robot.sdf.xacro` | 本任务新写 | 参数化简化全向车体(**SDF**,不是 URDF,原因见 §5) |
|
||||
| `launch/robocon_robot.launch.py` | 本任务新写 | 统一启动入口 |
|
||||
| `scripts/cmd_vel_timeout.py` | 本任务新写 | 单一命令转发节点 `/cmd_vel → /sim/cmd_vel` |
|
||||
| `CMakeLists.txt`、`package.xml` | 本任务新写 | 构建/安装本包驱动与资源 |
|
||||
| `scripts/sim_data_adapter.py` | P3 新写 | 精确时间 TF 的真值与世界点云适配 |
|
||||
| `src/contact_drive.cpp` | P5 新写 | 可选接触支撑全向力驱动,不复制算法或外部轮控 |
|
||||
| `src/mid360_sensor.cpp` | P6 新写 | 物理步实时射线、真实批次时间、原 Livox 消息;扫描轨迹为近似 |
|
||||
| `src/mid360_imu.cpp` | P6 新写 | 原生 ImuSensor 的带时间戳比力/角速度包装,姿态标为不可用 |
|
||||
|
||||
> **R1 修正**:早期版本有一份 `urdf/r2027_omni_robot.urdf.xacro`,已删除并整体改为
|
||||
> `sdf/r2027_omni_robot.sdf.xacro`。**本包与文档中不再存在任何 `urdf/` 路径**;
|
||||
> 若在别处看到 `urdf/r2027_omni_robot.urdf.xacro`,那是过期引用,请以本节为准。
|
||||
|
||||
## 2. 只读参考(未复制)
|
||||
|
||||
外部包:`/home/kevin/r2027_gazebo_model/src/r2027_robot_description/`(只读)。
|
||||
|
||||
参考了什么:
|
||||
|
||||
- 四个圆柱支撑轮的尺寸语义:半径 **0.10 m**、轮心相对车体中心 **z = −0.05 m**、
|
||||
轮宽 0.06 m(本任务按自己的车体重新布置轮位,见 §3)。
|
||||
- 车体箱体高度 **0.16 m**、车体质量 **5.51 kg**、轮质量 **1.2 kg**(建模假设,见 §4)。
|
||||
|
||||
**没有复制**(任务明确禁止):
|
||||
|
||||
- `config/controllers.yaml` 与 `ros2_control` 相关配置;
|
||||
- 它的 `launch/robocon_robot.launch.py` 启动逻辑;
|
||||
- 它的 `rviz/robot.rviz`、`scripts/cmd_vel_watchdog.py`
|
||||
(本包的 `cmd_vel_timeout.py` 是独立实现:输入输出话题分离、仿真时间超时、退出补零);
|
||||
- 它的插件参数写法(本包按本机 `.so` 的实测行为核对,见 §5)。
|
||||
|
||||
外部包**未被修改**:哈希记录见 `sim_ws/log/p2_001/deliver/MANIFEST.txt`。
|
||||
|
||||
## 3. 尺寸与几何(本任务决定,R1 未改动)
|
||||
|
||||
| 项 | 取值 | 依据 |
|
||||
|---|---|---|
|
||||
| 水平外包络 | **0.80 × 0.80 m** | `minco_ws/src/scan/plan_manage/config/planner_vehicle.yaml` 记录的整车最大外包络 |
|
||||
| 车体箱体 | 0.80 × 0.80 × 0.16 m | 外包络即箱体 XY;高度沿用外部模型的 0.16 |
|
||||
| 支撑轮 | 4 × 圆柱,r = 0.10 m,宽 0.06 m | 半径沿用外部模型;**轮位重新布置** |
|
||||
| 轮心位置 | x = ±0.30 m,y = ±0.30 m,z = −0.05 m | 使轮外缘与箱体边沿齐平(max\|x\| = 0.40),外包络正好 0.80 |
|
||||
| `base_link` | 箱体几何中心 | 模型原点与它重合 |
|
||||
| 名义触地面 | base_link 下方 **0.15 m** | = 轮半径 0.10 − 轮心偏移 (−0.05) |
|
||||
|
||||
轮心位置是**本任务的设计决定**,不是外部模型的数值(外部为 x=±0.18、y=±0.22,配 0.53×0.56 车体)。
|
||||
改车体尺寸只需改 xacro 顶部四个 property。
|
||||
|
||||
## 4. 质量、质心与惯量(R1 修正为绕质心)
|
||||
|
||||
| 项 | 取值 | 说明 |
|
||||
|---|---|---|
|
||||
| 车体质量 | 5.51 kg | 沿用外部简化模型(建模假设) |
|
||||
| 轮质量 | 1.2 kg × 4 | 沿用外部简化模型 |
|
||||
| 总质量 M | **10.31 kg** | 5.51 + 4×1.2 |
|
||||
| 质心(相对 base_link) | **(0, 0, −0.023278370514) m** | `com_z = 4·m_w·wheel_z / M`;x/y 因对称性为 0 |
|
||||
| Ixx / Iyy / Izz(绕质心、轴向与 base_link 平行) | **0.757474524410 / 0.768034524410 / 1.465173333333 kg·m²** | 平行轴定理逐体累加 |
|
||||
| 非对角项 | **0** | 4 轮关于 x/y 对称,Σ m·dᵢdⱼ 相互抵消 |
|
||||
|
||||
**R1 改了什么**:惯性参考系从 base_link 原点移到组合质心
|
||||
(`<inertial><pose>0 0 com_z 0 0 0</pose>`),张量改为绕质心。
|
||||
**base_link、模型原点、collision、visual、TF 坐标一律未动**——
|
||||
`log/p2_001_r1/INERTIA_CHECK.md` 里有「修改前后几何签名一致」的核对。
|
||||
|
||||
> 改前那组值(ixx=iyy=0.7630613、izz=1.4651733)是**绕 base_link 原点**的,
|
||||
> 不是绕质心,**不能与上表混用**。
|
||||
|
||||
这些仍然是**建模假设**:真车质量、重心高度、轮组、雷达位置均未确认。
|
||||
P2 只验证平地运动学接口。后续 P5 接触模式与坡道实测见 `sim_ws/docs/P5_SLOPE.md`,
|
||||
仍不据此评价真实轮组牵引、打滑或实车制动距离。
|
||||
|
||||
## 5. 插件与本机实测行为
|
||||
|
||||
`libgazebo_ros_planar_move.so` 实际读取的参数:`update_rate`、`publish_rate`、
|
||||
`odometry_frame`、`robot_base_frame`、`publish_odom`、`publish_odom_tf`、
|
||||
`covariance_x/y/yaw`。
|
||||
|
||||
两点实测结论(不是照抄外部配置):
|
||||
|
||||
1. **`<cmd_vel>` 参数不被读取。** 写 `<cmd_vel>/sim/cmd_vel</cmd_vel>` 后
|
||||
`ros2 topic info /sim/cmd_vel` 显示**订阅者 0**,插件仍订阅 `/cmd_vel`,转发节点被绕过。
|
||||
改用官方 ROS remapping `<ros><remapping>cmd_vel:=sim/cmd_vel</remapping></ros>` 后生效
|
||||
(`/sim/cmd_vel` 订阅者为 `planar_move`)。
|
||||
2. **接触参数必须放在原生 SDF 里。** 同样的 `<mu1>/<mu2>/<kp>/<kd>` 写在 URDF 的
|
||||
`<gazebo reference>` 下不会进入物理引擎(证据见 `docs/P2_OMNI.md` §4.1)。
|
||||
|
||||
**频率口径**:`update_rate=100`、`publish_rate=50` 是**插件参数配置值**;
|
||||
实测 `/odom` 约 50 Hz(与 `publish_rate` 一致)。转发节点的发布率 100 Hz 同样是
|
||||
**配置值**,本轮没有逐条统计它的实测频率,不能互相替代。
|
||||
|
||||
## 6. 世界文件
|
||||
|
||||
`robocon_gazebo/worlds/robocon_robot.world` = 本包 `robocon_track_full.world` **原样** +
|
||||
一个 `libgazebo_ros_state.so`(WorldPlugin)声明。
|
||||
场地几何、物理、光照、`model://robocon_ground_full` 引用全部不变;
|
||||
原 `robocon_track_full.world` **未改动**(R1 亦未动)。
|
||||
|
||||
## 7. P5 可选接触驱动
|
||||
|
||||
`drive:=planar` 保持默认;`drive:=contact` 加载本包 `libbr_contact_drive.so`。
|
||||
只施加世界水平力和 Z 力矩,重力、真实碰撞决定 Z/roll/pitch;空中不施加推进力。
|
||||
坡面法线来自求解器接触,含理想重力补偿,不是轮子扭矩/真实摩擦模型。
|
||||
几何、质量、质心、惯量与上表一致,没有引入独立轮 link 或球形替代支撑。
|
||||
完整真值 odom 的线/角速度转为 base_link 系,TF 与 odom 由同一插件发布。
|
||||
场地包的坡道碰撞面朝向修复另见该包的 SOURCE_PROVENANCE.md;地图顶点与外部源不变。
|
||||
|
||||
## 8. P6 可选 MID360 兼容模式
|
||||
|
||||
`lidar:=true sensor_model:=mid360` 采用物理步射线和 200 Hz 原生 ImuSensor。
|
||||
光学原点仍为 base_link+(0,0,0.30) m;内置 IMU 相对光学原点的偏置按官方手册
|
||||
设为 (0.011,0.02329,−0.04412) m,轴向一致。车体安装仍是假设,未测量实车位置。
|
||||
采用非重复近似方向序列,不声称复现厂家光学轨迹;默认 ideal 无注入噪声,无材质反射率模型。
|
||||
可选 mild/stress 在物理观测后增加径向白噪声、丢点及 IMU 白噪声/固定偏置;
|
||||
参数来自本项目工程压力配置,不是厂家规格或实车标定,时间字段保持真实采样时刻。
|
||||
射线在每个真实 1 ms 物理步求交、每 100 ms 打包,时间字段没有人为细分到物理步之内。
|
||||
复用仓库原 Livox 消息定义,不运行硬件驱动;MID360 模式停用原瞬时点云适配器。
|
||||
默认 generic 模式保持原 P3 入口,详细语义与对照证据见 `sim_ws/docs/P6_LOCALIZATION.md`。
|
||||
@@ -0,0 +1,5 @@
|
||||
gazebo:
|
||||
ros__parameters:
|
||||
# 10 Hz makes 50/100 Hz ROS control timers advance in coarse bursts.
|
||||
# This affects only the robot launch; the historical field baseline stays intact.
|
||||
publish_rate: 100.0
|
||||
@@ -0,0 +1,25 @@
|
||||
# Engineering stress inputs, NOT calibrated specifications for a real MID360.
|
||||
ideal:
|
||||
range_stddev: 0.0
|
||||
dropout: 0.0
|
||||
accel_stddev: 0.0
|
||||
gyro_stddev: 0.0
|
||||
accel_bias: [0.0, 0.0, 0.0]
|
||||
gyro_bias: [0.0, 0.0, 0.0]
|
||||
seed: 2027
|
||||
mild:
|
||||
range_stddev: 0.005
|
||||
dropout: 0.01
|
||||
accel_stddev: 0.01
|
||||
gyro_stddev: 0.0005
|
||||
accel_bias: [0.005, -0.005, 0.01]
|
||||
gyro_bias: [0.0001, -0.0001, 0.0002]
|
||||
seed: 2027
|
||||
stress:
|
||||
range_stddev: 0.015
|
||||
dropout: 0.05
|
||||
accel_stddev: 0.04
|
||||
gyro_stddev: 0.0015
|
||||
accel_bias: [0.02, 0.01, 0.03]
|
||||
gyro_bias: [0.0005, -0.0005, 0.001]
|
||||
seed: 2027
|
||||
@@ -0,0 +1,236 @@
|
||||
"""启动简化全向机器人(SIM-P2-001)。
|
||||
|
||||
入口:
|
||||
ros2 launch r2027_robot_description robocon_robot.launch.py
|
||||
ros2 launch r2027_robot_description robocon_robot.launch.py gui:=false paused:=true
|
||||
|
||||
参数:
|
||||
drive planar(默认平地)或 contact(重力/接触决定高度和倾斜)
|
||||
gui 是否启动 gzclient(默认 true)
|
||||
paused 是否以暂停状态启动 gzserver(默认 false)
|
||||
verbose gzserver 详细日志(默认 false)
|
||||
world 覆盖 world(默认 robocon_gazebo/worlds/robocon_robot.world)
|
||||
x / y / z / yaw 出生位姿(默认 -4.5 / 4.5 / 0.17 / 0.0)
|
||||
entity 模型名(默认 r2027_omni)
|
||||
|
||||
启动的节点:
|
||||
gzserver(官方 gazebo_ros gzserver.launch.py,init/factory 各一次,force_system:=false)
|
||||
spawn_entity.py(-file,插入 xacro 展开后的 SDF 模型)
|
||||
static_transform_publisher(world -> odom,单位变换)
|
||||
cmd_vel_timeout(/cmd_vel -> /sim/cmd_vel,仿真时间超时零速)
|
||||
|
||||
为什么模型是 SDF 而不是 URDF:
|
||||
URDF 的 <gazebo reference="link"><mu1>/<mu2>/<kp>/<kd> 在本机链路上**不会**进入物理引擎
|
||||
(`gz sdf -p` 转换出的 collision 没有 <surface>,且 μ=0.05 与 μ=0.0 实测位移完全相同)。
|
||||
轮子因此退回默认 μ=1.0,planar_move 设定的速度每 10 ms 被摩擦拉低,2 s 只走出 0.31 m。
|
||||
改原生 SDF 后接触参数真正生效。代价是不再有 robot_state_publisher 的 URDF 关节树,
|
||||
而任务要求的 TF 只有 world->odom(静态)与 odom->base_link(插件发布),
|
||||
不含轮子帧,因此不需要 robot_state_publisher。
|
||||
|
||||
设计约束:
|
||||
1. 只起一个 gzserver;不启动 ros_gz_bridge、不加载 Fortress。
|
||||
2. odom->base_link 只由插件发布,world->odom 只由静态变换发布,没有第二处重复。
|
||||
3. 世界文件只比 robocon_track_full.world 多一个 libgazebo_ros_state.so world 插件。
|
||||
4. GAZEBO_MASTER_URI=11355、ROS_DOMAIN_ID=77、ROS_LOCALHOST_ONLY=1 与已验收基线一致。
|
||||
"""
|
||||
|
||||
import os
|
||||
import tempfile
|
||||
import math
|
||||
import yaml
|
||||
|
||||
import xacro
|
||||
from ament_index_python.packages import get_package_share_directory, get_package_prefix
|
||||
from launch import LaunchDescription
|
||||
from launch.actions import (
|
||||
DeclareLaunchArgument,
|
||||
IncludeLaunchDescription,
|
||||
SetEnvironmentVariable,
|
||||
OpaqueFunction,
|
||||
)
|
||||
from launch.conditions import IfCondition
|
||||
from launch.launch_description_sources import PythonLaunchDescriptionSource
|
||||
from launch.substitutions import LaunchConfiguration, PythonExpression, EnvironmentVariable
|
||||
from launch_ros.actions import Node
|
||||
|
||||
GAZEBO_MASTER_URI = 'http://127.0.0.1:11355'
|
||||
|
||||
DEFAULT_X = '-4.5'
|
||||
DEFAULT_Y = '4.5'
|
||||
DEFAULT_Z = '0.17'
|
||||
DEFAULT_YAW = '0.0'
|
||||
|
||||
|
||||
def generate_launch_description():
|
||||
gz_share = get_package_share_directory('robocon_gazebo')
|
||||
robot_share = get_package_share_directory('r2027_robot_description')
|
||||
gazebo_ros_share = get_package_share_directory('gazebo_ros')
|
||||
|
||||
sdf_xacro = os.path.join(robot_share, 'sdf', 'r2027_omni_robot.sdf.xacro')
|
||||
# 展开期就确定下来,写成一个文件交给 spawn_entity(-file),
|
||||
# 这样"实际插入的模型"是一个可直接复查的文件,而不是只在内存里的字符串。
|
||||
# Expand after launch arguments are resolved; no second physical sensor link.
|
||||
def expand_model(context):
|
||||
drive = LaunchConfiguration('drive').perform(context)
|
||||
if drive not in ('planar', 'contact'):
|
||||
raise ValueError('drive must be planar or contact')
|
||||
sensor_model = LaunchConfiguration('sensor_model').perform(context)
|
||||
if sensor_model not in ('generic', 'mid360'):
|
||||
raise ValueError('sensor_model must be generic or mid360')
|
||||
profile_name=LaunchConfiguration('sensor_profile').perform(context)
|
||||
with open(os.path.join(robot_share,'config','sensor_profiles.yaml'),encoding='utf-8') as stream:
|
||||
profiles=yaml.safe_load(stream)
|
||||
if profile_name not in profiles or (sensor_model!='mid360' and profile_name!='ideal'):
|
||||
raise ValueError('Unknown sensor profile or noisy profile with generic lidar')
|
||||
profile=profiles[profile_name]
|
||||
scalars=[profile[k] for k in ('range_stddev','dropout','accel_stddev','gyro_stddev')]
|
||||
if not all(math.isfinite(v) and v>=0 for v in scalars) or profile['dropout']>1:
|
||||
raise ValueError('Invalid sensor noise profile')
|
||||
for key in ('accel_bias','gyro_bias'):
|
||||
if len(profile[key])!=3 or not all(math.isfinite(v) for v in profile[key]):
|
||||
raise ValueError('Invalid IMU bias vector')
|
||||
if type(profile['seed']) is not int or not 0<=profile['seed']<2**32:
|
||||
raise ValueError('Invalid noise seed')
|
||||
noise={k:str(profile[k]) for k in ('range_stddev','dropout','accel_stddev','gyro_stddev')}
|
||||
noise.update({k:' '.join(map(str,profile[k])) for k in ('accel_bias','gyro_bias')})
|
||||
noise['noise_seed']=str(profile['seed'])
|
||||
model_xml = xacro.process_file(sdf_xacro, mappings={
|
||||
'lidar': LaunchConfiguration('lidar').perform(context), 'drive': drive,
|
||||
'sensor_model': sensor_model,**noise}).toxml()
|
||||
fd, path = tempfile.mkstemp(prefix='r2027_omni_', suffix='.sdf')
|
||||
with os.fdopen(fd, 'w', encoding='utf-8') as stream:
|
||||
stream.write(model_xml)
|
||||
context.launch_configurations['expanded_model'] = path
|
||||
return []
|
||||
|
||||
default_world = os.path.join(gz_share, 'worlds', 'robocon_robot.world')
|
||||
|
||||
model_path_parts = [os.path.join(gz_share, 'models'),
|
||||
os.path.expanduser('~/.gazebo/models')]
|
||||
if os.environ.get('GAZEBO_MODEL_PATH'):
|
||||
model_path_parts.append(os.environ['GAZEBO_MODEL_PATH'])
|
||||
|
||||
declared_args = [
|
||||
DeclareLaunchArgument('sensor_profile',default_value='ideal'),
|
||||
DeclareLaunchArgument('ros_domain_id',default_value=EnvironmentVariable('ROS_DOMAIN_ID',default_value='77')),
|
||||
DeclareLaunchArgument('ros_localhost_only',default_value=EnvironmentVariable('ROS_LOCALHOST_ONLY',default_value='1')),
|
||||
DeclareLaunchArgument('drive', default_value='planar'),
|
||||
DeclareLaunchArgument('sensor_model', default_value='generic'),
|
||||
DeclareLaunchArgument('lidar', default_value='false',
|
||||
description='Enable generic CPU 3D lidar and truth data adapter'),
|
||||
DeclareLaunchArgument('gui', default_value='true'),
|
||||
DeclareLaunchArgument('paused', default_value='false'),
|
||||
DeclareLaunchArgument('verbose', default_value='false'),
|
||||
DeclareLaunchArgument('world', default_value=default_world),
|
||||
DeclareLaunchArgument('x', default_value=DEFAULT_X),
|
||||
DeclareLaunchArgument('y', default_value=DEFAULT_Y),
|
||||
DeclareLaunchArgument('z', default_value=DEFAULT_Z),
|
||||
DeclareLaunchArgument('yaw', default_value=DEFAULT_YAW),
|
||||
DeclareLaunchArgument('entity', default_value='r2027_omni'),
|
||||
]
|
||||
|
||||
env_actions = [
|
||||
SetEnvironmentVariable('GAZEBO_PLUGIN_PATH', os.pathsep.join([
|
||||
os.path.join(get_package_prefix('r2027_robot_description'), 'lib'),
|
||||
os.environ.get('GAZEBO_PLUGIN_PATH', '')])),
|
||||
SetEnvironmentVariable('GAZEBO_MASTER_URI', GAZEBO_MASTER_URI),
|
||||
SetEnvironmentVariable('ROS_DOMAIN_ID', LaunchConfiguration('ros_domain_id')),
|
||||
SetEnvironmentVariable('ROS_LOCALHOST_ONLY', LaunchConfiguration('ros_localhost_only')),
|
||||
SetEnvironmentVariable('GAZEBO_MODEL_PATH', os.pathsep.join(model_path_parts)),
|
||||
# /usr/bin 放最前:本机 `python3` 可能先命中别的解释器(例如 3.13),
|
||||
# 而 rclpy / numpy 只装在系统 3.10 下。spawn_entity.py 用的是
|
||||
# `#!/usr/bin/env python3`,不固定 PATH 会 ImportError。
|
||||
SetEnvironmentVariable('PATH', '/usr/bin:' + os.environ.get('PATH', '')),
|
||||
]
|
||||
|
||||
gzserver = IncludeLaunchDescription(
|
||||
PythonLaunchDescriptionSource(
|
||||
os.path.join(gazebo_ros_share, 'launch', 'gzserver.launch.py')),
|
||||
launch_arguments={
|
||||
'world': LaunchConfiguration('world'),
|
||||
'verbose': LaunchConfiguration('verbose'),
|
||||
'pause': LaunchConfiguration('paused'),
|
||||
'init': 'true',
|
||||
'factory': 'true',
|
||||
'force_system': 'false',
|
||||
'params_file': os.path.join(robot_share, 'config', 'gazebo.yaml'),
|
||||
'server_required': 'true',
|
||||
}.items(),
|
||||
)
|
||||
|
||||
gzclient = IncludeLaunchDescription(
|
||||
PythonLaunchDescriptionSource(
|
||||
os.path.join(gazebo_ros_share, 'launch', 'gzclient.launch.py')),
|
||||
condition=IfCondition(LaunchConfiguration('gui')),
|
||||
)
|
||||
|
||||
spawn = Node(
|
||||
package='gazebo_ros',
|
||||
executable='spawn_entity.py',
|
||||
name='spawn_entity',
|
||||
output='screen',
|
||||
parameters=[{'use_sim_time': True}],
|
||||
arguments=[
|
||||
'-file', LaunchConfiguration('expanded_model'),
|
||||
'-entity', LaunchConfiguration('entity'),
|
||||
'-x', LaunchConfiguration('x'),
|
||||
'-y', LaunchConfiguration('y'),
|
||||
'-z', LaunchConfiguration('z'),
|
||||
'-Y', LaunchConfiguration('yaw'),
|
||||
'-timeout', '120',
|
||||
],
|
||||
)
|
||||
|
||||
# world -> odom:单位变换(真值模式,odom 与世界同源同向)
|
||||
world_to_odom = Node(
|
||||
package='tf2_ros',
|
||||
executable='static_transform_publisher',
|
||||
name='world_to_odom',
|
||||
output='screen',
|
||||
parameters=[{'use_sim_time': True}],
|
||||
arguments=['--frame-id', 'world',
|
||||
'--child-frame-id', 'odom',
|
||||
'--x', '0', '--y', '0', '--z', '0',
|
||||
'--roll', '0', '--pitch', '0', '--yaw', '0'],
|
||||
)
|
||||
|
||||
cmd_timeout = Node(
|
||||
package='r2027_robot_description',
|
||||
executable='cmd_vel_timeout.py',
|
||||
name='cmd_vel_timeout',
|
||||
output='screen',
|
||||
parameters=[{'use_sim_time': True,
|
||||
'input_topic': '/cmd_vel',
|
||||
'output_topic': '/sim/cmd_vel',
|
||||
'timeout': 0.5,
|
||||
'publish_rate': 100.0}],
|
||||
)
|
||||
|
||||
lidar_tf = Node(
|
||||
package='tf2_ros', executable='static_transform_publisher',
|
||||
name='base_to_lidar', condition=IfCondition(LaunchConfiguration('lidar')),
|
||||
parameters=[{'use_sim_time': True}],
|
||||
arguments=['--frame-id', 'base_link', '--child-frame-id', 'lidar',
|
||||
'--x', '0', '--y', '0', '--z', '0.30',
|
||||
'--roll', '0', '--pitch', '0', '--yaw', '0'])
|
||||
adapter = Node(
|
||||
package='r2027_robot_description', executable='sim_data_adapter.py',
|
||||
name='sim_data_adapter', condition=IfCondition(PythonExpression([
|
||||
"'", LaunchConfiguration('lidar'), "'.lower() == 'true' and '",
|
||||
LaunchConfiguration('sensor_model'), "' == 'generic'"])),
|
||||
parameters=[{'use_sim_time': True}])
|
||||
|
||||
imu_tf = Node(
|
||||
package='tf2_ros', executable='static_transform_publisher',name='base_to_mid360_imu',
|
||||
condition=IfCondition(PythonExpression([
|
||||
"'", LaunchConfiguration('lidar'), "'.lower() == 'true' and '",
|
||||
LaunchConfiguration('sensor_model'), "' == 'mid360'"])),
|
||||
parameters=[{'use_sim_time': True}],
|
||||
arguments=['--frame-id','base_link','--child-frame-id','mid360_imu',
|
||||
'--x','0.011','--y','0.02329','--z','0.25588',
|
||||
'--roll','0','--pitch','0','--yaw','0'])
|
||||
|
||||
return LaunchDescription(
|
||||
declared_args + env_actions
|
||||
+ [OpaqueFunction(function=expand_model), gzserver, gzclient, spawn,
|
||||
world_to_odom, cmd_timeout, lidar_tf, adapter, imu_tf])
|
||||
@@ -0,0 +1,42 @@
|
||||
<?xml version="1.0"?>
|
||||
<?xml-model href="http://download.ros.org/schema/package_format3.xsd" schematypens="http://www.w3.org/2001/XMLSchema"?>
|
||||
<package format="3">
|
||||
<name>r2027_robot_description</name>
|
||||
<version>0.1.0</version>
|
||||
<description>Gazebo Classic 11 / ROS 2 Humble simplified omni robot: planar or optional contact-force drive, command timeout guard, generic 3D lidar and truth adaptation.</description>
|
||||
<maintainer email="[email protected]">xie</maintainer>
|
||||
<license>Apache-2.0</license>
|
||||
|
||||
<buildtool_depend>ament_cmake</buildtool_depend>
|
||||
<build_depend>gazebo_dev</build_depend>
|
||||
<build_depend>gazebo_ros</build_depend>
|
||||
<build_depend>rclcpp</build_depend>
|
||||
<build_depend>nav_msgs</build_depend>
|
||||
<build_depend>geometry_msgs</build_depend>
|
||||
<build_depend>gazebo_msgs</build_depend>
|
||||
<build_depend>tf2_ros</build_depend>
|
||||
<depend>livox_ros_driver2</depend>
|
||||
<build_depend>sensor_msgs</build_depend>
|
||||
<depend>std_msgs</depend>
|
||||
|
||||
<exec_depend>gazebo_ros</exec_depend>
|
||||
<exec_depend>gazebo_plugins</exec_depend>
|
||||
<exec_depend>gazebo_msgs</exec_depend>
|
||||
<exec_depend>geometry_msgs</exec_depend>
|
||||
<exec_depend>nav_msgs</exec_depend>
|
||||
<exec_depend>sensor_msgs</exec_depend>
|
||||
<exec_depend>python3-numpy</exec_depend>
|
||||
<exec_depend>python3-yaml</exec_depend>
|
||||
<exec_depend>launch</exec_depend>
|
||||
<exec_depend>launch_ros</exec_depend>
|
||||
<exec_depend>ament_index_python</exec_depend>
|
||||
<exec_depend>rclpy</exec_depend>
|
||||
<exec_depend>rclcpp</exec_depend>
|
||||
<exec_depend>tf2_ros</exec_depend>
|
||||
<exec_depend>xacro</exec_depend>
|
||||
<exec_depend>robocon_gazebo</exec_depend>
|
||||
|
||||
<export>
|
||||
<build_type>ament_cmake</build_type>
|
||||
</export>
|
||||
</package>
|
||||
@@ -0,0 +1,121 @@
|
||||
#!/usr/bin/python3
|
||||
# -*- coding: utf-8 -*-
|
||||
"""单一命令转发节点(SIM-P2-001)。
|
||||
|
||||
职责边界(只做这一件事,不做运动学、不发布里程计):
|
||||
/cmd_vel ──► 本节点 ──► /sim/cmd_vel ──► libgazebo_ros_planar_move.so
|
||||
|
||||
为什么要它:planar_move 会把最近一次速度一直保持下去,本身没有超时保护。
|
||||
这里做三件事:
|
||||
1. 输入输出话题分开(订阅 /cmd_vel,发布 /sim/cmd_vel),插件只订阅后者,
|
||||
**不存在「订阅与发布同一话题」的反馈回路**;
|
||||
2. 指令静默超过 `timeout` 秒**仿真时间**后持续输出零速度;
|
||||
从未收到指令时也一直输出零;
|
||||
3. 正常退出前补发若干帧零速度,避免插件停在最后一帧非零速度上。
|
||||
|
||||
时间口径:全部用 ROS 仿真时间(`use_sim_time=true`)。暂停时时钟不前进,定时器不触发,
|
||||
所以暂停期间不会因为「墙钟超时」而擅自发零——这是有意的。
|
||||
"""
|
||||
|
||||
import rclpy
|
||||
from geometry_msgs.msg import Twist
|
||||
from rclpy.node import Node
|
||||
|
||||
|
||||
def _zero():
|
||||
return Twist()
|
||||
|
||||
|
||||
class CmdVelTimeout(Node):
|
||||
def __init__(self):
|
||||
super().__init__('cmd_vel_timeout')
|
||||
|
||||
self.declare_parameter('input_topic', '/cmd_vel')
|
||||
self.declare_parameter('output_topic', '/sim/cmd_vel')
|
||||
self.declare_parameter('timeout', 0.5) # 秒(仿真时间)
|
||||
self.declare_parameter('publish_rate', 50.0) # Hz(仿真时间)
|
||||
self.declare_parameter('shutdown_zero_frames', 5)
|
||||
|
||||
in_topic = self.get_parameter('input_topic').value
|
||||
out_topic = self.get_parameter('output_topic').value
|
||||
self.timeout = float(self.get_parameter('timeout').value)
|
||||
rate = float(self.get_parameter('publish_rate').value)
|
||||
self.shutdown_zero_frames = int(self.get_parameter('shutdown_zero_frames').value)
|
||||
|
||||
self.last_cmd_sim = None # 最近一次收到指令的仿真时刻
|
||||
self.last_cmd = _zero()
|
||||
self.is_stale = False # 当前是否处于「已超时、正在发零」
|
||||
self.count_in = 0
|
||||
self.count_out = 0
|
||||
self.count_zero_by_timeout = 0
|
||||
self.events = [] # [(sim_time, event)]
|
||||
|
||||
self.sub = self.create_subscription(Twist, in_topic, self._on_cmd, 10)
|
||||
self.pub = self.create_publisher(Twist, out_topic, 10)
|
||||
self.timer = self.create_timer(1.0 / max(rate, 1e-3), self._tick)
|
||||
|
||||
self.get_logger().info(
|
||||
'命令转发已启动:%s -> %s,超时 %.2f s(仿真时间),输出 %.0f Hz'
|
||||
% (in_topic, out_topic, self.timeout, rate))
|
||||
|
||||
# ------------------------------------------------------------------ 回调
|
||||
def _now_sim(self):
|
||||
return self.get_clock().now().nanoseconds * 1e-9
|
||||
|
||||
def _on_cmd(self, msg):
|
||||
self.count_in += 1
|
||||
self.last_cmd_sim = self._now_sim()
|
||||
self.last_cmd = msg
|
||||
if self.is_stale:
|
||||
self.is_stale = False
|
||||
self.events.append((self.last_cmd_sim, 'resume_from_timeout'))
|
||||
self.get_logger().info('收到新指令,结束超时零速(t=%.3f)' % self.last_cmd_sim)
|
||||
|
||||
def _tick(self):
|
||||
now = self._now_sim()
|
||||
if self.last_cmd_sim is None:
|
||||
self._publish(_zero())
|
||||
return
|
||||
if now - self.last_cmd_sim > self.timeout:
|
||||
if not self.is_stale:
|
||||
self.is_stale = True
|
||||
self.events.append((now, 'timeout_zero_start'))
|
||||
self.get_logger().info(
|
||||
'指令静默 %.3f s > %.2f s,开始持续输出零速度(t=%.3f)'
|
||||
% (now - self.last_cmd_sim, self.timeout, now))
|
||||
self.count_zero_by_timeout += 1
|
||||
self._publish(_zero())
|
||||
return
|
||||
self._publish(self.last_cmd)
|
||||
|
||||
def _publish(self, msg):
|
||||
self.pub.publish(msg)
|
||||
self.count_out += 1
|
||||
|
||||
# ------------------------------------------------------------------ 退出
|
||||
def shutdown_zero(self):
|
||||
"""正常退出前补发零速度,别让插件停在最后一帧非零上。"""
|
||||
for _ in range(max(self.shutdown_zero_frames, 1)):
|
||||
self.pub.publish(_zero())
|
||||
rclpy.spin_once(self, timeout_sec=0.01)
|
||||
|
||||
|
||||
def main():
|
||||
rclpy.init()
|
||||
node = CmdVelTimeout()
|
||||
try:
|
||||
rclpy.spin(node)
|
||||
except KeyboardInterrupt:
|
||||
pass
|
||||
finally:
|
||||
try:
|
||||
node.shutdown_zero()
|
||||
except Exception: # noqa: BLE001 - 退出阶段不再抛
|
||||
pass
|
||||
node.destroy_node()
|
||||
if rclpy.ok():
|
||||
rclpy.shutdown()
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
@@ -0,0 +1,140 @@
|
||||
#!/usr/bin/python3
|
||||
"""Truth-mode SCAN inputs. No localization, command integration or invented timing.
|
||||
|
||||
The instantaneous lidar cloud is transformed with TF at its acquisition stamp.
|
||||
Pose is in world; Odometry twist stays in the stated child frame. The virtual
|
||||
lidar's 0.30 m mount is shared with the SDF and static TF in the robot launch.
|
||||
"""
|
||||
from array import array
|
||||
from collections import deque
|
||||
import copy
|
||||
|
||||
import numpy as np
|
||||
import rclpy
|
||||
from rclpy.duration import Duration
|
||||
from rclpy.node import Node
|
||||
from rclpy.qos import qos_profile_sensor_data
|
||||
from rclpy.time import Time
|
||||
from nav_msgs.msg import Odometry
|
||||
from sensor_msgs.msg import PointCloud2, PointField
|
||||
from tf2_ros import Buffer, TransformException, TransformListener
|
||||
|
||||
|
||||
def rotation(q):
|
||||
v = np.array([q.x, q.y, q.z, q.w], dtype=float)
|
||||
norm = np.linalg.norm(v)
|
||||
if not np.isfinite(norm) or norm < 1e-9:
|
||||
raise ValueError('invalid quaternion')
|
||||
x, y, z, w = v / norm
|
||||
return np.array([[1-2*(y*y+z*z), 2*(x*y-z*w), 2*(x*z+y*w)],
|
||||
[2*(x*y+z*w), 1-2*(x*x+z*z), 2*(y*z-x*w)],
|
||||
[2*(x*z-y*w), 2*(y*z+x*w), 1-2*(x*x+y*y)]])
|
||||
|
||||
|
||||
def xyz_views(msg, data=None):
|
||||
"""Respect PointCloud2 endianness, field offsets and row padding."""
|
||||
fields = {f.name: f for f in msg.fields}
|
||||
prefix = '>' if msg.is_bigendian else '<'
|
||||
result = []
|
||||
for name in ('x', 'y', 'z'):
|
||||
f = fields[name]
|
||||
if f.count != 1 or f.datatype not in (PointField.FLOAT32, PointField.FLOAT64):
|
||||
raise ValueError('unsupported XYZ layout')
|
||||
dt = prefix + ('f4' if f.datatype == PointField.FLOAT32 else 'f8')
|
||||
result.append(np.ndarray((msg.height, msg.width), dtype=dt,
|
||||
buffer=msg.data if data is None else data, offset=f.offset,
|
||||
strides=(msg.row_step, msg.point_step)))
|
||||
return result
|
||||
|
||||
|
||||
class SimDataAdapter(Node):
|
||||
def __init__(self):
|
||||
super().__init__('sim_data_adapter')
|
||||
self.tf = Buffer(cache_time=Duration(seconds=10))
|
||||
self.listener = TransformListener(self.tf, self)
|
||||
self.cloud_pub = self.create_publisher(PointCloud2, '/cloud_registered', 5)
|
||||
self.body_pub = self.create_publisher(Odometry, '/body_odom', 10)
|
||||
self.sensor_pub = self.create_publisher(Odometry, '/aft_mapped_to_init', 10)
|
||||
self.pending_cloud = deque(maxlen=10)
|
||||
self.pending_odom = deque(maxlen=50)
|
||||
self.create_subscription(PointCloud2, '/lidar/points',
|
||||
self.pending_cloud.append, qos_profile_sensor_data)
|
||||
self.create_subscription(Odometry, '/odom', self.pending_odom.append, 50)
|
||||
self.create_timer(0.02, self.flush)
|
||||
self.mount = np.array([0., 0., .30])
|
||||
self.clouds = 0
|
||||
self.odoms = 0
|
||||
|
||||
def flush(self):
|
||||
# Nonblocking TF queries: allow this executor to receive the next TF.
|
||||
for queue, handler in ((self.pending_odom, self.publish_odom),
|
||||
(self.pending_cloud, self.publish_cloud)):
|
||||
for _ in range(len(queue)):
|
||||
msg = queue.popleft()
|
||||
try:
|
||||
handler(msg)
|
||||
except TransformException:
|
||||
age = (self.get_clock().now() - Time.from_msg(msg.header.stamp)).nanoseconds
|
||||
if age < 2_000_000_000:
|
||||
queue.append(msg)
|
||||
else:
|
||||
self.get_logger().warning('Dropped sample: exact-stamp TF unavailable')
|
||||
except (ValueError, KeyError, TypeError) as exc:
|
||||
self.get_logger().error('Invalid input: %s' % exc)
|
||||
|
||||
def publish_cloud(self, msg):
|
||||
tr = self.tf.lookup_transform('world', msg.header.frame_id,
|
||||
Time.from_msg(msg.header.stamp))
|
||||
xyz = np.stack(xyz_views(msg), axis=-1)
|
||||
t = tr.transform.translation
|
||||
transformed = xyz @ rotation(tr.transform.rotation).T + [t.x, t.y, t.z]
|
||||
out = copy.deepcopy(msg)
|
||||
data = bytearray(msg.data)
|
||||
for i, v in enumerate(xyz_views(msg, data)):
|
||||
v[:] = transformed[..., i]
|
||||
out.data = array('B', data)
|
||||
out.header.frame_id = 'world'
|
||||
# Acquisition timestamp and every non-XYZ field stay unchanged.
|
||||
self.cloud_pub.publish(out)
|
||||
self.clouds += 1
|
||||
|
||||
def publish_odom(self, msg):
|
||||
tr = self.tf.lookup_transform('world', msg.header.frame_id,
|
||||
Time.from_msg(msg.header.stamp))
|
||||
# The current contract is an explicit identity world->odom static TF.
|
||||
# Reject a changed contract instead of silently relabelling coordinates.
|
||||
t = tr.transform.translation
|
||||
if np.linalg.norm([t.x, t.y, t.z]) > 1e-8 or not np.allclose(
|
||||
rotation(tr.transform.rotation), np.eye(3), atol=1e-8):
|
||||
raise ValueError('world->odom must be identity in truth mode')
|
||||
body = copy.deepcopy(msg)
|
||||
body.header.frame_id = 'world'
|
||||
self.body_pub.publish(body)
|
||||
sensor = copy.deepcopy(body)
|
||||
sensor.child_frame_id = 'lidar'
|
||||
p = body.pose.pose.position
|
||||
sensor_pos = np.array([p.x, p.y, p.z]) + rotation(body.pose.pose.orientation) @ self.mount
|
||||
sensor.pose.pose.position.x, sensor.pose.pose.position.y, sensor.pose.pose.position.z = map(float, sensor_pos)
|
||||
v = sensor.twist.twist.linear
|
||||
w = sensor.twist.twist.angular
|
||||
shifted = np.array([v.x, v.y, v.z]) + np.cross([w.x, w.y, w.z], self.mount)
|
||||
v.x, v.y, v.z = map(float, shifted)
|
||||
self.sensor_pub.publish(sensor)
|
||||
self.odoms += 1
|
||||
|
||||
|
||||
def main():
|
||||
rclpy.init()
|
||||
node = SimDataAdapter()
|
||||
try:
|
||||
rclpy.spin(node)
|
||||
except KeyboardInterrupt:
|
||||
pass
|
||||
finally:
|
||||
node.destroy_node()
|
||||
if rclpy.ok():
|
||||
rclpy.shutdown()
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
@@ -0,0 +1,246 @@
|
||||
<?xml version="1.0"?>
|
||||
<!--
|
||||
SIM-P2-001 / -R1 简化全向机器人(Gazebo Classic 11 + ROS 2 Humble)—— 原生 SDF
|
||||
|
||||
为什么是 SDF 而不是 URDF(实测结论,不是偏好):
|
||||
URDF 的 <gazebo reference="link"><mu1>/<mu2>/<kp>/<kd> 在本机这条链路上**没有生效**。
|
||||
证据:μ 改 0.05 与改 0.0 测得的 2 s 位移完全一致(均 0.3137 m),
|
||||
且 `gz sdf -p`(gazebo 11.10.2 自带工具)转换 URDF 时输出的 collision **没有 <surface>**。
|
||||
改成原生 SDF 后 <surface> 直接进入物理引擎。
|
||||
|
||||
单刚体:四个支撑轮以 collision/visual 的形式并在 base_link 内。做成一个刚体而不是
|
||||
5 个 link + fixed joint,是实测驱动的选择(见 docs/P2_OMNI.md §4.2)。
|
||||
注意:那只解释了「当时观察到转向只有指令的 0.386 倍」这一现象,**内部机理尚未完全定位**,
|
||||
不能推广成「独立轮 link 必然如此」。
|
||||
|
||||
几何(R1 未改动):
|
||||
- 水平外包络 0.80 × 0.80 m(含四个支撑轮),与 planner_vehicle.yaml 一致;
|
||||
- 车体箱体 0.80 × 0.80 × 0.16 m,mass 5.51 kg(建模假设);
|
||||
- 四个圆柱支撑轮 r=0.10 m、宽 0.06 m、mass 1.2 kg,轮心相对车体中心 z=-0.05 m;
|
||||
- base_link 位于箱体几何中心,模型原点与它重合,名义触地面在 base_link 下方 0.15 m。
|
||||
|
||||
惯量(R1 修正):惯性参考系移到**组合质心**(z = com_z),张量绕质心、轴向与 base_link 平行。
|
||||
只改惯性参考系与张量;base_link、模型原点、collision、visual 和 TF 坐标一律不移动。
|
||||
-->
|
||||
<sdf version="1.6" xmlns:xacro="http://www.ros.org/wiki/xacro">
|
||||
<xacro:arg name="lidar" default="false"/>
|
||||
<xacro:arg name="drive" default="planar"/>
|
||||
<xacro:arg name="sensor_model" default="generic"/>
|
||||
<xacro:arg name="range_stddev" default="0"/>
|
||||
<xacro:arg name="dropout" default="0"/>
|
||||
<xacro:arg name="accel_stddev" default="0"/>
|
||||
<xacro:arg name="gyro_stddev" default="0"/>
|
||||
<xacro:arg name="accel_bias" default="0 0 0"/>
|
||||
<xacro:arg name="gyro_bias" default="0 0 0"/>
|
||||
<xacro:arg name="noise_seed" default="2027"/>
|
||||
<xacro:property name="body_length" value="0.80"/>
|
||||
<xacro:property name="body_width" value="0.80"/>
|
||||
<xacro:property name="body_height" value="0.16"/>
|
||||
|
||||
<xacro:property name="body_mass" value="5.51"/>
|
||||
<xacro:property name="wheel_mass" value="1.2"/>
|
||||
|
||||
<xacro:property name="wheel_radius" value="0.10"/>
|
||||
<xacro:property name="wheel_width" value="0.06"/>
|
||||
<xacro:property name="wheel_x" value="0.30"/>
|
||||
<xacro:property name="wheel_y" value="0.30"/>
|
||||
<xacro:property name="wheel_z" value="-0.05"/>
|
||||
|
||||
<!-- 各刚体绕自身 COM 的惯量(按简化几何算,不是实车惯量) -->
|
||||
<xacro:property name="body_ixx"
|
||||
value="${body_mass * (body_width*body_width + body_height*body_height) / 12.0}"/>
|
||||
<xacro:property name="body_iyy"
|
||||
value="${body_mass * (body_length*body_length + body_height*body_height) / 12.0}"/>
|
||||
<xacro:property name="body_izz"
|
||||
value="${body_mass * (body_length*body_length + body_width*body_width) / 12.0}"/>
|
||||
<!-- 圆柱轴沿 Y(绕 X 转 90°):轴向 = Y,径向 = X/Z -->
|
||||
<xacro:property name="wheel_i_axis"
|
||||
value="${0.5 * wheel_mass * wheel_radius * wheel_radius}"/>
|
||||
<xacro:property name="wheel_i_perp"
|
||||
value="${wheel_mass * (3.0*wheel_radius*wheel_radius + wheel_width*wheel_width) / 12.0}"/>
|
||||
|
||||
<!-- 组合刚体:总质量、质心、绕质心的惯量(全部由参数算,不写近似常数)。
|
||||
车体箱体 COM 在 base_link 原点 (0,0,0);四个轮子 COM 在 (±wheel_x, ±wheel_y, wheel_z),
|
||||
关于 x/y 对称 ⇒ 质心只在 z 上偏移:com_z = 4·m_w·wheel_z / M。
|
||||
绕质心用平行轴:自身 COM 惯量 + m·|d|²,d 为自身 COM 指向系统质心的向量。
|
||||
z 向偏移只进 Ixx/Iyy(含 dz²),不进 Izz(只含 dx²+dy²)。 -->
|
||||
<xacro:property name="total_mass" value="${body_mass + 4.0*wheel_mass}"/>
|
||||
<xacro:property name="com_z" value="${4.0*wheel_mass*wheel_z / total_mass}"/>
|
||||
<xacro:property name="dz_body" value="${0.0 - com_z}"/>
|
||||
<xacro:property name="dz_wheel" value="${wheel_z - com_z}"/>
|
||||
<xacro:property name="tot_ixx"
|
||||
value="${body_ixx + body_mass*dz_body*dz_body + 4.0*(wheel_i_perp + wheel_mass*(wheel_y*wheel_y + dz_wheel*dz_wheel))}"/>
|
||||
<xacro:property name="tot_iyy"
|
||||
value="${body_iyy + body_mass*dz_body*dz_body + 4.0*(wheel_i_axis + wheel_mass*(wheel_x*wheel_x + dz_wheel*dz_wheel))}"/>
|
||||
<xacro:property name="tot_izz"
|
||||
value="${body_izz + 4.0*(wheel_i_perp + wheel_mass*(wheel_x*wheel_x + wheel_y*wheel_y))}"/>
|
||||
|
||||
<!-- 支撑轮:碰撞 + 显示,作为单刚体的一部分(不是独立 link) -->
|
||||
<xacro:macro name="omni_wheel" params="name x_sign y_sign">
|
||||
<collision name="${name}_wheel_collision">
|
||||
<pose>${x_sign * wheel_x} ${y_sign * wheel_y} ${wheel_z} 1.5707963267948966 0 0</pose>
|
||||
<geometry>
|
||||
<cylinder>
|
||||
<radius>${wheel_radius}</radius>
|
||||
<length>${wheel_width}</length>
|
||||
</cylinder>
|
||||
</geometry>
|
||||
<!-- 轮子是**固定支撑件**,不是被驱动的摩擦轮:planar_move 每 10 ms 直接设定车体速度,
|
||||
接触摩擦按 μ=1.0 会把这个速度每周期拉低三成(实测 0.19→0.12 m/s)。
|
||||
μ=0.01 是建模选择,让运动学接口不被轮胎摩擦掩盖;**不代表实车轮组摩擦**,
|
||||
也不用于评价爬坡/制动。 -->
|
||||
<surface>
|
||||
<friction>
|
||||
<ode>
|
||||
<mu>0.01</mu>
|
||||
<mu2>0.01</mu2>
|
||||
<slip1>0.0</slip1>
|
||||
<slip2>0.0</slip2>
|
||||
</ode>
|
||||
</friction>
|
||||
<contact>
|
||||
<ode>
|
||||
<soft_cfm>0</soft_cfm>
|
||||
<soft_erp>0.2</soft_erp>
|
||||
<kp>1000000.0</kp>
|
||||
<kd>100.0</kd>
|
||||
<max_vel>0.1</max_vel>
|
||||
<min_depth>0.001</min_depth>
|
||||
</ode>
|
||||
</contact>
|
||||
</surface>
|
||||
</collision>
|
||||
<visual name="${name}_wheel_visual">
|
||||
<pose>${x_sign * wheel_x} ${y_sign * wheel_y} ${wheel_z} 1.5707963267948966 0 0</pose>
|
||||
<geometry>
|
||||
<cylinder>
|
||||
<radius>${wheel_radius}</radius>
|
||||
<length>${wheel_width}</length>
|
||||
</cylinder>
|
||||
</geometry>
|
||||
<material>
|
||||
<ambient>0.18 0.18 0.18 1</ambient>
|
||||
<diffuse>0.18 0.18 0.18 1</diffuse>
|
||||
</material>
|
||||
</visual>
|
||||
</xacro:macro>
|
||||
|
||||
<model name="r2027_omni">
|
||||
<static>false</static>
|
||||
<allow_auto_disable>false</allow_auto_disable>
|
||||
|
||||
<!-- ===== 车体:base_link 即箱体几何中心,模型原点与它重合 ===== -->
|
||||
<link name="base_link">
|
||||
<pose>0 0 0 0 0 0</pose>
|
||||
<inertial>
|
||||
<!-- 惯性参考系在组合质心(z = com_z),不是 base_link 原点 -->
|
||||
<pose>0 0 ${com_z} 0 0 0</pose>
|
||||
<mass>${total_mass}</mass>
|
||||
<inertia>
|
||||
<ixx>${tot_ixx}</ixx>
|
||||
<ixy>0</ixy>
|
||||
<ixz>0</ixz>
|
||||
<iyy>${tot_iyy}</iyy>
|
||||
<iyz>0</iyz>
|
||||
<izz>${tot_izz}</izz>
|
||||
</inertia>
|
||||
</inertial>
|
||||
<collision name="body_collision">
|
||||
<pose>0 0 0 0 0 0</pose>
|
||||
<geometry>
|
||||
<box><size>${body_length} ${body_width} ${body_height}</size></box>
|
||||
</geometry>
|
||||
</collision>
|
||||
<visual name="body_visual">
|
||||
<pose>0 0 0 0 0 0</pose>
|
||||
<geometry>
|
||||
<box><size>${body_length} ${body_width} ${body_height}</size></box>
|
||||
</geometry>
|
||||
<material>
|
||||
<ambient>0.206 0.396 0.831 1</ambient>
|
||||
<diffuse>0.206 0.396 0.831 1</diffuse>
|
||||
<specular>0.1 0.1 0.1 1</specular>
|
||||
</material>
|
||||
</visual>
|
||||
|
||||
<xacro:omni_wheel name="front_left" x_sign="1" y_sign="1"/>
|
||||
<xacro:omni_wheel name="front_right" x_sign="1" y_sign="-1"/>
|
||||
<xacro:omni_wheel name="rear_left" x_sign="-1" y_sign="1"/>
|
||||
<xacro:omni_wheel name="rear_right" x_sign="-1" y_sign="-1"/>
|
||||
<!-- Generic instantaneous 3D ray sensor; this is not a MID360 timing model.
|
||||
Mount is a simulation assumption: 0.30 m above base_link, axes aligned. -->
|
||||
<xacro:if value="$(arg lidar)">
|
||||
<xacro:if value="${'$(arg sensor_model)' == 'generic'}">
|
||||
<sensor name="lidar" type="ray">
|
||||
<pose>0 0 0.30 0 0 0</pose>
|
||||
<always_on>true</always_on>
|
||||
<visualize>false</visualize>
|
||||
<update_rate>10</update_rate>
|
||||
<ray>
|
||||
<scan>
|
||||
<horizontal><samples>720</samples><resolution>1</resolution>
|
||||
<min_angle>-3.141592653589793</min_angle><max_angle>3.141592653589793</max_angle>
|
||||
</horizontal>
|
||||
<vertical><samples>32</samples><resolution>1</resolution>
|
||||
<min_angle>-0.523598775598299</min_angle><max_angle>0.523598775598299</max_angle>
|
||||
</vertical>
|
||||
</scan>
|
||||
<range><min>0.15</min><max>20</max><resolution>0.01</resolution></range>
|
||||
</ray>
|
||||
<plugin name="lidar_ros" filename="libgazebo_ros_ray_sensor.so">
|
||||
<ros><remapping>~/out:=/lidar/points</remapping></ros>
|
||||
<output_type>sensor_msgs/PointCloud2</output_type>
|
||||
<frame_name>lidar</frame_name>
|
||||
</plugin>
|
||||
</sensor>
|
||||
</xacro:if>
|
||||
<xacro:if value="${'$(arg sensor_model)' == 'mid360'}">
|
||||
<!-- Official manual: IMU is (11,23.29,-44.12) mm in optical coordinates. -->
|
||||
<sensor name="mid360_imu" type="imu">
|
||||
<pose>0.011 0.02329 0.25588 0 0 0</pose>
|
||||
<always_on>true</always_on><update_rate>200</update_rate>
|
||||
<imu/>
|
||||
<plugin name="mid360_imu" filename="libbr_mid360_imu.so">
|
||||
<accel_stddev>$(arg accel_stddev)</accel_stddev><gyro_stddev>$(arg gyro_stddev)</gyro_stddev>
|
||||
<accel_bias>$(arg accel_bias)</accel_bias><gyro_bias>$(arg gyro_bias)</gyro_bias>
|
||||
<noise_seed>$(arg noise_seed)</noise_seed>
|
||||
</plugin>
|
||||
</sensor>
|
||||
</xacro:if>
|
||||
</xacro:if>
|
||||
</link>
|
||||
<xacro:if value="$(arg lidar)">
|
||||
<xacro:if value="${'$(arg sensor_model)' == 'mid360'}">
|
||||
<plugin name="mid360_sensor" filename="libbr_mid360_sensor.so">
|
||||
<range_stddev>$(arg range_stddev)</range_stddev><dropout>$(arg dropout)</dropout>
|
||||
<noise_seed>$(arg noise_seed)</noise_seed>
|
||||
</plugin>
|
||||
</xacro:if>
|
||||
</xacro:if>
|
||||
|
||||
<!-- ===== 运动插件:只订阅 /sim/cmd_vel,发 /odom 与 odom→base_link ===== -->
|
||||
<xacro:if value="${'$(arg drive)' == 'planar'}">
|
||||
<plugin filename="libgazebo_ros_planar_move.so" name="planar_move">
|
||||
<update_rate>100</update_rate>
|
||||
<publish_rate>50</publish_rate>
|
||||
<!-- 命令话题用官方 ROS remapping 指定,不用 <cmd_vel> 参数:
|
||||
本机实测 <cmd_vel>/sim/cmd_vel</cmd_vel> 会被忽略,插件仍订阅 /cmd_vel
|
||||
(`ros2 topic info /sim/cmd_vel` 订阅者数 = 0),转发节点因此被绕过。
|
||||
remapping 是 gazebo_ros 官方支持的方式,实测生效。 -->
|
||||
<ros>
|
||||
<remapping>cmd_vel:=sim/cmd_vel</remapping>
|
||||
</ros>
|
||||
<odometry_frame>odom</odometry_frame>
|
||||
<robot_base_frame>base_link</robot_base_frame>
|
||||
<publish_odom>true</publish_odom>
|
||||
<publish_odom_tf>true</publish_odom_tf>
|
||||
<covariance_x>0.0</covariance_x>
|
||||
<covariance_y>0.0</covariance_y>
|
||||
<covariance_yaw>0.0</covariance_yaw>
|
||||
</plugin>
|
||||
</xacro:if>
|
||||
<xacro:if value="${'$(arg drive)' == 'contact'}">
|
||||
<plugin filename="libbr_contact_drive.so" name="contact_drive"/>
|
||||
</xacro:if>
|
||||
</model>
|
||||
</sdf>
|
||||
@@ -0,0 +1,160 @@
|
||||
// Simplified contact-supported omnidirectional actuator, not a wheel traction model.
|
||||
// No SetPose/SetLinearVel/SetAngularVel: z, roll and pitch belong to the physics solver.
|
||||
#include <algorithm>
|
||||
#include <cmath>
|
||||
#include <functional>
|
||||
#include <mutex>
|
||||
#include <gazebo/gazebo.hh>
|
||||
#include <gazebo/physics/physics.hh>
|
||||
#include <gazebo_ros/node.hpp>
|
||||
#include <gazebo_ros/conversions/builtin_interfaces.hpp>
|
||||
#include <geometry_msgs/msg/twist.hpp>
|
||||
#include <geometry_msgs/msg/wrench_stamped.hpp>
|
||||
#include <gazebo_msgs/msg/contacts_state.hpp>
|
||||
#include <nav_msgs/msg/odometry.hpp>
|
||||
#include <tf2_ros/transform_broadcaster.h>
|
||||
|
||||
namespace br_sim {
|
||||
class ContactDrive : public gazebo::ModelPlugin {
|
||||
public:
|
||||
void Load(gazebo::physics::ModelPtr model, sdf::ElementPtr sdf) override {
|
||||
model_ = model;
|
||||
world_ = model->GetWorld();
|
||||
link_ = model->GetLink("base_link");
|
||||
if (!link_) { gzerr << "ContactDrive requires base_link\n"; return; }
|
||||
node_ = gazebo_ros::Node::Get(sdf);
|
||||
manager_ = world_->Physics()->GetContactManager();
|
||||
// Request real ODE contact geometry even without a separate contact sensor.
|
||||
manager_->SetNeverDropContacts(true);
|
||||
sub_ = node_->create_subscription<geometry_msgs::msg::Twist>("/sim/cmd_vel", 1,
|
||||
[this](geometry_msgs::msg::Twist::SharedPtr m) {
|
||||
if (!std::isfinite(m->linear.x) || !std::isfinite(m->linear.y) ||
|
||||
!std::isfinite(m->angular.z)) return;
|
||||
std::lock_guard<std::mutex> guard(mutex_);
|
||||
cmd_ = *m; received_ = world_->SimTime().Double();
|
||||
});
|
||||
odom_pub_ = node_->create_publisher<nav_msgs::msg::Odometry>("/odom", 10);
|
||||
contact_pub_ = node_->create_publisher<gazebo_msgs::msg::ContactsState>("/sim/drive_contacts", 10);
|
||||
force_pub_ = node_->create_publisher<geometry_msgs::msg::WrenchStamped>("/sim/drive_wrench", 10);
|
||||
tf_ = std::make_shared<tf2_ros::TransformBroadcaster>(node_);
|
||||
begin_ = gazebo::event::Events::ConnectWorldUpdateBegin(
|
||||
std::bind(&ContactDrive::Actuate, this));
|
||||
end_ = gazebo::event::Events::ConnectWorldUpdateEnd(
|
||||
std::bind(&ContactDrive::Publish, this));
|
||||
RCLCPP_INFO(node_->get_logger(), "Contact force drive: gravity/contact control z/R/P; odom at base_link");
|
||||
}
|
||||
|
||||
private:
|
||||
bool Own(gazebo::physics::Collision *c) const { return c && c->GetLink() == link_; }
|
||||
void Actuate() {
|
||||
ignition::math::Vector3d normal(0,0,0);
|
||||
for (unsigned i=0; i<manager_->GetContactCount(); ++i) {
|
||||
const auto *c = manager_->GetContact(i);
|
||||
if (!Own(c->collision1) && !Own(c->collision2)) continue;
|
||||
for (int j=0; j<c->count; ++j) {
|
||||
auto n = c->normals[j]; if (n.Z()<0) n=-n;
|
||||
if (n.Z()>.5) normal += n;
|
||||
}
|
||||
}
|
||||
applied_force_.Set(0,0,0); applied_torque_.Set(0,0,0);
|
||||
if (normal.Length()<1e-6) return; // No ground support => no flight actuator.
|
||||
normal.Normalize();
|
||||
geometry_msgs::msg::Twist cmd;
|
||||
{
|
||||
std::lock_guard<std::mutex> guard(mutex_);
|
||||
if (world_->SimTime().Double()-received_ >= 0 &&
|
||||
world_->SimTime().Double()-received_ <= .5) cmd=cmd_;
|
||||
}
|
||||
const auto desired=link_->WorldPose().Rot().RotateVector(ignition::math::Vector3d(
|
||||
std::clamp(cmd.linear.x,-.5,.5),std::clamp(cmd.linear.y,-.5,.5),0));
|
||||
const double vx=desired.X(),vy=desired.Y();
|
||||
const auto v=link_->WorldLinearVel();
|
||||
const double ax=std::clamp(40*(vx-v.X()),-4.,4.);
|
||||
const double ay=std::clamp(40*(vy-v.Y()),-4.,4.);
|
||||
// Project dynamics into the measured contact tangent plane. Solve the 2x2
|
||||
// horizontal block for force; its z component remains exactly zero.
|
||||
const auto g=world_->Gravity();
|
||||
const auto gt=g-normal*normal.Dot(g);
|
||||
const double nx=normal.X(), ny=normal.Y(), nz=normal.Z();
|
||||
const double bx=ax-gt.X(), by=ay-gt.Y();
|
||||
const double mass=link_->GetInertial()->Mass();
|
||||
const double det=nz*nz;
|
||||
applied_force_.Set(mass*((1-ny*ny)*bx+nx*ny*by)/det,
|
||||
mass*(nx*ny*bx+(1-nx*nx)*by)/det,0);
|
||||
if (applied_force_.Length()>150.) applied_force_ *= 150./applied_force_.Length();
|
||||
const double wz=std::clamp(cmd.angular.z,-.5,.5);
|
||||
const double alpha=std::clamp(40*(wz-link_->WorldAngularVel().Z()),-5.,5.);
|
||||
applied_torque_.Z(link_->GetInertial()->IZZ()*alpha);
|
||||
link_->AddForce(applied_force_);
|
||||
link_->AddTorque(applied_torque_);
|
||||
}
|
||||
|
||||
void Publish() {
|
||||
const double now=world_->SimTime().Double();
|
||||
if (now-last_pub_<.02-1e-9 && now>=last_pub_) return;
|
||||
last_pub_=now;
|
||||
const auto stamp=gazebo_ros::Convert<builtin_interfaces::msg::Time>(world_->SimTime());
|
||||
const auto pose=link_->WorldPose();
|
||||
const auto linear=pose.Rot().RotateVectorReverse(link_->WorldLinearVel());
|
||||
const auto angular=pose.Rot().RotateVectorReverse(link_->WorldAngularVel());
|
||||
nav_msgs::msg::Odometry od;
|
||||
od.header.stamp=stamp; od.header.frame_id="odom"; od.child_frame_id="base_link";
|
||||
auto &p=od.pose.pose.position; p.x=pose.Pos().X();p.y=pose.Pos().Y();p.z=pose.Pos().Z();
|
||||
auto &q=od.pose.pose.orientation;q.x=pose.Rot().X();q.y=pose.Rot().Y();q.z=pose.Rot().Z();q.w=pose.Rot().W();
|
||||
auto &v=od.twist.twist.linear;v.x=linear.X();v.y=linear.Y();v.z=linear.Z();
|
||||
auto &w=od.twist.twist.angular;w.x=angular.X();w.y=angular.Y();w.z=angular.Z();
|
||||
odom_pub_->publish(od);
|
||||
geometry_msgs::msg::TransformStamped tf;
|
||||
tf.header=od.header;tf.child_frame_id=od.child_frame_id;tf.transform.rotation=q;
|
||||
tf.transform.translation.x=p.x;tf.transform.translation.y=p.y;tf.transform.translation.z=p.z;
|
||||
tf_->sendTransform(tf);
|
||||
geometry_msgs::msg::WrenchStamped force;
|
||||
force.header.stamp=stamp;force.header.frame_id="world";
|
||||
force.wrench.force.x=applied_force_.X();force.wrench.force.y=applied_force_.Y();
|
||||
force.wrench.torque.z=applied_torque_.Z();force_pub_->publish(force);
|
||||
gazebo_msgs::msg::ContactsState contacts;
|
||||
contacts.header.stamp=stamp;contacts.header.frame_id="world";
|
||||
for (unsigned i=0; i<manager_->GetContactCount(); ++i) {
|
||||
const auto *c=manager_->GetContact(i);
|
||||
const bool first=Own(c->collision1);
|
||||
if (!first && !Own(c->collision2)) continue;
|
||||
gazebo_msgs::msg::ContactState state;
|
||||
state.collision1_name=c->collision1->GetScopedName();
|
||||
state.collision2_name=c->collision2->GetScopedName();
|
||||
for(int j=0;j<c->count;++j) {
|
||||
geometry_msgs::msg::Vector3 n;geometry_msgs::msg::Vector3 pos;
|
||||
n.x=c->normals[j].X();n.y=c->normals[j].Y();n.z=c->normals[j].Z();
|
||||
pos.x=c->positions[j].X();pos.y=c->positions[j].Y();pos.z=c->positions[j].Z();
|
||||
state.contact_positions.push_back(pos);state.contact_normals.push_back(n);
|
||||
state.depths.push_back(c->depths[j]);
|
||||
geometry_msgs::msg::Wrench wr;
|
||||
const auto f=first?c->wrench[j].body1Force:c->wrench[j].body2Force;
|
||||
const auto t=first?c->wrench[j].body1Torque:c->wrench[j].body2Torque;
|
||||
wr.force.x=f.X();wr.force.y=f.Y();wr.force.z=f.Z();
|
||||
wr.torque.x=t.X();wr.torque.y=t.Y();wr.torque.z=t.Z();
|
||||
state.wrenches.push_back(wr);
|
||||
state.total_wrench.force.x+=wr.force.x;state.total_wrench.force.y+=wr.force.y;state.total_wrench.force.z+=wr.force.z;
|
||||
state.total_wrench.torque.x+=wr.torque.x;state.total_wrench.torque.y+=wr.torque.y;state.total_wrench.torque.z+=wr.torque.z;
|
||||
}
|
||||
contacts.states.push_back(state);
|
||||
}
|
||||
contact_pub_->publish(contacts);
|
||||
}
|
||||
gazebo::physics::ModelPtr model_;
|
||||
gazebo::physics::WorldPtr world_;
|
||||
gazebo::physics::LinkPtr link_;
|
||||
gazebo::physics::ContactManager *manager_{};
|
||||
gazebo_ros::Node::SharedPtr node_;
|
||||
gazebo::event::ConnectionPtr begin_,end_;
|
||||
rclcpp::Subscription<geometry_msgs::msg::Twist>::SharedPtr sub_;
|
||||
rclcpp::Publisher<nav_msgs::msg::Odometry>::SharedPtr odom_pub_;
|
||||
rclcpp::Publisher<gazebo_msgs::msg::ContactsState>::SharedPtr contact_pub_;
|
||||
rclcpp::Publisher<geometry_msgs::msg::WrenchStamped>::SharedPtr force_pub_;
|
||||
std::shared_ptr<tf2_ros::TransformBroadcaster> tf_;
|
||||
std::mutex mutex_;
|
||||
geometry_msgs::msg::Twist cmd_;
|
||||
double received_{-1},last_pub_{-1};
|
||||
ignition::math::Vector3d applied_force_,applied_torque_;
|
||||
};
|
||||
GZ_REGISTER_MODEL_PLUGIN(ContactDrive)
|
||||
} // namespace br_sim
|
||||
@@ -0,0 +1,65 @@
|
||||
// Thin ROS wrapper over Gazebo's physical ImuSensor, with no attitude oracle.
|
||||
#include <functional>
|
||||
#include <memory>
|
||||
#include <random>
|
||||
#include <cmath>
|
||||
#include <stdexcept>
|
||||
#include <gazebo/gazebo.hh>
|
||||
#include <gazebo/sensors/ImuSensor.hh>
|
||||
#include <gazebo_ros/node.hpp>
|
||||
#include <gazebo_ros/conversions/builtin_interfaces.hpp>
|
||||
#include <sensor_msgs/msg/imu.hpp>
|
||||
|
||||
namespace br_sim {
|
||||
class Mid360Imu : public gazebo::SensorPlugin {
|
||||
public:
|
||||
void Load(gazebo::sensors::SensorPtr sensor,sdf::ElementPtr sdf) override {
|
||||
sensor_=std::dynamic_pointer_cast<gazebo::sensors::ImuSensor>(sensor);
|
||||
if(!sensor_) {gzerr << "Mid360Imu requires a physical ImuSensor\n";return;}
|
||||
accel_stddev_=sdf->Get<double>("accel_stddev",0.).first;
|
||||
gyro_stddev_=sdf->Get<double>("gyro_stddev",0.).first;
|
||||
accel_bias_=sdf->Get<ignition::math::Vector3d>("accel_bias",{}).first;
|
||||
gyro_bias_=sdf->Get<ignition::math::Vector3d>("gyro_bias",{}).first;
|
||||
if(!std::isfinite(accel_stddev_) || accel_stddev_<0 || !std::isfinite(gyro_stddev_) || gyro_stddev_<0 ||
|
||||
!accel_bias_.IsFinite() || !gyro_bias_.IsFinite()) throw std::invalid_argument("Invalid IMU noise/bias");
|
||||
rng_.seed(sdf->Get<unsigned>("noise_seed",2027u).first+1u);
|
||||
node_=gazebo_ros::Node::Get(sdf);
|
||||
pub_=node_->create_publisher<sensor_msgs::msg::Imu>("/sim/mid360/imu",rclcpp::SensorDataQoS().reliable());
|
||||
update_=sensor_->ConnectUpdated(std::bind(&Mid360Imu::Publish,this));
|
||||
}
|
||||
private:
|
||||
void Publish() {
|
||||
// One synchronized sensor reading, including its actual link-data timestamp.
|
||||
const auto reading=sensor_->ImuMessage();
|
||||
sensor_msgs::msg::Imu msg;
|
||||
msg.header.stamp=gazebo_ros::Convert<builtin_interfaces::msg::Time>(gazebo::msgs::Convert(reading.stamp()));
|
||||
msg.header.frame_id="mid360_imu";
|
||||
msg.orientation.w=1.;msg.orientation_covariance[0]=-1.; // MID360 has no attitude solution.
|
||||
msg.angular_velocity.x=reading.angular_velocity().x();
|
||||
msg.angular_velocity.y=reading.angular_velocity().y();
|
||||
msg.angular_velocity.z=reading.angular_velocity().z();
|
||||
msg.linear_acceleration.x=reading.linear_acceleration().x();
|
||||
msg.linear_acceleration.y=reading.linear_acceleration().y();
|
||||
msg.linear_acceleration.z=reading.linear_acceleration().z();
|
||||
// Perturb physical SI observations only, never their acquisition times.
|
||||
double *accel[]={&msg.linear_acceleration.x,&msg.linear_acceleration.y,&msg.linear_acceleration.z};
|
||||
double *gyro[]={&msg.angular_velocity.x,&msg.angular_velocity.y,&msg.angular_velocity.z};
|
||||
for(int i=0;i<3;++i) {
|
||||
*accel[i]+=accel_bias_[i]+accel_stddev_*normal_(rng_);
|
||||
*gyro[i]+=gyro_bias_[i]+gyro_stddev_*normal_(rng_);
|
||||
msg.linear_acceleration_covariance[4*i]=accel_stddev_*accel_stddev_;
|
||||
msg.angular_velocity_covariance[4*i]=gyro_stddev_*gyro_stddev_;
|
||||
}
|
||||
pub_->publish(msg);
|
||||
}
|
||||
double accel_stddev_{0},gyro_stddev_{0};
|
||||
ignition::math::Vector3d accel_bias_,gyro_bias_;
|
||||
std::mt19937 rng_;
|
||||
std::normal_distribution<double> normal_{0.,1.};
|
||||
gazebo::sensors::ImuSensorPtr sensor_;
|
||||
gazebo_ros::Node::SharedPtr node_;
|
||||
rclcpp::Publisher<sensor_msgs::msg::Imu>::SharedPtr pub_;
|
||||
gazebo::event::ConnectionPtr update_;
|
||||
};
|
||||
GZ_REGISTER_SENSOR_PLUGIN(Mid360Imu)
|
||||
} // namespace br_sim
|
||||
@@ -0,0 +1,137 @@
|
||||
// MID360-compatible ideal sensor, not a reconstruction of Livox's optical pattern.
|
||||
// Rays are cast at the current physical state. A physics-step batch shares its
|
||||
// actual acquisition stamp; no fictitious sub-step times or instantaneous scans.
|
||||
#include <cmath>
|
||||
#include <functional>
|
||||
#include <sstream>
|
||||
#include <random>
|
||||
#include <stdexcept>
|
||||
#include <gazebo/gazebo.hh>
|
||||
#include <gazebo/physics/physics.hh>
|
||||
#include <gazebo/physics/RayShape.hh>
|
||||
#include <gazebo_ros/node.hpp>
|
||||
#include <gazebo_ros/conversions/builtin_interfaces.hpp>
|
||||
#include <livox_ros_driver2/msg/custom_msg.hpp>
|
||||
#include <sensor_msgs/msg/point_cloud2.hpp>
|
||||
#include <sensor_msgs/point_cloud2_iterator.hpp>
|
||||
#include <std_msgs/msg/string.hpp>
|
||||
|
||||
namespace br_sim {
|
||||
class Mid360Sensor : public gazebo::ModelPlugin {
|
||||
public:
|
||||
void Load(gazebo::physics::ModelPtr model, sdf::ElementPtr sdf) override {
|
||||
world_=model->GetWorld();link_=model->GetLink("base_link");
|
||||
if (!link_) { gzerr << "Mid360Sensor needs base_link\n";return; }
|
||||
step_ns_=std::llround(world_->Physics()->GetMaxStepSize()*1e9);
|
||||
if(step_ns_!=1000000) {
|
||||
gzerr << "Mid360Sensor requires the validated 1 ms physics step\n";return;
|
||||
}
|
||||
range_stddev_=sdf->Get<double>("range_stddev",0.).first;
|
||||
dropout_=sdf->Get<double>("dropout",0.).first;
|
||||
seed_=sdf->Get<unsigned>("noise_seed",2027u).first;
|
||||
if(!std::isfinite(range_stddev_) || range_stddev_<0 || !std::isfinite(dropout_) || dropout_<0 || dropout_>1)
|
||||
throw std::invalid_argument("Invalid MID360 range noise/dropout");
|
||||
rng_.seed(seed_);
|
||||
node_=gazebo_ros::Node::Get(sdf);
|
||||
ray_=boost::dynamic_pointer_cast<gazebo::physics::RayShape>(
|
||||
world_->Physics()->CreateShape("ray",gazebo::physics::CollisionPtr()));
|
||||
if(!ray_) { gzerr << "Physics engine does not provide RayShape\n";return; }
|
||||
cloud_pub_=node_->create_publisher<livox_ros_driver2::msg::CustomMsg>("/sim/mid360/lidar",10);
|
||||
view_pub_=node_->create_publisher<sensor_msgs::msg::PointCloud2>("/sim/mid360/points",5);
|
||||
status_pub_=node_->create_publisher<std_msgs::msg::String>("/sim/mid360/status",10);
|
||||
update_=gazebo::event::Events::ConnectWorldUpdateEnd(std::bind(&Mid360Sensor::Sample,this));
|
||||
RCLCPP_INFO(node_->get_logger(),
|
||||
"MID360-compatible sensor: 200 rays/1 ms, 100 ms frames, actual acquisition stamps; optional noise/dropout");
|
||||
}
|
||||
|
||||
private:
|
||||
static double Fraction(double x) { return x-std::floor(x); }
|
||||
void Begin(int64_t now) {
|
||||
frame_=livox_ros_driver2::msg::CustomMsg();
|
||||
frame_.header.frame_id="lidar";
|
||||
frame_.header.stamp=gazebo_ros::Convert<builtin_interfaces::msg::Time>(world_->SimTime());
|
||||
frame_.timebase=now;frame_.lidar_id=0;
|
||||
frame_.points.reserve(20000);first_=now;last_sample_=now;rays_=0;hits_=0;dropped_=0;rejected_=0;
|
||||
}
|
||||
void Sample() {
|
||||
const int64_t now=world_->SimTime().sec*int64_t(1000000000)+world_->SimTime().nsec;
|
||||
if(first_<0) Begin(now);
|
||||
if(last_>=0 && now-last_!=step_ns_) {
|
||||
RCLCPP_WARN(node_->get_logger(),"Simulation time discontinuity: discard partial sensor frame");
|
||||
Begin(now);
|
||||
}
|
||||
if(now-first_>=100000000) { Publish();Begin(now); }
|
||||
last_=now;last_sample_=now;
|
||||
const auto body=link_->WorldPose();
|
||||
const auto origin=body.Pos()+body.Rot().RotateVector({0,0,.30});
|
||||
constexpr double pi=3.14159265358979323846;
|
||||
for(unsigned i=0;i<200;++i,++index_,++rays_) {
|
||||
// Documented quasi-uniform, non-repeating approximation; channels are
|
||||
// software groups for the Livox interface, not measured emitter identities.
|
||||
const double az=2*pi*Fraction(index_*.6180339887498948482);
|
||||
const double el=(-7+59*Fraction(.5+index_*.7548776662466927600))*pi/180;
|
||||
const ignition::math::Vector3d direction(std::cos(el)*std::cos(az),
|
||||
std::cos(el)*std::sin(az),std::sin(el));
|
||||
const auto world_dir=body.Rot().RotateVector(direction);
|
||||
ray_->SetPoints(origin,origin+40*world_dir);
|
||||
double distance;std::string entity;
|
||||
ray_->GetIntersection(distance,entity);
|
||||
if(entity.empty() || !std::isfinite(distance) || distance<.1 || distance>40) continue;
|
||||
++hits_;
|
||||
if(dropout_>0 && uniform_(rng_)<dropout_) { ++dropped_;continue; }
|
||||
if(range_stddev_>0) distance+=range_stddev_*normal_(rng_);
|
||||
if(distance<.1 || distance>40) { ++rejected_;continue; }
|
||||
livox_ros_driver2::msg::CustomPoint point;
|
||||
point.x=direction.X()*distance;point.y=direction.Y()*distance;point.z=direction.Z()*distance;
|
||||
point.offset_time=static_cast<uint32_t>(now-first_);
|
||||
point.line=index_%4;point.tag=0x10;
|
||||
point.reflectivity=100; // Ideal constant return strength; no material model.
|
||||
frame_.points.push_back(point);
|
||||
}
|
||||
}
|
||||
void Publish() {
|
||||
frame_.point_num=frame_.points.size();cloud_pub_->publish(frame_);
|
||||
sensor_msgs::msg::PointCloud2 view;
|
||||
view.header=frame_.header;
|
||||
sensor_msgs::PointCloud2Modifier modifier(view);
|
||||
modifier.setPointCloud2Fields(7,"x",1,sensor_msgs::msg::PointField::FLOAT32,
|
||||
"y",1,sensor_msgs::msg::PointField::FLOAT32,"z",1,sensor_msgs::msg::PointField::FLOAT32,
|
||||
"intensity",1,sensor_msgs::msg::PointField::FLOAT32,
|
||||
"offset_time",1,sensor_msgs::msg::PointField::UINT32,
|
||||
"line",1,sensor_msgs::msg::PointField::UINT8,"tag",1,sensor_msgs::msg::PointField::UINT8);
|
||||
modifier.resize(frame_.point_num);
|
||||
sensor_msgs::PointCloud2Iterator<float> x(view,"x"),y(view,"y"),z(view,"z"),intensity(view,"intensity");
|
||||
sensor_msgs::PointCloud2Iterator<uint32_t> t(view,"offset_time");
|
||||
sensor_msgs::PointCloud2Iterator<uint8_t> line(view,"line"),tag(view,"tag");
|
||||
for(const auto &p:frame_.points) {
|
||||
*x=p.x;*y=p.y;*z=p.z;*intensity=p.reflectivity;*t=p.offset_time;*line=p.line;*tag=p.tag;
|
||||
++x;++y;++z;++intensity;++t;++line;++tag;
|
||||
}
|
||||
view.is_dense=true;view_pub_->publish(view);
|
||||
std::ostringstream text;
|
||||
text << "{\"first_sample_ns\":" << first_ << ",\"last_sample_ns\":" << last_sample_
|
||||
<< ",\"rays\":" << rays_ << ",\"returns\":" << frame_.point_num
|
||||
<< ",\"step_ns\":" << step_ns_ << ",\"idealized_pattern\":true"
|
||||
<< ",\"range_stddev_m\":" << range_stddev_ << ",\"dropout_probability\":" << dropout_
|
||||
<< ",\"candidate_hits\":" << hits_ << ",\"dropped\":" << dropped_
|
||||
<< ",\"range_rejected\":" << rejected_ << ",\"seed\":" << seed_ << "}";
|
||||
std_msgs::msg::String status;status.data=text.str();status_pub_->publish(status);
|
||||
}
|
||||
gazebo::physics::WorldPtr world_;
|
||||
gazebo::physics::LinkPtr link_;
|
||||
gazebo::physics::RayShapePtr ray_;
|
||||
gazebo_ros::Node::SharedPtr node_;
|
||||
rclcpp::Publisher<livox_ros_driver2::msg::CustomMsg>::SharedPtr cloud_pub_;
|
||||
rclcpp::Publisher<sensor_msgs::msg::PointCloud2>::SharedPtr view_pub_;
|
||||
rclcpp::Publisher<std_msgs::msg::String>::SharedPtr status_pub_;
|
||||
livox_ros_driver2::msg::CustomMsg frame_;
|
||||
int64_t first_{-1},last_{-1},last_sample_{-1},step_ns_{};
|
||||
uint64_t index_{0};unsigned rays_{0},hits_{0},dropped_{0},rejected_{0},seed_{2027};
|
||||
double range_stddev_{0},dropout_{0};
|
||||
std::mt19937 rng_;
|
||||
std::normal_distribution<double> normal_{0.,1.};
|
||||
std::uniform_real_distribution<double> uniform_{0.,1.};
|
||||
gazebo::event::ConnectionPtr update_;
|
||||
};
|
||||
GZ_REGISTER_MODEL_PLUGIN(Mid360Sensor)
|
||||
} // namespace br_sim
|
||||
@@ -0,0 +1,21 @@
|
||||
cmake_minimum_required(VERSION 3.8)
|
||||
project(robocon_gazebo)
|
||||
|
||||
find_package(ament_cmake REQUIRED)
|
||||
|
||||
# SIM-P1-004-C: 只安装包内资源。
|
||||
# 原 CMakeLists 依赖仓库克隆目录 ../../gazebo_models,并强制校验
|
||||
# ${ROBOCON_MODELS_DIR}/robocon_track.world 存在;本任务要求资源路径
|
||||
# 不依赖 /home/kevin/r2027_gazebo_model,故该依赖与校验全部去掉。
|
||||
#
|
||||
# 包内自带:
|
||||
# launch/ 启动入口
|
||||
# worlds/ robocon_track_full.world(仅移除两个错位的 ROS 系统插件声明)
|
||||
# models/ robocon_ground_full(model.config + model.sdf + meshes/)
|
||||
|
||||
install(DIRECTORY launch worlds models
|
||||
DESTINATION share/${PROJECT_NAME}
|
||||
PATTERN "__pycache__" EXCLUDE
|
||||
PATTERN "*.pyc" EXCLUDE)
|
||||
|
||||
ament_package()
|
||||
@@ -0,0 +1,92 @@
|
||||
# 来源清单(SIM-P1-004-C)
|
||||
|
||||
本包把 `/home/kevin/r2027_gazebo_model/src/robocon_gazebo/` 里的**完整场地**正式纳入
|
||||
本项目。包名保持 `robocon_gazebo`,但**只导入完整场地所需资源**,不复制外部工作区的
|
||||
`build/`、`install/`、缓存、`gazebo_models/` 克隆目录,也不复制 MuJoCo 或机器人包。
|
||||
|
||||
## 1. 导入来源
|
||||
|
||||
| 项 | 路径 |
|
||||
|---|---|
|
||||
| 源工作区 | `/home/kevin/r2027_gazebo_model/` |
|
||||
| 源包 | `/home/kevin/r2027_gazebo_model/src/robocon_gazebo/` |
|
||||
| 导入目标 | `sim_ws/src/robocon_gazebo/` |
|
||||
| 导入时间 | 2026-11-07 |
|
||||
|
||||
**未导入**:`src/r2027_robot_description/`(机器人描述)、`gazebo_models/`(上游克隆目录)、
|
||||
`urdf/`、`scripts/`、`build/`、`install/`、`log/`、`.cache/`、`.Trash-0/`。
|
||||
|
||||
## 2. 导入时四个模型文件字节一致;当前坡道有面朝向修复
|
||||
|
||||
| 文件 | 上游原始 SHA256(导入时与目标一致) |
|
||||
|---|---|
|
||||
| `models/robocon_ground_full/model.sdf` | `f7bb3481dfb626ee87a05347c51c64b2075479383a3cd255af50cc587844cc4a` |
|
||||
| `models/robocon_ground_full/model.config` | `9a6e197fad5a32a48f7055e3bd7cd3147e65c21b08d1530d69264921e5990864` |
|
||||
| `models/robocon_ground_full/meshes/Untitled.dae` | `f69ef7a035924a9eac48e53df4e2fbd9eeb22312712f8e4f2e78f935b9d007bb` |
|
||||
| `models/robocon_ground_full/meshes/ramp.obj` | `5344932eae23391872e371758bbe9a70a6b5b9979fa53d3862b3183bee331f13` |
|
||||
|
||||
2026-11-08 坡道行驶测试发现 `ramp.obj` 的 8 个三角面全部朝内(有向体积 −1.04475 m³)。
|
||||
原圆柱支撑不能从坡脚建立坡面支撑接触;改球形支撑也未解决。仅反转面索引后,同一驱动和
|
||||
原圆柱支撑完成上坡、坡中停车、顶部落脚区、下坡,且实际点云与坡面几何一致。
|
||||
|
||||
**当前修复**:仅反转 `ramp.obj` 所有面顶点顺序;6 个顶点坐标、尺寸、模型位姿和连接关系不变。
|
||||
模型仍闭合,有向体积 +1.04475 m³。修复后 SHA256:
|
||||
`c53e36c47838b79d93de6d6119e5089ace361808af9a6fff48b9952885894dcd`。
|
||||
其余三个模型文件继续与上游逐字节一致,外部源文件未改动。
|
||||
|
||||
修复可用 `sim_ws/tools/repair_ramp_winding.py` 重现,该脚本只接受上述固定上游哈希,
|
||||
资源检查独立验证“顶点不变、全部面恰好反向、修复前后闭合、修复后体积为正”。
|
||||
证据:`sim_ws/log/codex_p5_slope_20261108/winding_diagnostic/`、`ramp_flipped/`、
|
||||
`winding_repair.json`;本改动不沿用旧“所有文件仍与源一致”的结论。
|
||||
|
||||
## 3. world:只删了两个错位的插件声明
|
||||
|
||||
| 项 | SHA256 |
|
||||
|---|---|
|
||||
| 源 `worlds/robocon_track_full.world` | `d611b2974b90d42d62537b277be6330786458e42c694119d9b0342e09b55e3af` |
|
||||
| 包内 `worlds/robocon_track_full.world` | `e26310e8e0e7e9e97c352b197129cbeb4c88f45a14f4e388e68ba8adaa080055` |
|
||||
|
||||
删除的两行(位于 `</world>` 前):
|
||||
|
||||
```xml
|
||||
<plugin name="gazebo_ros_init" filename="libgazebo_ros_init.so"/>
|
||||
<plugin name="gazebo_ros_factory" filename="libgazebo_ros_factory.so"/>
|
||||
```
|
||||
|
||||
原因:本机头文件确认 `libgazebo_ros_init.so` 与 `libgazebo_ros_factory.so` 都是
|
||||
`gazebo::SystemPlugin`,**不是 world plugin**,写在世界里加载方式不对。
|
||||
改由官方 `gazebo_ros/gzserver.launch.py` 的 `init:=true` / `factory:=true`
|
||||
通过 `-s` 命令行各加载一次。
|
||||
|
||||
删除位置只替换为一段说明注释。**物理、光照、场景、`<include>` 模型与位姿全部保持原样**,
|
||||
`world name="robocon_world"` 不变。
|
||||
|
||||
## 4. 未导入的上游 world
|
||||
|
||||
`worlds/robocon_track_ros.world` 未导入:它是同一场地的早期版本(碰撞不完整),
|
||||
本任务只以 `robocon_track_full.world` 为几何基准。
|
||||
|
||||
## 5. 新地图为几何基准
|
||||
|
||||
按任务要求,**不再按旧 Blender 场地修正尺寸**。此前 `br_gazebo`(Fortress 路线)
|
||||
的场地几何不作为 Classic 验收依据。2026-11-08 按用户清理要求删除了旧包及专用导出工具,
|
||||
过期调查说明已移出源码树,`sim_ws/docs/archive/fortress/` 仅保留退役说明;
|
||||
旧文档备份、测量和接触日志在本机忽略的 log/ 中保留,原始外部资源未改动。
|
||||
|
||||
## 6. 碰撞体清点(静态核对 model.sdf)
|
||||
|
||||
| 项 | 数量 |
|
||||
|---|---|
|
||||
| link | 1(`link`,模型 `static=true`) |
|
||||
| collision 合计 | **50** |
|
||||
| ├ box | **46** |
|
||||
| ├ cylinder | **2**(`Cylinder`、`Cylinder.001`) |
|
||||
| └ mesh | **2**(`ramp_north`、`ramp_south`,同一 `ramp.obj`) |
|
||||
| visual | 1(`Untitled.dae`,整场共用一张视觉网格) |
|
||||
|
||||
与任务给出的「实际 50 个碰撞体:46 box、2 cylinder、2 mesh」一致。
|
||||
|
||||
`ramp.obj` 是 6 顶点楔形(局部 x∈[−0.8, 2.7]、y∈[0,1]、z∈[0,0.597]),
|
||||
坡面在 x=−0.8 处高 0.597 m,向 +X 降到 0,即**坡道下降方向为 +X**。
|
||||
`ramp_north` pose=(0, 3, 0) → 世界 y∈[3,4](红方 +Y 侧);
|
||||
`ramp_south` pose=(0, −4, 0) → 世界 y∈[−4,−3](蓝方)。
|
||||
@@ -0,0 +1,94 @@
|
||||
"""启动 ROBOCON 2027 完整场地(Gazebo Classic 11 + ROS 2 Humble)。
|
||||
|
||||
入口统一为:
|
||||
ros2 launch robocon_gazebo robocon_gazebo.launch.py
|
||||
ros2 launch robocon_gazebo robocon_gazebo.launch.py gui:=false paused:=true verbose:=true
|
||||
|
||||
参数:
|
||||
gui 是否启动一个 gzclient(默认 true)
|
||||
paused 是否以暂停状态启动 gzserver(默认 false)
|
||||
verbose gzserver 是否输出详细日志(默认 false)
|
||||
world 可覆盖 world 路径(默认包内 worlds/robocon_track_full.world)
|
||||
|
||||
设计要点(SIM-P1-004-C):
|
||||
1. 只通过**官方 gazebo_ros 的 gzserver.launch.py** 加载 libgazebo_ros_init.so 与
|
||||
libgazebo_ros_factory.so,各一次(对应其 init:= / factory:= 参数,最终落到
|
||||
gzserver 的 `-s` 命令行选项)。这两个插件在本机头文件中属于 SystemPlugin,
|
||||
不能写在 world 的 <plugin> 里,源 world 的那两行已在包内 world 中移除。
|
||||
2. force_system:=false,避免额外加载第三个插件,保证「init、factory 各一次」。
|
||||
3. 不启动 ros_gz_bridge,不加载 Fortress(ignition)任何组件。
|
||||
4. GAZEBO_MASTER_URI 固定到 127.0.0.1:11355(与默认 11345 隔离),
|
||||
server / client / 采集工具共用同一 master;ROS_DOMAIN_ID=77、ROS_LOCALHOST_ONLY=1。
|
||||
5. 不接入机器人、TF、里程计、点云或 /cmd_vel。
|
||||
"""
|
||||
|
||||
import os
|
||||
|
||||
from ament_index_python.packages import get_package_share_directory
|
||||
from launch import LaunchDescription
|
||||
from launch.actions import (
|
||||
DeclareLaunchArgument,
|
||||
IncludeLaunchDescription,
|
||||
SetEnvironmentVariable,
|
||||
)
|
||||
from launch.conditions import IfCondition
|
||||
from launch.launch_description_sources import PythonLaunchDescriptionSource
|
||||
from launch.substitutions import LaunchConfiguration
|
||||
|
||||
# 与采集工具、手动 gzclient 保持一致(改这里就要同步改 tools/check_classic_baseline.py)
|
||||
GAZEBO_MASTER_URI = 'http://127.0.0.1:11355'
|
||||
ROS_DOMAIN_ID = '77'
|
||||
|
||||
|
||||
def generate_launch_description():
|
||||
share = get_package_share_directory('robocon_gazebo')
|
||||
models_dir = os.path.join(share, 'models')
|
||||
default_world = os.path.join(share, 'worlds', 'robocon_track_full.world')
|
||||
gazebo_ros_share = get_package_share_directory('gazebo_ros')
|
||||
|
||||
# 模型查找路径:本包安装的模型在前,其余沿用环境与 ~/.gazebo/models
|
||||
model_path_parts = [models_dir, os.path.expanduser('~/.gazebo/models')]
|
||||
if os.environ.get('GAZEBO_MODEL_PATH'):
|
||||
model_path_parts.append(os.environ['GAZEBO_MODEL_PATH'])
|
||||
model_path = os.pathsep.join(model_path_parts)
|
||||
|
||||
declared_args = [
|
||||
DeclareLaunchArgument('gui', default_value='true',
|
||||
description='是否启动 gzclient'),
|
||||
DeclareLaunchArgument('paused', default_value='false',
|
||||
description='以暂停状态启动'),
|
||||
DeclareLaunchArgument('verbose', default_value='false',
|
||||
description='gzserver 详细日志'),
|
||||
DeclareLaunchArgument('world', default_value=default_world,
|
||||
description='world 文件(默认完整场地)'),
|
||||
]
|
||||
|
||||
# 环境隔离:master 端口、ROS 域、仅本机通信、模型路径
|
||||
env_actions = [
|
||||
SetEnvironmentVariable('GAZEBO_MASTER_URI', GAZEBO_MASTER_URI),
|
||||
SetEnvironmentVariable('ROS_DOMAIN_ID', ROS_DOMAIN_ID),
|
||||
SetEnvironmentVariable('ROS_LOCALHOST_ONLY', '1'),
|
||||
SetEnvironmentVariable('GAZEBO_MODEL_PATH', model_path),
|
||||
]
|
||||
|
||||
gzserver = IncludeLaunchDescription(
|
||||
PythonLaunchDescriptionSource(
|
||||
os.path.join(gazebo_ros_share, 'launch', 'gzserver.launch.py')),
|
||||
launch_arguments={
|
||||
'world': LaunchConfiguration('world'),
|
||||
'verbose': LaunchConfiguration('verbose'),
|
||||
'pause': LaunchConfiguration('paused'),
|
||||
'init': 'true', # -s libgazebo_ros_init.so
|
||||
'factory': 'true', # -s libgazebo_ros_factory.so
|
||||
'force_system': 'false', # 不再多加载一个系统插件
|
||||
'server_required': 'true', # 关掉 launch 时一起收掉 gzserver
|
||||
}.items(),
|
||||
)
|
||||
|
||||
gzclient = IncludeLaunchDescription(
|
||||
PythonLaunchDescriptionSource(
|
||||
os.path.join(gazebo_ros_share, 'launch', 'gzclient.launch.py')),
|
||||
condition=IfCondition(LaunchConfiguration('gui')),
|
||||
)
|
||||
|
||||
return LaunchDescription(env_actions + declared_args + [gzserver, gzclient])
|
||||
File diff suppressed because one or more lines are too long
@@ -0,0 +1,18 @@
|
||||
# 楔形坡道碰撞网格 (视觉 Cube.001/Cube.006 的归一化形状)
|
||||
# 坡面: x=-0.8 处高 0.597m, 向 +x 降到 x=2.7 处 0m; 宽度沿 y 1m
|
||||
# 北坡道 pose=(0,3,0), 南坡道 pose=(0,-4,0)
|
||||
o ramp
|
||||
v -0.8 0 0.597
|
||||
v -0.8 1 0.597
|
||||
v -0.8 0 0
|
||||
v -0.8 1 0
|
||||
v 2.7 0 0
|
||||
v 2.7 1 0
|
||||
f 4 3 1
|
||||
f 2 4 1
|
||||
f 6 5 3
|
||||
f 4 6 3
|
||||
f 6 2 1
|
||||
f 5 6 1
|
||||
f 3 5 1
|
||||
f 6 4 2
|
||||
@@ -0,0 +1,10 @@
|
||||
<?xml version="1.0"?>
|
||||
<model>
|
||||
<name>robocon_ground_full</name>
|
||||
<version>1.1</version>
|
||||
<sdf version="1.6">model.sdf</sdf>
|
||||
<author>
|
||||
<name>xie (collision rebuilt from visual DAE)</name>
|
||||
</author>
|
||||
<description>ROBOCON ground with complete collision: solid L1/L2, ramps, stairs, rails, pillar bases. Visual mesh shared with robocon_ground.</description>
|
||||
</model>
|
||||
@@ -0,0 +1,462 @@
|
||||
<?xml version="1.0"?>
|
||||
<!-- 由 scripts/gen_full_collision.py 从视觉 DAE 自动生成, 请勿手改 -->
|
||||
<sdf version="1.6">
|
||||
<model name="robocon_ground_full">
|
||||
<static>true</static>
|
||||
<link name="link">
|
||||
<visual name="visual">
|
||||
<geometry><mesh><uri>model://robocon_ground_full/meshes/Untitled.dae</uri></mesh></geometry>
|
||||
</visual>
|
||||
<!-- ground (z=0 顶面) -->
|
||||
<collision name="ground">
|
||||
<geometry><box><size>11 11 0.02</size></box></geometry>
|
||||
<pose>0 0 -0.01 0 0 0</pose>
|
||||
<surface>
|
||||
<friction><ode><mu>0.8</mu><mu2>0.8</mu2></ode></friction>
|
||||
<contact><ode><max_vel>0.1</max_vel><min_depth>0.001</min_depth></ode></contact>
|
||||
</surface>
|
||||
</collision>
|
||||
<!-- center_divider -->
|
||||
<collision name="center_divider">
|
||||
<geometry><box><size>11 0.08 0.08</size></box></geometry>
|
||||
<pose>0 0 0.04 0 0 0</pose>
|
||||
<surface>
|
||||
<friction><ode><mu>0.8</mu><mu2>0.8</mu2></ode></friction>
|
||||
<contact><ode><max_vel>0.1</max_vel><min_depth>0.001</min_depth></ode></contact>
|
||||
</surface>
|
||||
</collision>
|
||||
<!-- Boundary_Wall_Back -->
|
||||
<collision name="Boundary_Wall_Back">
|
||||
<geometry><box><size>0.1 11 0.08</size></box></geometry>
|
||||
<pose>5.55 0 0 0 0 0</pose>
|
||||
<surface>
|
||||
<friction><ode><mu>0.8</mu><mu2>0.8</mu2></ode></friction>
|
||||
<contact><ode><max_vel>0.1</max_vel><min_depth>0.001</min_depth></ode></contact>
|
||||
</surface>
|
||||
</collision>
|
||||
<!-- Boundary_Wall_Front -->
|
||||
<collision name="Boundary_Wall_Front">
|
||||
<geometry><box><size>0.1 11 0.08</size></box></geometry>
|
||||
<pose>-5.55 0 0 0 0 0</pose>
|
||||
<surface>
|
||||
<friction><ode><mu>0.8</mu><mu2>0.8</mu2></ode></friction>
|
||||
<contact><ode><max_vel>0.1</max_vel><min_depth>0.001</min_depth></ode></contact>
|
||||
</surface>
|
||||
</collision>
|
||||
<!-- Boundary_Wall_Left -->
|
||||
<collision name="Boundary_Wall_Left">
|
||||
<geometry><box><size>11 0.1 0.08</size></box></geometry>
|
||||
<pose>0 5.55 0 0 0 0</pose>
|
||||
<surface>
|
||||
<friction><ode><mu>0.8</mu><mu2>0.8</mu2></ode></friction>
|
||||
<contact><ode><max_vel>0.1</max_vel><min_depth>0.001</min_depth></ode></contact>
|
||||
</surface>
|
||||
</collision>
|
||||
<!-- Boundary_Wall_Right -->
|
||||
<collision name="Boundary_Wall_Right">
|
||||
<geometry><box><size>11 0.1 0.08</size></box></geometry>
|
||||
<pose>0 -5.55 0 0 0 0</pose>
|
||||
<surface>
|
||||
<friction><ode><mu>0.8</mu><mu2>0.8</mu2></ode></friction>
|
||||
<contact><ode><max_vel>0.1</max_vel><min_depth>0.001</min_depth></ode></contact>
|
||||
</surface>
|
||||
</collision>
|
||||
<!-- Cube -->
|
||||
<collision name="Cube">
|
||||
<geometry><box><size>6 6 0.6</size></box></geometry>
|
||||
<pose>0 0 0.3 0 0 0</pose>
|
||||
<surface>
|
||||
<friction><ode><mu>0.8</mu><mu2>0.8</mu2></ode></friction>
|
||||
<contact><ode><max_vel>0.1</max_vel><min_depth>0.001</min_depth></ode></contact>
|
||||
</surface>
|
||||
</collision>
|
||||
<!-- Cube.001 -->
|
||||
<collision name="ramp_north">
|
||||
<geometry><mesh><uri>meshes/ramp.obj</uri></mesh></geometry>
|
||||
<pose>0 3 0 0 0 0</pose>
|
||||
<surface>
|
||||
<friction><ode><mu>0.9</mu><mu2>0.9</mu2></ode></friction>
|
||||
<contact><ode><max_vel>0.1</max_vel><min_depth>0.001</min_depth></ode></contact>
|
||||
</surface>
|
||||
</collision>
|
||||
<!-- Cube.002 -->
|
||||
<collision name="Cube.002">
|
||||
<geometry><box><size>1.9 1 0.15</size></box></geometry>
|
||||
<pose>-1.75 3.5 0.075 0 0 0</pose>
|
||||
<surface>
|
||||
<friction><ode><mu>0.8</mu><mu2>0.8</mu2></ode></friction>
|
||||
<contact><ode><max_vel>0.1</max_vel><min_depth>0.001</min_depth></ode></contact>
|
||||
</surface>
|
||||
</collision>
|
||||
<!-- Cube.003 -->
|
||||
<collision name="Cube.003">
|
||||
<geometry><box><size>1.6 1 0.15</size></box></geometry>
|
||||
<pose>-1.6 3.5 0.225 0 0 0</pose>
|
||||
<surface>
|
||||
<friction><ode><mu>0.8</mu><mu2>0.8</mu2></ode></friction>
|
||||
<contact><ode><max_vel>0.1</max_vel><min_depth>0.001</min_depth></ode></contact>
|
||||
</surface>
|
||||
</collision>
|
||||
<!-- Cube.004 -->
|
||||
<collision name="Cube.004">
|
||||
<geometry><box><size>1.3 1 0.15</size></box></geometry>
|
||||
<pose>-1.45 3.5 0.375 0 0 0</pose>
|
||||
<surface>
|
||||
<friction><ode><mu>0.8</mu><mu2>0.8</mu2></ode></friction>
|
||||
<contact><ode><max_vel>0.1</max_vel><min_depth>0.001</min_depth></ode></contact>
|
||||
</surface>
|
||||
</collision>
|
||||
<!-- Cube.005 -->
|
||||
<collision name="Cube.005">
|
||||
<geometry><box><size>1 1 0.15</size></box></geometry>
|
||||
<pose>-1.3 3.5 0.525 0 0 0</pose>
|
||||
<surface>
|
||||
<friction><ode><mu>0.8</mu><mu2>0.8</mu2></ode></friction>
|
||||
<contact><ode><max_vel>0.1</max_vel><min_depth>0.001</min_depth></ode></contact>
|
||||
</surface>
|
||||
</collision>
|
||||
<!-- Cube.006 -->
|
||||
<collision name="ramp_south">
|
||||
<geometry><mesh><uri>meshes/ramp.obj</uri></mesh></geometry>
|
||||
<pose>0 -4 0 0 0 0</pose>
|
||||
<surface>
|
||||
<friction><ode><mu>0.9</mu><mu2>0.9</mu2></ode></friction>
|
||||
<contact><ode><max_vel>0.1</max_vel><min_depth>0.001</min_depth></ode></contact>
|
||||
</surface>
|
||||
</collision>
|
||||
<!-- Cube.007 -->
|
||||
<collision name="Cube.007">
|
||||
<geometry><box><size>1.9 1 0.15</size></box></geometry>
|
||||
<pose>-1.75 -3.5 0.075 0 0 0</pose>
|
||||
<surface>
|
||||
<friction><ode><mu>0.8</mu><mu2>0.8</mu2></ode></friction>
|
||||
<contact><ode><max_vel>0.1</max_vel><min_depth>0.001</min_depth></ode></contact>
|
||||
</surface>
|
||||
</collision>
|
||||
<!-- Cube.008 -->
|
||||
<collision name="Cube.008">
|
||||
<geometry><box><size>1.6 1 0.15</size></box></geometry>
|
||||
<pose>-1.6 -3.5 0.225 0 0 0</pose>
|
||||
<surface>
|
||||
<friction><ode><mu>0.8</mu><mu2>0.8</mu2></ode></friction>
|
||||
<contact><ode><max_vel>0.1</max_vel><min_depth>0.001</min_depth></ode></contact>
|
||||
</surface>
|
||||
</collision>
|
||||
<!-- Cube.009 -->
|
||||
<collision name="Cube.009">
|
||||
<geometry><box><size>1.3 1 0.15</size></box></geometry>
|
||||
<pose>-1.45 -3.5 0.375 0 0 0</pose>
|
||||
<surface>
|
||||
<friction><ode><mu>0.8</mu><mu2>0.8</mu2></ode></friction>
|
||||
<contact><ode><max_vel>0.1</max_vel><min_depth>0.001</min_depth></ode></contact>
|
||||
</surface>
|
||||
</collision>
|
||||
<!-- Cube.010 -->
|
||||
<collision name="Cube.010">
|
||||
<geometry><box><size>1 1 0.15</size></box></geometry>
|
||||
<pose>-1.3 -3.5 0.525 0 0 0</pose>
|
||||
<surface>
|
||||
<friction><ode><mu>0.8</mu><mu2>0.8</mu2></ode></friction>
|
||||
<contact><ode><max_vel>0.1</max_vel><min_depth>0.001</min_depth></ode></contact>
|
||||
</surface>
|
||||
</collision>
|
||||
<!-- Cube.011 -->
|
||||
<collision name="Cube.011">
|
||||
<geometry><box><size>0.05 6 0.05</size></box></geometry>
|
||||
<pose>-3 0 0.625 0 0 0</pose>
|
||||
<surface>
|
||||
<friction><ode><mu>0.8</mu><mu2>0.8</mu2></ode></friction>
|
||||
<contact><ode><max_vel>0.1</max_vel><min_depth>0.001</min_depth></ode></contact>
|
||||
</surface>
|
||||
</collision>
|
||||
<!-- Cube.012 -->
|
||||
<collision name="Cube.012">
|
||||
<geometry><box><size>0.05 6 0.05</size></box></geometry>
|
||||
<pose>3 0 0.625 0 0 0</pose>
|
||||
<surface>
|
||||
<friction><ode><mu>0.8</mu><mu2>0.8</mu2></ode></friction>
|
||||
<contact><ode><max_vel>0.1</max_vel><min_depth>0.001</min_depth></ode></contact>
|
||||
</surface>
|
||||
</collision>
|
||||
<!-- Cube.013 -->
|
||||
<collision name="Cube.013">
|
||||
<geometry><box><size>3.8 0.05 0.05</size></box></geometry>
|
||||
<pose>1.1 3 0.625 0 0 0</pose>
|
||||
<surface>
|
||||
<friction><ode><mu>0.8</mu><mu2>0.8</mu2></ode></friction>
|
||||
<contact><ode><max_vel>0.1</max_vel><min_depth>0.001</min_depth></ode></contact>
|
||||
</surface>
|
||||
</collision>
|
||||
<!-- Cube.014 -->
|
||||
<collision name="Cube.014">
|
||||
<geometry><box><size>1.2 0.05 0.05</size></box></geometry>
|
||||
<pose>-2.4 3 0.625 0 0 0</pose>
|
||||
<surface>
|
||||
<friction><ode><mu>0.8</mu><mu2>0.8</mu2></ode></friction>
|
||||
<contact><ode><max_vel>0.1</max_vel><min_depth>0.001</min_depth></ode></contact>
|
||||
</surface>
|
||||
</collision>
|
||||
<!-- Cube.015 -->
|
||||
<collision name="Cube.015">
|
||||
<geometry><box><size>3.8 0.05 0.05</size></box></geometry>
|
||||
<pose>1.1 -3 0.625 0 0 0</pose>
|
||||
<surface>
|
||||
<friction><ode><mu>0.8</mu><mu2>0.8</mu2></ode></friction>
|
||||
<contact><ode><max_vel>0.1</max_vel><min_depth>0.001</min_depth></ode></contact>
|
||||
</surface>
|
||||
</collision>
|
||||
<!-- Cube.016 -->
|
||||
<collision name="Cube.016">
|
||||
<geometry><box><size>1.2 0.05 0.05</size></box></geometry>
|
||||
<pose>-2.4 -3 0.625 0 0 0</pose>
|
||||
<surface>
|
||||
<friction><ode><mu>0.8</mu><mu2>0.8</mu2></ode></friction>
|
||||
<contact><ode><max_vel>0.1</max_vel><min_depth>0.001</min_depth></ode></contact>
|
||||
</surface>
|
||||
</collision>
|
||||
<!-- Cube.017 -->
|
||||
<collision name="Cube.017">
|
||||
<geometry><box><size>3 3 0.3</size></box></geometry>
|
||||
<pose>0 0 0.75 0 0 0</pose>
|
||||
<surface>
|
||||
<friction><ode><mu>0.8</mu><mu2>0.8</mu2></ode></friction>
|
||||
<contact><ode><max_vel>0.1</max_vel><min_depth>0.001</min_depth></ode></contact>
|
||||
</surface>
|
||||
</collision>
|
||||
<!-- Cube.020 -->
|
||||
<collision name="Cube.020">
|
||||
<geometry><box><size>0.2 0.1 0.2</size></box></geometry>
|
||||
<pose>-3.8 -0.5 0.13 0 0 0</pose>
|
||||
<surface>
|
||||
<friction><ode><mu>0.8</mu><mu2>0.8</mu2></ode></friction>
|
||||
<contact><ode><max_vel>0.1</max_vel><min_depth>0.001</min_depth></ode></contact>
|
||||
</surface>
|
||||
</collision>
|
||||
<!-- Cube.021 -->
|
||||
<collision name="Cube.021">
|
||||
<geometry><box><size>0.2 0.1 0.2</size></box></geometry>
|
||||
<pose>-3.8 -0.4 0.13 0 0 0</pose>
|
||||
<surface>
|
||||
<friction><ode><mu>0.8</mu><mu2>0.8</mu2></ode></friction>
|
||||
<contact><ode><max_vel>0.1</max_vel><min_depth>0.001</min_depth></ode></contact>
|
||||
</surface>
|
||||
</collision>
|
||||
<!-- Cube.022 -->
|
||||
<collision name="Cube.022">
|
||||
<geometry><box><size>0.2 0.1 0.2</size></box></geometry>
|
||||
<pose>-3.8 0.05 0.13 0 0 0</pose>
|
||||
<surface>
|
||||
<friction><ode><mu>0.8</mu><mu2>0.8</mu2></ode></friction>
|
||||
<contact><ode><max_vel>0.1</max_vel><min_depth>0.001</min_depth></ode></contact>
|
||||
</surface>
|
||||
</collision>
|
||||
<!-- Cube.023 -->
|
||||
<collision name="Cube.023">
|
||||
<geometry><box><size>0.2 0.1 0.2</size></box></geometry>
|
||||
<pose>-3.8 -0.05 0.13 0 0 0</pose>
|
||||
<surface>
|
||||
<friction><ode><mu>0.8</mu><mu2>0.8</mu2></ode></friction>
|
||||
<contact><ode><max_vel>0.1</max_vel><min_depth>0.001</min_depth></ode></contact>
|
||||
</surface>
|
||||
</collision>
|
||||
<!-- Cube.024 -->
|
||||
<collision name="Cube.024">
|
||||
<geometry><box><size>0.2 0.1 0.2</size></box></geometry>
|
||||
<pose>-3.8 0.5 0.13 0 0 0</pose>
|
||||
<surface>
|
||||
<friction><ode><mu>0.8</mu><mu2>0.8</mu2></ode></friction>
|
||||
<contact><ode><max_vel>0.1</max_vel><min_depth>0.001</min_depth></ode></contact>
|
||||
</surface>
|
||||
</collision>
|
||||
<!-- Cube.025 -->
|
||||
<collision name="Cube.025">
|
||||
<geometry><box><size>0.2 0.1 0.2</size></box></geometry>
|
||||
<pose>-3.8 0.4 0.13 0 0 0</pose>
|
||||
<surface>
|
||||
<friction><ode><mu>0.8</mu><mu2>0.8</mu2></ode></friction>
|
||||
<contact><ode><max_vel>0.1</max_vel><min_depth>0.001</min_depth></ode></contact>
|
||||
</surface>
|
||||
</collision>
|
||||
<!-- Cube.026 -->
|
||||
<collision name="Cube.026">
|
||||
<geometry><box><size>0.2 0.1 0.2</size></box></geometry>
|
||||
<pose>-4 0.275 0.13 0 0 0</pose>
|
||||
<surface>
|
||||
<friction><ode><mu>0.8</mu><mu2>0.8</mu2></ode></friction>
|
||||
<contact><ode><max_vel>0.1</max_vel><min_depth>0.001</min_depth></ode></contact>
|
||||
</surface>
|
||||
</collision>
|
||||
<!-- Cube.027 -->
|
||||
<collision name="Cube.027">
|
||||
<geometry><box><size>0.2 0.1 0.2</size></box></geometry>
|
||||
<pose>-4 0.175 0.13 0 0 0</pose>
|
||||
<surface>
|
||||
<friction><ode><mu>0.8</mu><mu2>0.8</mu2></ode></friction>
|
||||
<contact><ode><max_vel>0.1</max_vel><min_depth>0.001</min_depth></ode></contact>
|
||||
</surface>
|
||||
</collision>
|
||||
<!-- Cube.028 -->
|
||||
<collision name="Cube.028">
|
||||
<geometry><box><size>0.2 0.1 0.2</size></box></geometry>
|
||||
<pose>-4 -0.175 0.13 0 0 0</pose>
|
||||
<surface>
|
||||
<friction><ode><mu>0.8</mu><mu2>0.8</mu2></ode></friction>
|
||||
<contact><ode><max_vel>0.1</max_vel><min_depth>0.001</min_depth></ode></contact>
|
||||
</surface>
|
||||
</collision>
|
||||
<!-- Cube.029 -->
|
||||
<collision name="Cube.029">
|
||||
<geometry><box><size>0.2 0.1 0.2</size></box></geometry>
|
||||
<pose>-4 -0.275 0.13 0 0 0</pose>
|
||||
<surface>
|
||||
<friction><ode><mu>0.8</mu><mu2>0.8</mu2></ode></friction>
|
||||
<contact><ode><max_vel>0.1</max_vel><min_depth>0.001</min_depth></ode></contact>
|
||||
</surface>
|
||||
</collision>
|
||||
<!-- Cube.030 -->
|
||||
<collision name="Cube.030">
|
||||
<geometry><box><size>0.2 0.1 0.2</size></box></geometry>
|
||||
<pose>-4.2 0.5 0.13 0 0 0</pose>
|
||||
<surface>
|
||||
<friction><ode><mu>0.8</mu><mu2>0.8</mu2></ode></friction>
|
||||
<contact><ode><max_vel>0.1</max_vel><min_depth>0.001</min_depth></ode></contact>
|
||||
</surface>
|
||||
</collision>
|
||||
<!-- Cube.031 -->
|
||||
<collision name="Cube.031">
|
||||
<geometry><box><size>0.2 0.1 0.2</size></box></geometry>
|
||||
<pose>-4.2 0.4 0.13 0 0 0</pose>
|
||||
<surface>
|
||||
<friction><ode><mu>0.8</mu><mu2>0.8</mu2></ode></friction>
|
||||
<contact><ode><max_vel>0.1</max_vel><min_depth>0.001</min_depth></ode></contact>
|
||||
</surface>
|
||||
</collision>
|
||||
<!-- Cube.032 -->
|
||||
<collision name="Cube.032">
|
||||
<geometry><box><size>0.2 0.1 0.2</size></box></geometry>
|
||||
<pose>-4.2 -0.4 0.13 0 0 0</pose>
|
||||
<surface>
|
||||
<friction><ode><mu>0.8</mu><mu2>0.8</mu2></ode></friction>
|
||||
<contact><ode><max_vel>0.1</max_vel><min_depth>0.001</min_depth></ode></contact>
|
||||
</surface>
|
||||
</collision>
|
||||
<!-- Cube.033 -->
|
||||
<collision name="Cube.033">
|
||||
<geometry><box><size>0.2 0.1 0.2</size></box></geometry>
|
||||
<pose>-4.2 -0.5 0.13 0 0 0</pose>
|
||||
<surface>
|
||||
<friction><ode><mu>0.8</mu><mu2>0.8</mu2></ode></friction>
|
||||
<contact><ode><max_vel>0.1</max_vel><min_depth>0.001</min_depth></ode></contact>
|
||||
</surface>
|
||||
</collision>
|
||||
<!-- Cube.034 -->
|
||||
<collision name="Cube.034">
|
||||
<geometry><box><size>0.2 0.1 0.2</size></box></geometry>
|
||||
<pose>-4.4 0.275 0.13 0 0 0</pose>
|
||||
<surface>
|
||||
<friction><ode><mu>0.8</mu><mu2>0.8</mu2></ode></friction>
|
||||
<contact><ode><max_vel>0.1</max_vel><min_depth>0.001</min_depth></ode></contact>
|
||||
</surface>
|
||||
</collision>
|
||||
<!-- Cube.035 -->
|
||||
<collision name="Cube.035">
|
||||
<geometry><box><size>0.2 0.1 0.2</size></box></geometry>
|
||||
<pose>-4.4 0.175 0.13 0 0 0</pose>
|
||||
<surface>
|
||||
<friction><ode><mu>0.8</mu><mu2>0.8</mu2></ode></friction>
|
||||
<contact><ode><max_vel>0.1</max_vel><min_depth>0.001</min_depth></ode></contact>
|
||||
</surface>
|
||||
</collision>
|
||||
<!-- Cube.036 -->
|
||||
<collision name="Cube.036">
|
||||
<geometry><box><size>0.2 0.1 0.2</size></box></geometry>
|
||||
<pose>-4.4 -0.175 0.13 0 0 0</pose>
|
||||
<surface>
|
||||
<friction><ode><mu>0.8</mu><mu2>0.8</mu2></ode></friction>
|
||||
<contact><ode><max_vel>0.1</max_vel><min_depth>0.001</min_depth></ode></contact>
|
||||
</surface>
|
||||
</collision>
|
||||
<!-- Cube.037 -->
|
||||
<collision name="Cube.037">
|
||||
<geometry><box><size>0.2 0.1 0.2</size></box></geometry>
|
||||
<pose>-4.4 -0.275 0.13 0 0 0</pose>
|
||||
<surface>
|
||||
<friction><ode><mu>0.8</mu><mu2>0.8</mu2></ode></friction>
|
||||
<contact><ode><max_vel>0.1</max_vel><min_depth>0.001</min_depth></ode></contact>
|
||||
</surface>
|
||||
</collision>
|
||||
<!-- Cube.038 -->
|
||||
<collision name="Cube.038">
|
||||
<geometry><box><size>0.2 0.1 0.2</size></box></geometry>
|
||||
<pose>-4.6 0.5 0.13 0 0 0</pose>
|
||||
<surface>
|
||||
<friction><ode><mu>0.8</mu><mu2>0.8</mu2></ode></friction>
|
||||
<contact><ode><max_vel>0.1</max_vel><min_depth>0.001</min_depth></ode></contact>
|
||||
</surface>
|
||||
</collision>
|
||||
<!-- Cube.039 -->
|
||||
<collision name="Cube.039">
|
||||
<geometry><box><size>0.2 0.1 0.2</size></box></geometry>
|
||||
<pose>-4.6 0.4 0.13 0 0 0</pose>
|
||||
<surface>
|
||||
<friction><ode><mu>0.8</mu><mu2>0.8</mu2></ode></friction>
|
||||
<contact><ode><max_vel>0.1</max_vel><min_depth>0.001</min_depth></ode></contact>
|
||||
</surface>
|
||||
</collision>
|
||||
<!-- Cube.040 -->
|
||||
<collision name="Cube.040">
|
||||
<geometry><box><size>0.2 0.1 0.2</size></box></geometry>
|
||||
<pose>-4.6 0.05 0.13 0 0 0</pose>
|
||||
<surface>
|
||||
<friction><ode><mu>0.8</mu><mu2>0.8</mu2></ode></friction>
|
||||
<contact><ode><max_vel>0.1</max_vel><min_depth>0.001</min_depth></ode></contact>
|
||||
</surface>
|
||||
</collision>
|
||||
<!-- Cube.041 -->
|
||||
<collision name="Cube.041">
|
||||
<geometry><box><size>0.2 0.1 0.2</size></box></geometry>
|
||||
<pose>-4.6 -0.05 0.13 0 0 0</pose>
|
||||
<surface>
|
||||
<friction><ode><mu>0.8</mu><mu2>0.8</mu2></ode></friction>
|
||||
<contact><ode><max_vel>0.1</max_vel><min_depth>0.001</min_depth></ode></contact>
|
||||
</surface>
|
||||
</collision>
|
||||
<!-- Cube.042 -->
|
||||
<collision name="Cube.042">
|
||||
<geometry><box><size>0.2 0.1 0.2</size></box></geometry>
|
||||
<pose>-4.6 -0.4 0.13 0 0 0</pose>
|
||||
<surface>
|
||||
<friction><ode><mu>0.8</mu><mu2>0.8</mu2></ode></friction>
|
||||
<contact><ode><max_vel>0.1</max_vel><min_depth>0.001</min_depth></ode></contact>
|
||||
</surface>
|
||||
</collision>
|
||||
<!-- Cube.043 -->
|
||||
<collision name="Cube.043">
|
||||
<geometry><box><size>0.2 0.1 0.2</size></box></geometry>
|
||||
<pose>-4.6 -0.5 0.13 0 0 0</pose>
|
||||
<surface>
|
||||
<friction><ode><mu>0.8</mu><mu2>0.8</mu2></ode></friction>
|
||||
<contact><ode><max_vel>0.1</max_vel><min_depth>0.001</min_depth></ode></contact>
|
||||
</surface>
|
||||
</collision>
|
||||
<!-- Cylinder -->
|
||||
<collision name="Cylinder">
|
||||
<geometry><cylinder><radius>0.135</radius><length>0.5</length></cylinder></geometry>
|
||||
<pose>4.15 0 0.25 0 0 0</pose>
|
||||
<surface>
|
||||
<friction><ode><mu>0.8</mu><mu2>0.8</mu2></ode></friction>
|
||||
<contact><ode><max_vel>0.1</max_vel><min_depth>0.001</min_depth></ode></contact>
|
||||
</surface>
|
||||
</collision>
|
||||
<!-- Cylinder.001 -->
|
||||
<collision name="Cylinder.001">
|
||||
<geometry><cylinder><radius>0.135</radius><length>0.8</length></cylinder></geometry>
|
||||
<pose>0 0 1.3 0 0 0</pose>
|
||||
<surface>
|
||||
<friction><ode><mu>0.8</mu><mu2>0.8</mu2></ode></friction>
|
||||
<contact><ode><max_vel>0.1</max_vel><min_depth>0.001</min_depth></ode></contact>
|
||||
</surface>
|
||||
</collision>
|
||||
</link>
|
||||
</model>
|
||||
</sdf>
|
||||
@@ -0,0 +1,23 @@
|
||||
<?xml version="1.0"?>
|
||||
<?xml-model href="http://download.ros.org/schema/package_format3.xsd" schematypens="http://www.w3.org/2001/XMLSchema"?>
|
||||
<package format="3">
|
||||
<name>robocon_gazebo</name>
|
||||
<version>0.2.0</version>
|
||||
<description>ROBOCON 2027 完整场地(Gazebo Classic 11 + ROS 2 Humble)。资源自包含,不依赖外部克隆目录。</description>
|
||||
<maintainer email="[email protected]">xie</maintainer>
|
||||
<license>Apache-2.0</license>
|
||||
|
||||
<buildtool_depend>ament_cmake</buildtool_depend>
|
||||
|
||||
<exec_depend>gazebo_ros</exec_depend>
|
||||
<exec_depend>gazebo_plugins</exec_depend>
|
||||
<exec_depend>gazebo_msgs</exec_depend>
|
||||
<exec_depend>launch</exec_depend>
|
||||
<exec_depend>launch_ros</exec_depend>
|
||||
<exec_depend>rclpy</exec_depend>
|
||||
<exec_depend>rosgraph_msgs</exec_depend>
|
||||
|
||||
<export>
|
||||
<build_type>ament_cmake</build_type>
|
||||
</export>
|
||||
</package>
|
||||
@@ -0,0 +1,53 @@
|
||||
<?xml version="1.0"?>
|
||||
<!--
|
||||
ROBOCON 2027 场地 (完整碰撞版)
|
||||
与 robocon_track_ros.world 的区别: 场地模型换成 robocon_ground_full
|
||||
- L1 实体 6×6×0.6、L2 实体 3×3×0.3
|
||||
- 南北侧楔形坡道(网格碰撞) + 阶梯盒
|
||||
- 平台边缘护栏、L1/L2 方块阵列、柱体基座(位置修正为 x=4.15)
|
||||
视觉网格仍复用上游 robocon_ground 的 DAE
|
||||
-->
|
||||
<sdf version="1.6">
|
||||
<world name="robocon_world">
|
||||
<physics type="ode">
|
||||
<max_step_size>0.001</max_step_size>
|
||||
<real_time_factor>1.0</real_time_factor>
|
||||
<real_time_update_rate>1000</real_time_update_rate>
|
||||
</physics>
|
||||
|
||||
<scene>
|
||||
<ambient>0.4 0.4 0.4 1</ambient>
|
||||
<background>0.7 0.7 0.7 1</background>
|
||||
<shadows>true</shadows>
|
||||
</scene>
|
||||
|
||||
<light type="directional" name="sun">
|
||||
<cast_shadows>true</cast_shadows>
|
||||
<pose>0 0 10 0 0 0</pose>
|
||||
<diffuse>0.8 0.8 0.8 1</diffuse>
|
||||
<specular>0.2 0.2 0.2 1</specular>
|
||||
<direction>0.1 0.1 -1</direction>
|
||||
</light>
|
||||
|
||||
<include>
|
||||
<uri>model://robocon_ground_full</uri>
|
||||
<pose>0 0 0 0 0 0</pose>
|
||||
</include>
|
||||
|
||||
<!-- SIM-P1-004-C: 此处原有的 libgazebo_ros_init.so / libgazebo_ros_factory.so
|
||||
world 级 <plugin> 声明已移除。本机头文件确认两者为 SystemPlugin,
|
||||
不能作为 world <plugin> 加载;改由官方 gzserver.launch.py 以
|
||||
`-s libgazebo_ros_init.so -s libgazebo_ros_factory.so` 各加载一次。
|
||||
其余内容与源 world 完全一致。 -->
|
||||
|
||||
<!-- SIM-P2-001: 官方 libgazebo_ros_state.so(WorldPlugin)提供独立真值查询:
|
||||
/gazebo/get_entity_state、/gazebo/set_entity_state、/gazebo/link_states。
|
||||
场地几何、物理与光照与本包 robocon_track_full.world 完全一致。 -->
|
||||
<plugin name="gazebo_ros_state" filename="libgazebo_ros_state.so">
|
||||
<ros>
|
||||
<namespace>/gazebo</namespace>
|
||||
</ros>
|
||||
<update_rate>100</update_rate>
|
||||
</plugin>
|
||||
</world>
|
||||
</sdf>
|
||||
@@ -0,0 +1,43 @@
|
||||
<?xml version="1.0"?>
|
||||
<!--
|
||||
ROBOCON 2027 场地 (完整碰撞版)
|
||||
与 robocon_track_ros.world 的区别: 场地模型换成 robocon_ground_full
|
||||
- L1 实体 6×6×0.6、L2 实体 3×3×0.3
|
||||
- 南北侧楔形坡道(网格碰撞) + 阶梯盒
|
||||
- 平台边缘护栏、L1/L2 方块阵列、柱体基座(位置修正为 x=4.15)
|
||||
视觉网格仍复用上游 robocon_ground 的 DAE
|
||||
-->
|
||||
<sdf version="1.6">
|
||||
<world name="robocon_world">
|
||||
<physics type="ode">
|
||||
<max_step_size>0.001</max_step_size>
|
||||
<real_time_factor>1.0</real_time_factor>
|
||||
<real_time_update_rate>1000</real_time_update_rate>
|
||||
</physics>
|
||||
|
||||
<scene>
|
||||
<ambient>0.4 0.4 0.4 1</ambient>
|
||||
<background>0.7 0.7 0.7 1</background>
|
||||
<shadows>true</shadows>
|
||||
</scene>
|
||||
|
||||
<light type="directional" name="sun">
|
||||
<cast_shadows>true</cast_shadows>
|
||||
<pose>0 0 10 0 0 0</pose>
|
||||
<diffuse>0.8 0.8 0.8 1</diffuse>
|
||||
<specular>0.2 0.2 0.2 1</specular>
|
||||
<direction>0.1 0.1 -1</direction>
|
||||
</light>
|
||||
|
||||
<include>
|
||||
<uri>model://robocon_ground_full</uri>
|
||||
<pose>0 0 0 0 0 0</pose>
|
||||
</include>
|
||||
|
||||
<!-- SIM-P1-004-C: 此处原有的 libgazebo_ros_init.so / libgazebo_ros_factory.so
|
||||
world 级 <plugin> 声明已移除。本机头文件确认两者为 SystemPlugin,
|
||||
不能作为 world <plugin> 加载;改由官方 gzserver.launch.py 以
|
||||
`-s libgazebo_ros_init.so -s libgazebo_ros_factory.so` 各加载一次。
|
||||
其余内容与源 world 完全一致。 -->
|
||||
</world>
|
||||
</sdf>
|
||||
Reference in New Issue
Block a user