原文链接:【Gazebo】ROS2加载URDF到Gazebo11
ros2 加载urdf到gazebo11
笔记:
下载gazebo_model 解压到 ~/.bazebo/models目录下。
killall gzserver //第二次运行launch时关闭服务器
killall gzclient
//构建,获取安装,启动
colcon build --packages-select irb52urdf
. install/setup.bash //启动前将irb52urdf包拷贝到models目录下
ros2 launch irb52urdf gazebo.launch.py
不拷贝包到models目录下报错
拷贝到这里
launch.py文件:
import os
from ament_index_python.packages import get_package_share_directory
from launch import LaunchDescription
from launch.actions import DeclareLaunchArgument, ExecuteProcess
from launch.substitutions import LaunchConfiguration
from launch_ros.actions import Node
from launch.launch_description_sources import PythonLaunchDescriptionSource
from scripts import GazeboRosPaths
def generate_launch_description():
use_sim_time = LaunchConfiguration('use_sim_time', default='false')
urdf_file_name = 'urdf/irb52urdf.urdf'#
print("urdf_file_name : {}".format(urdf_file_name))
urdf = os.path.join(
get_package_share_directory('irb52urdf'),
urdf_file_name)
return LaunchDescription([
DeclareLaunchArgument(
'use_sim_time',
default_value='false',
description='Use simulation (Gazebo) clock if true'),
ExecuteProcess(
cmd=['gazebo', '--verbose', '-s', 'libgazebo_ros_factory.so'],
output='screen'),
Node(
package='robot_state_publisher',
executable='robot_state_publisher',
name='robot_state_publisher',
output='screen',
parameters=[{'use_sim_time': use_sim_time}],
arguments=[urdf]),
Node(
package='joint_state_publisher',
executable='joint_state_publisher',
name='joint_state_publisher',
output='screen',
parameters=[{'use_sim_time': use_sim_time}]
),
Node(
package='gazebo_ros',
executable='spawn_entity.py',
name='urdf_spawner',
output='screen',
arguments=["-topic", "/robot_description", "-entity", "irb52urdf", "-x", "0.0", "-y", "0.0", "-z", "0.0"],
#arguments=["-topic", "robot_description", "-entity", "robot", "-x", "0.0", "-y", "0.0", "-z", "0.0"],
#arguments=["-entity","irb52urdf","-b","-file", urdf,],
)
])
参考:
http://gazebosim.org/tutorials
https://github.com/osrf/gazebo_models
https://www.ncnynl.com/archives/202110/4811.html
http://www.lxshaw.com/tech/ros/2021/05/22/gazebo%e5%85%a5%e9%97%a8%ef%bc%88%e4%b9%9d%ef%bc%89%ef%bc%9a%e4%b8%80%e4%b8%aa%e6%9b%b4%e5%a5%bd%e7%9a%84ros2-gazebo%e6%8f%92%e4%bb%b6%e6%a8%a1%e6%9d%bf/