dual_arm_panda_moveit_config/launch/demo.launch.py

dual_arm_panda_moveit_config/launch/demo.launch.py

demo.launch.py

cpp 复制代码
import os
from launch import LaunchDescription
from launch_ros.actions import Node
from launch.actions import ExecuteProcess
from ament_index_python.packages import get_package_share_directory
from moveit_configs_utils import MoveItConfigsBuilder

# 生成启动描述函数
def generate_launch_description():

    # 配置 MoveIt
    moveit_config = (
        MoveItConfigsBuilder("dual_arm_panda")
        .robot_description(file_path="config/panda.urdf.xacro")
        .robot_description_semantic(file_path="config/panda.srdf")
        .trajectory_execution(file_path="config/moveit_controllers.yaml")
        .planning_pipelines(pipelines=["ompl"])
        .to_moveit_configs()
    )

    # 启动 move_group 节点/动作服务器
    move_group_node = Node(
        package="moveit_ros_move_group",
        executable="move_group",
        output="screen",
        parameters=[moveit_config.to_dict()],
    )

    # RViz 配置
    rviz_config = os.path.join(
        get_package_share_directory("dual_arm_panda_moveit_config"),
        "launch/moveit.rviz",
    )
    rviz_node = Node(
        package="rviz2",
        executable="rviz2",
        name="rviz2",
        output="log",
        arguments=["-d", rviz_config],
        parameters=[
            moveit_config.robot_description,
            moveit_config.robot_description_semantic,
            moveit_config.planning_pipelines,
            moveit_config.robot_description_kinematics,
        ],
    )

    # 发布 TF
    robot_state_publisher = Node(
        package="robot_state_publisher",
        executable="robot_state_publisher",
        name="robot_state_publisher",
        output="both",
        parameters=[moveit_config.robot_description],
    )

    # 使用 FakeSystem 作为硬件的 ros2_control
    ros2_controllers_path = os.path.join(
        get_package_share_directory("dual_arm_panda_moveit_config"),
        "config/",
        "ros2_controllers.yaml",
    )
    ros2_control_node = Node(
        package="controller_manager",
        executable="ros2_control_node",
        parameters=[ros2_controllers_path],
        remappings=[
            ("/controller_manager/robot_description", "/robot_description"),
        ],
        output="both",
    )

    # 加载控制器
    load_controllers = []
    for controller in [
        "joint_state_broadcaster",
        "left_arm_controller",
        "right_arm_controller",
    ]:
        load_controllers += [
            ExecuteProcess(
                cmd=["ros2 run controller_manager spawner {}".format(controller)],
                shell=True,
                output="screen",
            )
        ]

    # 返回启动描述
    return LaunchDescription(
        [
            rviz_node,
            robot_state_publisher,
            move_group_node,
            ros2_control_node,
        ]
        + load_controllers
    )
相关推荐
谢家小布柔5 小时前
Git图形界面以及idea中集合Git使用
java·git
winner88816 小时前
git merge 冲突 解决 show case
java·git·git merge·git冲突
玩电脑的辣条哥10 小时前
怎么给git动图扣除背景?
git·抠图
谢家小布柔12 小时前
git中的多人协作
git
isolusion13 小时前
git分支管理及策略
git
isolusion13 小时前
git仓库的基本概念和流程以及一些基本命令
git
scoone14 小时前
VSCode 中 Git 功能比较:内置 Git、GitLens 与 Git History 插件
ide·git·vscode
赛博末影猫15 小时前
git全教程(长期更新)
git
Y编程小白16 小时前
Git版本控制工具--基础命令和分支管理
大数据·git·elasticsearch
Pafey19 小时前
git 删除鉴权缓存及账号信息
git·缓存