This repository serves as the foundation for all tutorial and demonstration code for Duke's UR3e robot platform. This guide will walk you through setting up a UR3e robotic arm with ROS2 on an Ubuntu system. By the end, you will be able to control and simulate the UR3e arm using ROS2.
- A computer running Ubuntu 22.04. If you're on Windows, install a Linux subsystem by opening a terminal and typing
wsl --install. After installation, you can open Ubuntu terminals by searching "Ubuntu" in the Windows search bar. - Basic command line operation knowledge.
- Internet connection for downloading packages.
-
Install software-properties-common
sudo apt install software-properties-common
For general first time setup. This package provides an abstraction of the used apt repositories. It allows you to easily manage your distribution and independent software vendor software sources.
-
Add the universe repository
sudo add-apt-repository universe
For general first time setup. The universe repository contains open-source software maintained by the community, which is necessary for many ROS2 packages.
-
Update package list and install curl
sudo apt update && sudo apt install curl -yFor general first time setup.
curlis a command-line tool for transferring data with URLs, which is needed for downloading external packages.
-
Add ROS2 GPG key
sudo curl -sSL https://raw.githubusercontent.com/ros/rosdistro/master/ros.key -o /usr/share/keyrings/ros-archive-keyring.gpg
This GPG key makes sure the ROS packages you download are authenticated and have not been tampered with.
-
Add ROS2 repository to your sources list
echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/ros-archive-keyring.gpg] http://packages.ros.org/ros2/ubuntu $(. /etc/os-release && echo $UBUNTU_CODENAME) main" | sudo tee /etc/apt/sources.list.d/ros2.list > /dev/null
This command adds the ROS2 repository to your system, so you can install ROS2 packages via apt.
-
Update package list and install ROS development tools
sudo apt update && sudo apt install ros-dev-toolsROS development tools include utilities for building and managing ROS2 packages.
-
Update package list and upgrade existing packages
sudo apt update && sudo apt upgrade -y -
Install ROS2 desktop
sudo apt install ros-iron-desktop
This installs the full ROS2 desktop environment, including all necessary tools and libraries for development.
-
Install Visual Studio Code (VScode)
wget -q https://packages.microsoft.com/keys/microsoft.asc -O- | sudo apt-key add - sudo add-apt-repository "deb [arch=amd64] https://packages.microsoft.com/repos/vscode stable main" sudo apt update sudo apt install code
Visual Studio Code makes navigating and editing files in linux much easier.
-
Install UR Robot Driver
sudo apt-get install ros-iron-ur
This package contains the necessary drivers to interface with UR robots within ROS2.
-
Install necessary packages for Docker
sudo apt install apt-transport-https ca-certificates curl software-properties-common
These packages are required for downloading and installing Docker.
-
Add Docker's official GPG key and repository
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add - sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu focal stable"
Adding Docker’s GPG key and repository to get the official Docker packages.
-
Install Docker CE
sudo apt update && sudo apt install docker-ceDocker CE allows you to run URSIM
-
Add your user to the Docker group
sudo usermod -aG docker $USER exec su -l $USER
Adding your user to the Docker group allows you to run Docker commands without needing
sudo.
-
Create a ROS2 workspace and source directory
mkdir -p ~/ros2_iron_ws/src cd ~/ros2_iron_ws/src source /opt/ros/iron/setup.bash
Creating a workspace and sourcing the directory for the ROS2 project.
-
Clone the URSim, PyMoveit2, and ur3e codebase GitHub repositories
git clone https://github.com/will-d-chen/Universal_Robots_ROS2_Gazebo_Simulation.git git clone https://github.com/will-d-chen/pymoveit2.git git clone https://github.com/will-d-chen/ur3e-codebase.git
These repositories contain packages necessary to simulate and control the UR3e robot.
-
Install necessary dependencies
rosdep init rosdep update && rosdep install --ignore-src --from-paths . -y
rosdepinstalls system dependencies required by your ROS2 packages. -
Build and activate ROS2 packages
colcon build source install/setup.bashcolconis the command-line tool used to build ROS2 packages, and sourcing the setup script activates the environment.
-
Download MATLAB (if needed)
https://www.mathworks.com/downloads/
Download MATLAB from the official website.
-
Follow the Installation Instructions (if needed)
https://www.mathworks.com/help/install/ug/install-products-with-internet-connection.html
Follow the instructions to install MATLAB and required toolboxes: the Robotics System Toolbox and the ROS Toolbox.
-
Open the Wrapper Script for Executing ROS2 commands in MATLAB
cd ~/ros2_iron_ws/src/ur3e-codebase nano run_ros2_command.sh
This script makes it possible to execute ROS2 commands within MATLAB.
-
Edit the Wrapper Script Change USERNAME in line 4 to yours, then hit
Ctrl + SandCtrl + Xto save and close the file. -
Make the wrapper script executable In the terminal, run:
chmod +x run_ros2_command.sh
-
Open a new terminal and source the ROS2 setup script
source /opt/ros/iron/setup.bash -
Start the URSim simulator
ros2 run ur_client_library start_ursim.sh -m ur3e
-
Open the Polyscope interface
- If you are on WSL, open a separate terminal and type
firefox, install it if you haven't yet
http://192.168.56.101:6080/vnc.html
- If you are on WSL, open a separate terminal and type
-
Setup the robot for external control
- Inside Polyscope:
- Click "Program the Robot", then click the red button on the bottom left; if this is your first time starting, click "confirm configuration" on the pop-up.
- Click "On".
- Click "Start" when it becomes available.
- Click "Exit".
- Navigate to "Program" -> Urcaps.
- Click on "External Control" once.
- Inside Polyscope:
-
Launch the UR3e driver and RViz
source /opt/ros/iron/setup.bash ros2 launch ur_robot_driver ur_control.launch.py ur_type:=ur3e robot_ip:=192.168.56.101 launch_rviz:=true -
Setup the robot for external control
- Go back inside Polyscope:
- Click on the start/pause button on the bottom right of the screen, on the left of "Simulation".
- Click on "Play from selection #: Control by .....".
- Go back inside Polyscope:
-
Ensure your workspace is built and activated
cd ~/ros2_iron_ws source install/setup.bash
-
Launch Gazebo and Moveit
ros2 launch ur_simulation_gazebo ur_sim_moveit.launch.py
Note: The launch defaults to a ur5e, make sure to go into the launch files and edit them to default to ur3e.
-
Setup the robot for external control
- On the robot tablet:
- Press the red button (power off) on the bottom left; if this is your first time starting, click "confirm configuration" on the pop-up.
- Press "On".
- Press "Start" when it becomes available.
- Press "Exit".
- Navigate to "Program" -> Urcaps.
- Press on "External Control" once.
- On the robot tablet:
-
Launch the UR3e driver and RViz
source /opt/ros/iron/setup.bash ros2 launch ur_robot_driver ur_control.launch.py ur_type:=ur3e robot_ip:=192.168.56.101 launch_rviz:=true -
Setup the robot for external control
- Go back to the tablet:
- Press on the start/pause button on the bottom right of the screen, on the left of "Simulation".
- Press on "Play from selection #: Control by Desktop".
- Go back to the tablet:
-
AFTER you finish with the robot
- Go back to the tablet:
- Press the green button on the bottom left (normal)
- Press on the red "Off" button
- Press the metal on/off button on the tablet to shut down, click "do not save" if prompted
- Go back to the tablet:
- In a new terminal
source /opt/ros/iron/setup.bash colcon build source install/setup.bash
-
If using URSIM or the real robot
- Complete the corresponding steps from Option 1 or Option 3.
ros2 launch ur_moveit_config ur_moveit.launch.py ur_type:=ur3e launch_rviz:=true
-
If using Gazebo
- If you completed the corresponding steps from Option 2, it should already be running, if not.
ros2 launch ur_simulation_gazebo ur_sim_moveit.launch.py
- In a new terminal, repeat step 1, then finally, run your package
ros2 run ur3e_control_package initials_demo
- Launch MATLAB
- Launch MATLAB through the UI or by typing the command
matlabin the terminal. If you need to install the toolboxes, usesudo matlabto start MATLAB initially. - Navigate to /home/user/ros2_iron_ws/src/ur3e-codebase within MATLAB.
- Open
run_ros2.m - Run the script, running section by section is recommended
- Launch MATLAB through the UI or by typing the command
This tutorial will guide you through using the custom 'move_command' code to control the UR3e robot. We'll cover the basics of ROS 2 (Robot Operating System 2) and how this code interacts with a robotic system.
- Basic understanding of Python programming
- Everything in part 1 installed on your system
ROS 2 is a framework for writing robot software. It consists of:
- Nodes: Processes that perform computation
- Topics: Buses over which nodes exchange messages
- Messages: ROS data type used when subscribing or publishing to a topic
- Parameters: Configuration values for nodes
After you launch the necessary launch files, you can open a new terminal, source ROS2, and use this command to see all the broadcasting topics
ros2 topic list
If you want to access one of the topics, you can use this command to have ROS2 return the currently broadcasting values, joint states for example:
ros2 topic echo /joint_states
All the topics can be accessed within python scripts as well. For example, in the move_command file, the joint states are automatically being accessed and saved in a csv file, in the directory that you are executing the code from.
The DynamicTrajectoryExecutor is a custom ROS 2 node inside 'move_command' that:
- Plans and executes trajectories for a UR3e robot
- Logs joint states and force/torque data
- Handles collision objects in the robot's environment
The code can be run using the ros2 run command with various parameters. Here are some example commands:
- Move to initial position in joint space (Recommended):
ros2 run ur3e_control_package move_command --ros-args -p initial_move:=True -p initial_joint_pos:="[-1.9991989999999866, -1.835606000000002, -2.0968710000000046, -2.349238999999997, -0.4251269999999927, -0.0012429999999703512]" -p velocity:=0.02 -p dt:=0.2 - Execute a trajectory in world frame in task space:
ros2 run ur3e_control_package move_command --ros-args -p initial_move:=False -p waypoints:="'[[[0.30, 0.14, 0.25], [0.5, 0.5, 0.5, 0.5]]]'" -p velocity:=0.02 -p dt:=0.2 - Execute a trajectory in end-effector frame in task space:
ros2 run ur3e_control_package move_command --ros-args -p initial_move:=False -p waypoints:="'[[[0.0,0.1,0.0], [0.0,0.0,0.0,1.0]]]'" -p frame:="ef" -p velocity:=0.02 -p dt:=0.2
If you decide to not run from the command line, you can also go into the script to directly edit it to run your movement sequence.
initial_move: Boolean to decide if the robot will move to an initial position using joint space control, this makes it safer as you will know exactly where the first joint pose of the robot will be, since task space control will yield different joint configurations, making them less predictable.initial_joint_pos: Initial joint positions ifinitial_moveis Truewaypoints: List of positions and orientations for the robot to move throughframe: Coordinate frame for the waypoints (default is "world", declare "ef" for end-effector)velocity: Velocity in m/s that the robot will move it's end effector atreal_robot: Boolean to determine whether to run it on the real system or in simulationdt: Float to set the bandwidth
The __init__ method sets up the node, declares parameters, and initializes the MoveIt2 interface for robot control.
The declare_and_get_parameters method declares all the parameters the node can accept and retrieves their values.
The setup_moveit2 method initializes the MoveIt2 interface, which is used for motion planning and execution.
The setup_data_logging method sets up CSV logging for joint states and force/torque data.
The setup_collision_objects method adds collision objects (currently includes a floor and a pen) to the planning scene.
The compute_and_execute_trajectory method computes a trajectory through the given waypoints and executes it.
-Will Chen: will.chen@duke.edu