This repository provides a simple and easy-to-use guide and a ROS2 package to control the Universal Robot robots using the Universal Robot ROS2 driver.
Note: currenly this repo only support ROS2 humble since official driver files are a bit different in jazzy
- Install ROS2 dependencies:
sudo apt install ros-humble-ur-* ros-humble-ros2-control ros-humble-ros2-controllers - Define your workspace location and create ros2 workspace:
export ROS2_WS=~/ros2_ws # or any other location you prefer mkdir -p ${ROS2_WS}/src cd ${ROS2_WS}/src
- Clone the repository:
git clone https://github.com/idra-lab/easy_ur_control.git
- Connect to the robot via ethernet, make sure the robot is powered on and connected to the same network as your computer. You can check the robot's IP address on the teach pendant (tablet) pressing
Top left options button->Settings->System->Networkand readIP Addressand then usually just set yours as the same +1 in the last digit. Also annoate the robot ip address, you will need it later. For example, if the robot's IP is192.168.1.100, you can set your computer's IP to192.168.1.101with the same subnet mask255.255.255.0 - Calibrate the robot and save the calibration data in the config folder of this package, set the robot IP address you noted before:
ros2 launch ur_calibration calibration_correction.launch.py robot_ip:=<robot_ip> target_filename:="${ROS2_WS}/src/easy_ur_control/config/calibration.yaml"
- Build the workspace:
cd ${ROS2_WS} colcon build --symlink-install
- Remember to source the workspace after building:
source ${ROS2_WS}/install/setup.bash
If you want to control the robot end effector in Cartesian space, you need to perform inverse kinematics to compute the joint angles from the desired end effector pose.
I suggest you to use the Cartesian Controllers repository for this purpose.
You can install the controllers with:
mkdir -p ~/controller_ws/src
cd ~/controller_ws/src
git clone -b ros2 https://github.com/fzi-forschungszentrum-informatik/cartesian_controllers.git
rosdep install --from-paths ./ --ignore-src -y
cd ..
colcon build --packages-skip cartesian_controller_simulation cartesian_controller_tests --cmake-args -DCMAKE_BUILD_TYPE=Release
Remember to source the workspace after building:
source ~/controller_ws/install/setup.bash- Put the robot in
Remote Controlmode from the teach pendant (tablet) pressingTop left options button->Local->Remote Control - Run the prepared launch file:
Different control techniques are supported:
- Cartesian control:
ctrl:=cartesian_motion_controller - Simulated cartesian impedance control:
ctrl:=cartesian_compliance_controller - Joint trajectory control:
ctrl:=scaled_joint_trajectory_controller
- Cartesian control:
ros2 launch easy_ur_control easy_ur_launcher.launch.py robot_ip:=<robot_ip> ur_type:=<ur_type> ctrl:=<control-method> # ur3e, ur5e, ur10e, ur16e
- Publish your command on topic:
- Cartesian control receives commands on
/cartesian_motion_controller/target_frame - Simulated cartesian impedance control receives commands on
/cartesian_compliance_controller/target_frame - Joint position control receives commands on
/scaled_joint_trajectory_controller/joint_trajectory
- Cartesian control receives commands on
For a simple simulation of your executable, you can easily use a fake hardware configuration which doesn't connect to the robot. Simply call
ros2 launch easy_ur_control easy_ur_launcher.launch.py use_fake_hardware:=true ur_type:=<ur_type> # and additional arguments
To simplify the launch of the UR robots with the recommended cartesian controllers, when connected with the real robot and using the fake hardware, some topic remappings have been put in place.
This requires the modification of the file /opt/ros/humble/share/ur_robot_driver/launch/ur_control.launch.py shipped by the ur_robot_driver package; to avoid end user to modify (using sudo 😅) the file on their machine, a local copy of ur_control.launch.py is present in this repository and is loaded by default in the easy_ur_launcher.launch.py file.
The required mappings are
...
control_node = Node(
package="controller_manager",
executable="ros2_control_node",
parameters=[
robot_description,
update_rate_config_file,
ParameterFile(initial_joint_controllers, allow_substs=True),
],
remappings=[
("/cartesian_motion_controller/target_frame", "/target_frame"),
("/cartesian_compliance_controller/target_frame", "/target_frame"),
("/cartesian_compliance_controller/ft_sensor_wrench","/force_torque_sensor_broadcaster/wrench"),
("/cartesian_compliance_controller/target_wrench", "/target_wrench"),
("/cartesian_compliance_controller/target_wrench", "/target_wrench"),
("/cartesian_force_controller/target_frame", "/target_frame"),
("/motion_control_handle/target_frame", "/target_frame"),
],
output="screen",
condition=IfCondition(use_fake_hardware),
)
...
ur_control_node = Node(
package="ur_robot_driver",
executable="ur_ros2_control_node",
parameters=[
robot_description,
update_rate_config_file,
ParameterFile(initial_joint_controllers, allow_substs=True),
],
remappings=[
("/cartesian_motion_controller/target_frame", "/target_frame"),
("/cartesian_compliance_controller/target_frame", "/target_frame"),
("/cartesian_compliance_controller/ft_sensor_wrench","/force_torque_sensor_broadcaster/wrench"),
("/cartesian_compliance_controller/target_wrench", "/target_wrench"),
("/cartesian_compliance_controller/target_wrench", "/target_wrench"),
("/cartesian_force_controller/target_frame", "/target_frame"),
("/motion_control_handle/target_frame", "/target_frame"),
],
output="screen",
condition=UnlessCondition(use_fake_hardware),
)
...