Electronics 12 01426
Electronics 12 01426
Article
Feasibility Study for a Python-Based Embedded Real-Time
Control System
Se Yeon Cho 1 , Raimarius Delgado 2 and Byoung Wook Choi 1, *
1 Department of Electrical and Information Engineering, Seoul National University of Science and Technology,
Seoul 01811, Republic of Korea; seyeon@seoultech.ac.kr
2 Center for Intelligent & Interactive Robotics, Korea Institute of Science and Technology,
Seoul 02792, Republic of Korea; raim.delgado@kist.re.kr
* Correspondence: bwchoi@seoultech.ac.kr; Tel.: +82-02-970-6412
Abstract: Because of its simplicity and the support of numerous useful libraries, Python has become
one of the most popular programming languages for application development, even in embedded
systems. However, in existing control systems where specific tasks must meet specific temporal
deadlines and support schedulability with proper priority assignments, the Python interpreter may
not satisfy real-time requirements, owing to features such as the global interpreter lock and garbage
collector. This paper addresses these constraints with an approach that executes periodic real-time
tasks under the fixed-priority preemptible scheduler of RT-Preempt. First, we implemented a Python
real-time module that allows users to create and execute periodic tasks with fixed priorities based on
Python. Then, we conducted experiments on an open embedded system, in this case, a Raspberry
Pi 4. We evaluated the real-time performance, focusing on test metrics for control systems, such
as task periodicity, responsiveness, and interrupt response. The results were then compared to
those of conventional real-time tasks developed using the C language to validate the feasibility of
the proposed method. Finally, we performed experimental validation by tracking the position of
EtherCAT servo motors to demonstrate the feasibility of a Python-based real-time control system in a
practical application.
demands because of its global interrupt lock and garbage collection processes [8]. There
have been attempts to improve the runtime speed of Python. For example, NumPy, short
for Numerical Python, integrates C/C++ and Fortran to execute vector and matrix oper-
ations without calling back into Python. In addition, Numba compiles Python code and
runs a faster version inside the typical interpreter runtime. Still, more is needed to meet the
temporal deadlines required in real-time systems.
Ionescu et al. [9] reported that MicroPython could be an alternative to C/C++ to reduce
the complexity of developing applications for embedded systems, employing MicroPython
in real-time systems. However, it still requires further resource management and garbage
collection optimizations. For example, Bucher et al. [10] developed the pysimCoder package
to design control systems in Python and generate the C/C++ code to be compiled for real-
time application. The common drawback of these studies is their limited—or complete
absence of—support for applications with multiple tasks (threads).
This paper describes a Python method for executing real-time periodical tasks un-
der the real-time Linux extension RT-Preempt using a POSIX Linker and the Ctypes
module [11,12]. The method is tested on a Raspberry Pi 4 device and evaluated through
various real-time performance analyses, including periodicity and interrupt latency [13].
The results are compared to those of the same program developed in C/C++. The paper
also demonstrates the feasibility of a Python-based real-time embedded control system by
performing servo motor control using the industrial Fieldbus EtherCAT [14–17]. This work
aims to provide a stepping-stone for easier integration of recent trends in machine learning
and numerical analysis on real-time systems for use in various fields, such as data analytics,
robotics, and industrial control. The main contributions of this study are as follows:
• The development of a Python method for executing real-time periodical tasks under the
real-time Linux extension RT-Preempt, using a POSIX Linker and the Ctypes module;
• An evaluation of the method on a Raspberry Pi 4 device through various real-time
performance analyses, including periodicity and interrupt latency;
• A comparison of the results to those of the same program developed in C/C++ to
validate the potential of the Python-based real-time system;
• A demonstration of the feasibility of a Python-based real-time embedded control
system by performing servo motor control using the industrial Fieldbus EtherCAT;
• Providing a stepping-stone for easier integration of recent trends in machine learning
and numerical analysis on real-time systems for use in various fields, such as data
analytics, robotics, and industrial control.
The rest of this document consists of the following: Section 2 presents and implements
the structure and implementation of Python-based real-time systems. Furthermore, experi-
ments are described and conducted to understand the performance and feasibility of the
proposed Python-based real-time system. The results of the experiment are then presented
and discussed. Section 3 uses EtherCAT to construct and experiment with systems for
real-time control of servo motors. The results also demonstrate the feasibility of Python-
based real-time systems presented in the study through analysis via probabilistic statistical
methods. Finally, Section 4 summarizes our findings and discusses future research.
Task Handler consists of information for controlling and managing tasks, such as
process ID, name, stack size, period, and priority. Task creation generates a task handler
and stores the period, priority, stack size, and name information that are user-specified
arguments. In Start Execution, storing the user-typed function in a task handler, configuring
the task as the previously stored task information, and executing the user function are
conducted. Set Task Timer can store or change the task handler period information. Wait
Period is a time wait function that has an important function in creating periodicity, one of
the real-time features. This should be called within the function of a periodic task to wait
for the next scheduled entry point after the current iteration has expired. Read Time is a
function that reads the current system time, and the unit is nanosecond.
In RT-Preempt, 99 denotes the highest priority, and 1 is the lowest, and these three
tasks operate on an isolated CPU core 1. Low priority τ3 is configured to run every 40 ms,
In RT-Preempt, 99 denotes the highest priority, and 1 is the lowest, and the
tasks operate on an isolated CPU core 1. Low priority τ3 is configured to run ever
medium priority τ2 runs every 20 ms, and highest priority τ1 runs every 10 ms.
time tasks are scheduled with fixed-priority and pre-emptive scheduling, the wo
Electronics 2023, 12, 1426 response time (WCRT) can be calculated via rate monotonic analysis (RMA)
5 of 14 [20].
𝑅
𝑅 = 𝐶 𝐵 𝐶
𝑃
medium priority τ2 runs every 20 ms, and highest priority τ1 runs every 10 ms. As real-
∈
time tasks are scheduled with fixed-priority and pre-emptive scheduling, the worst-case
response
Herein, C denotes the execution time, and B denotes(RMA)
time (WCRT) can be calculated via rate monotonic analysis [20].
the blocking time, whi
time duration when a lower-priority task blocks &
Rik
' higher-priority ones. The block
R
is zero for all tasks as long
k +1
i = C i + Bi + ∑ j
C
as RT-Preempt isPcorrectly configured and no
j (1) locking
j∈hp(i )
nisms are shared between the tasks. hp(i) is the set of all tasks with higher priori
the Herein,
currentC denotes
task. The the calculation
execution time, forand
theB denotes
WCRT the requires
blocking the
time,iteration
which isof the(1) unti
𝑅 or 𝑅
time duration when𝐷 is satisfied. Take note that for the first iteration, the is
a lower-priority task blocks higher-priority ones. The blocking time response
zero for all tasks as long as RT-Preempt is correctly configured and no locking mechanisms
equal to the execution time. For the given real-time tasks, the WCRTs are calcula
are shared between the tasks. hp(i) is the set of all tasks with higher priorities than the
3 ms, 8task.
current ms,Theand 29 ms, respectively.
calculation for the WCRT requires the iteration of (1) until Rik+1 = Rik or
k +1 In the configured tasks, the function loop is conducted on each task to perf
Ri ≥ Di is satisfied. Take note that for the first iteration, the response time is equal to the
performance
execution metric
time. For measurements,
the given real-time tasks, such as actual
the WCRTs are period
calculatedand response
to be 3 ms, 8 ms,time. To
and
the29 ms, respectively.load and the configured run time, we burn CPU resources for 1
computational
In the configured tasks, the function loop is conducted on each task to perform two
implement loop functions that are repeated until the required run time is compl
performance metric measurements, such as actual period and response time. To simulate
callcomputational
the this function spin.
load andIntheaddition,
configured each
run task
time, is
weconfigured to toggle
burn CPU resources forthe
1 msGPIO ou
during
and everyloop
implement spin operation
functions to repeated
that are measure thethepreemption
until required run andtime isvisualization
completed. thro
We call this
oscilloscope. function spin. In addition, each task is configured to toggle the GPIO output
pin during
The every spin operation
experiment to measure
uses wiringPi forthe
thepreemption
GPIO controland visualization
of Raspberry through
Pi 4, and m
the oscilloscope.
ments are conducted for ten minutes to obtain sufficient sample
The experiment uses wiringPi for the GPIO control of Raspberry Pi 4, and measure- measurement
addition,
ments both C/C++
are conducted for tenand Python
minutes languages,
to obtain sufficientused
sample tomeasurement
implement data. real-time
In test
Preempt,
addition, areC/C++
both used here to compare
and Python and analyze
languages, the periodicity
used to implement real-time and responsivenes
tests in RT-
Preempt, are used here to compare and analyze the
the Python real-time tests through statistical measurements. periodicity and responsiveness during
the Python real-time tests through statistical measurements.
Figures 2 and 3 show the results after measuring the periodicity by imple
Figures 2 and 3 show the results after measuring the periodicity by implementing
real-time
real-time tests
tests using
using Python Python and C/C++,
and C/C++, respectively,
respectively, and after
and after measuring measuring
actual GPIO actu
signals using an oscilloscope.
signals using an oscilloscope.
Figure
Figure Real
2. 2. −time tasktask
Real−time periodicity using the
periodicity oscilloscope
using in Python. in
the oscilloscope Python.
The figure of the waveforms uses a method of toggling GPIO when the task is running.
It can be observed that for a single hyper-period, τ1 runs four times, and τ2 runs twice,
while τ3 only has a single execution. A fixed-priority pre-emptive scheduler of RT-Preempt
handles the execution of real-time tasks. Thus, it can be seen that τ3 is being pre-empted by
τ1 and τ2 at specific points of its execution. The results show that the Python real-time test
implementations also have priority preemption.
Electronics 2023, 12, x FOR PEER REVIEW
Electronics 2023, 12, 1426 6 of 14
Figure
Figure3. Real −time task task
3. Real−time periodicity using the
periodicity oscilloscope
using in C/C++. in
the oscilloscope C/C++.
Table 3 shows the timing measurements of periodicity and response time in an idle
The figure
environment withoutof stress.
the waveforms uses
In the period a method
metric, both theofC/C++
toggling
and GPIO
Python when
imple- the tas
ning. It can
mentations meetbetheobserved that for
mean duration of τ1a, τsingle
2 , and τhyper-period,
3 . Regarding theτmaximum
1 runs four times, and
values,
ittwice,
can be while
seen that the Python implementation has higher values compared to
τ3 only has a single execution. A fixed-priority pre-emptive schedul C/C++,
with 10.088 ms, 20.222 ms, and 40.312 ms, respectively, for the real-time tasks. These slight
Preempt handles the execution of real-time tasks. Thus, it can be seen that τ3 is be
differences are negligible relative to the total number of data samples and the minimal
empted
change bystandard
in the τ1 and deviation
τ2 at specific points of its execution. The results show that the
(Sdev).
real-time test implementations also have priority preemption.
Table 3.Table
Period 3 shows
and thetime
Response timing measurements
of Real-Time of periodicity and response time i
Task in idle environment.
environment without stress. In the period metric,C/C++ both the C/C++ and Python im
Metric
tations meet the mean duration of ττ1,1 τ2, and τ3. Regarding the maximum values,
τ2 τ3
seen that the Python implementation
Mean 10.000has higher20.000values compared to C/C++, wit
40.000
ms, 20.222
Period ms, and 40.312
Min ms, respectively,
9.954 for the19.948
real-time tasks. These slight di
39.949
[ms]
are negligible Maxto the total number
relative 10.048 of data20.051 40.051
samples and the minimal chan
Sdev 0.003 0.004 0.004
standard deviation (Sdev).
Mean 3.008 8.017 29.021
Response Min 3.006 8.014 29.019
Table[ms]
3. Period and Response
Max time of Real-Time
3.056 Task in idle environment.
8.067 29.068
Sdev 0.002 0.003 0.003
C/C++
Python
Metric
Metric
τ1 τ1 τ2 τ2 τ3 τ3
MeanMean 10.000
10.000 20.00020.000 40.000 40.000
Period
Period Min Min 9.9549.918 19.78319.948 39.693 39.949
[ms] Max 10.088 20.222 40.312
[ms] Max Sdev 10.0480.023 0.03820.051 0.013 40.051
SdevMean 0.0033.064 8.136 0.004 29.184 0.004
Response Min 3.041 8.106 29.135
Mean 3.008 8.017 29.021
[ms] Max 3.190 8.399 29.441
Response Min Sdev 3.0060.016 0.020 8.014 0.013 29.019
[ms] Max 3.056 8.067 29.068
The response Sdev
measurement results0.002
confirm that each task meets 0.003
the requirement of the 0.003
WCRT. Hence, it is possible to know whether the task operates periodically and accurately
Python
Metric
in a real-time system that is scheduled based on a fixed priority. It is confirmed that the
WCRT expected by RMA is 3 ms at τ1 , 8τms 1 at τ2 , and 29 ms at τ3 ,τand
2 both C/C++ and τ3
Python satisfy the Mean 10.000
average value. However, at the maximum value,20.000
τ 2 is 8.399 ms in Python, 40.000
and τ3 is 29.441 ms, which is not satisfactory. However, if Sdev is checked, it can be seen
Period Min 9.918 19.783 39.693
[ms] Max 10.088 20.222 40.312
Sdev 0.023 0.038 0.013
Mean 3.064 8.136 29.184
Electronics 2023, 12, 1426 7 of 14
that τ2 is 0.020 ms and τ3 is 0.013 ms, which satisfies WCRT with a very low probability
of occurrence.
Table 4 shows the results of the experiments in a stressed environment. To evaluate the
behavior under interfering loads, the same experimental procedures are conducted with the
following stress conditions: stress-ng utilizing 100% of the CPU and 70% of system memory.
This method emulates an environment where multiple non–real-time threads attempt to
occupy the CPU and memory resources when they are available. This test should have
minimal effect on the performance of real-time tasks with high priorities. Otherwise, it can
be concluded that real-time tasks violate real-time constraints, which may lead to missing
stringent deadlines.
C/C++
Metric
τ1 τ2 τ3
Mean 10.000 19.999 40.000
Period Min 9.935 19.929 39.935
[ms] Max 10.068 20.068 40.058
Sdev 0.009 0.014 0.010
Mean 3.018 8.035 29.041
Response Min 3.007 8.018 29.028
[ms] Max 3.082 8.100 29.101
Sdev 0.007 0.008 0.007
Python
Metric
τ1 τ2 τ3
Mean 10.000 20.000 40.000
Period Min 9.715 19.646 39.702
[ms] Max 10.262 20.298 40.282
Sdev 0.064 0.082 0.066
Mean 3.216 8.474 29.636
Response Min 3.060 8.219 29.287
[ms] Max 3.459 8.751 29.871
Sdev 0.066 0.067 0.069
In the results, it has been shown that the average period of all real-time tasks is equal
to the idle environment with a minimal increase in the standard deviation. The response
time also has shown a slight increase in comparison to the results in an idle environment.
Even with their increased response times, all of the real-time tasks have met their respective
deadlines. This means that Python-based real-time tasks with high priorities are scheduled
as expected and are able to satisfy real-time constraints even in an environment with
multiple non–real-time threads.
Figure4.4.Interrupt
Figure Interrupt response
response of C/C++
of C/C++ andand python
python in theinRT −Preempt
the RT−Preempt patched
patched Linux kernel.
Linux kernel.
2.3.3. Discussion
2.3.3. Discussion
The feasibility of the Python real-time system implemented through this experiment
The feasibility
was researched throughofperiodicity
the Pythonandreal-time system
responsiveness, asimplemented through
well as preemption this experimen
and interrupt
was researchedItthrough
responsiveness. periodicity
was confirmed and responsiveness,
that preemption as well
and periodicity as preemption
according and inter
to priority
ruptobserved,
were responsiveness.
and thereItwas
wasnoconfirmed
significant that preemption
difference andresponse
in interrupt periodicity according to pri
performance.
However,
ority were in observed,
response performance,
and there was there
nowere cases in difference
significant which Python did not satisfy
in interrupt the perfor
response
WCRT predicted.
mance. However, in response performance, there were cases in which Python did not sat
isfyThis result shows that Python is not satisfied with real-time systems with hard con-
the WCRT predicted.
straints, but it will be fully available in real-time systems with soft constraints. This paper
This result shows that Python is not satisfied with real-time systems with hard con
can also serve as a springboard for flexible integration with existing studies of machine
straints,and
learning butnumerical
it will beanalysis
fully available in real-time
on real-time systems
systems for with soft
use in various constraints.
areas, This pape
such as data
can also serve as a springboard for flexible integration with existing
analytics, robotics, and industrial control, which require execution and safety. studies of machin
learning and numerical analysis on real-time systems for use in various areas, such as dat
3.analytics,
Experimental Validation
robotics, and industrial control, which require execution and safety.
This chapter describes the experimental environment and method for verifying the
feasibility of the implemented
3. Experimental Validation Python-based real-time control system and discusses the
experimental results.
This chapter describes the experimental environment and method for verifying th
feasibility
3.1. of the implemented Python-based real-time control system and discusses th
Environment
experimental results.used to implement the EtherCAT Master using a Python-based
The environment
real-time system for this paper is shown in Table 5. The control unit uses the Intel MIO-
5272U-U6A1E x86-based single board computer (SBC) used in industrial embedded systems
and the low-power Intel i7-6600U processor, 8GB of DDR4 RAM, and an Intel i219 network
controller with an e1000e driver.
Electronics 2023, 12, 1426 9 of 14
Item Description
Master
Board MIO-5272U-U6A1E
CPU Intel i7-6600U
Memory DDR4 8GB
Network Controller intel i219
Linux Kernel kernel 4.14.134-rt63
OS Distribution Lubuntu 18.04
Python 3.6.9
EtherCAT Master IgH EtherCAT Master 1.5.2
Slave-1
Product LS Mecapion L7N Servo Drive
26 bytes for each slave
PDO
(RxPDO 13 bytes, TxPDO 13 bytes)
Slave-2
Product Beckhoff EL2024 Digital Output
1 byte for each slave
PDO
(RxPDO 1 byte, TxPDO 0 bytes)
To build a real-time system environment for the EtherCAT Master using a Python-
based real-time system on this platform, kernel 4.14.134-rt63, a stable version compatible
with the EtherCAT master of the RT-PREEMPT-patched Linux kernel, is used. To ensure
maximum real-time performance, the kernel uses a method suggested in previous studies
to set kernel options for the power management and debugger sections [20]. Power
management is an essential factor related to the latency of real-time systems and should
be disabled.
Kernel debugging features are another source of latency that affects real-time require-
ments. In particular, KGDB functions, which are debuggers used to examine variables, the
call stack information, and memory usage all affect the latency. Therefore, KGDB must be
disabled. Similarly, Lubuntu is used to prevent real-time performance degradation due to
the GUI and uses the latest Python version, 3.6.9, which can be applied accordingly.
The EtherCAT master uses the open-source IgH EtherCAT master, using version 1.5.2,
which is known to be stable [21]. It also uses the Ctypes module to configure the IgH
EtherCAT master shared library to interface with Python.
The EtherCAT slaves to be used to verify and test the implemented Python-based
real-time system use LS Mecapion L7N servo drives and the Beckhoff EL2024 digital output.
The PDO (process data object) used for communication is 13 bytes for transmission and
reception for the servo devices and 1 byte for the digital IO.
This development environment can be an example of a real-time embedded system’s
platform selection and system environment configuration for controlling industrial machinery.
Figure 5. Environment diagram of the EtherCAT Master using Python-based real-time contro
Figure
tem. 5. 5.
Figure Environment
Environment diagram
diagram of the EtherCAT
of the EtherCAT Master
Master using using Python-based
Python-based real-time controlreal-time
system. contro
tem.
Figure
Figure 6. Environment
6. Environment picture
picture of the EtherCAT
of the EtherCAT Master
Master using using Python-based
Python-based real-time controlreal-time
system. contro
Figure
tem. 6. Environment picture of the EtherCAT Master using Python-based real-time contro
tem.The experiment used two digital outputs and three servos, with 1 byte for the digital
outputs andexperiment
The 26 bytes for the
usedservos. Data amounting
two digital outputs to 80 bytes
and threewere exchanged
servos, with 1 during
byte for the d
one control
The andperiod.
experiment
outputs 26 bytesused twoservos.
for the digitalData
outputs and three
amounting to servos,
80 byteswith
were1 byte for the du
exchanged di
The digital outputs (see Figure 5) executed the toggle control task every period and
outputs andperiod.
oneconfigured
were control 26 bytes for the servos. Data amounting to 80 bytes were exchanged du
at both ends of the EtherCAT network topology to measure the output pin
one control
of position period.
The 1digital
and theoutputs (see
output pin of Figure
position5) executed
6 through the toggle control
an oscilloscope. task every
For the servo, 1 Hz period
sineThe
ofwere digital
was outputs
configured
control at both (see
performed up Figure
ends toof−the 5)EtherCAT
90 to executed
90 the
withtoggle
degrees,network control
topology
the control task
to
being every period
measure
operated the ou
were
pin ofconfigured
correctly. The
position 1 andat both
experiment the ends
lasted a
output ofpin
theof
total of 5EtherCAT
position 6network
min. It throughtopology
measured the period, to measure
response
an oscilloscope. time, the ser
For the ou
and
pin position
of of the1 EtherCAT
position and the servo every
output pin 1 ms,
of which 6
position was the taskan
through period, and a totalFor
oscilloscope. of the ser
Hz sine control was performed up to −90 to 90 degrees, with the control being ope
300,000 sample data were obtained. At the same time, the EtherCAT digital output pin was
Hz of sine The
correctly. control was performed
experiment lasted aup to −90
total of 5tomin.
90 degrees, with the
It measured the control
period,being oper
response
measured using an oscilloscope to measure the actual control period and synchronization
correctly.
ofand Theof
the position
EtherCAT experiment
thedevice.
slave EtherCATlasted a total
servo everyof 15 ms,
min.which
It measured
was thethetaskperiod,
period,response
and a to
and position
300,000 of the
sample dataEtherCAT servo At
were obtained. every 1 ms, time,
the same whichthe was the taskdigital
EtherCAT period,output
and a pin
to
3.3. Experimental
300,000
measured sample Results
usingdata were obtained.
an oscilloscope At the same
to measure the time,
actualthe EtherCAT
control perioddigital output pin
and synchroniz
The
measured operation period
using an
of the EtherCAT and response
oscilloscope
slave time measurement results of the task
device. to measure the actual control period and synchronizdescribed
above
of theare summarized
EtherCAT in terms
slave of statistical values, in this case, the mean, maximum (Max),
device.
minimum (Min), and standard deviation (Std), as shown in Table 6.
Electronics 2023, 12, 1426 As a result of the response time measurement, it was confirmed 11 of 14 that
data transmission data processing and transmission operations were com
the task operation period with a maximum of 0.131 ms, a minimum of 0.0
As a result of the response time measurement, it was confirmed that the EtherCAT
average
data of 0.077
transmission datams. In theand
processing periodic measurement
transmission results,
operations were the within
completed average ope
wastask
the 1 ms, but the
operation maximum
period operating
with a maximum period
of 0.131 was 1.238
ms, a minimum ms, and
of 0.069 theanminimu
ms, and
average of 0.077 ms. In the periodic measurement results, the average
0.766 ms. This exceeded 1 ms, but this occurred once among 300,000 sampl operating period
was 1 ms, but the maximum operating period was 1.238 ms, and the minimum period was
A histogram
0.766 ms. This exceededof thebutZ−scores
1 ms, calculated
this occurred once amongusing
300,000Equation
samples. (2) to interpre
measurement
A histogram ofdata
the Zprobabilistic statistically
−scores calculated is shown
using Equation in Figure
(2) to interpret 7.
the periodic
measurement data probabilistic statistically is shown in Figure 7.
𝜒 − 𝜇
𝛧=
Z=
χ−µ 𝜎 (2)
σ
The digital output can be toggled for every 1 ms period, allowing the o
predict a measurement period of 2 ms when taking measurements. The me
Figure
Figure
sults 8. Digital
8. Digital
showed outputoutput
that the control
control period
digitalandperiod
outputand of skew
skew measurement measurement
results.
position results. and fou
1 was measured
average period
The digital of 1.99
output mstoggled
can be and aformaximum
every 1 ms period of 2.04 the
period, allowing ms.oscilloscope
The digital outp
6 was also measured, showing an average period of 1.99 ms allowing
to The
predict a digital
measurement output
period can
of 2be
ms toggled
when for
taking every 1
measurements. ms period,
The measurement
and a maxim the
predict
results
2.04 aBoth
showed
ms. measurement period
that the digital output
signals
of of 2 msdeviation
position 1when taking4.6
was measured measurements.
and found to have anThe m
average period of 1.99 ms andhad a standard
a maximum period of 2.04 ms. Theofdigital us and
output of an expected
position
sults
6period
showed
was also ofmeasured, that
2.0 ms. In the digital
addition,
showing
output
skewperiod
an average
of position
measurements
of 1.99 ms and
1 was
ofa the measured
two signals
maximum
and fou
period ofshowed
average
2.04
an ms. Both
average period
signals
of 1.45 of
had1.99 ams
a standard
us, anddeviation
maximum a maximum
of of usperiod
2.54.6us, and an of
a minimum 2.04 of
expected ms. The
toggle
0.68 digital
and aout
control
us, st
6 was
period of also
2.0
tionanofaverage
ms.
0.18 us. measured,
In addition, showing
skew an average
measurements of the period
two of
signals 1.99
showedms and
that theya maxim
had of 1.45 us, a maximum of 2.5 us, a minimum of 0.68 us, and a standard
2.04 ms.
Figure
deviation
Both
of 0.189us.
signalsthe
shows had a standard
result deviationthe
after measuring of position
4.6 us and an expected
feedback data
period
Figure
drivers of
for 2.0
9 shows ms.
everythe In addition,
result
1 ms skew
after measuring
period, measurements
the position
the control reference of
feedback the two
data of at
position signals
three servo
2−3 showe
s, and the
an average
drivers for everyof 1.45
1 ms us,
period, a
themaximum of
control reference2.5 us,
position a 2−3 s, and theofposition
atminimum 0.68 us,
dataand a s
of each servo driver.
of each servo driver.
tion of 0.18 us.
Figure 9 shows the result after measuring the position feedback data
drivers for every 1 ms period, the control reference position at 2−3 s, and th
of each servo driver.
The servo driver performed −90 to 90 degree 1 Hz sine position control, as shown in
Figure 9. When zoomed in around 2.5 s, the control response of approximately 25 ms is
observable, indicating the performance of the position controller built into the servo driver.
The results of the confirmed feedback data show that position control of the servo motor
via EtherCAT was performed correctly.
As a result of the experiment, it was confirmed that precise control was possible
through servo driver position control feedback data, with the performance of the imple-
mented Python EtherCAT master verified by confirming an average simultaneity of 1.45 ms
and the 1 ms constant period control. In addition, environments using motors and I/O,
such as those in this experiment, can be used in applications such as conveyor belts, assem-
bly processes, and industrial factories [22], with the use of Python-based programming
languages enabling the flexible integration of technologies such as artificial intelligence
and big data with EtherCAT control applications.
4. Conclusions
To demonstrate the feasibility of real-time systems in Python, we implemented real-
time tasks in Python using the Ctypes module in a real-time Linux environment. We
compared the real-time metrics of periodicity and responsiveness in Python and C/C++
languages. The statistical results always showed promising results in C/C++. While Python
could be easily and rapidly implemented in the experimental condition, C/C++ had the
disadvantage of being somewhat complicated and time-consuming concerning its coding
and compiling processes. Lastly, an environment was built using EtherCAT Fieldbus-
based servo motors and digital outputs used in actual industrial sites, and periodicity and
synchronicity were measured through a python-based real-time control system experiment
also performed statistical analysis using Z−score.
As a result, Python was shown to work in a real-time environment, task periodicity was
satisfied, priority-based preemption occurred, and the feasibility of Python was researched
on a real-time control system.
The results here can be applied to industrial controllers, robots, and the mobility field
where real-time performance is required, and this method can extend the limits and relax
the constraints of real-time performance with Python, enabling integration with real-time
systems in various fields, such as artificial intelligence(AI), data science, and networking.
For future studies, as shown in RT−AIDE, performance evaluations and research using
a greater variety of real-time metrics will be conducted to improve experiment and analysis
methods, including power consumption, which may be applied only to RT-Preempt but
also to several RTOSs, and both non–real-time and real-time types. In addition, we will be
conducting research on intelligent control systems leveraging machine learning and neural
network inference for service and industrial robots [23–25].
Author Contributions: S.Y.C. and R.D. contributed equally to this paper. The joint first authors
surveyed the background of this research, conceptualized and developed the software and environ-
ment, formulated the experiment procedures, and analyzed the results of the experiments. B.W.C.
supervised and supported this study. All authors have read and agreed to the published version of
the manuscript.
Funding: This work has been financially supported by SeoulTech (Seoul National University of
Science and Technology).
Data Availability Statement: The data presented in this study are available on request from the
corresponding author.
Conflicts of Interest: The authors declare no conflict of interest.
Electronics 2023, 12, 1426 14 of 14
References
1. Kim, M. Guaranteeing That Multilevel Prioritized DNN Models on an Embedded GPU Have Inference Performance Proportional
to Respective Priorities. IEEE Embed. Syst. Lett. 2022, 14, 83–86. [CrossRef]
2. Meyer, E.; Robinson, H.; Rasheed, A.; San, O. Taming an Autonomous Surface Vehicle for Path Following and Collision Avoidance
Using Deep Reinforcement Learning. IEEE Access 2020, 8, 41466–41481. [CrossRef]
3. Stephen Cass Top Programming Languages 2021. Available online: https://spectrum.ieee.org/top-programming-languages-2021
(accessed on 10 February 2023).
4. Ian Skerrett Profile of an Iot Developer: Results of the Iot Developer Survey. Available online: https://ianskerrett.wordpress.
com/2016/04/14/profile-of-an-iot-developer-results-of-the-iot-developer-survey (accessed on 10 February 2023).
5. Reghenzani, F.; Massari, G.; Fornaciari, W. The Real-Time Linux Kernel: A Survey on PREEMPT_RT. ACM Comput. Surv. 2019, 52,
1–36. [CrossRef]
6. Krishna, C.M. Fault-Tolerant Scheduling in Homogeneous Real-Time Systems. ACM Comput. Surv. 2014, 46, 1–34. [CrossRef]
7. Devaraj, R.; Sarkar, A. Resource-Optimal Fault-Tolerant Scheduler Design for Task Graphs Using Supervisory Control. IEEE
Trans. Industr. Inform. 2021, 17, 7325–7337. [CrossRef]
8. Jerome Joseph, T.; Swaminathan, J. An Experimental Study of Parallelism in Different Python Frameworks. In Proceedings of the
2022 International Conference on Inventive Computation Technologies (ICICT), Kathmandu, Nepal, 20–22 July 2022; pp. 363–366.
9. Ionescu, V.M.; Enescu, F.M. Investigating the Performance of MicroPython and C on ESP32 and STM32 Microcontrollers. In
Proceedings of the 2020 IEEE 26th International Symposium for Design and Technology in Electronic Packaging (SIITME), Pitesti,
Romania, 21–24 October 2020; pp. 234–237.
10. Bucher, R. Practical Experiences with Python and Linux RT at the SUPSI Laboratory. IFAC-PapersOnLine 2019, 52, 133–138.
[CrossRef]
11. Jun, L.; Ling, L. Comparative Research on Python Speed Optimization Strategies. In Proceedings of the 2010 International
Conference on Intelligent Computing and Integrated Systems, Guilin, China, 22–24 October 2010; pp. 57–59.
12. Python Software Foundation Ctypes—A Foreign Function Library for Python. Available online: https://docs.python.org/3/
library/ctypes.html (accessed on 10 February 2023).
13. Carvalho, A.; Machado, C.; Moraes, F. Raspberry Pi Performance Analysis in Real-Time Applications with the RT-Preempt Patch.
In Proceedings of the 2019 Latin American Robotics Symposium (LARS), 2019 Brazilian Symposium on Robotics (SBR) and 2019
Workshop on Robotics in Education (WRE), Rio Grande do Sul, Brazil, 22–26 October 2019; pp. 162–167.
14. Wang, S.; Ouyang, J.; Li, D.; Liu, C. An Integrated Industrial Ethernet Solution for the Implementation of Smart Factory. IEEE
Access 2017, 5, 25455–25462. [CrossRef]
15. Delgado, R.; Park, J.; Choi, B.W. Open Embedded Real-Time Controllers for Industrial Distributed Control Systems. Electronics
2019, 8, 223. [CrossRef]
16. Lee, S.-Y.; Sung, M. Design and Implementation of an Ethernet-Based Linear Motor Drive for Industrial Transport Systems. IEEE
Access 2021, 9, 33061–33074. [CrossRef]
17. Chan, C.-C.; Tsai, C.-C. Collision-Free Speed Alteration Strategy for Human Safety in Human-Robot Coexistence Environments.
IEEE Access 2020, 8, 80120–80133. [CrossRef]
18. Delgado, R.; Jo, Y.H.; Choi, B.W. RT-AIDE: A RTOS-Agnostic and Interoperable Development Environment for Real-Time Systems.
IEEE Trans. Industr. Inform. 2022, 19, 2772–2781. [CrossRef]
19. King, C.I. Stress-Ng. Available online: https://github.com/ColinIanKing/stress-ng (accessed on 1 March 2023).
20. Delgado, R.; Choi, B.W. New Insights into the Real-Time Performance of a Multicore Processor. IEEE Access 2020, 8, 186199–186211.
[CrossRef]
21. Florian, P. IgH EtherCAT Master1.5.2 Documentation. Available online: https://www.etherlab.org/download/ethercat/ethercat-
1.5.2.pdf (accessed on 10 February 2023).
22. Akpinar, K.O.; Ozcelik, I. Analysis of Machine Learning Methods in EtherCAT-Based Anomaly Detection. IEEE Access 2019, 7,
184365–184374. [CrossRef]
23. Yasar, M.S.; Evans, D.; Alemzadeh, H. Context-Aware Monitoring in Robotic Surgery. In Proceedings of the 2019 International
Symposium on Medical Robotics (ISMR), Atlanta, GA, USA, 3–5 April 2019; pp. 1–7.
24. Li, Z.; Hutchinson, K.; Alemzadeh, H. Runtime Detection of Executional Errors in Robot-Assisted Surgery. In Proceedings of the
2022 International Conference on Robotics and Automation (ICRA), Philadelphia, PA, USA, 23–27 May 2022; pp. 3850–3856.
25. Long, Y.; Wu, J.Y.; Lu, B.; Jin, Y.; Unberath, M.; Liu, Y.-H.; Heng, P.A.; Dou, Q. Relational Graph Learning on Visual and Kinematics
Embeddings for Accurate Gesture Recognition in Robotic Surgery. In Proceedings of the 2021 IEEE International Conference on
Robotics and Automation (ICRA), Xi’an, China, 30 May–5 June 2021; pp. 13346–13353.
Disclaimer/Publisher’s Note: The statements, opinions and data contained in all publications are solely those of the individual
author(s) and contributor(s) and not of MDPI and/or the editor(s). MDPI and/or the editor(s) disclaim responsibility for any injury to
people or property resulting from any ideas, methods, instructions or products referred to in the content.