From 02b37ee4bd81512adaf892496d9b627a68426969 Mon Sep 17 00:00:00 2001 From: dream1112221 <2199305792@qq.com> Date: Thu, 18 Dec 2025 21:22:48 +0800 Subject: [PATCH 1/8] =?UTF-8?q?=E8=AE=BE=E7=BD=AE=E4=B8=89=E7=A7=8D?= =?UTF-8?q?=E5=B7=A5=E4=BD=9C=E6=A8=A1=E5=BC=8F=E4=B8=8B=E7=9A=84=E5=AF=BC?= =?UTF-8?q?=E8=88=AA=E7=B3=BB=E7=BB=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../carla_navigation.launch | 231 ++++++++++++++++++ .../carla_slam_navigation.launch | 185 ++++++++++++++ 2 files changed, 416 insertions(+) create mode 100644 src/carla_slam_gmapping/carla_navigation.launch create mode 100644 src/carla_slam_gmapping/carla_slam_navigation.launch diff --git a/src/carla_slam_gmapping/carla_navigation.launch b/src/carla_slam_gmapping/carla_navigation.launch new file mode 100644 index 0000000000..50e1b10ea2 --- /dev/null +++ b/src/carla_slam_gmapping/carla_navigation.launch @@ -0,0 +1,231 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/carla_slam_gmapping/carla_slam_navigation.launch b/src/carla_slam_gmapping/carla_slam_navigation.launch new file mode 100644 index 0000000000..158c263aeb --- /dev/null +++ b/src/carla_slam_gmapping/carla_slam_navigation.launch @@ -0,0 +1,185 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + From 99a7e96be841ca78c4424d75f1945348c89df1db Mon Sep 17 00:00:00 2001 From: dream1112221 <2199305792@qq.com> Date: Fri, 19 Dec 2025 10:30:59 +0800 Subject: [PATCH 2/8] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E9=85=8D=E7=BD=AE?= =?UTF-8?q?=E6=96=87=E4=BB=B6=EF=BC=8C=E5=AE=8C=E5=96=84=E5=AF=BC=E8=88=AA?= =?UTF-8?q?=E7=B3=BB=E7=BB=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../costmap_common_params.yaml | 24 +++++++++ .../dwa_local_planner_params.yaml | 52 +++++++++++++++++++ .../global_costmap_params.yaml | 19 +++++++ .../local_costmap_params.yaml | 17 ++++++ src/carla_slam_gmapping/move_base_params.yaml | 29 +++++++++++ 5 files changed, 141 insertions(+) create mode 100644 src/carla_slam_gmapping/costmap_common_params.yaml create mode 100644 src/carla_slam_gmapping/dwa_local_planner_params.yaml create mode 100644 src/carla_slam_gmapping/global_costmap_params.yaml create mode 100644 src/carla_slam_gmapping/local_costmap_params.yaml create mode 100644 src/carla_slam_gmapping/move_base_params.yaml diff --git a/src/carla_slam_gmapping/costmap_common_params.yaml b/src/carla_slam_gmapping/costmap_common_params.yaml new file mode 100644 index 0000000000..d339aff288 --- /dev/null +++ b/src/carla_slam_gmapping/costmap_common_params.yaml @@ -0,0 +1,24 @@ +# Common costmap parameters for both global and local costmaps + +# Obstacle marking parameters +obstacle_range: 50.0 +raytrace_range: 100.0 + +# Robot footprint (Tesla Model3 approximate dimensions) +footprint: [[-2.0, -1.0], [-2.0, 1.0], [2.5, 1.0], [2.5, -1.0]] +inflation_radius: 1.5 +cost_scaling_factor: 10.0 + +# Observation sources +observation_sources: laser_scan_sensor + +laser_scan_sensor: + sensor_frame: ego_vehicle/lidar + data_type: LaserScan + topic: /carla/ego_vehicle/scan + marking: true + clearing: true + min_obstacle_height: -0.5 + max_obstacle_height: 2.0 + obstacle_range: 50.0 + raytrace_range: 100.0 diff --git a/src/carla_slam_gmapping/dwa_local_planner_params.yaml b/src/carla_slam_gmapping/dwa_local_planner_params.yaml new file mode 100644 index 0000000000..6b7407b833 --- /dev/null +++ b/src/carla_slam_gmapping/dwa_local_planner_params.yaml @@ -0,0 +1,52 @@ +# DWA Local Planner parameters + +DWAPlannerROS: + # Robot configuration (Tesla Model3 specs) + max_vel_x: 10.0 + min_vel_x: -2.0 + max_vel_y: 0.0 + min_vel_y: 0.0 + + max_trans_vel: 10.0 + min_trans_vel: 0.5 + trans_stopped_vel: 0.1 + + max_rot_vel: 1.0 + min_rot_vel: 0.2 + rot_stopped_vel: 0.1 + + # Acceleration limits + acc_lim_x: 2.5 + acc_lim_y: 0.0 + acc_lim_theta: 3.0 + decel_lim_x: -2.5 + decel_lim_theta: -3.0 + + # Goal tolerance + xy_goal_tolerance: 0.5 + yaw_goal_tolerance: 0.1 + latch_xy_goal_tolerance: false + + # Forward simulation + sim_time: 2.0 + sim_granularity: 0.025 + vx_samples: 20 + vy_samples: 0 + vtheta_samples: 40 + + # Trajectory scoring + path_distance_bias: 32.0 + goal_distance_bias: 20.0 + occdist_scale: 0.02 + forward_point_distance: 0.325 + stop_time_buffer: 0.2 + scaling_speed: 0.25 + max_scaling_factor: 0.2 + + # Oscillation prevention + oscillation_reset_dist: 0.05 + oscillation_reset_angle: 0.2 + + # Debugging + publish_traj_pc: true + publish_cost_grid_pc: true diff --git a/src/carla_slam_gmapping/global_costmap_params.yaml b/src/carla_slam_gmapping/global_costmap_params.yaml new file mode 100644 index 0000000000..1a4fb93ece --- /dev/null +++ b/src/carla_slam_gmapping/global_costmap_params.yaml @@ -0,0 +1,19 @@ +# Global costmap parameters + +global_costmap: + global_frame: map + robot_base_frame: ego_vehicle + update_frequency: 2.0 + publish_frequency: 1.0 + static_map: true + + # Use rolling window for exploration mode + rolling_window: false + width: 200.0 + height: 200.0 + resolution: 0.05 + + plugins: + - {name: static_layer, type: "costmap_2d::StaticLayer"} + - {name: obstacle_layer, type: "costmap_2d::ObstacleLayer"} + - {name: inflation_layer, type: "costmap_2d::InflationLayer"} diff --git a/src/carla_slam_gmapping/local_costmap_params.yaml b/src/carla_slam_gmapping/local_costmap_params.yaml new file mode 100644 index 0000000000..9226cd29ba --- /dev/null +++ b/src/carla_slam_gmapping/local_costmap_params.yaml @@ -0,0 +1,17 @@ +# Local costmap parameters + +local_costmap: + global_frame: odom + robot_base_frame: ego_vehicle + update_frequency: 5.0 + publish_frequency: 2.0 + static_map: false + rolling_window: true + + width: 20.0 + height: 20.0 + resolution: 0.05 + + plugins: + - {name: obstacle_layer, type: "costmap_2d::ObstacleLayer"} + - {name: inflation_layer, type: "costmap_2d::InflationLayer"} diff --git a/src/carla_slam_gmapping/move_base_params.yaml b/src/carla_slam_gmapping/move_base_params.yaml new file mode 100644 index 0000000000..109571fa59 --- /dev/null +++ b/src/carla_slam_gmapping/move_base_params.yaml @@ -0,0 +1,29 @@ +# Move base parameters + +# Controller frequency +controller_frequency: 10.0 +controller_patience: 15.0 + +# Planner frequency +planner_frequency: 5.0 +planner_patience: 5.0 + +# Oscillation parameters +oscillation_timeout: 10.0 +oscillation_distance: 0.2 + +# Recovery behaviors +recovery_behavior_enabled: true +clearing_rotation_allowed: true + +recovery_behaviors: + - name: 'conservative_reset' + type: 'clear_costmap_recovery/ClearCostmapRecovery' + - name: 'aggressive_reset' + type: 'clear_costmap_recovery/ClearCostmapRecovery' + +conservative_reset: + reset_distance: 3.0 + +aggressive_reset: + reset_distance: 5.0 From d99b1c3fb4f0b7bcc84001623e0a4d947a772b01 Mon Sep 17 00:00:00 2001 From: dream1112221 <2199305792@qq.com> Date: Fri, 19 Dec 2025 15:29:08 +0800 Subject: [PATCH 3/8] =?UTF-8?q?=E6=8F=90=E4=BA=A4=E7=9B=AE=E6=A0=87?= =?UTF-8?q?=E7=82=B9=E5=8F=91=E5=B8=83=E8=8A=82=E7=82=B9=E4=BB=A3=E7=A0=81?= =?UTF-8?q?=EF=BC=8C=E5=AE=8C=E5=96=84=E5=AF=BC=E8=88=AA=E7=B3=BB=E7=BB=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/carla_slam_gmapping/goal_publisher.py | 157 ++++++++++++++++++++++ 1 file changed, 157 insertions(+) create mode 100755 src/carla_slam_gmapping/goal_publisher.py diff --git a/src/carla_slam_gmapping/goal_publisher.py b/src/carla_slam_gmapping/goal_publisher.py new file mode 100755 index 0000000000..ae779e7543 --- /dev/null +++ b/src/carla_slam_gmapping/goal_publisher.py @@ -0,0 +1,157 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- + +""" +导航目标点发布器 +功能:向move_base发布导航目标点 +使用:python3 goal_publisher.py [x] [y] [yaw] +""" + +import rospy +import sys +from geometry_msgs.msg import PoseStamped +from move_base_msgs.msg import MoveBaseActionGoal +import math + + +class GoalPublisher: + def __init__(self): + rospy.init_node('goal_publisher', anonymous=True) + + # 发布器 + self.goal_pub = rospy.Publisher('/move_base_simple/goal', PoseStamped, queue_size=10) + + rospy.loginfo("Goal Publisher initialized") + rospy.sleep(1.0) # 等待发布器准备好 + + def publish_goal(self, x, y, yaw=0.0): + """ + 发布导航目标点 + + Args: + x: 目标点X坐标(米) + y: 目标点Y坐标(米) + yaw: 目标朝向(弧度) + """ + goal = PoseStamped() + goal.header.frame_id = "map" + goal.header.stamp = rospy.Time.now() + + # 位置 + goal.pose.position.x = x + goal.pose.position.y = y + goal.pose.position.z = 0.0 + + # 朝向(欧拉角转四元数) + goal.pose.orientation.x = 0.0 + goal.pose.orientation.y = 0.0 + goal.pose.orientation.z = math.sin(yaw / 2.0) + goal.pose.orientation.w = math.cos(yaw / 2.0) + + rospy.loginfo(f"Publishing goal: x={x}, y={y}, yaw={yaw:.2f} rad") + self.goal_pub.publish(goal) + rospy.loginfo("Goal published successfully!") + + def publish_goal_sequence(self, goals): + """ + 发布一系列导航目标点(按顺序) + + Args: + goals: 目标点列表,每个元素为 (x, y, yaw) + """ + rospy.loginfo(f"Publishing {len(goals)} goals in sequence...") + + for i, (x, y, yaw) in enumerate(goals): + rospy.loginfo(f"Goal {i+1}/{len(goals)}") + self.publish_goal(x, y, yaw) + + # 等待用户确认或超时 + input(f"Press Enter to send next goal (or Ctrl+C to stop)...") + + +def predefined_goals(): + """ + 预定义的测试目标点集合(Town01场景) + """ + return { + "straight": [ + (10.0, 0.0, 0.0), + (20.0, 0.0, 0.0), + (30.0, 0.0, 0.0), + ], + "square": [ + (20.0, 0.0, 0.0), + (20.0, 20.0, 1.57), + (0.0, 20.0, 3.14), + (0.0, 0.0, -1.57), + ], + "explore": [ + (50.0, 0.0, 0.0), + (50.0, 50.0, 1.57), + (-50.0, 50.0, 3.14), + (-50.0, -50.0, -1.57), + (0.0, 0.0, 0.0), + ], + } + + +def main(): + if len(sys.argv) < 2: + print("\n=== Goal Publisher Usage ===") + print("1. Single goal:") + print(" python3 goal_publisher.py [yaw]") + print(" Example: python3 goal_publisher.py 10.0 5.0 1.57") + print("\n2. Predefined goal sequences:") + print(" python3 goal_publisher.py straight # 直线前进") + print(" python3 goal_publisher.py square # 方形路径") + print(" python3 goal_publisher.py explore # 探索路径") + print("\n3. Interactive mode:") + print(" python3 goal_publisher.py interactive") + return + + try: + publisher = GoalPublisher() + + # 预定义路径 + if sys.argv[1] in predefined_goals(): + goals = predefined_goals()[sys.argv[1]] + publisher.publish_goal_sequence(goals) + + # 交互模式 + elif sys.argv[1] == "interactive": + print("\n=== Interactive Goal Publisher ===") + print("Enter goal coordinates (or 'q' to quit)") + while not rospy.is_shutdown(): + try: + x = input("X coordinate (m): ") + if x.lower() == 'q': + break + y = input("Y coordinate (m): ") + yaw = input("Yaw angle (rad, default=0.0): ") + + x = float(x) + y = float(y) + yaw = float(yaw) if yaw else 0.0 + + publisher.publish_goal(x, y, yaw) + except ValueError: + print("Invalid input! Please enter numbers.") + except KeyboardInterrupt: + break + + # 单个目标点 + else: + x = float(sys.argv[1]) + y = float(sys.argv[2]) + yaw = float(sys.argv[3]) if len(sys.argv) > 3 else 0.0 + + publisher.publish_goal(x, y, yaw) + + except rospy.ROSInterruptException: + rospy.loginfo("Goal Publisher shutdown") + except Exception as e: + rospy.logerr(f"Error: {e}") + + +if __name__ == '__main__': + main() From a76c8b72caca8fd61ef8c012ff464d9eba45caef Mon Sep 17 00:00:00 2001 From: dream1112221 <2199305792@qq.com> Date: Fri, 19 Dec 2025 17:44:02 +0800 Subject: [PATCH 4/8] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E7=AE=A1=E7=90=86CARLA?= =?UTF-8?q?=E4=BB=BF=E7=9C=9F=E5=9C=BA=E6=99=AF=E4=BB=A3=E7=A0=81=EF=BC=8C?= =?UTF-8?q?=E5=AE=8C=E5=96=84=E5=AF=BC=E8=88=AA=E2=9E=95=E5=BB=BA=E5=9B=BE?= =?UTF-8?q?=E7=B3=BB=E7=BB=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/carla_slam_gmapping/scenario_manager.py | 185 ++++++++++++++++++++ 1 file changed, 185 insertions(+) create mode 100755 src/carla_slam_gmapping/scenario_manager.py diff --git a/src/carla_slam_gmapping/scenario_manager.py b/src/carla_slam_gmapping/scenario_manager.py new file mode 100755 index 0000000000..65ba49c4a5 --- /dev/null +++ b/src/carla_slam_gmapping/scenario_manager.py @@ -0,0 +1,185 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- + +""" +CARLA场景管理器 +功能:切换CARLA地图,支持不同场景的重复实验 +""" + +import rospy +import carla +import sys +import time + + +class ScenarioManager: + def __init__(self, host='localhost', port=2000, timeout=10.0): + """ + 初始化场景管理器 + + Args: + host: CARLA服务器地址 + port: CARLA服务器端口 + timeout: 连接超时时间 + """ + try: + self.client = carla.Client(host, port) + self.client.set_timeout(timeout) + self.world = self.client.get_world() + print(f"Connected to CARLA server at {host}:{port}") + print(f"Current map: {self.world.get_map().name}") + except Exception as e: + print(f"Failed to connect to CARLA: {e}") + sys.exit(1) + + def list_available_maps(self): + """列出所有可用的地图""" + maps = self.client.get_available_maps() + print("\n=== Available Maps ===") + for i, map_name in enumerate(maps, 1): + print(f"{i}. {map_name}") + return maps + + def switch_map(self, map_name): + """ + 切换地图 + + Args: + map_name: 地图名称(如 'Town01', 'Town02' 等) + """ + print(f"\nSwitching to map: {map_name}") + try: + # 如果不包含完整路径,自动补全 + if not map_name.startswith('/Game/Carla/Maps'): + map_name = f'/Game/Carla/Maps/{map_name}' + + self.world = self.client.load_world(map_name) + print(f"Map switched successfully!") + print(f"Current map: {self.world.get_map().name}") + time.sleep(2) # 等待地图加载完成 + return True + except Exception as e: + print(f"Failed to switch map: {e}") + return False + + def get_spawn_points(self): + """获取当前地图的所有出生点""" + spawn_points = self.world.get_map().get_spawn_points() + print(f"\n=== Spawn Points ({len(spawn_points)} total) ===") + for i, point in enumerate(spawn_points[:10], 1): # 只显示前10个 + loc = point.location + print(f"{i}. x={loc.x:.2f}, y={loc.y:.2f}, z={loc.z:.2f}, yaw={point.rotation.yaw:.2f}") + if len(spawn_points) > 10: + print(f"... and {len(spawn_points) - 10} more") + return spawn_points + + def set_weather(self, weather_preset='ClearNoon'): + """ + 设置天气 + + Args: + weather_preset: 天气预设名称 + """ + weather_presets = { + 'ClearNoon': carla.WeatherParameters.ClearNoon, + 'CloudyNoon': carla.WeatherParameters.CloudyNoon, + 'WetNoon': carla.WeatherParameters.WetNoon, + 'WetCloudyNoon': carla.WeatherParameters.WetCloudyNoon, + 'SoftRainNoon': carla.WeatherParameters.SoftRainNoon, + 'MidRainyNoon': carla.WeatherParameters.MidRainyNoon, + 'HardRainNoon': carla.WeatherParameters.HardRainNoon, + 'ClearSunset': carla.WeatherParameters.ClearSunset, + 'CloudySunset': carla.WeatherParameters.CloudySunset, + 'WetSunset': carla.WeatherParameters.WetSunset, + } + + if weather_preset in weather_presets: + self.world.set_weather(weather_presets[weather_preset]) + print(f"Weather set to: {weather_preset}") + else: + print(f"Unknown weather preset: {weather_preset}") + print(f"Available presets: {', '.join(weather_presets.keys())}") + + +def main(): + if len(sys.argv) < 2: + print("\n=== Scenario Manager Usage ===") + print("1. List available maps:") + print(" python3 scenario_manager.py list") + print("\n2. Switch to a specific map:") + print(" python3 scenario_manager.py switch ") + print(" Example: python3 scenario_manager.py switch Town02") + print("\n3. Show spawn points:") + print(" python3 scenario_manager.py spawns") + print("\n4. Set weather:") + print(" python3 scenario_manager.py weather ") + print(" Example: python3 scenario_manager.py weather CloudyNoon") + print("\n5. Interactive mode:") + print(" python3 scenario_manager.py interactive") + return + + try: + manager = ScenarioManager() + + command = sys.argv[1].lower() + + if command == "list": + manager.list_available_maps() + + elif command == "switch": + if len(sys.argv) < 3: + print("Error: Please specify map name") + print("Example: python3 scenario_manager.py switch Town02") + else: + manager.switch_map(sys.argv[2]) + + elif command == "spawns": + manager.get_spawn_points() + + elif command == "weather": + if len(sys.argv) < 3: + print("Error: Please specify weather preset") + else: + manager.set_weather(sys.argv[2]) + + elif command == "interactive": + print("\n=== Interactive Scenario Manager ===") + manager.list_available_maps() + + while True: + print("\nCommands:") + print(" switch - Switch to map") + print(" spawns - Show spawn points") + print(" weather - Set weather") + print(" list - List maps") + print(" q - Quit") + + cmd = input("\n> ").strip().split() + if not cmd: + continue + + if cmd[0] == 'q': + break + elif cmd[0] == 'switch' and len(cmd) > 1: + manager.switch_map(cmd[1]) + elif cmd[0] == 'spawns': + manager.get_spawn_points() + elif cmd[0] == 'weather' and len(cmd) > 1: + manager.set_weather(cmd[1]) + elif cmd[0] == 'list': + manager.list_available_maps() + else: + print("Unknown command or missing argument") + + else: + print(f"Unknown command: {command}") + print("Run without arguments to see usage") + + except KeyboardInterrupt: + print("\nScenario Manager interrupted") + except Exception as e: + print(f"Error: {e}") + + +if __name__ == '__main__': + main() From 40dd4115408cb8f28f4069b6d37586513b32c3ec Mon Sep 17 00:00:00 2001 From: dream1112221 <2199305792@qq.com> Date: Mon, 22 Dec 2025 08:23:48 +0800 Subject: [PATCH 5/8] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E9=A1=B9=E7=9B=AE?= =?UTF-8?q?=E6=89=80=E9=9C=80=E4=BE=9D=E8=B5=96=E6=96=87=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/carla_slam_gmapping/requirements.txt | 32 ++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 src/carla_slam_gmapping/requirements.txt diff --git a/src/carla_slam_gmapping/requirements.txt b/src/carla_slam_gmapping/requirements.txt new file mode 100644 index 0000000000..5a2f851f67 --- /dev/null +++ b/src/carla_slam_gmapping/requirements.txt @@ -0,0 +1,32 @@ +# CARLA SLAM GMMapping Navigation System - Python Dependencies +# Generated for deep learning-based autonomous navigation with CARLA simulator + +# Deep Learning Framework +torch>=1.12.0 +torchvision>=0.13.0 + +# Computer Vision +opencv-python>=4.5.0 + +# Scientific Computing +numpy>=1.21.0 +pandas>=1.3.0 + +# Visualization and Plotting +matplotlib>=3.5.0 + +# CARLA Simulator Python API +# Note: CARLA Python API typically needs to be installed from the CARLA distribution +# For CARLA 0.9.x, install from: carla--py3.x-linux-x86_64.egg +# Example: pip install /path/to/carla/PythonAPI/carla/dist/carla-0.9.13-cp38-cp38-linux_x86_64.whl +carla>=0.9.13 + +# ROS Bridge Dependencies (if using ROS Python packages directly) +# Note: Most ROS dependencies are handled through ROS installation +# These are supplementary Python packages that might be needed +# tf-transformations>=1.0.0 # Uncomment if not using ROS's built-in version + +# Optional: Additional utilities for development +# jupyter>=1.0.0 # For interactive development +# tensorboard>=2.8.0 # For training visualization +# scikit-learn>=1.0.0 # For additional ML utilities From 206dfda8bbb2abfef5daee03a606b37837b60e4b Mon Sep 17 00:00:00 2001 From: dream1112221 <2199305792@qq.com> Date: Mon, 22 Dec 2025 10:54:07 +0800 Subject: [PATCH 6/8] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E7=BC=96=E8=AF=91?= =?UTF-8?q?=E9=85=8D=E7=BD=AE=E6=96=87=E4=BB=B6CMakeList.txt?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/carla_slam_gmapping/CMakeLists.txt | 108 +++++++++++++++++++++++++ 1 file changed, 108 insertions(+) create mode 100644 src/carla_slam_gmapping/CMakeLists.txt diff --git a/src/carla_slam_gmapping/CMakeLists.txt b/src/carla_slam_gmapping/CMakeLists.txt new file mode 100644 index 0000000000..d97af17d46 --- /dev/null +++ b/src/carla_slam_gmapping/CMakeLists.txt @@ -0,0 +1,108 @@ +cmake_minimum_required(VERSION 3.0.2) +project(carla_slam_gmapping) + +## Find catkin macros and libraries +find_package(catkin REQUIRED COMPONENTS + rospy + roscpp + std_msgs + sensor_msgs + geometry_msgs + nav_msgs + move_base_msgs + visualization_msgs + carla_msgs + tf + tf2_ros + cv_bridge + image_transport +) + +## System dependencies are found with CMake's conventions +# find_package(OpenCV REQUIRED) + +################################### +## catkin specific configuration ## +################################### +catkin_package( + CATKIN_DEPENDS + rospy + roscpp + std_msgs + sensor_msgs + geometry_msgs + nav_msgs + move_base_msgs + visualization_msgs + carla_msgs + tf + tf2_ros + cv_bridge + image_transport +) + +########### +## Build ## +########### + +## Specify additional locations of header files +include_directories( + ${catkin_INCLUDE_DIRS} +) + +############# +## Install ## +############# + +## Mark Python scripts as executable +catkin_install_python(PROGRAMS + goal_publisher.py + main.py + scenario_manager.py + DESTINATION ${CATKIN_PACKAGE_BIN_DESTINATION} +) + +## Mark launch files for installation +install(FILES + carla_navigation.launch + carla_slam_gmapping.launch + carla_slam_navigation.launch + save_map.launch + DESTINATION ${CATKIN_PACKAGE_SHARE_DESTINATION}/launch +) + +## Mark config files for installation +install(FILES + costmap_common_params.yaml + dwa_local_planner_params.yaml + global_costmap_params.yaml + local_costmap_params.yaml + move_base_params.yaml + DESTINATION ${CATKIN_PACKAGE_SHARE_DESTINATION}/config +) + +## Mark shell scripts for installation +install(PROGRAMS + start_slam_navigation.sh + DESTINATION ${CATKIN_PACKAGE_BIN_DESTINATION} +) + +## Mark other files for installation (e.g. documentation) +install(FILES + README.md + requirements.txt + DESTINATION ${CATKIN_PACKAGE_SHARE_DESTINATION} +) + +############# +## Testing ## +############# + +## Add gtest based cpp test target and link libraries +# catkin_add_gtest(${PROJECT_NAME}-test test/test_carla_slam_gmapping.cpp) +# if(TARGET ${PROJECT_NAME}-test) +# target_link_libraries(${PROJECT_NAME}-test ${PROJECT_NAME}) +# endif() + +## Add folders to be run by python nosetests +# catkin_add_nosetests(test) From 7f5d497a8ef5790b48b396bae96b0132df6f3861 Mon Sep 17 00:00:00 2001 From: dream1112221 <2199305792@qq.com> Date: Tue, 23 Dec 2025 14:21:00 +0800 Subject: [PATCH 7/8] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E6=96=87=E4=BB=B6?= =?UTF-8?q?=E5=AE=9A=E4=B9=89=E8=B7=AF=E5=BE=84=E8=A7=84=E5=88=92=E6=9C=8D?= =?UTF-8?q?=E5=8A=A1=E7=9A=84=E8=AF=B7=E6=B1=82=E5=92=8C=E5=93=8D=E5=BA=94?= =?UTF-8?q?=E6=A0=BC=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/carla_slam_gmapping/srv/PlanGlobalPath.srv | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 src/carla_slam_gmapping/srv/PlanGlobalPath.srv diff --git a/src/carla_slam_gmapping/srv/PlanGlobalPath.srv b/src/carla_slam_gmapping/srv/PlanGlobalPath.srv new file mode 100644 index 0000000000..48a9ba3955 --- /dev/null +++ b/src/carla_slam_gmapping/srv/PlanGlobalPath.srv @@ -0,0 +1,9 @@ +# Service definition for global path planning +# Request: starting position (odometry) +nav_msgs/Odometry start + +--- +# Response: planned path +nav_msgs/Path path +bool success +string message From ae99d15ef1eaaa221706409c8cc4e1d21b0046de Mon Sep 17 00:00:00 2001 From: dream1112221 <2199305792@qq.com> Date: Tue, 23 Dec 2025 16:22:18 +0800 Subject: [PATCH 8/8] =?UTF-8?q?=E6=B7=BB=E5=8A=A0sh=E6=96=87=E4=BB=B6?= =?UTF-8?q?=EF=BC=8C=E4=B8=80=E9=94=AE=E5=AE=8C=E6=88=90=E6=89=80=E6=9C=89?= =?UTF-8?q?=E5=AE=89=E8=A3=85=E6=AD=A5=E9=AA=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/carla_slam_gmapping/install.sh | 185 +++++++++++++++++++++++++++++ 1 file changed, 185 insertions(+) create mode 100755 src/carla_slam_gmapping/install.sh diff --git a/src/carla_slam_gmapping/install.sh b/src/carla_slam_gmapping/install.sh new file mode 100755 index 0000000000..b5a1f012dc --- /dev/null +++ b/src/carla_slam_gmapping/install.sh @@ -0,0 +1,185 @@ +#!/bin/bash +# CARLA SLAM GMMapping 自动化安装脚本 + +set -e # 遇到错误立即退出 + +echo "==========================================" +echo " CARLA SLAM GMMapping 安装脚本" +echo "==========================================" +echo "" + +# 颜色定义 +GREEN='\033[0;32m' +YELLOW='\033[1;33m' +RED='\033[0;31m' +NC='\033[0m' # No Color + +# 检查是否在ROS工作空间中 +check_ros_workspace() { + if [ ! -f "../../CMakeLists.txt" ]; then + echo -e "${RED}错误: 请在ROS工作空间的src目录中运行此脚本${NC}" + echo "例如: cd ~/catkin_ws/src/carla_slam_gmapping && ./install.sh" + exit 1 + fi +} + +# 检查ROS是否安装 +check_ros_installation() { + echo -e "${YELLOW}[1/6] 检查ROS安装...${NC}" + if [ -z "$ROS_DISTRO" ]; then + echo -e "${RED}错误: 未检测到ROS环境变量${NC}" + echo "请先source ROS环境:" + echo " source /opt/ros/noetic/setup.bash" + exit 1 + fi + echo -e "${GREEN}✓ ROS $ROS_DISTRO 已安装${NC}" +} + +# 安装ROS依赖 +install_ros_dependencies() { + echo -e "${YELLOW}[2/6] 安装ROS包依赖...${NC}" + + # 返回到工作空间根目录 + cd ../.. + + # 使用rosdep安装依赖 + if command -v rosdep &> /dev/null; then + echo "使用rosdep安装依赖..." + rosdep update + rosdep install --from-paths src --ignore-src -r -y + else + echo -e "${YELLOW}警告: rosdep未安装,手动安装必需包...${NC}" + sudo apt-get update + sudo apt-get install -y \ + ros-$ROS_DISTRO-gmapping \ + ros-$ROS_DISTRO-map-server \ + ros-$ROS_DISTRO-move-base \ + ros-$ROS_DISTRO-dwa-local-planner \ + ros-$ROS_DISTRO-global-planner \ + ros-$ROS_DISTRO-carla-ros-bridge \ + ros-$ROS_DISTRO-carla-msgs \ + ros-$ROS_DISTRO-rviz + fi + + echo -e "${GREEN}✓ ROS依赖安装完成${NC}" + + # 返回到包目录 + cd src/carla_slam_gmapping +} + +# 安装Python依赖 +install_python_dependencies() { + echo -e "${YELLOW}[3/6] 安装Python依赖...${NC}" + + if [ ! -f "requirements.txt" ]; then + echo -e "${RED}错误: requirements.txt 文件不存在${NC}" + exit 1 + fi + + # 检查pip + if ! command -v pip3 &> /dev/null; then + echo "安装pip3..." + sudo apt-get install -y python3-pip + fi + + # 安装Python包 + pip3 install -r requirements.txt + + echo -e "${GREEN}✓ Python依赖安装完成${NC}" +} + +# 安装CARLA Python API +install_carla_api() { + echo -e "${YELLOW}[4/6] 检查CARLA Python API...${NC}" + + # 检查CARLA是否已安装 + if python3 -c "import carla" 2>/dev/null; then + echo -e "${GREEN}✓ CARLA Python API 已安装${NC}" + else + echo -e "${YELLOW}警告: CARLA Python API 未安装${NC}" + echo "请手动安装CARLA Python API:" + echo "1. 下载CARLA: https://github.com/carla-simulator/carla/releases" + echo "2. 安装egg文件:" + echo " pip3 install /path/to/carla/PythonAPI/carla/dist/carla-0.9.15-py3.x-linux-x86_64.egg" + echo "" + read -p "是否跳过此步骤继续? (y/n) " -n 1 -r + echo + if [[ ! $REPLY =~ ^[Yy]$ ]]; then + exit 1 + fi + fi +} + +# 编译工作空间 +build_workspace() { + echo -e "${YELLOW}[5/6] 编译ROS工作空间...${NC}" + + # 返回到工作空间根目录 + cd ../.. + + # 使用catkin_make编译 + if command -v catkin_make &> /dev/null; then + catkin_make + elif command -v catkin &> /dev/null; then + catkin build carla_slam_gmapping + else + echo -e "${RED}错误: 未找到catkin编译工具${NC}" + exit 1 + fi + + echo -e "${GREEN}✓ 编译完成${NC}" +} + +# 配置环境 +setup_environment() { + echo -e "${YELLOW}[6/6] 配置环境...${NC}" + + # 创建必要的目录 + cd src/carla_slam_gmapping + mkdir -p maps logs + + echo -e "${GREEN}✓ 环境配置完成${NC}" +} + +# 显示安装完成信息 +show_completion_message() { + echo "" + echo "==========================================" + echo -e "${GREEN} 安装完成!${NC}" + echo "==========================================" + echo "" + echo "下一步操作:" + echo "" + echo "1. 更新环境变量:" + echo " source ~/catkin_ws/devel/setup.bash" + echo "" + echo "2. 启动CARLA模拟器 (另开终端):" + echo " cd /path/to/carla" + echo " ./CarlaUE4.sh" + echo "" + echo "3. 启动ROS Bridge (另开终端):" + echo " roslaunch carla_ros_bridge carla_ros_bridge.launch" + echo "" + echo "4. 启动SLAM导航系统:" + echo " roslaunch carla_slam_gmapping carla_slam_navigation.launch" + echo "" + echo "5. 或使用快速启动脚本:" + echo " ./start_slam_navigation.sh" + echo "" + echo "==========================================" +} + +# 主函数 +main() { + check_ros_workspace + check_ros_installation + install_ros_dependencies + install_python_dependencies + install_carla_api + build_workspace + setup_environment + show_completion_message +} + +# 运行主函数 +main