SlideShare uma empresa Scribd logo
1 de 12
1
Real-time PID control of an
inverted pendulum
Pasquale Buonocunto –
Francesco Corucci –
MSc in Computer Engineering, University of Pisa – Italy
"In theory, there is no difference between theory and practice.
But, in practice, there is"
Jan L. A. van de Snepscheut
1 Introduction
In this report we will describe a project we developed for an Embedded
Systems class. Our goal was to experiment in practice with a simple control
plant, that could be approached with the famous PID controller.
When moving from simulation to practical implementation a lot of
unexpected issues arise, and must be handled: this forced us to deeply
understand the essence of the problem.
2 Brief description of the physical system
The case study consisted in the control of an inverted pendulum, in the
cart-and-pole version. As shown in Figure 1, there is a pole with a mass
mounted on his top, hinged on a cart that can move horizontally. The
control goal is to stabilize the pole in the vertical position ( ),
corresponding to an unstable equilibrium.
Figure 1 - Model of the physical system
2
3 Testbed
3.1 Plant
Figure 2 shows the real plant on which we worked. The cart is actuated
with a DC motor through a belt: the motor also provides an encoder, that
we used to deduce the horizontal position of the cart. The inclination of the
pole is measured with a potentiometer placed at its bottom.
Figure 2 – The plant
The motor (Figure 3) is a ESCAP DC
MOTOR/ENCODER 22V E9-0500-2.0-1: it
is a little bit underutilized since the board
Belt
Potentiometer
DC Motor
Motor encoder
Figure 3 - The DC motor used to control
the plant
3
provides it less voltage/current than expected, but we used it anyway since
we had just demonstration purposes (otherwise a dedicated power circuit
should have been necessary). Other limitations of the plant will be
discussed later in this paper.
3.2 Control electronics
Figure 4 shows the control electronics.
Figure 4 - Control electronics
We used an Evidence1
FLEX motion board equipped with the DC
Motor plug-in. The board mounts a microcontroller of the dsPIC33 serie.
We also realized a simple circuit with three potentiometers, in order to be
able to regulate online the control parameters. The wiring is realized as
follows (refer to the appendix for the nomenclature):
1
http://www.evidence.eu.com
CON23
PIN NO. 4 3 2 1
CONNECTED TO B A + -
CON22
PIN NO. 2
CONNECTED TO ENC_STDBY
CON24
PIN NO. 4 3
CONNECTED TO Vmotor+ Vmotor-
4
CON8
PIN NO. 20 19 12 10 2 1
CONNECTED
TO
- + Ki_POT Kd_POT POLE_POT Kp_POT
DC Motor + encoder
B, A, +, -
Vmotor+, Vmotor-
ENC_STDBY
EncoderDC motor
Kp Ki Kd
+
Bar
potentiometer
-
Figure 5 - Wiring scheme
5
4 Angle control: the first PID controller
For what concerns the stabilization of the pole, we implemented a speed
control of the DC motor using a PID controller.
Below the digital implementation of the PID controller (simplified code):
float PID(float setpoint,float actual_position)
{
static float pre_error = 0.0;
static float integral = 0.0;
static EE_UINT8 count = 0;
static float errors[I_WINDOW_SIZE];
float error;
float derivative;
float output;
EE_UINT8 i;
...
// Calculate error
error = setpoint - actual_position;
// Integral component
if(Ki > 0.0 && WINDOWED_INTEGR)
{ // Windowed integration mode
integral = 0.0;
// The truncated integration is realized with
// a cyclic array
// Insert new value in the window
errors[count] = error;
// Update counter
count = (count+1) % I_WINDOW_SIZE;
// Accumulation
for(i = 0; i < I_WINDOW_SIZE; i++)
integral += errors[i]*dt;
}
else if(Ki > 0.0) // Non-windowed integration mode
integral += error*dt;
//
// Anti-windup saturation of integral component
//
float Ki_integral = Ki*integral;
if(Ki_integral> ANTI_WINDUP_THR)
Ki_integral = ANTI_WINDUP_THR;
6
else if(Ki_integral < -ANTI_WINDUP_THR)
Ki_integral = -ANTI_WINDUP_THR;
// Derivative component
derivative = (error - pre_error)/dt;
// Calculate output
output = Kp*error + Ki_integral + Kd*derivative;
...
//Saturation Filter
if(output > MAX_PID)
{
output = MAX_PID;
}
else if(output < MIN_PID)
{
output = MIN_PID;
}
//Update error
pre_error = error;
return output;
}
Figure 6 - Digital implementation of the PID controller
Some comments about the code:
- It is possible to choose two different modes of integration: windowed
and not windowed
- Our PID provides an anti-windup saturation of the integral component
- The control output is (obviously) saturated
5 Position control: the second PID
A PID is sufficient to stabilize the pole in a vertical position, but since
the rail is bounded it is important to make the controller aware of the fact
that it could end up hitting the physical bounds of the rail (this is possible
in practice using an encoder placed on the DC motor, whose angular
information is translated into a linear one). A software strategy that tries
to manually manage this condition preserving the stability of the pole is
quite difficult to think. We thought that the better thing to do was to try
to keep the cart away from the bounds (ideally in the center of the rail)
7
with some additional control, in order to decrease the probability of hitting
the bounds.
Theoretically speaking it should be necessary a much more complex
modellization in order to simultaneously control the angle of the pole and
the position of the cart, since the two variables are not independent.
However, trying to keep things easy, we tried an alternative way to realize
something similar to the ideal behavior. We programmed two independent
PID controllers, one for the angle stabilization, one for the position
stabilization, and we tuned the parameters in order to give more priority to
the angle stabilization: this way we are able to obtain a quite stable system,
that tries to converge to the center of the rail when this does not disturb
the pole stabilization. This corresponds to a simplification of the model,
that can be mitigated with an appropriate tuning of the parameters2
. We
like to think this simplified modellization as if the second PID (the position
control) acts like a disturbance on the first PID (the angle stabilization
controller). Figure 7 shows the block description of the system.
The code below illustrates how this was implemented (pseudocode):
float current_position = <get pole inclination>;
float current_ticks = <get cart displacement from center>;
float angle_control = PID1(ANGLE_SETPOINT,
current_position);
float position_control = PID2(POSITION_SETPOINT,
current_ticks);
float control = angle_control + position_control;
<saturation of the resulting control variable>
Figure 8 - Control variable calculation
2
This is the interpretation we gave to our idea, that seems to be confirmed by
some works found in literature, like [1]
Ref
angle
PID1
PID2
Ref
pos
+ PLANT
+
-
+
-
pole_angle
cart_position
angle_control
pos_control
control
Figure 7 - Complete control system
8
For what concerns the output control variable (controlling the speed of the
DC motor), it was saturated from -100 to +100, using the sign as
discriminator for the direction. The amplitude is from 0 to 100 because the
control is a PWM duty creating a linear voltage for the DC motor.
However, due to practical limitations caused by the cart friction on the rail,
the minimum PWM duty cycle usefull to really move the cart is quite high
(about 30% with good lubrification), so we limitated it in a shorter range
defined by two thresholds (±[MIN_PID, MAX_PID]).
6 PID tuning
Given the control system architecture, the proper way to tune the whole
system is the following:
1. Keeping the second PID disabled, tune the parameters of the first
PID (the angle stabilization one) as if it is the only controller in the
system;
2. Once the angle stability is reached, enable and tune the second PID
(the position control one) with “light” parameters, in order to preserve
the angle stabilization previously obtained.
The single PID can be tuned with any of the classical methods, such
Ziegler-Nichols: we followed an heuristic methodology inspired to the latter,
also driven by the practical interpretation we gave to every parameter.
7 Software organization
The application is composed of 5 tasks:
- TASK_HOMING [aperiodic]: activated only one time at the startup, it
manages the necessary homing steps in order to make system aware of
the control set points (rail center, and pole equilibrium position). It
requires the user intervention.
- TASK_POSITION_CONTROL [period: 150ms, priority: 53
]: reads the
position of the cart and calculates the PID for the position control. The
computed value is used from the the angle control task, that performs
the real actuation merging the two control variables.
- TASK_ANGLE_CONTROL [period: 50ms, priority: 6]: reads the
inclination of the bar, calculates the PID for the stabilization of the
bar, combines this value with the one from the position control task,
then actuates the motor.
3
Task priority in OSEK is specified by a number from 1 to 10. Higher values
represents higher priorities
9
- TASK_READ_POT [period: 200ms, priority: 3]: this task acquires
values from the three external potentiometer, and updates the control
parameters accordingly.
- TASK_SERIAL_PRINT [period: 500ms, priority: 2]: feedsback some
useful information via UART.
Figure 9 shows the execution flow of the application:
8 Running demonstration
A running demonstration of the implemented system can be viewed in the
following videos:
http://www.youtube.com/watch?v=zEF6a_m0kdQ
http://www.youtube.com/watch?v=9Mg-y6TDef4
9 Limitations
The physical system we worked on presented considerable non-idealities,
that made quite hard the task of making things work properly. The main
limitation of the plant relies in the friction between the rail and the cart,
that remains considerable also with appropriate lubrification. Also the
traction offered by the belt is asymmetric in the two direction and causes
some extra friction. Another issue relies in the motor, its poor precision and
its underutilization (since the board provides it less voltage/current than
1. Maintain the bar, press the
button, and let the cart
scan the rail to identify the
center
2. Once the cart have reached
the center of the rail, put
the pole in the steady state
and press again the button
main init
TASK_HOMING
button pressed / activate task
TASK_POSITION_
CONTROL
TASK_ANGLE_
CONTROL
button pressed / activate task
TASK_SERIAL_
PRINT
TASK_READ_
POT
Figure 9 - Execution flow
10
expected). The final effect of these limitation is that the movements of the
cart are inevitably jerky, making quite difficult to obtain a smooth control
and, as a consequence, a good stabilization of the system.
10 Future work
The potentiometer used to read the inclination of the pole is quite noisy:
with a rough strategy, we just truncated the measures after the second
decimal digit, because all we got beyond that was nothing but noise. This
was enough for our purposes, but it should be interesting, instead, to
implement some filtering strategy to gain accuracy in the angle
measurement. For example it could be usefull to oversample the value with
a higher frequency in respect to the control frequency (i.e. the frequency
with which the measure is consumed), and then apply some filtering (es:
low pass, median, …). Another filter that is commonly used in this context
is the Kalman filter, used to estimate the measure ensuring a good
immunity to noise.
11 References
[1] “Simulation and Robustness Studies on an Inverted Pendulum”, HUANG
Chun-E, LI Dong-Hai, SU Yong, Proceedings of the 30th Chinese Control
Conference, July 22-24, 2011, Yantai, China
11
12 Appendices
12

Mais conteúdo relacionado

Mais procurados

final year presentation
final year presentationfinal year presentation
final year presentationrao tahir
 
The stabilization of forced inverted pendulum via fuzzy controller
The stabilization of forced inverted pendulum via fuzzy controllerThe stabilization of forced inverted pendulum via fuzzy controller
The stabilization of forced inverted pendulum via fuzzy controllereSAT Journals
 
2_DOF_Inverted_Pendulum_Laboratory_Session
2_DOF_Inverted_Pendulum_Laboratory_Session2_DOF_Inverted_Pendulum_Laboratory_Session
2_DOF_Inverted_Pendulum_Laboratory_SessionPeixi Gong
 
Backstepping control of cart pole system
Backstepping  control of cart pole systemBackstepping  control of cart pole system
Backstepping control of cart pole systemShubhobrata Rudra
 
Analysis of a pendulum problem
Analysis of a pendulum problemAnalysis of a pendulum problem
Analysis of a pendulum problemSuman Lata
 
Simulation of inverted pendulum presentation
Simulation of inverted pendulum  presentationSimulation of inverted pendulum  presentation
Simulation of inverted pendulum presentationPourya Parsa
 
Linear quadratic regulator and pole placement for stabilizing a cart inverted...
Linear quadratic regulator and pole placement for stabilizing a cart inverted...Linear quadratic regulator and pole placement for stabilizing a cart inverted...
Linear quadratic regulator and pole placement for stabilizing a cart inverted...journalBEEI
 
Robust control theory based performance investigation of an inverted pendulum...
Robust control theory based performance investigation of an inverted pendulum...Robust control theory based performance investigation of an inverted pendulum...
Robust control theory based performance investigation of an inverted pendulum...Mustefa Jibril
 
Attitude Control of Satellite Test Setup Using Reaction Wheels
Attitude Control of Satellite Test Setup Using Reaction WheelsAttitude Control of Satellite Test Setup Using Reaction Wheels
Attitude Control of Satellite Test Setup Using Reaction WheelsA. Bilal Özcan
 
1 mrac for inverted pendulum
1 mrac for inverted pendulum1 mrac for inverted pendulum
1 mrac for inverted pendulumnazir1988
 
Comparative analysis of observer-based LQR and LMI controllers of an inverted...
Comparative analysis of observer-based LQR and LMI controllers of an inverted...Comparative analysis of observer-based LQR and LMI controllers of an inverted...
Comparative analysis of observer-based LQR and LMI controllers of an inverted...journalBEEI
 
07 15 sep14 6532 13538-1-rv-edit_
07 15 sep14 6532 13538-1-rv-edit_07 15 sep14 6532 13538-1-rv-edit_
07 15 sep14 6532 13538-1-rv-edit_IAES-IJPEDS
 
Stabilized controller of a two wheels robot
Stabilized controller of a two wheels robotStabilized controller of a two wheels robot
Stabilized controller of a two wheels robotjournalBEEI
 
Modelling and Control of Ground Test Set-up of Attitude of Satellite
Modelling and Control of Ground Test Set-up of Attitude of SatelliteModelling and Control of Ground Test Set-up of Attitude of Satellite
Modelling and Control of Ground Test Set-up of Attitude of SatelliteA. Bilal Özcan
 
Intermittent predictive control of an inverted pendulum
Intermittent predictive control of an inverted pendulumIntermittent predictive control of an inverted pendulum
Intermittent predictive control of an inverted pendulumIvan Tim Oloya
 
Welcome to International Journal of Engineering Research and Development (IJERD)
Welcome to International Journal of Engineering Research and Development (IJERD)Welcome to International Journal of Engineering Research and Development (IJERD)
Welcome to International Journal of Engineering Research and Development (IJERD)IJERD Editor
 
Real Time Implementation of Fuzzy Adaptive PI-sliding Mode Controller for Ind...
Real Time Implementation of Fuzzy Adaptive PI-sliding Mode Controller for Ind...Real Time Implementation of Fuzzy Adaptive PI-sliding Mode Controller for Ind...
Real Time Implementation of Fuzzy Adaptive PI-sliding Mode Controller for Ind...IJECEIAES
 

Mais procurados (20)

final year presentation
final year presentationfinal year presentation
final year presentation
 
final project
final projectfinal project
final project
 
report
reportreport
report
 
The stabilization of forced inverted pendulum via fuzzy controller
The stabilization of forced inverted pendulum via fuzzy controllerThe stabilization of forced inverted pendulum via fuzzy controller
The stabilization of forced inverted pendulum via fuzzy controller
 
2_DOF_Inverted_Pendulum_Laboratory_Session
2_DOF_Inverted_Pendulum_Laboratory_Session2_DOF_Inverted_Pendulum_Laboratory_Session
2_DOF_Inverted_Pendulum_Laboratory_Session
 
Backstepping control of cart pole system
Backstepping  control of cart pole systemBackstepping  control of cart pole system
Backstepping control of cart pole system
 
Analysis of a pendulum problem
Analysis of a pendulum problemAnalysis of a pendulum problem
Analysis of a pendulum problem
 
Simulation of inverted pendulum presentation
Simulation of inverted pendulum  presentationSimulation of inverted pendulum  presentation
Simulation of inverted pendulum presentation
 
FINAL PROJ REP
FINAL PROJ REPFINAL PROJ REP
FINAL PROJ REP
 
Linear quadratic regulator and pole placement for stabilizing a cart inverted...
Linear quadratic regulator and pole placement for stabilizing a cart inverted...Linear quadratic regulator and pole placement for stabilizing a cart inverted...
Linear quadratic regulator and pole placement for stabilizing a cart inverted...
 
Robust control theory based performance investigation of an inverted pendulum...
Robust control theory based performance investigation of an inverted pendulum...Robust control theory based performance investigation of an inverted pendulum...
Robust control theory based performance investigation of an inverted pendulum...
 
Attitude Control of Satellite Test Setup Using Reaction Wheels
Attitude Control of Satellite Test Setup Using Reaction WheelsAttitude Control of Satellite Test Setup Using Reaction Wheels
Attitude Control of Satellite Test Setup Using Reaction Wheels
 
1 mrac for inverted pendulum
1 mrac for inverted pendulum1 mrac for inverted pendulum
1 mrac for inverted pendulum
 
Comparative analysis of observer-based LQR and LMI controllers of an inverted...
Comparative analysis of observer-based LQR and LMI controllers of an inverted...Comparative analysis of observer-based LQR and LMI controllers of an inverted...
Comparative analysis of observer-based LQR and LMI controllers of an inverted...
 
07 15 sep14 6532 13538-1-rv-edit_
07 15 sep14 6532 13538-1-rv-edit_07 15 sep14 6532 13538-1-rv-edit_
07 15 sep14 6532 13538-1-rv-edit_
 
Stabilized controller of a two wheels robot
Stabilized controller of a two wheels robotStabilized controller of a two wheels robot
Stabilized controller of a two wheels robot
 
Modelling and Control of Ground Test Set-up of Attitude of Satellite
Modelling and Control of Ground Test Set-up of Attitude of SatelliteModelling and Control of Ground Test Set-up of Attitude of Satellite
Modelling and Control of Ground Test Set-up of Attitude of Satellite
 
Intermittent predictive control of an inverted pendulum
Intermittent predictive control of an inverted pendulumIntermittent predictive control of an inverted pendulum
Intermittent predictive control of an inverted pendulum
 
Welcome to International Journal of Engineering Research and Development (IJERD)
Welcome to International Journal of Engineering Research and Development (IJERD)Welcome to International Journal of Engineering Research and Development (IJERD)
Welcome to International Journal of Engineering Research and Development (IJERD)
 
Real Time Implementation of Fuzzy Adaptive PI-sliding Mode Controller for Ind...
Real Time Implementation of Fuzzy Adaptive PI-sliding Mode Controller for Ind...Real Time Implementation of Fuzzy Adaptive PI-sliding Mode Controller for Ind...
Real Time Implementation of Fuzzy Adaptive PI-sliding Mode Controller for Ind...
 

Semelhante a Real-time PID control of an inverted pendulum

Optimal and pid controller for controlling camera’s position in unmanned aeri...
Optimal and pid controller for controlling camera’s position in unmanned aeri...Optimal and pid controller for controlling camera’s position in unmanned aeri...
Optimal and pid controller for controlling camera’s position in unmanned aeri...Zac Darcy
 
Optimal and Pid Controller for Controlling Camera's Position InUnmanned Aeria...
Optimal and Pid Controller for Controlling Camera's Position InUnmanned Aeria...Optimal and Pid Controller for Controlling Camera's Position InUnmanned Aeria...
Optimal and Pid Controller for Controlling Camera's Position InUnmanned Aeria...Zac Darcy
 
Modeling, simulation and control of a robotic arm
Modeling, simulation and control of a robotic armModeling, simulation and control of a robotic arm
Modeling, simulation and control of a robotic armcesarportilla8
 
D0255033039
D0255033039D0255033039
D0255033039theijes
 
IJSRED-V2I5P33
IJSRED-V2I5P33IJSRED-V2I5P33
IJSRED-V2I5P33IJSRED
 
IRJET- Speed Control of Induction Motor using Hybrid PID Fuzzy Controller
IRJET- Speed Control of Induction Motor using Hybrid PID Fuzzy ControllerIRJET- Speed Control of Induction Motor using Hybrid PID Fuzzy Controller
IRJET- Speed Control of Induction Motor using Hybrid PID Fuzzy ControllerIRJET Journal
 
control system lab 02 - PID tuning
control system lab 02 - PID tuning control system lab 02 - PID tuning
control system lab 02 - PID tuning nalan karunanayake
 
Lecture Notes: EEEC4340318 Instrumentation and Control Systems - Introductio...
Lecture Notes:  EEEC4340318 Instrumentation and Control Systems - Introductio...Lecture Notes:  EEEC4340318 Instrumentation and Control Systems - Introductio...
Lecture Notes: EEEC4340318 Instrumentation and Control Systems - Introductio...AIMST University
 
Design of imc based controller for industrial purpose
Design of imc based controller for industrial purposeDesign of imc based controller for industrial purpose
Design of imc based controller for industrial purpose375ankit
 
Chapter 8 - Robot Control System
Chapter 8 - Robot Control SystemChapter 8 - Robot Control System
Chapter 8 - Robot Control SystemHaffiz Radzi
 
Reviews of Cascade Control of Dc Motor with Advance Controller
Reviews of Cascade Control of Dc Motor with Advance ControllerReviews of Cascade Control of Dc Motor with Advance Controller
Reviews of Cascade Control of Dc Motor with Advance Controllerijsrd.com
 
Speed control of dc motor using relay feedback tuned pi
Speed control of dc motor using relay feedback tuned piSpeed control of dc motor using relay feedback tuned pi
Speed control of dc motor using relay feedback tuned piAlexander Decker
 
Iaetsd design of fuzzy self-tuned load frequency controller for power system
Iaetsd design of fuzzy self-tuned load frequency controller for power systemIaetsd design of fuzzy self-tuned load frequency controller for power system
Iaetsd design of fuzzy self-tuned load frequency controller for power systemIaetsd Iaetsd
 
Speed control of a dc motor a matlab approach
Speed control of a dc motor a matlab approachSpeed control of a dc motor a matlab approach
Speed control of a dc motor a matlab approachIAEME Publication
 

Semelhante a Real-time PID control of an inverted pendulum (20)

Optimal and pid controller for controlling camera’s position in unmanned aeri...
Optimal and pid controller for controlling camera’s position in unmanned aeri...Optimal and pid controller for controlling camera’s position in unmanned aeri...
Optimal and pid controller for controlling camera’s position in unmanned aeri...
 
Optimal and Pid Controller for Controlling Camera's Position InUnmanned Aeria...
Optimal and Pid Controller for Controlling Camera's Position InUnmanned Aeria...Optimal and Pid Controller for Controlling Camera's Position InUnmanned Aeria...
Optimal and Pid Controller for Controlling Camera's Position InUnmanned Aeria...
 
Modeling, simulation and control of a robotic arm
Modeling, simulation and control of a robotic armModeling, simulation and control of a robotic arm
Modeling, simulation and control of a robotic arm
 
D0255033039
D0255033039D0255033039
D0255033039
 
IJSRED-V2I5P33
IJSRED-V2I5P33IJSRED-V2I5P33
IJSRED-V2I5P33
 
IRJET- Speed Control of Induction Motor using Hybrid PID Fuzzy Controller
IRJET- Speed Control of Induction Motor using Hybrid PID Fuzzy ControllerIRJET- Speed Control of Induction Motor using Hybrid PID Fuzzy Controller
IRJET- Speed Control of Induction Motor using Hybrid PID Fuzzy Controller
 
CE150--Hongyi Huang
CE150--Hongyi HuangCE150--Hongyi Huang
CE150--Hongyi Huang
 
control system lab 02 - PID tuning
control system lab 02 - PID tuning control system lab 02 - PID tuning
control system lab 02 - PID tuning
 
Control
ControlControl
Control
 
Lecture Notes: EEEC4340318 Instrumentation and Control Systems - Introductio...
Lecture Notes:  EEEC4340318 Instrumentation and Control Systems - Introductio...Lecture Notes:  EEEC4340318 Instrumentation and Control Systems - Introductio...
Lecture Notes: EEEC4340318 Instrumentation and Control Systems - Introductio...
 
Design of imc based controller for industrial purpose
Design of imc based controller for industrial purposeDesign of imc based controller for industrial purpose
Design of imc based controller for industrial purpose
 
Chapter 8 - Robot Control System
Chapter 8 - Robot Control SystemChapter 8 - Robot Control System
Chapter 8 - Robot Control System
 
B010511015
B010511015B010511015
B010511015
 
air craft Pitch
air craft Pitchair craft Pitch
air craft Pitch
 
PSOC.pptx
PSOC.pptxPSOC.pptx
PSOC.pptx
 
Reviews of Cascade Control of Dc Motor with Advance Controller
Reviews of Cascade Control of Dc Motor with Advance ControllerReviews of Cascade Control of Dc Motor with Advance Controller
Reviews of Cascade Control of Dc Motor with Advance Controller
 
Speed control of dc motor using relay feedback tuned pi
Speed control of dc motor using relay feedback tuned piSpeed control of dc motor using relay feedback tuned pi
Speed control of dc motor using relay feedback tuned pi
 
Pi controller ieee format
Pi controller ieee formatPi controller ieee format
Pi controller ieee format
 
Iaetsd design of fuzzy self-tuned load frequency controller for power system
Iaetsd design of fuzzy self-tuned load frequency controller for power systemIaetsd design of fuzzy self-tuned load frequency controller for power system
Iaetsd design of fuzzy self-tuned load frequency controller for power system
 
Speed control of a dc motor a matlab approach
Speed control of a dc motor a matlab approachSpeed control of a dc motor a matlab approach
Speed control of a dc motor a matlab approach
 

Mais de Francesco Corucci

Teleoperating a robotic arm through a gyroscopic helmet
Teleoperating a robotic arm through a gyroscopic helmetTeleoperating a robotic arm through a gyroscopic helmet
Teleoperating a robotic arm through a gyroscopic helmetFrancesco Corucci
 
Social Network Analysis Project
Social Network Analysis ProjectSocial Network Analysis Project
Social Network Analysis ProjectFrancesco Corucci
 
A wearable MIDI interface using a wireless sensor network
A wearable MIDI interface using a wireless sensor networkA wearable MIDI interface using a wireless sensor network
A wearable MIDI interface using a wireless sensor networkFrancesco Corucci
 
Implementation of a lane-tracking system for autonomous driving using Kalman ...
Implementation of a lane-tracking system for autonomous driving using Kalman ...Implementation of a lane-tracking system for autonomous driving using Kalman ...
Implementation of a lane-tracking system for autonomous driving using Kalman ...Francesco Corucci
 
An overview on Quantum Key Distribution
An overview on Quantum Key DistributionAn overview on Quantum Key Distribution
An overview on Quantum Key DistributionFrancesco Corucci
 
P-Systems for approximating NP-Complete optimization problems
P-Systems for approximating NP-Complete optimization problemsP-Systems for approximating NP-Complete optimization problems
P-Systems for approximating NP-Complete optimization problemsFrancesco Corucci
 

Mais de Francesco Corucci (6)

Teleoperating a robotic arm through a gyroscopic helmet
Teleoperating a robotic arm through a gyroscopic helmetTeleoperating a robotic arm through a gyroscopic helmet
Teleoperating a robotic arm through a gyroscopic helmet
 
Social Network Analysis Project
Social Network Analysis ProjectSocial Network Analysis Project
Social Network Analysis Project
 
A wearable MIDI interface using a wireless sensor network
A wearable MIDI interface using a wireless sensor networkA wearable MIDI interface using a wireless sensor network
A wearable MIDI interface using a wireless sensor network
 
Implementation of a lane-tracking system for autonomous driving using Kalman ...
Implementation of a lane-tracking system for autonomous driving using Kalman ...Implementation of a lane-tracking system for autonomous driving using Kalman ...
Implementation of a lane-tracking system for autonomous driving using Kalman ...
 
An overview on Quantum Key Distribution
An overview on Quantum Key DistributionAn overview on Quantum Key Distribution
An overview on Quantum Key Distribution
 
P-Systems for approximating NP-Complete optimization problems
P-Systems for approximating NP-Complete optimization problemsP-Systems for approximating NP-Complete optimization problems
P-Systems for approximating NP-Complete optimization problems
 

Último

Pigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesSinan KOZAK
 
Artificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning eraArtificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning eraDeakin University
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationRidwan Fadjar
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 3652toLead Limited
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Patryk Bandurski
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...shyamraj55
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Mattias Andersson
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machinePadma Pradeep
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Scott Keck-Warren
 
Build your next Gen AI Breakthrough - April 2024
Build your next Gen AI Breakthrough - April 2024Build your next Gen AI Breakthrough - April 2024
Build your next Gen AI Breakthrough - April 2024Neo4j
 
Bluetooth Controlled Car with Arduino.pdf
Bluetooth Controlled Car with Arduino.pdfBluetooth Controlled Car with Arduino.pdf
Bluetooth Controlled Car with Arduino.pdfngoud9212
 
Snow Chain-Integrated Tire for a Safe Drive on Winter Roads
Snow Chain-Integrated Tire for a Safe Drive on Winter RoadsSnow Chain-Integrated Tire for a Safe Drive on Winter Roads
Snow Chain-Integrated Tire for a Safe Drive on Winter RoadsHyundai Motor Group
 
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr LapshynFwdays
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024Scott Keck-Warren
 
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024BookNet Canada
 
APIForce Zurich 5 April Automation LPDG
APIForce Zurich 5 April  Automation LPDGAPIForce Zurich 5 April  Automation LPDG
APIForce Zurich 5 April Automation LPDGMarianaLemus7
 

Último (20)

Pigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping Elbows
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen Frames
 
Artificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning eraArtificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning era
 
Vulnerability_Management_GRC_by Sohang Sengupta.pptx
Vulnerability_Management_GRC_by Sohang Sengupta.pptxVulnerability_Management_GRC_by Sohang Sengupta.pptx
Vulnerability_Management_GRC_by Sohang Sengupta.pptx
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 Presentation
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machine
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024
 
Build your next Gen AI Breakthrough - April 2024
Build your next Gen AI Breakthrough - April 2024Build your next Gen AI Breakthrough - April 2024
Build your next Gen AI Breakthrough - April 2024
 
Bluetooth Controlled Car with Arduino.pdf
Bluetooth Controlled Car with Arduino.pdfBluetooth Controlled Car with Arduino.pdf
Bluetooth Controlled Car with Arduino.pdf
 
Snow Chain-Integrated Tire for a Safe Drive on Winter Roads
Snow Chain-Integrated Tire for a Safe Drive on Winter RoadsSnow Chain-Integrated Tire for a Safe Drive on Winter Roads
Snow Chain-Integrated Tire for a Safe Drive on Winter Roads
 
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
 
Hot Sexy call girls in Panjabi Bagh 🔝 9953056974 🔝 Delhi escort Service
Hot Sexy call girls in Panjabi Bagh 🔝 9953056974 🔝 Delhi escort ServiceHot Sexy call girls in Panjabi Bagh 🔝 9953056974 🔝 Delhi escort Service
Hot Sexy call girls in Panjabi Bagh 🔝 9953056974 🔝 Delhi escort Service
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024
 
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
 
APIForce Zurich 5 April Automation LPDG
APIForce Zurich 5 April  Automation LPDGAPIForce Zurich 5 April  Automation LPDG
APIForce Zurich 5 April Automation LPDG
 
The transition to renewables in India.pdf
The transition to renewables in India.pdfThe transition to renewables in India.pdf
The transition to renewables in India.pdf
 

Real-time PID control of an inverted pendulum

  • 1. 1 Real-time PID control of an inverted pendulum Pasquale Buonocunto – Francesco Corucci – MSc in Computer Engineering, University of Pisa – Italy "In theory, there is no difference between theory and practice. But, in practice, there is" Jan L. A. van de Snepscheut 1 Introduction In this report we will describe a project we developed for an Embedded Systems class. Our goal was to experiment in practice with a simple control plant, that could be approached with the famous PID controller. When moving from simulation to practical implementation a lot of unexpected issues arise, and must be handled: this forced us to deeply understand the essence of the problem. 2 Brief description of the physical system The case study consisted in the control of an inverted pendulum, in the cart-and-pole version. As shown in Figure 1, there is a pole with a mass mounted on his top, hinged on a cart that can move horizontally. The control goal is to stabilize the pole in the vertical position ( ), corresponding to an unstable equilibrium. Figure 1 - Model of the physical system
  • 2. 2 3 Testbed 3.1 Plant Figure 2 shows the real plant on which we worked. The cart is actuated with a DC motor through a belt: the motor also provides an encoder, that we used to deduce the horizontal position of the cart. The inclination of the pole is measured with a potentiometer placed at its bottom. Figure 2 – The plant The motor (Figure 3) is a ESCAP DC MOTOR/ENCODER 22V E9-0500-2.0-1: it is a little bit underutilized since the board Belt Potentiometer DC Motor Motor encoder Figure 3 - The DC motor used to control the plant
  • 3. 3 provides it less voltage/current than expected, but we used it anyway since we had just demonstration purposes (otherwise a dedicated power circuit should have been necessary). Other limitations of the plant will be discussed later in this paper. 3.2 Control electronics Figure 4 shows the control electronics. Figure 4 - Control electronics We used an Evidence1 FLEX motion board equipped with the DC Motor plug-in. The board mounts a microcontroller of the dsPIC33 serie. We also realized a simple circuit with three potentiometers, in order to be able to regulate online the control parameters. The wiring is realized as follows (refer to the appendix for the nomenclature): 1 http://www.evidence.eu.com CON23 PIN NO. 4 3 2 1 CONNECTED TO B A + - CON22 PIN NO. 2 CONNECTED TO ENC_STDBY CON24 PIN NO. 4 3 CONNECTED TO Vmotor+ Vmotor-
  • 4. 4 CON8 PIN NO. 20 19 12 10 2 1 CONNECTED TO - + Ki_POT Kd_POT POLE_POT Kp_POT DC Motor + encoder B, A, +, - Vmotor+, Vmotor- ENC_STDBY EncoderDC motor Kp Ki Kd + Bar potentiometer - Figure 5 - Wiring scheme
  • 5. 5 4 Angle control: the first PID controller For what concerns the stabilization of the pole, we implemented a speed control of the DC motor using a PID controller. Below the digital implementation of the PID controller (simplified code): float PID(float setpoint,float actual_position) { static float pre_error = 0.0; static float integral = 0.0; static EE_UINT8 count = 0; static float errors[I_WINDOW_SIZE]; float error; float derivative; float output; EE_UINT8 i; ... // Calculate error error = setpoint - actual_position; // Integral component if(Ki > 0.0 && WINDOWED_INTEGR) { // Windowed integration mode integral = 0.0; // The truncated integration is realized with // a cyclic array // Insert new value in the window errors[count] = error; // Update counter count = (count+1) % I_WINDOW_SIZE; // Accumulation for(i = 0; i < I_WINDOW_SIZE; i++) integral += errors[i]*dt; } else if(Ki > 0.0) // Non-windowed integration mode integral += error*dt; // // Anti-windup saturation of integral component // float Ki_integral = Ki*integral; if(Ki_integral> ANTI_WINDUP_THR) Ki_integral = ANTI_WINDUP_THR;
  • 6. 6 else if(Ki_integral < -ANTI_WINDUP_THR) Ki_integral = -ANTI_WINDUP_THR; // Derivative component derivative = (error - pre_error)/dt; // Calculate output output = Kp*error + Ki_integral + Kd*derivative; ... //Saturation Filter if(output > MAX_PID) { output = MAX_PID; } else if(output < MIN_PID) { output = MIN_PID; } //Update error pre_error = error; return output; } Figure 6 - Digital implementation of the PID controller Some comments about the code: - It is possible to choose two different modes of integration: windowed and not windowed - Our PID provides an anti-windup saturation of the integral component - The control output is (obviously) saturated 5 Position control: the second PID A PID is sufficient to stabilize the pole in a vertical position, but since the rail is bounded it is important to make the controller aware of the fact that it could end up hitting the physical bounds of the rail (this is possible in practice using an encoder placed on the DC motor, whose angular information is translated into a linear one). A software strategy that tries to manually manage this condition preserving the stability of the pole is quite difficult to think. We thought that the better thing to do was to try to keep the cart away from the bounds (ideally in the center of the rail)
  • 7. 7 with some additional control, in order to decrease the probability of hitting the bounds. Theoretically speaking it should be necessary a much more complex modellization in order to simultaneously control the angle of the pole and the position of the cart, since the two variables are not independent. However, trying to keep things easy, we tried an alternative way to realize something similar to the ideal behavior. We programmed two independent PID controllers, one for the angle stabilization, one for the position stabilization, and we tuned the parameters in order to give more priority to the angle stabilization: this way we are able to obtain a quite stable system, that tries to converge to the center of the rail when this does not disturb the pole stabilization. This corresponds to a simplification of the model, that can be mitigated with an appropriate tuning of the parameters2 . We like to think this simplified modellization as if the second PID (the position control) acts like a disturbance on the first PID (the angle stabilization controller). Figure 7 shows the block description of the system. The code below illustrates how this was implemented (pseudocode): float current_position = <get pole inclination>; float current_ticks = <get cart displacement from center>; float angle_control = PID1(ANGLE_SETPOINT, current_position); float position_control = PID2(POSITION_SETPOINT, current_ticks); float control = angle_control + position_control; <saturation of the resulting control variable> Figure 8 - Control variable calculation 2 This is the interpretation we gave to our idea, that seems to be confirmed by some works found in literature, like [1] Ref angle PID1 PID2 Ref pos + PLANT + - + - pole_angle cart_position angle_control pos_control control Figure 7 - Complete control system
  • 8. 8 For what concerns the output control variable (controlling the speed of the DC motor), it was saturated from -100 to +100, using the sign as discriminator for the direction. The amplitude is from 0 to 100 because the control is a PWM duty creating a linear voltage for the DC motor. However, due to practical limitations caused by the cart friction on the rail, the minimum PWM duty cycle usefull to really move the cart is quite high (about 30% with good lubrification), so we limitated it in a shorter range defined by two thresholds (±[MIN_PID, MAX_PID]). 6 PID tuning Given the control system architecture, the proper way to tune the whole system is the following: 1. Keeping the second PID disabled, tune the parameters of the first PID (the angle stabilization one) as if it is the only controller in the system; 2. Once the angle stability is reached, enable and tune the second PID (the position control one) with “light” parameters, in order to preserve the angle stabilization previously obtained. The single PID can be tuned with any of the classical methods, such Ziegler-Nichols: we followed an heuristic methodology inspired to the latter, also driven by the practical interpretation we gave to every parameter. 7 Software organization The application is composed of 5 tasks: - TASK_HOMING [aperiodic]: activated only one time at the startup, it manages the necessary homing steps in order to make system aware of the control set points (rail center, and pole equilibrium position). It requires the user intervention. - TASK_POSITION_CONTROL [period: 150ms, priority: 53 ]: reads the position of the cart and calculates the PID for the position control. The computed value is used from the the angle control task, that performs the real actuation merging the two control variables. - TASK_ANGLE_CONTROL [period: 50ms, priority: 6]: reads the inclination of the bar, calculates the PID for the stabilization of the bar, combines this value with the one from the position control task, then actuates the motor. 3 Task priority in OSEK is specified by a number from 1 to 10. Higher values represents higher priorities
  • 9. 9 - TASK_READ_POT [period: 200ms, priority: 3]: this task acquires values from the three external potentiometer, and updates the control parameters accordingly. - TASK_SERIAL_PRINT [period: 500ms, priority: 2]: feedsback some useful information via UART. Figure 9 shows the execution flow of the application: 8 Running demonstration A running demonstration of the implemented system can be viewed in the following videos: http://www.youtube.com/watch?v=zEF6a_m0kdQ http://www.youtube.com/watch?v=9Mg-y6TDef4 9 Limitations The physical system we worked on presented considerable non-idealities, that made quite hard the task of making things work properly. The main limitation of the plant relies in the friction between the rail and the cart, that remains considerable also with appropriate lubrification. Also the traction offered by the belt is asymmetric in the two direction and causes some extra friction. Another issue relies in the motor, its poor precision and its underutilization (since the board provides it less voltage/current than 1. Maintain the bar, press the button, and let the cart scan the rail to identify the center 2. Once the cart have reached the center of the rail, put the pole in the steady state and press again the button main init TASK_HOMING button pressed / activate task TASK_POSITION_ CONTROL TASK_ANGLE_ CONTROL button pressed / activate task TASK_SERIAL_ PRINT TASK_READ_ POT Figure 9 - Execution flow
  • 10. 10 expected). The final effect of these limitation is that the movements of the cart are inevitably jerky, making quite difficult to obtain a smooth control and, as a consequence, a good stabilization of the system. 10 Future work The potentiometer used to read the inclination of the pole is quite noisy: with a rough strategy, we just truncated the measures after the second decimal digit, because all we got beyond that was nothing but noise. This was enough for our purposes, but it should be interesting, instead, to implement some filtering strategy to gain accuracy in the angle measurement. For example it could be usefull to oversample the value with a higher frequency in respect to the control frequency (i.e. the frequency with which the measure is consumed), and then apply some filtering (es: low pass, median, …). Another filter that is commonly used in this context is the Kalman filter, used to estimate the measure ensuring a good immunity to noise. 11 References [1] “Simulation and Robustness Studies on an Inverted Pendulum”, HUANG Chun-E, LI Dong-Hai, SU Yong, Proceedings of the 30th Chinese Control Conference, July 22-24, 2011, Yantai, China
  • 12. 12