在完成02-启程:webots和ros2笔记02-启程 - 古月居 (guyuehome.com)

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

简要分析一下:

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  


 ————————————————