@zzpcp3 @3164066018 @捶你胸口 @凄凉的泪水
我在gazebo.launch.py中加入的代码是这样的
from ament_index_python.packages import get_package_prefix
package_name = 'cubot_v2_sw2urdf'
pkg_share = os.pathsep + os.path.join(get_package_prefix(package_name), 'share')
if 'GAZEBO_MODEL_PATH' in os.environ: # 如果你修改了~/.bashrc, 就会执行这个
os.environ['GAZEBO_MODEL_PATH'] += pkg_share
else: # 注意此处gazebo-11修改为你的gazebo版本
os.environ['GAZEBO_MODEL_PATH'] = "/usr/share/gazebo-11/models" + pkg_share
注意把gazebo-11替换为你的gazebo版本,可以先去找找对应的路径是否存在
全部的sw转urdf流程可以在我的blog里面看看
完整launch文件如下
import launch
import launch_ros
from ament_index_python.packages import get_package_share_directory, get_package_prefix
from launch.launch_description_sources import PythonLaunchDescriptionSource
import os
def generate_launch_description():
# Get default path
robot_name_in_model = "cubot_v2_sw2urdf"
urdf_tutorial_path = get_package_share_directory('cubot_v2_sw2urdf')
default_model_path = os.path.join(
urdf_tutorial_path, 'urdf', 'cubot_v2_sw2urdf.urdf')
# Read URDF file content
with open(default_model_path, 'r') as urdf_file:
robot_description = urdf_file.read()
robot_state_publisher_node = launch_ros.actions.Node(
package='robot_state_publisher',
executable='robot_state_publisher',
parameters=[{'robot_description': robot_description}]
)
# Include another launch file for Gazebo
launch_gazebo = launch.actions.IncludeLaunchDescription(
PythonLaunchDescriptionSource([get_package_share_directory(
'gazebo_ros'), '/launch', '/gazebo.launch.py']),
)
# Request Gazebo to spawn the robot
spawn_entity_node = launch_ros.actions.Node(
package='gazebo_ros',
executable='spawn_entity.py',
arguments=['-topic', '/robot_description',
'-entity', robot_name_in_model])
package_name = 'cubot_v2_sw2urdf'
pkg_share = os.pathsep + os.path.join(get_package_prefix(package_name), 'share')
if 'GAZEBO_MODEL_PATH' in os.environ:
os.environ['GAZEBO_MODEL_PATH'] += pkg_share
else:
os.environ['GAZEBO_MODEL_PATH'] = "/usr/share/gazebo-11/models" + pkg_share
return launch.LaunchDescription([
robot_state_publisher_node,
launch_gazebo,
spawn_entity_node
])