webots和ros2笔记03-解析

该博客详细介绍了如何使用ROS2和Webots模拟环境控制两个机械臂(ABB IRB4600和UR5e)协同工作,拾取易拉罐。通过`armed_robots.launch.py`启动文件配置Webots世界及控制器,确保两者同步运动。每个机械臂的控制器节点发送关节轨迹目标,实现精确的抓取和释放动作。博客提供了具体的关节坐标和时间参数,展示了从初始位置到抓取再到释放易拉罐的完整轨迹。
摘要由CSDN通过智能技术生成

在完成02-启程:https://zhangrelay.blog.csdn.net/article/details/112675018

那么会思考两个机械臂拿起易拉罐的过程是如何实现了。

简要分析一下:

launch(armed_robots.launch.py):

import os
import launch
from ament_index_python.packages import get_package_share_directory
from webots_ros2_core.utils import ControllerLauncher
from webots_ros2_core.webots_launcher import WebotsLauncher


def generate_launch_description():
    # Webots
    webots = WebotsLauncher(world=os.path.join(get_package_share_directory('webots_ros2_demos'), 'worlds', 'armed_robots.wbt'))

    # Controller nodes
    synchronization = launch.substitutions.LaunchConfiguration('synchronization', default=False)
    abb_controller = ControllerLauncher(
        package='webots_ros2_core',
        executable='webots_robotic_arm_node',
        arguments=['--webots-robot-name=abbirb4600'],
        parameters=[{'synchronization': synchronization, 'controller_name': 'abb'}],
        output='screen'
    )
    ure5_controller = ControllerLauncher(
        package='webots_ros2_core',
        executable='webots_robotic_arm_node',
        arguments=['--webots-robot-name=UR5e'],
        parameters=[{'synchronization': synchronization, 'controller_name': 'ur'}],
        output='screen'
    )

    # Control nodes
    armed_robots_ur = ControllerLauncher(
        package='webots_ros2_demos',
        executable='armed_robots_ur',
        output='screen'
    )
    armed_robots_abb = ControllerLauncher(
        package='webots_ros2_demos',
        executable='armed_robots_abb',
        output='screen'
    )
    return launch.LaunchDescription([
        webots, abb_controller, ure5_controller, armed_robots_ur, armed_robots_abb,
        launch.actions.RegisterEventHandler(
            event_handler=launch.event_handlers.OnProcessExit(
                target_action=webots,
                on_exit=[launch.actions.EmitEvent(event=launch.events.Shutdown())],
            )
        ),
    ])

启动环境和机械臂:

成功

失败

使用world下armed_robots环境文件。

    # Webots
    webots = WebotsLauncher(world=os.path.join(get_package_share_directory('webots_ros2_demos'), 'worlds', 'armed_robots.wbt'))

控制器节点(两个机械臂分别为ur和abb):

ur:

    ure5_controller = ControllerLauncher(
        package='webots_ros2_core',
        executable='webots_robotic_arm_node',
        arguments=['--webots-robot-name=UR5e'],
        parameters=[{'synchronization': synchronization, 'controller_name': 'ur'}],
        output='screen'
    )

abb:

    abb_controller = ControllerLauncher(
        package='webots_ros2_core',
        executable='webots_robotic_arm_node',
        arguments=['--webots-robot-name=abbirb4600'],
        parameters=[{'synchronization': synchronization, 'controller_name': 'abb'}],
        output='screen'
    )

这里需要注意(synchronization同步)两个机械臂要同步运动否则无法协调完成任务。

控制器不同于控制,对于两个机械臂有具体的控制节点完成对应的控制指令,如下:

ur:

    armed_robots_ur = ControllerLauncher(
        package='webots_ros2_demos',
        executable='armed_robots_ur',
        output='screen'
    )

具体指令为一系列轨迹和抓取动作坐标。

import rclpy
from webots_ros2_demos.follow_joint_trajectory_client import FollowJointTrajectoryClient


def main(args=None):
    rclpy.init(args=args)
    armed_robot_ur = FollowJointTrajectoryClient('armed_robots_ur', '/ur/follow_joint_trajectory')
    armed_robot_ur.send_goal({
        'joint_names': [
            'shoulder_pan_joint',
            'shoulder_lift_joint',
            'elbow_joint',
            'wrist_1_joint',
            'finger_1_joint_1',
            'finger_2_joint_1',
            'finger_middle_joint_1'
        ],
        'points': [
            {
                'positions': [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0],
                'velocities': [5] * 7,
                'accelerations': [5] * 7,
                'time_from_start': {'sec': 3, 'nanosec': 0}
            },
            {
                'positions': [0.0, 0.0, 0.0, 0.0, 0.85, 0.85, 0.6],
                'velocities': [5] * 7,
                'accelerations': [5] * 7,
                'time_from_start': {'sec': 4, 'nanosec': 0}
            },
            {
                'positions': [0.63, -2.26, -1.88, -2.14, 0.85, 0.85, 0.6],
                'velocities': [5] * 7,
                'accelerations': [5] * 7,
                'time_from_start': {'sec': 5, 'nanosec': 0}
            },
            {
                'positions': [0.63, -2.26, -1.88, -2.14, 0.0, 0.0, 0.0],
                'velocities': [5] * 7,
                'accelerations': [5] * 7,
                'time_from_start': {'sec': 6, 'nanosec': 0}
            },
            {
                'positions': [0.63, -2.0, -1.88, -2.14, 0.0, 0.0, 0.0],
                'velocities': [5] * 7,
                'accelerations': [5] * 7,
                'time_from_start': {'sec': 7, 'nanosec': 0}
            },
            {
                'positions': [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0],
                'velocities': [5] * 7,
                'accelerations': [5] * 7,
                'time_from_start': {'sec': 8, 'nanosec': 0}
            },
            {
                'positions': [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0],
                'velocities': [5] * 7,
                'accelerations': [5] * 7,
                'time_from_start': {'sec': 9, 'nanosec': 0}
            }
        ]
    }, 10)
    rclpy.spin(armed_robot_ur)


if __name__ == '__main__':
    main()

要能够知道位置指令中抓取部分:

            {
                'positions': [0.0, 0.0, 0.0, 0.0, 0.85, 0.85, 0.6],
                'velocities': [5] * 7,
                'accelerations': [5] * 7,
                'time_from_start': {'sec': 4, 'nanosec': 0}
            },
            {
                'positions': [0.63, -2.26, -1.88, -2.14, 0.85, 0.85, 0.6],
                'velocities': [5] * 7,
                'accelerations': [5] * 7,
                'time_from_start': {'sec': 5, 'nanosec': 0}
            },

abb:

    armed_robots_abb = ControllerLauncher(
        package='webots_ros2_demos',
        executable='armed_robots_abb',
        output='screen'
    )

具体指令为一系列轨迹和抓取动作坐标。

import rclpy
from webots_ros2_demos.follow_joint_trajectory_client import FollowJointTrajectoryClient


def main(args=None):
    rclpy.init(args=args)
    armed_robot_abb = FollowJointTrajectoryClient('armed_robots_abb', '/abb/follow_joint_trajectory')
    armed_robot_abb.send_goal({
        'joint_names': [
            'A motor',
            'B motor',
            'C motor',
            'E motor',
            'finger_1_joint_1',
            'finger_2_joint_1',
            'finger_middle_joint_1'
        ],
        'points': [
            {
                'positions': [0.0, 0.0, 0.0, 0., 0.0, 0.0, 0.0],
                'velocities': [5] * 7,
                'accelerations': [5] * 7,
                'time_from_start': {'sec': 0, 'nanosec': 0}
            },
            {
                'positions': [-0.025, 0.0, 0.82, -0.86, 0.0, 0.0, 0.0],
                'velocities': [5] * 7,
                'accelerations': [5] * 7,
                'time_from_start': {'sec': 1, 'nanosec': 0}
            },
            {
                'positions': [-0.025, 0.1, 0.82, -0.86, 0.0, 0.0, 0.0],
                'velocities': [5] * 7,
                'accelerations': [5] * 7,
                'time_from_start': {'sec': 2, 'nanosec': 0}
            },
            {
                'positions': [-0.025, 0.1, 0.82, -0.86, 0.85, 0.85, 0.6],
                'velocities': [5] * 7,
                'accelerations': [5] * 7,
                'time_from_start': {'sec': 3, 'nanosec': 0}
            },
            {
                'positions': [-0.025, -0.44, 0.82, -0.86, 0.85, 0.85, 0.6],
                'velocities': [5] * 7,
                'accelerations': [5] * 7,
                'time_from_start': {'sec': 4, 'nanosec': 0}
            },
            {
                'positions': [1.57, -0.1, 0.95, -0.71, 0.85, 0.85, 0.6],
                'velocities': [5] * 7,
                'accelerations': [5] * 7,
                'time_from_start': {'sec': 5, 'nanosec': 0}
            },
            {
                'positions': [1.57, -0.1, 0.8, -0.81, 0.0, 0.0, 0.0],
                'velocities': [5] * 7,
                'accelerations': [5] * 7,
                'time_from_start': {'sec': 6, 'nanosec': 0}
            },
            {
                'positions': [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0],
                'velocities': [5] * 7,
                'accelerations': [5] * 7,
                'time_from_start': {'sec': 7, 'nanosec': 0}
            },
            {
                'positions': [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0],
                'velocities': [5] * 7,
                'accelerations': [5] * 7,
                'time_from_start': {'sec': 9, 'nanosec': 0}
            }
        ]
    }, 10)
    rclpy.spin(armed_robot_abb)


if __name__ == '__main__':
    main()

更多内容和教程,稍后补充。

  • C:\ros_ws\webots2>ros2 launch webots_ros2_tutorials line_following_launch.py  


 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

zhangrelay

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值