Professional Documents
Culture Documents
DSCC2014
October 22-24, 2014, San Antonio, TX, USA
DSCC2014-5846
Ryan W. Krauss
Associate Professor
Mechanical and Industrial Engineering
Southern Illinois University Edwardsville
Edwardsville, IL 62026
Email: rkrauss@siue.edu
ABSTRACT Introduction
Arduino microcontrollers are popular, low-cost, easy-to- In order to ensure performance and stability, experiential
program, and have an active user community. This paper seeks feedback control systems must read sensor signals and send com-
to quantitatively assess whether or not Arduinos are a good fit mand signals at hard real-time intervals typically on the order of
for real-time feedback control experiments and controls educa- 1-10 millisecond. This can be surprisingly challenging and the
tion. Bode plots and serial echo tests are used to assess the need has lead to a number of commercially available hardware/-
use of Arduinos in two scenarios: a prototyping mode that in- software solutions to the problem. These systems have been
volves bidirectional real-time serial communication with a PC well-received by students in feedback control courses [1, 2, 3].
and a hybrid mode that streams data in real-time over serial. These solutions can cost several thousand dollars per lab station.
The closed-loop performance with the Arduino is comparable to A number of open-source and lower cost solutions to this prob-
that of another more complicated and more expensive microcon- lem have been presented in the literature [4, 5, 6, 7, 8].
troller for the plant considered. Some practical tips on using an
Arduino for real-time feedback control are also given. Microcontroller-in-the-Loop Systems
One approach to low cost, real-time feedback control is a
microcontroller-in-the-loop (MIL) system [7, 8, 9, 10, 11]. These
systems place a microcontroller in the feedback loop and are
NOMENCLATURE
in some ways similar to other hardware-in-the-loop systems. If
u closed-loop system input the microcontroller is communicating with a personal computer
v command voltage sent to the plant (PC), then an MIL system can be used for control prototyping
e error signal between desired and actual plant output or other educational purposes. If communication with a PC is
no longer necessary, the MIL system essentially becomes an em-
SFLR single-flexible-link robot (experimental plant)
bedded control system.
θ encoder output for the plant (SFLR)
θd desired encoder position (closed-loop input)
Arduino Microcontrollers
ẍtip tip acceleration for the SFLR
Evaluation boards for Arduino microcontrollers cost
Gθ (s) position control transfer function roughly $30 each. They are very popular, open-source, and easy
Ga (s) vibration suppression transfer function to program. This paper addresses the question of whether or not
ADC/Counters u e v y
− controller DAC plant
PC Microcontroller
Voltage (counts)
100 θd
θ
Ga(s) 50 ẍtip
0
Figure 4. Block diagram of the vibration suppression control scheme for
the SFLR of Figure 3. −50
−100
0.0 0.5 1.0 1.5 2.0 2.5 3.0
Time (sec)
Serial
Communication Figure 6. Step response for the SFLR without vibration suppression.
Command Voltage
250
Plant 200
(SFLR)
Sensor Signals
Voltage (counts) 150
Personal Microcontroller
Computer 100 θd
−50
−100
0.0 0.5 1.0 1.5 2.0 2.5 3.0
Time (sec)
Comparison/Benchmark System
Figure 7. Step response for the SFLR with vibration suppression.
In this paper, the Arduino will be compared to a
Programmable-System-on-Chip (PSoC) microcontroller from
Cypress for suitability for real-time feedback control applica-
Essential Elements of a Microcontroller-in-the-Loop
tions. While PSoC’s are in some ways more powerful than the
System
Arduino, they are also more difficult to configure and they are
What is required to use a microcontroller and a computer to
more expensive. A schematic of the PSoC being used in the
effectively form a real-time control prototyping system? First,
microcontroller-in-the-loop (MIL) system is shown in Figure 5.
the PC and the microcontroller have to be able to transfer small
This system has been used in real-time control with digital up-
amounts of data back and forth in real-time. The easiest way
date frequencies of 500 Hz. It has also been shown to be effective
to do this using an Arduino is with USB-to-serial. The Arduino
in controls education [12].
board has a USB port that is designed for serial communication.
Figure 6 shows the step response for the SFLR system be- The Arduino software includes a serial monitor that might be
ing controlled by the PSoC MIL approach. There is no vibration sufficient for hybrid mode. This work used Python on the PC
suppression in this case. Note that the encoder signal shows that side to communicate back and forth with the Arduino as well as
the joint is back driven by the vibrations and it takes 2-3 sec- perform control calculations in real-time, visualize data from a
onds for the vibrations to die out. Figure 7 shows the response finished test, and perform control design.
with vibration suppression. Note that the settling time is less In addition to serial communication, the microcontroller
than one second. The Arduino control system will be considered must be able to read all of the sensor signals, send command sig-
successful if it can reproduce these results, especially those with nals, and enforce the real-time execution of the control law. For
vibration suppression (Figure 7). the SFLR, the Arduino will need to be able to decode the A and
Response
to send to the DC motor H-bridge. The microcontroller would
receive these two numbers as two-byte integers: 15000
nIn = readtwobytes();
v = readtwobytes();
10000
20000 20000
Response
Response
15000 0.800 0.805 0.810 15000
10000 10000
5000 expected response 5000
actual response
0
0.0 0.2 0.4 0.6 0.8 1.0 0
Time (sec.) 0.0 0.1 0.2 0.3 0.4 0.5 0.6 0.7
Time (sec.)
Figure 10. Serial echo test results at 175 Hz.
Figure 12. Serial echo test results at 200 Hz.
cant near the crossover frequency of the control system, then the
0.6 Receive update frequency is fast enough.
Send
0.4
Rigid Link Bode and Step Responses
0.2 Figure 13 compares Bode plots from the PSoC MIL system
operating at 500 Hz with the Arduino operating in prototyping
mode at 150 Hz and hybrid mode at 500 Hz for the rigid link
0.0 0.800 0.805 0.810 case. The input to the Bode plot is the command voltage sent
Time (sec) to the H-bridge and the output is the joint angular position from
Figure 11. Plot of the timing signal from LabVIEW for the serial echo test the encoder. Not surprisingly, there is more phase lag for the
at 175 Hz. Arduino in prototyping mode at 150 Hz than for the other two
cases. Using this Bode plot to design a compensator for motor
control will lead to a lower crossover frequency for prototyping
for 10-20 iterations. mode, resulting in a slightly slower closed-loop response.
Unless some means can be found for reducing the latency in Figure 14 shows step responses for the rigid link robot for
the USB-to-serial approach, it appears that the Arduino MIL sys- three different cases: PSoC in prototyping mode at 500 Hz, Ar-
tem can only be used with digital control frequencies up to about duino in prototyping mode at 150 Hz, and Arduino in hybrid
150 Hz in prototyping mode. This seems to raise two questions: mode at 500 Hz. The designs can be made more aggressive as
is 150 Hz fast enough to use on interesting control problems and the phase lag in the system decreases.
can faster update frequencies be achieved using hybrid mode?
0
−10 PSoC Proto 500Hz
−20 Arduino Proto 150Hz 150
Voltage (counts)
−30
−40 Arduino Hybrid 500Hz
100 θd
−50 -1
10 100 101 θ
−60 50 ẍtip
−80
−100
Phase (deg.)
−120 0
−140
−160 −50
−180
−200 −100
−220 -1 0.0 0.5 1.0 1.5 2.0 2.5 3.0
10 100 101 Time (sec)
Freq. (Hz)
Figure 15. Step response for the Arduino in prototyping mode (without
Figure 13. Bode plot comparing the PSoC based system operating at
vibration suppression).
500 Hz with the Arduino system operating at 100 and 150 Hz. Both the
PSoC and Arduino are operating in prototyping mode.
250
250 200
Joint Angle θ (Encoder Counts)
150
Voltage (counts)
200
100 θd
θ
150 θd
50 ẍtip
PSoC θ
Arduino Proto θ 0
100 Arduino Hybrid θ
−50
50 −100
0.0 0.5 1.0 1.5 2.0 2.5 3.0
Time (sec)
0 0.0 0.5 1.0 1.5 Figure 16. Step response for the Arduino in prototyping mode (with vi-
Time (sec) bration suppression).
Figure 14. Step responses for the rigid link robot. The PSoC test is
performed in prototyping mode. The PSoC test and the Arduino hybrid controller. This conversion can be a challenging task. In order to
test are performed at 500 Hz. The Arduino prototyping test is performed simplify the task, an Arduino library has been created that imple-
at 150 Hz. ments a digital compensator. The idea is to easily allow a digital
transfer function such as
Final Comparison
Figure 17 compares the step responses for three cases: PSoC v(z) b0 + b1 z−1 + b2 z−2 + · · · + bm z−m
= (2)
in prototyping mode, Arduino in prototyping mode, and Arduino e(z) a0 + a1 z−1 + a2 z−2 + · · · + an z−n
in hybrid mode. The three cases agree fairly well with one an-
other and demonstrate the suitability of the Arduino for real-time to be expressed in C code that is easy to use for transfer functions
feedback control on this particular plant. of any order. At each digital time step, the next output needs to
be calculated:
Hybrid Mode Digital Compensator Class v(k) = (b0 e(k) + b1 e(k − 1) + b2 e(k − 2) + · · · + bm e(k − m)
Hybrid mode requires converting the control logic of the −a1 v(k − 1) − a2 v(k − 2) − · · · − an v(k − n)) /a0
block diagram such as that of Figure 4 to C code for the micro- (3)
250 was not as consistent as the timing between rising edges. The
analogWrite command occurs just before the falling edge of
200 the timing signal.
The results of this timing consistency verification are sum-
Labview
150 marized in Table 1. While the rising edges of the timing square-
Arduino wave show very little variation (top row), the falling edges are
100 not quite as consistent (bottom row). The average for both rising
and falling edges is 99.12 sampling periods. After performing
several tests, it seems repeatable that for the falling edges there
50
is one digital time step (out of roughly 1500) where the timing is
off by roughly +10% and one that is off by roughly -10%. If this
0 0.0 0.5 1.0 1.5 variation in the sending of the analog voltage lead to unaccept-
Time (sec) able performance, the timing of the analog write could be con-
Figure 18. Comparison of the encoder measurement from the Arduino trolled precisely by putting the analogWrite command in the
and LabVIEW. timer ISR. The drawback of this approach is that it would intro-
duce a one time step delay in sending the voltage command (the
voltage that is written in the ISR would be based on calculations
completed during the previous time step). Another alternative
would be to use a dedicated chip such as a hardware counter to
Timing Verification decoder the encoder signals and send the encoder signal to the
Moving the control calculations out of the ISR raises one Arduino via i2 c. The dedicated hardware would add cost and
concern: will the timing between analogWrite commands complexity to the system.
still be maintained accurately (i.e. the sending of the control A final verification of the timing of hybrid mode at 500 Hz
commands to the H-bridge). A digital pin was made to toggle on the Arduino is shown in Figure 20. The lower part of the
up and down when the control calculations begin and end so figure shows that the ISR that responds to encoder signals fires
that the timing could be measured using LabVIEW. The num- multiple times per control update period. The encoder ISR is
ber of LabVIEW samples between the rising and falling edges very brief. The top portion of the figure shows how long it takes
of the square-wave generated by timing signal was used to as- the Arduino to complete the control calculations and then send
sess the consistency of the real-time intervals. The MIL system the data for that time step back to the PC. The control calcula-
was operating at 500 Hz and the LabVIEW sample frequency tions could take 2-3 times longer and still be completed before
was set to 50 kHz, so there should be 100 LabVIEW samples in the end of the time step. The control calculations for the case
between each test. Because of the possibility of the control cal- with accelerometer feedback include two digital compensators,
Control Calculations
0.4 Send Serial Time Distributed Computing, 2003. Sixth IEEE Interna-
tional Symposium on, IEEE, pp. 11–18.
0.2 [6] Bucher, R., and Balemi, S., 2005. “Scilab/Scicos and Linux
0.0 RTAI - A unified approach”. In Control Applications,
0.150 0.152 0.154 0.156 0.158 2005. CCA 2005. Proceedings of 2005 IEEE Conference
1.0 on, IEEE, pp. 1121–1126.
0.8 [7] Jack, H., and Blauch, A., 2004. “A Modeling and Controls
0.6 Course using Microcontrollers”. In Proceedings of the 2004
Voltage