|
| 1 | +# Universal Robots UR5 |
| 2 | + |
| 3 | +[](https://github.com/j3soon/ros2-essentials/tree/main/ur5_ws) |
| 4 | +[](https://github.com/j3soon/ros2-essentials/commits/main/ur5_ws) |
| 5 | + |
| 6 | +[](https://hub.docker.com/r/j3soon/ros2-ur5-ws/tags) |
| 7 | + |
| 8 | + |
| 9 | + |
| 10 | + |
| 11 | +This workspace provides a ROS 2 Humble environment for controlling **Universal Robots UR5** manipulators. It includes the official [Universal_Robots_ROS2_Driver](https://github.com/UniversalRobots/Universal_Robots_ROS2_Driver), description packages, **OnRobot RG2** gripper support, **servo control**, and **pose tracking**. |
| 12 | + |
| 13 | +> Please note that this workspace has only been tested on the UR5 (CB3 version). In theory, it can support other models with minor configuration adjustments; please feel free to modify the settings as needed for your specific use case. |
| 14 | +
|
| 15 | +## Start Container |
| 16 | + |
| 17 | +> Make sure your system meets the [system requirements](https://j3soon.github.io/ros2-essentials/#system-requirements) and have followed the [setup instructions](https://j3soon.github.io/ros2-essentials/#setup) before using this workspace. |
| 18 | +
|
| 19 | +Run the following commands in a Ubuntu desktop environment. If you are using a remote server, make sure you're using a terminal within a remote desktop session (e.g., VNC) instead of SSH (i.e., don't use `ssh -X` or `ssh -Y`). |
| 20 | + |
| 21 | +```sh |
| 22 | +cd ~/ros2-essentials/ur5_ws/docker |
| 23 | +docker compose build |
| 24 | +xhost +local:docker |
| 25 | +docker compose up -d |
| 26 | +# The initial build will take a while, please wait patiently. |
| 27 | +``` |
| 28 | + |
| 29 | +> If your user's UID is `1000`, you may use `docker compose pull` instead of `docker compose build`. |
| 30 | +
|
| 31 | +The commands in the following sections assume that you are inside the Docker container: |
| 32 | + |
| 33 | +```sh |
| 34 | +# in a new terminal |
| 35 | +docker exec -it ros2-ur5-ws bash |
| 36 | +``` |
| 37 | + |
| 38 | +If the initial build failed, rebuild the workspace inside the container: |
| 39 | + |
| 40 | +```sh |
| 41 | +cd /home/ros2-essentials/ur5_ws |
| 42 | +rm -rf build install |
| 43 | +colcon build --symlink-install |
| 44 | +``` |
| 45 | + |
| 46 | +To stop and remove the container: |
| 47 | + |
| 48 | +```sh |
| 49 | +docker compose down |
| 50 | +``` |
| 51 | + |
| 52 | + |
| 53 | +## Simulation with URSim (CB3) |
| 54 | + |
| 55 | +To test without hardware, run **URSim CB3** with the External Control URCap in Docker: |
| 56 | + |
| 57 | +```sh |
| 58 | +cd ~/ros2-essentials/ur5_ws/docker/ursim |
| 59 | +docker compose up |
| 60 | +``` |
| 61 | + |
| 62 | +This starts a UR5 simulator at `192.168.56.101` (VNC on port 5900, Web on 6080). The ports 5900 and 6080 are forwarded to localhost, please change them in `docker/ursim/compose.yaml` if those ports conflict with existing services. Open <http://localhost:6080/vnc.html?host=localhost&port=6080> in your browser to access the URSim interface. |
| 63 | + |
| 64 | +> ⚠️ Important: If you plan to switch to the physical robot, you must run `docker compose down` to remove the virtual network first. Failing to do so will cause IP address conflicts. |
| 65 | +
|
| 66 | +URSim provides an interface identical to the physical robot, making it ideal for rapid testing. However, please note that unlike `Gazebo` or `IsaacSim`, URSim does not possess a realistic physics engine. Therefore, it is not suitable for simulations requiring high physical fidelity. |
| 67 | + |
| 68 | +Regarding the RG2 gripper: although it is not explicitly modeled in URSim, our control script operates via Digital I/O. Consequently, there is no need to disable the gripper configuration when running URSim; the code will execute without errors. |
| 69 | + |
| 70 | +Since URSim aims to faithfully replicate the real robot's behavior, you should follow all the steps outlined in the subsequent sections, including calibration and bring-up. |
| 71 | + |
| 72 | +## Setup Robot |
| 73 | + |
| 74 | +> For URSim users, the settings are already pre-configured in the docker compose file, so you can skip this step. |
| 75 | +
|
| 76 | +Please refer to the [official installation](https://docs.universal-robots.com/Universal_Robots_ROS2_Documentation/doc/ur_client_library/doc/setup/robot_setup.html) guide. If the robot has been configured previously, you can typically skip this step. |
| 77 | + |
| 78 | +For network setup, please refer to [this section](https://docs.universal-robots.com/Universal_Robots_ROS2_Documentation/doc/ur_client_library/doc/setup/network_setup.html) for network configuration. |
| 79 | + |
| 80 | +## Robot Calibration |
| 81 | + |
| 82 | +To improve accuracy, run the calibration correction and save the result to the workspace description config: |
| 83 | + |
| 84 | +```sh |
| 85 | +cd /home/ros2-essentials/ur5_ws |
| 86 | +./scripts/ur5_calibration.sh |
| 87 | +``` |
| 88 | + |
| 89 | +You only need to run this once for each robot. This creates `default_kinematics.yaml` which is required for the subsequent steps. |
| 90 | + |
| 91 | +## Bring Up Robot |
| 92 | + |
| 93 | +Use the script: |
| 94 | + |
| 95 | +```sh |
| 96 | +cd /home/ros2-essentials/ur5_ws |
| 97 | +./scripts/ur5_bringup.sh |
| 98 | +``` |
| 99 | + |
| 100 | +Or run the launch file directly: |
| 101 | + |
| 102 | +```sh |
| 103 | +ros2 launch ur_robot_driver ur_control.launch.py \ |
| 104 | + ur_type:=ur5 \ |
| 105 | + use_rg2_gripper:=true \ |
| 106 | + robot_ip:=192.168.56.101 \ |
| 107 | + launch_rviz:=true |
| 108 | +``` |
| 109 | + |
| 110 | +> Set `use_rg2_gripper` parameter to **false** to disable the RG2 gripper. |
| 111 | +
|
| 112 | +Quick test for gripper actuation: |
| 113 | + |
| 114 | +```sh |
| 115 | +# true = open, false = close |
| 116 | +ros2 topic pub --once /rg2/command std_msgs/msg/Bool "{data: true}" |
| 117 | +``` |
| 118 | + |
| 119 | +After bringing up the robot, make sure to click `Play` in the UR interface to start the control loop. |
| 120 | + |
| 121 | +In the UR interface, go to `Home > Program Robot > Empty Program > Program > Structure > URCaps > External Control` and then click the Play button. |
| 122 | + |
| 123 | + |
| 124 | + |
| 125 | +The UR interface control program will automatically stop if the ROS2 bring up node is stopped or crashes for safety reasons. If that happens, simply restart the bring up node and click `Play` again. |
| 126 | + |
| 127 | +## Launch MoveIt 2 |
| 128 | + |
| 129 | +Launch MoveIt 2 for a quick test. You can move the arm by dragging the end-effector (EE) to a target position in RViz2, then clicking `Plan & Execute`. |
| 130 | + |
| 131 | +```sh |
| 132 | +ros2 launch ur_moveit_config ur_moveit.launch.py \ |
| 133 | + launch_rviz:=true \ |
| 134 | + use_rg2_gripper:=true |
| 135 | +``` |
| 136 | + |
| 137 | +> Ensure the robot driver is already running before testing. |
| 138 | +
|
| 139 | +## Servo Control |
| 140 | + |
| 141 | +The **ur_servo_control** package provides a simple example for controlling end-effector (EE) velocity. Please ensure the robot driver is launched before testing. |
| 142 | + |
| 143 | +```sh |
| 144 | +ros2 launch ur_servo_control ur_servo.launch.py |
| 145 | +``` |
| 146 | + |
| 147 | +You can control the robot arm by publishing target velocities to the `/servo_node/delta_twist_cmds` topic. |
| 148 | + |
| 149 | +For an implementation example within a ros node, refer to `ur5_ws/src/ur_servo_control/ur_servo_control/ur_servo_control.py`. Please be careful when selecting the reference frame. Use the following command to launch it: |
| 150 | + |
| 151 | +```sh |
| 152 | +ros2 launch ur_servo_control ur_servo_control.launch.py |
| 153 | +``` |
| 154 | + |
| 155 | +The default velocities above are set to 0, you can modify the linear/angular velocities (`twist_msg.twist.{linear|angular}.{x|y|z}`) in `publish_servo_command_callback` in `ur5_ws/src/ur_servo_control/ur_servo_control/ur_servo_control.py`. But note that a constant velocity command will cause the robot to keep moving, which may be dangerous for real robot control (but fine for URSim testing). |
| 156 | + |
| 157 | +## Pose Tracking |
| 158 | + |
| 159 | +The **ur_pose_tracking** package provides an interface for controlling the end-effector (EE) position. |
| 160 | + |
| 161 | +```sh |
| 162 | +# In terminal 1 (Launch the servo node): |
| 163 | +ros2 launch ur_servo_control ur_servo.launch.py |
| 164 | +# In terminal 2: |
| 165 | +ros2 launch ur_pose_tracking ur_pose_tracking.launch.py |
| 166 | +``` |
| 167 | + |
| 168 | +You can control the robot arm by publishing target pose to the `/target_pose` topic. |
| 169 | + |
| 170 | +For application integration, it is recommended to refer to the **servo control implementation within the ros node**. To perform a quick test, please use the following command: |
| 171 | + |
| 172 | +```sh |
| 173 | +ros2 topic pub --once /target_pose geometry_msgs/msg/PoseStamped "{header: {frame_id: 'world', stamp: {sec: 0, nanosec: 0}}, pose: {position: {x: -0.3, y: 0.0, z: 0.5}, orientation: {x: -0.35, y: 0.01, z: 0.93, w: -0.05}}}" |
| 174 | +``` |
| 175 | + |
| 176 | +> Note: This implementation does not account for singularities or collision avoidance and only supports linear paths between points. Consequently, it is ideal for high-density trajectory points. If your input points are sparse or require complex path planning and obstacle avoidance, please use the MoveIt planner instead. |
| 177 | +
|
| 178 | +## Troubleshooting |
| 179 | + |
| 180 | +If you encounter issues on reproducing the examples above, consider remove all containers (`docker compose down` for URSim and workspace) and try again. |
| 181 | + |
| 182 | +## References |
| 183 | + |
| 184 | +- [Universal Robots ROS 2 Documentation](https://docs.universal-robots.com/Universal_Robots_ROS2_Documentation/) |
| 185 | + - [Robot Setup](https://docs.universal-robots.com/Universal_Robots_ROS2_Documentation/doc/ur_client_library/doc/setup/robot_setup.html) |
| 186 | + - [Setup URSim with Docker](https://docs.universal-robots.com/Universal_Robots_ROS2_Documentation/doc/ur_client_library/doc/setup/ursim_docker.html) |
| 187 | +- [Universal_Robots_ROS2_Driver](https://github.com/UniversalRobots/Universal_Robots_ROS2_Driver) |
0 commit comments