|
| 1 | +:github_url: https://github.com/UniversalRobots/Universal_Robots_ROS2_Tutorials/blob/main/my_dual_robot_cell/doc/start_ur_driver.rst |
| 2 | + |
| 3 | +========================= |
| 4 | +Start the ur_robot_driver |
| 5 | +========================= |
| 6 | + |
| 7 | +In the last chapter we created a custom scene description containing our two robots. In order to make |
| 8 | +that description usable to ``ros2_control`` and hence the ``ur_robot_driver``, we need to add |
| 9 | +control information. We will also add a custom launchfile to start up our demonstrator. |
| 10 | + |
| 11 | +We will generate a new package called `my_dual_robot_cell_control <https://github.com/UniversalRobots/Universal_Robots_ROS2_Tutorials/tree/main/my_dual_robot_cell/my_dual_robot_cell_control>`_ for that purpose. |
| 12 | + |
| 13 | +Create a description with ros2_control tag |
| 14 | +------------------------------------------ |
| 15 | + |
| 16 | +The first step is to create a description containing the control instructions: |
| 17 | + |
| 18 | +.. literalinclude:: ../my_dual_robot_cell_control/urdf/my_dual_robot_cell_controlled.urdf.xacro |
| 19 | + :language: xml |
| 20 | + :linenos: |
| 21 | + :caption: my_dual_robot_cell_control/urdf/my_dual_robot_cell_controlled.urdf.xacro |
| 22 | + |
| 23 | +This URDF is very similar to the one we have already assembled. We simply need to include the ros2_control macro, |
| 24 | + |
| 25 | +.. literalinclude:: ../my_dual_robot_cell_control/urdf/my_dual_robot_cell_controlled.urdf.xacro |
| 26 | + :language: xml |
| 27 | + :start-at: <xacro:include filename="$(find ur_robot_driver)/urdf/ur.ros2_control.xacro" /> |
| 28 | + :end-at: <xacro:include filename="$(find ur_robot_driver)/urdf/ur.ros2_control.xacro" /> |
| 29 | + :caption: my_dual_robot_cell_control/urdf/my_dual_robot_cell_controlled.urdf.xacro |
| 30 | + |
| 31 | +define the necessary arguments that need to be passed to the macro, |
| 32 | + |
| 33 | +.. literalinclude:: ../my_dual_robot_cell_control/urdf/my_dual_robot_cell_controlled.urdf.xacro |
| 34 | + :language: xml |
| 35 | + :start-at: <xacro:arg name="alice_use_mock_hardware" default="false" /> |
| 36 | + :end-at: <xacro:arg name="ur_input_recipe_filename" default="$(find ur_robot_driver)/resources/rtde_input_recipe.txt" /> |
| 37 | + :caption: my_dual_robot_cell_control/urdf/my_dual_robot_cell_controlled.urdf.xacro |
| 38 | + |
| 39 | +and then call the macro by providing all the specified arguments. |
| 40 | + |
| 41 | +.. literalinclude:: ../my_dual_robot_cell_control/urdf/my_dual_robot_cell_controlled.urdf.xacro |
| 42 | + :language: xml |
| 43 | + :start-at: <xacro:ur_ros2_control |
| 44 | + :end-before: </robot> |
| 45 | + :caption: my_robot_cell_control/urdf/my_robot_cell_controlled.urdf.xacro |
| 46 | + |
| 47 | +Extract the calibration |
| 48 | +----------------------- |
| 49 | + |
| 50 | +One very important step is to extract each robot's specific calibration and save it to our |
| 51 | +workcell's startup package. For details, please refer to `our documentation on extracting the calibration information <https://docs.ros.org/en/ros2_packages/rolling/api/ur_robot_driver/installation/robot_setup.html#extract-calibration-information>`_. |
| 52 | +For now, we just copy the default ones for the UR3e and UR5e. |
| 53 | + |
| 54 | +.. code-block:: |
| 55 | +
|
| 56 | + cp $(ros2 pkg prefix ur_description)/share/ur_description/config/ur3e/default_kinematics.yaml \ |
| 57 | + my_dual_robot_cell_control/config/alice_calibration.yaml |
| 58 | +
|
| 59 | + cp $(ros2 pkg prefix ur_description)/share/ur_description/config/ur5e/default_kinematics.yaml \ |
| 60 | + my_dual_robot_cell_control/config/bob_calibration.yaml |
| 61 | +
|
| 62 | +
|
| 63 | +Create robot_state_publisher launchfile |
| 64 | +--------------------------------------- |
| 65 | + |
| 66 | +To use the custom controlled description, we need to generate a launchfile loading that description |
| 67 | +(Since it contains less / potentially different) arguments than the "default" one. In that |
| 68 | +launchfile we need to start a ``robot_state_publisher`` (RSP) node that will get the description as a |
| 69 | +parameter and redistribute it via the ``robot_description`` topic: |
| 70 | + |
| 71 | +.. literalinclude:: ../my_dual_robot_cell_control/launch/rsp.launch.py |
| 72 | + :language: py |
| 73 | + :start-at: from launch import LaunchDescription |
| 74 | + :linenos: |
| 75 | + :caption: my_dual_robot_cell_control/launch/rsp.launch.py |
| 76 | + |
| 77 | +Before we can start our workcell we need to create a launchfile that will launch the two robot descriptions correctly. |
| 78 | + |
| 79 | +Create start_robot launchfile |
| 80 | +----------------------------- |
| 81 | + |
| 82 | +Here we create a launch file which will launch the driver with the correct description and robot state publisher, as well as start all of the controllers necessary to use the two robots. |
| 83 | + |
| 84 | +.. literalinclude:: ../my_dual_robot_cell_control/launch/start_robots.launch.py |
| 85 | + :language: py |
| 86 | + :linenos: |
| 87 | + :caption: my_dual_robot_cell_control/launch/start_robots.launch.py |
| 88 | + |
| 89 | +With that we can start the robot using |
| 90 | + |
| 91 | +.. code-block:: bash |
| 92 | +
|
| 93 | + ros2 launch my_dual_robot_cell_control start_robots.launch.py alice_use_mock_hardware:=true bob_use_mock_hardware:=true |
| 94 | +
|
| 95 | +Testing everything |
| 96 | +------------------ |
| 97 | + |
| 98 | +Before we can test our code, it's essential to build and source our Colcon workspace: |
| 99 | + |
| 100 | +.. code-block:: bash |
| 101 | +
|
| 102 | + #cd to your colcon workspace root, e.g. |
| 103 | + cd ~/colcon_ws |
| 104 | +
|
| 105 | + #source and build your workspace |
| 106 | + colcon build |
| 107 | + source install/setup.bash |
| 108 | +
|
| 109 | +We can start the system in a mocked simulation |
| 110 | + |
| 111 | +.. code-block:: bash |
| 112 | +
|
| 113 | + #start the driver with mocked hardware |
| 114 | + ros2 launch my_dual_robot_cell_control start_robots.launch.py alice_use_mock_hardware:=true bob_use_mock_hardware:=true |
| 115 | +
|
| 116 | +Or to use it with a real robot: |
| 117 | + |
| 118 | +.. code-block:: bash |
| 119 | +
|
| 120 | + #start the driver with real hardware (or the docker simulator included in this example) |
| 121 | + ros2 launch my_dual_robot_cell_control start_robots.launch.py |
| 122 | +
|
| 123 | +.. note:: |
| 124 | + We extracted the calibration information from the robot and saved it in the |
| 125 | + ``my_robot_cell_control`` package. If you have a different robot, you need to extract the |
| 126 | + calibration information from that, and pass that to the launch file. Changing the ``ur_type`` |
| 127 | + parameter only will lead to a wrong model, as it will still be using the example kinematics from |
| 128 | + a UR3e and UR5e. To use a UR10e and UR20, for example, you can do |
| 129 | + |
| 130 | + .. code-block:: bash |
| 131 | +
|
| 132 | + ros2 launch my_dual_robot_cell_control start_robots.launch.py bob_ur_type:=ur10e bob_use_mock_hardware:=true \ |
| 133 | + bob_kinematics_parameters_file:=$(ros2 pkg prefix ur_description)/share/ur_description/config/ur10e/default_kinematics.yaml \ |
| 134 | + alice_ur_type:=ur20 alice_use_mock_hardware:=true \ |
| 135 | + alice_kinematics_parameters_file:=$(ros2 pkg prefix ur_description)/share/ur_description/config/ur20/default_kinematics.yaml |
0 commit comments