add agv_pro_gazebo
This commit is contained in:
@@ -0,0 +1,41 @@
|
||||
import os
|
||||
|
||||
from ament_index_python.packages import get_package_share_directory
|
||||
|
||||
from launch import LaunchDescription
|
||||
from launch.substitutions import LaunchConfiguration
|
||||
from launch.actions import DeclareLaunchArgument
|
||||
from launch_ros.actions import Node
|
||||
|
||||
import xacro
|
||||
|
||||
|
||||
def generate_launch_description():
|
||||
|
||||
# Check if we're told to use sim time
|
||||
use_sim_time = LaunchConfiguration('use_sim_time')
|
||||
|
||||
# Process the URDF file
|
||||
pkg_path = os.path.join(get_package_share_directory('agv_pro_description'))
|
||||
xacro_file = os.path.join(pkg_path,'urdf','agv_pro.xacro')
|
||||
robot_description_config = xacro.process_file(xacro_file)
|
||||
|
||||
# Create a robot_state_publisher node
|
||||
params = {'robot_description': robot_description_config.toxml(), 'use_sim_time': use_sim_time}
|
||||
node_robot_state_publisher = Node(
|
||||
package='robot_state_publisher',
|
||||
executable='robot_state_publisher',
|
||||
output='screen',
|
||||
parameters=[params]
|
||||
)
|
||||
|
||||
|
||||
# Launch!
|
||||
return LaunchDescription([
|
||||
DeclareLaunchArgument(
|
||||
'use_sim_time',
|
||||
default_value='false',
|
||||
description='Use sim time if true'),
|
||||
|
||||
node_robot_state_publisher
|
||||
])
|
||||
@@ -0,0 +1,49 @@
|
||||
import os
|
||||
from launch import LaunchDescription
|
||||
from launch_ros.actions import Node
|
||||
from launch.conditions import IfCondition
|
||||
from launch.substitutions import LaunchConfiguration
|
||||
from ament_index_python.packages import get_package_share_directory
|
||||
|
||||
def generate_launch_description():
|
||||
|
||||
use_rviz = LaunchConfiguration('use_rviz', default='true')
|
||||
|
||||
rviz_config_dir = os.path.join(
|
||||
get_package_share_directory('agv_pro_description'),
|
||||
'rviz',
|
||||
'agvpro_display.rviz')
|
||||
|
||||
urdf_file = os.path.join(
|
||||
get_package_share_directory('agv_pro_description'),
|
||||
'urdf',
|
||||
'agv_pro.urdf'
|
||||
)
|
||||
|
||||
with open(urdf_file, 'r') as file:
|
||||
robot_description_content = file.read()
|
||||
|
||||
return LaunchDescription([
|
||||
|
||||
Node(
|
||||
package='joint_state_publisher',
|
||||
executable='joint_state_publisher',
|
||||
name='joint_state_publisher'
|
||||
),
|
||||
|
||||
Node(
|
||||
package='robot_state_publisher',
|
||||
executable='robot_state_publisher',
|
||||
name='robot_state_publisher',
|
||||
parameters=[{'robot_description': robot_description_content}]
|
||||
),
|
||||
|
||||
Node(
|
||||
package='rviz2',
|
||||
executable='rviz2',
|
||||
name='rviz2',
|
||||
arguments=['-d', rviz_config_dir],
|
||||
condition=IfCondition(use_rviz),
|
||||
output='screen')
|
||||
|
||||
])
|
||||
@@ -0,0 +1,66 @@
|
||||
import os
|
||||
from launch import LaunchDescription
|
||||
from launch.actions import IncludeLaunchDescription
|
||||
from launch.launch_description_sources import PythonLaunchDescriptionSource
|
||||
from launch.substitutions import Command
|
||||
from launch_ros.actions import Node
|
||||
from launch_ros.parameter_descriptions import ParameterValue
|
||||
from ament_index_python.packages import get_package_share_directory
|
||||
|
||||
def generate_launch_description():
|
||||
pkg_name = 'agv_pro_description'
|
||||
pkg_dir = get_package_share_directory(pkg_name)
|
||||
|
||||
xacro_file = os.path.join(pkg_dir, 'urdf', 'agv_pro.xacro')
|
||||
world_file = os.path.join(pkg_dir, 'worlds', 'empty.world')
|
||||
rviz_config = os.path.join(pkg_dir, 'rviz', 'agvpro_display.rviz')
|
||||
|
||||
robot_description_content = ParameterValue(
|
||||
Command(['xacro ', xacro_file]),
|
||||
value_type=str
|
||||
)
|
||||
robot_description = {'robot_description': robot_description_content}
|
||||
|
||||
return LaunchDescription([
|
||||
# Launch Gazebo
|
||||
IncludeLaunchDescription(
|
||||
PythonLaunchDescriptionSource(
|
||||
os.path.join(get_package_share_directory('gazebo_ros'), 'launch', 'gazebo.launch.py')
|
||||
),
|
||||
launch_arguments={'world': world_file}.items()
|
||||
),
|
||||
|
||||
# Spawn robot into Gazebo
|
||||
Node(
|
||||
package='gazebo_ros',
|
||||
executable='spawn_entity.py',
|
||||
arguments=['-topic', 'robot_description',
|
||||
'-entity', 'agv_pro'],
|
||||
output='screen'
|
||||
),
|
||||
|
||||
# State publisher
|
||||
Node(
|
||||
package='robot_state_publisher',
|
||||
executable='robot_state_publisher',
|
||||
name='robot_state_publisher',
|
||||
output='screen',
|
||||
parameters=[robot_description]
|
||||
),
|
||||
|
||||
Node(
|
||||
package='joint_state_publisher',
|
||||
executable='joint_state_publisher',
|
||||
name='joint_state_publisher',
|
||||
output='screen',
|
||||
),
|
||||
|
||||
# Optional: RViz
|
||||
Node(
|
||||
package='rviz2',
|
||||
executable='rviz2',
|
||||
name='rviz2',
|
||||
output='screen',
|
||||
arguments=['-d', rviz_config],
|
||||
),
|
||||
])
|
||||
@@ -0,0 +1,71 @@
|
||||
import os
|
||||
from launch import LaunchDescription
|
||||
from launch.actions import IncludeLaunchDescription, ExecuteProcess
|
||||
from launch.launch_description_sources import PythonLaunchDescriptionSource
|
||||
from launch.substitutions import Command, LaunchConfiguration, PathJoinSubstitution
|
||||
from launch_ros.actions import Node
|
||||
from ament_index_python.packages import get_package_share_directory
|
||||
|
||||
def generate_launch_description():
|
||||
pkg_name = 'agv_pro_description'
|
||||
|
||||
# Paths
|
||||
pkg_dir = get_package_share_directory(pkg_name)
|
||||
xacro_file = os.path.join(pkg_dir, 'urdf', 'agv_pro.xacro')
|
||||
world_file = os.path.join(pkg_dir, 'worlds', 'empty.world') # 创建一个空 world 即可
|
||||
rviz_config = os.path.join(pkg_dir, 'rviz', 'agvpro_display.rviz')
|
||||
|
||||
robot_description_content = Command(['xacro ', xacro_file])
|
||||
robot_description = {'robot_description': robot_description_content}
|
||||
|
||||
return LaunchDescription([
|
||||
|
||||
# Start Gazebo with empty world
|
||||
IncludeLaunchDescription(
|
||||
PythonLaunchDescriptionSource(
|
||||
[os.path.join(get_package_share_directory('gazebo_ros'), 'launch', 'gazebo.launch.py')]
|
||||
),
|
||||
launch_arguments={'world': world_file}.items()
|
||||
),
|
||||
|
||||
# Spawn robot into Gazebo
|
||||
Node(
|
||||
package='gazebo_ros',
|
||||
executable='spawn_entity.py',
|
||||
arguments=['-topic', 'robot_description',
|
||||
'-entity', 'agv_pro'],
|
||||
output='screen'
|
||||
),
|
||||
|
||||
# Robot state publisher
|
||||
Node(
|
||||
package='robot_state_publisher',
|
||||
executable='robot_state_publisher',
|
||||
name='robot_state_publisher',
|
||||
output='screen',
|
||||
parameters=[robot_description]
|
||||
),
|
||||
|
||||
# Optionally publish joint states if not using controllers
|
||||
Node(
|
||||
package='joint_state_publisher',
|
||||
executable='joint_state_publisher',
|
||||
name='joint_state_publisher',
|
||||
output='screen',
|
||||
),
|
||||
Node(
|
||||
package='controller_manager',
|
||||
executable='spawner',
|
||||
arguments=['joint_state_broadcaster'],
|
||||
output='screen',
|
||||
),
|
||||
|
||||
# RViz (optional, visualize TF & model)
|
||||
Node(
|
||||
package='rviz2',
|
||||
executable='rviz2',
|
||||
name='rviz2',
|
||||
output='screen',
|
||||
arguments=['-d', rviz_config],
|
||||
),
|
||||
])
|
||||
@@ -0,0 +1,17 @@
|
||||
import os
|
||||
from launch import LaunchDescription
|
||||
from launch_ros.actions import Node
|
||||
|
||||
def generate_launch_description():
|
||||
return LaunchDescription([
|
||||
Node(
|
||||
package='teleop_twist_keyboard',
|
||||
executable='teleop_twist_keyboard',
|
||||
name='teleop_keyboard',
|
||||
output='screen',
|
||||
prefix='xterm -e', # 或 'gnome-terminal --' 替换为你的终端命令
|
||||
remappings=[
|
||||
('/cmd_vel', '/diff_drive_controller/cmd_vel_unstamped')
|
||||
]
|
||||
)
|
||||
])
|
||||
@@ -0,0 +1,35 @@
|
||||
import os
|
||||
from launch import LaunchDescription
|
||||
from launch.actions import IncludeLaunchDescription
|
||||
from launch.launch_description_sources import PythonLaunchDescriptionSource
|
||||
from launch_ros.actions import Node
|
||||
from launch.substitutions import Command
|
||||
from ament_index_python.packages import get_package_share_directory
|
||||
|
||||
def generate_launch_description():
|
||||
pkg_dir = get_package_share_directory('agv_pro_description')
|
||||
xacro_file = os.path.join(pkg_dir, 'urdf', 'minimal_robot.xacro')
|
||||
world_file = os.path.join(pkg_dir, 'worlds', 'empty.world')
|
||||
|
||||
robot_description = {'robot_description': Command(['xacro ', xacro_file])}
|
||||
|
||||
return LaunchDescription([
|
||||
IncludeLaunchDescription(
|
||||
PythonLaunchDescriptionSource(
|
||||
os.path.join(get_package_share_directory('gazebo_ros'), 'launch', 'gazebo.launch.py')
|
||||
),
|
||||
launch_arguments={'world': world_file}.items()
|
||||
),
|
||||
Node(
|
||||
package='robot_state_publisher',
|
||||
executable='robot_state_publisher',
|
||||
parameters=[robot_description],
|
||||
output='screen'
|
||||
),
|
||||
Node(
|
||||
package='gazebo_ros',
|
||||
executable='spawn_entity.py',
|
||||
arguments=['-topic', 'robot_description', '-entity', 'minimal_bot'],
|
||||
output='screen'
|
||||
)
|
||||
])
|
||||
Reference in New Issue
Block a user