Download as pdf or txt
Download as pdf or txt
You are on page 1of 4

Controlling industrial robots with Simulink

1st Bucur Cosmin 2nd Andrei Alexandru 3st Tasu Sorin


Faculty of Engineering Faculty of Industrial Engineering and Faculty of Engineering
Ovidius University of Constanta Robotics Ovidius University of Constanta
Constanta, Romania Bucuresti, Romania Constanta, Romania
bcmircea@univ-ovidius.ro aandrei2405@stud.fiir.upb.ro sorin.tasu@365.univ-ovidius.ro

Abstract—Implementing machine learning algorithms like [6]. In this field some manufacturers are providing ROS2
reinforcement learning in robotics is a continuously changing drivers, for example Universal Robots and ABB.
topic due to continuous tool changes and updates to keep track MATLAB is a very powerful tool in the field of machine
of new algorithms and tools. This paper presents a new toolchain learning but has limited abilities to interconnect with other
to implement such algorithms with open-source packages like
open-source tools used in Reinforcement Learning, like
ROS2 for industrial robots. We developed new tools and
procedures to enable the implementation of reinforcement pytorch. It has very limited support for importing any trained
learning algorithms through simulation or controlling real models (like ONNX models) or exporting the models to be
robots with Matlab. used in a different environment. MATLAB through the
robotics system toolbox has support for both ROS1 and
Keywords—Industrial robots, ROS2, Matlab/Simulink, ROS2.
Reinforcement learning For robotics purposes, MATLAB has a robotics toolkit
that has many functions related to robotics simulation and
I. INTRODUCTION
control. This toolkit also enables ROS connectivity on both
Implementing machine learning algorithms like versions. With this toolkit, a new robotic arm can be defined
reinforcement learning in the field of robotics is a very known with Simulink block, or an existing one can be imported with
topic of research. Most of the work has been done with the ai the aid of urdf files.
of gym environments and different open-source frameworks URDF stands for Unified Robot Description Format. It is
like PyTorch and TensorFlow. an XML format for representing a robot model. It describes
As seen from the OpenAI robotics gym environment this the geometry and organization of robots in ROS. A URDF
work has been archived for different reasons, but mainly file is a tree structure with one root link. You can use URDF
because the transition from simulated environment training to to create your own robot description file and parse it with the
the real robot is prone to several errors and shortcomings. urdf parser.
Also, the gym environments are predefined, and very hard for In this paper, we present a framework for connecting
engineers to expand to real-world production line robots. MATLAB/Simulink environment to simulated or real-world
Lately, the usage of Robots Operating System (ROS2) is industrial robots from Universal Robots. Connecting
getting a lot of support in adopting it in industrial robots. MATLAB with the simulated or real industrial robot will
Universal Robots has implemented and continues to update a unleash all the tools MATLAB has to offer in the field of
ROS2 driver for the entire lineup of robots [1]. reinforcement learning. The algorithm is trained on a
The Robot Operating System (ROS) is a set of complex simulated robot and transition and verification to the real one
software libraries and tools for building robot applications. It is immediate since there is no need to update any code or new
has a lot of already built packages for implementing complex hardware porting.
algorithms for robotics like ros2_control (for motion control), Also, this would be the first step in creating a virtual
tf (for coordinates transformation), navigation, etc. The ROS commissioning software system based on MATLAB’s
applications can be implemented in C, C++, and python, and powerful modeling blocks and ROS2 which will enable the
the framework can be installed on different operation systems integration of many industrial robots.
(the list of Tier 1 support can be obtained on the ROS We have chosen Universal Robots due to their worldwide
website). use in industrial applications and the availability of
ROS has two versions, ROS1 which was the initial maintained ROS2 drivers for the entire robot lineup. There
platform, and ROS2 which is the second-generation version are several ways to connect online with UR robots with tools
that we have chosen for this system, more specifically the like RTDE (Real Time Data Exchange) that can be
Humble release. implemented in other software used for Reinforcement
ROS2 is the second version of the Robot Operating Learning. The main drawback is the lack of support for using
System (ROS), which is a communication interface that RTDE in a simulated environment, which makes it
enables different parts of a robot system to discover, send, impractical for usage in machine learning.
and receive data1. ROS2 was developed with an enhanced The tools developed are open-sourced and available in the
architecture feasible for use in the industry and academia and corresponding GitHub repository [7].
can run alongside the existing version of ROS1.
There are several software frameworks for simulating II. SYSTEM DESCRIPTION
robotic arm manipulators [2], like Ignition, Gazebo, PyBullet We aim to create a set of tools to glue together different
etc with different advantages or drawbacks (some lacks components in a ready-to-use and expand the system for
stability like gazebo and others consume a lot of resources). training reinforcement learning algorithms or direct control
Implementing ROS2 in the industrial environment is in of industrial robots.
the initial stages due to proprietary software from robotic arm The system is composed of six components:
manufacturers, but some work has been done [3],[4],[5] and • Real or simulated UR robot
• ROS2 system, Humble distribution

979-8-3503-2138-8/23/$31.00 ©2023 IEEE


• UR ROS2 driver communication between Simulink models and Universal
• MATLAB with robotics toolbox Robots ROS2 driver.
• Set of tools for controlling robot from Simulink We have created blocks for low-level ROS2 interface
types and creating or decoding the message types as defined
• Diagram for simulated robot
in the topics of interest.
Windows As per example the block of header creation is Simulink
is presented below:
Matlab tools

Linux Ubuntu topics

Doker – UR ROS2
provided image topics

Fig.3 Header creation


Fig.1 Components diagram
To construct the correct interfaces these blocks are
III. SIMULATED ROBOT SETUP reusing blank message types and populating the components
For implementation of reinforcement learning techniques with data.
the best approach is to provide a simulated environment. In We are proving blocks for creating the headers (for
our case we’ve set up a Linux ubuntu machine 64bit with timestamping), setting joint names, creating joint trajectories,
ROS2 Humble distribution installed. and reading the joint states.
A Universal Robots provided docker image is started on The robotics toolbox is mandatory because it provides
the machine which has installed as an urcap the ros2 driver ROS2 connectivity.
interface. Starting the image is done by simply running a These tools and examples are freely available on the
provided script [3,4]. A simple program should be created by GitHub repository.
inserting the External Control command. This command is V. PHILOSOPHY OF OPERATION
available on docker image but for a real robot the installation
of ROS2 driver is mandatory. To control a simulated or a real Universal Robot a
After starting the docker image, the ROS2 driver should Simulink model will send/receive messages over ROS2
be started spinning with provided command. After the driver topics to UR driver running on a Docker image (for simulated
is spinning the network connection should be available to robot) or installed on a real robot as described in UR ROS2
the host also and this should be checked by the topic list. GitHub repository [1].
In Matlab, the topic list should return the topics For control purposes, the main topic is
published by the ROS2 driver, the most important being /scaled_joint_trajectory_controller/joint_trajectory
/scaled_joint_trajectory_controller /joint_trajectory.and published by the spinning UR ROS2 driver. For this topic the
/joint_states. message type is trajectory_msgs/msg/JointTrajectory
To verify the correct functionality the UR robot is visualized described as:
synchronously with the robot in the UR program (simulated std_msgs/Header header
or real): builtin_interfaces/Time stamp
int32 sec
uint32 nanosec
string frame_id
string[] joint_names
# Array of trajectory points, which describe the positions,
velocities,
# accelerations and/or efforts of the joints at each time point.
JointTrajectoryPoint[] points
float64[] positions
float64[] velocities
float64[] accelerations
float64[] effort
builtin_interfaces/Duration time_from_start
Fig.2 UR Rviz user interface int32 sec
uint32 nanosec
IV. HOST SETUP To compose the required message, we’ve created helper
The host machine should have MATLAB with a robotics functions that takes a blank JointTrajectory message and
toolbox, to have access to ROS2 inside the MATLAB filles it with required data: joint_names and array of
environment and Simulink. We developed tools to convert JointTrajectoryPoint. These helper functions are available at
Simulink data into ROS2 message types to facilitate github repository that we created [7].
For retrieving the actual joint states, the Simulink model
is subscribing to /Joint_states topic. The /Joint_states topic
publishes a message defined as interface
sensor_msgs/msg/JointState:
std_msgs/Header header
builtin_interfaces/Time stamp
int32 sec
uint32 nanosec
string frame_id
string[] name
float64[] position
float64[] velocity
float64[] effort
For unpacking the message data, we’ve created a
Simulink helper algorithm, published in the GitHub
Fig.4 Robot starting position.
repository. The function unpacks the position, velocity,
After starting the program, the driver should return the
efforts, and joint names (links as defined in urdf description).
message ready to receive commands.
The data interpretation should consider that joint names
After launching the ur control file an action server is
returned by the /Joint_states topic may not be in the same
created /scaled_joint_trajectory_controller/
order as defined in /joint_trajectory topic.
follow_joint_trajectory. To this topic, Simulink will send
To program the real robot the user must use the pendant
messages as an interface.JointTrajectory.
and install the driver and program the simulated robot the user
The typical Simulink model diagram is presented below:
must connect to the docker image through VNC or other
remote desktop tools.
Map data Send
Creating a trajectory can be done directly by specifying
(axes names control
joint angles or by providing the tool position and using the Create and position) Joint
inverse kinematics blocks. header Joint trajectory
For using the inverse kinematics, the rigidBodyTree (timing) trajectory controller
should be provided. This is done by loading the UR robot into
MATLAB directly (which has support for all URx robots) but
in this case, any additional tool information would be
missing. The second option is to provide a urdf file with any
Feedback
additional tool description. The urdf files for Universal
Joint states
Robots are provided by the corresponding GitHub repository
{Position
[1].
Velocity
Timing of communication between the Simulink and ROS2
Efforts}
topics is imposed by the rate control clock block. This block
regulates Simulink simulation updates to ensure the time
Fig.5 Simulink concept diagram
interval between updates is close to the SampleTime
The control pose can be created directly by inputting the
property. We used an update rate of 1 second in the setup with
6 joint angles or, more commonly, by inputting the desired
a simulated robot.
tool’s final position and computing the joint angles with the
For simulation after the docker image is started and the
help o inverse kinematics algorithms. For this, in the example
ROS2 UR driver is spinning a very simple program should be
provided, we used the inverse kinematics Simulink block
implemented in Polyscope (the robot software). The program
provided by the robotics toolkit and coordinate
consists of a single command External Control, which is
transformation.
available if the URCaps for ROS2 driver is installed.
For feedback purposes, the ROS2 driver launch file starts
The driver is spinning but the control is not activated until
a state broadcasting node. This broadcaster reads the state of
the robot is in the home position. This home position is
the joints from a hardware interface and publishes it
defined in the parameter file initial_positions.yaml and can
as joint_states and dynamic_joint_states messages. These
be modified.
messages contain the names, positions, velocities, and efforts
The home position is defined by the following axes
of the joints, as well as the timestamp and frame_id of the
values:
message. The published rate is defined in the parameter file,
- Base 0o
and we used a 500Hz rate for initial testing purposes.
- Shoulder -900 Running the example from the repository, the user should
- Elbow 0o see, in RViz and in the docker image UR simulator, the robot
- Wrist1 -900 following the trajectories defined in Simulink and feedback
- Wrist2 0o data updates.
- Wrist3 0o A starting example and all the necessary blocks are
provided in the repository [7]. This repository is continuously
updated, mainly for extensions necessary for Gazebo
integration and 3D models.
VI. CONCLUSIONS [2] F. P. Audonnet, A. Hamilton and G. Aragon-Camarasa, "A Systematic
Comparison of Simulation Software for Robotic Arm Manipulation
In this paper, we presented a first step in creating a using ROS2," 2022 22nd International Conference on Control,
complete setup for the implementation of Reinforcement Automation and Systems (ICCAS), Jeju, Korea, Republic of, 2022, pp.
755-762, doi: 10.23919/ICCAS55662.2022
Learning algorithms for industrial robots based on
[3] H. Paul, Z. Qiu, Z. Wang, S. Hirai and S. Kawamura, "A ROS 2 Based
MATLAB, open-source tools like ROS2, and simulators for Robotic System to Pick-and-Place Granular Food Materials," 2022
Universal Robots. The setup can be used for controlling real IEEE International Conference on Robotics and Biomimetics
robots thus enabling easy algorithm verification with real (ROBIO), Jinghong, China, 2022, pp. 99-104
environments. Another advantage is decoupling the logic and [4] J. Golz, T. Wruetz, D. Eickmann and R. Biesenbach, "RoBO-2L, a
the simulator. The logic part is developed in MATLAB and Matlab interface for extended offline programming of KUKA
industrial robots," 2016 11th France-Japan & 9th Europe-Asia
the simulator is another software package that provides ROS2 Congress on Mechatronics (MECATRONICS) /17th International
controlled robot, like Universal Robots simulator or Gazebo. Conference on Research and Education in Mechatronics (REM),
The frameworks build the core components for messages Compiegne, France, 2016, pp. 064-067, doi:
between ROS2 nodes and Simulink models for real time 10.1109/MECATRONICS.2016.7547117
control of an industrial robot. [5] L. Puck et al., "Performance Evaluation of Real-Time ROS2 Robotic
Control in a Time-Synchronized Distributed Network," 2021 IEEE
The setup exhibits good results on real or simulated robots 17th International Conference on Automation Science and Engineering
with control trajectories being followed and feedback (CASE), Lyon, France, 2021, pp. 1670-1676, doi:
readings being consistent with the control. 10.1109/CASE49439.2021.9551447
Future work is directed in the integration of the Gazebo [6] Endre Erős, Martin Dahl, Kristofer Bengtsson, Atieh Hanna, Petter
Falkman, A ROS2 based communication architecture for control in
simulator and adding sensors and new environments for collaborative and intelligent automation systems, Procedia
industrial applications training. Manufacturing, Volume 38, 2019, Pages 349-357
[7] Bucur C., [online] Available: BucurCosmin/MatRosRob: Controlling
Robots from Matlab with ROS2
ACKNOWLEDGMENT [8] Tomas Horelican, Utilizability of Navigation2/ROS2 in Highly
The results presented in this article has been funded by the Automated and Distributed Multi-Robotic Systems for Industrial
Facilities, IFAC-PapersOnLine, Volume 55, Issue 4, 2022
Ministry of Investments and European Projects through the
[9] C. Plasberg, H. Nessau, D. Timmermann, C. Eichmann, A. Roennau
Human Capital Sectoral Operational Program 2014-2020, and R. Dillmann, "Towards Distributed Real-Time capable Robotic
Contract no. 62461/03.06.2022, SMIS code 153735.” Control using ROS2," 2022 IEEE 18th International Conference on
Automation Science and Engineering (CASE), Mexico City, Mexico,
2022, pp. 2205-2210
[10] S. Dehnavi, M. Koedam, A. Nelson, D. Goswami and K. Goossens,
"CompROS: A composable ROS2 based architecture for real-time
embedded robotic development," 2021 IEEE/RSJ International
REFERENCES Conference on Intelligent Robots and Systems (IROS), Prague, Czech
[1] Universal Robots, ROS2 driver [Online]: Republic, 2021
UniversalRobots/Universal_Robots_ROS2_Driver: Universal Robots
ROS2 driver supporting CB3 and e-Series

You might also like