Practicals Labs
Practicals Labs
INSTRUCTIONS
1. In carrying out the following laboratory exercises, you can form groups of 8 to 10 students
each that must be maintained across all the exercises. Use the same groups as in the
assignments.
2. Write lab reports in the constituted groups (but show workload distribution).
3. Use MATLAB & SIMULINK Software.
4. Submit softcopy reports IN WORD FORMAT to laloo@jkuat.ac.ke for the lab exercises.
5. Also, be ready to present if called upon to do so.
6. The labs shall be due for submission on or before 30/11/2024.
1
EEE 2507 CONTROL ENGINEERING IV
Laboratory Experiment 1
TITLE: CONTINUOUS TIME PID CONTROLLER
Figure 1 shows the elements of a closed-loop temperature control system.
2
EEE 2507 CONTROL ENGINEERING IV
12. Tune the PD controller to obtain the optimal gains and comment on the results obtained
13. Change the controller to a PID with 𝐾𝑃 = 10, 𝐾𝐼 = 10 and 𝐾𝐷 = 4 controller. Discuss
the effects of the PID controller in the system.
14. Tune the PID controller to obtain the optimal gains and comment on the results obtained
15. Based on the results obtained throughout the procedures, choose the best controller for
this system.
16. Recommend on some of the techniques that can be used to improve on the performance
of the closed-loop temperature control system undertaken in this lab.
Laboratory Experiment 2
DISCRETE CONTROLLER DESIGN IN MATLAB
1. Design a discrete PID controller for the following plants using MATLAB & SIMULINK.
a) G ( s ) Y ( s ) 663
Ri ( s ) s 101.71s 2 171s 663
3
b) Y ( s) 97.43
G ( s)
Ri ( s ) s 3 81.68s 2 481.63s 97.43
1
c) 𝐺(𝑠) = (𝑠+1)(𝑠+2)(𝑠+5)
2. Fig. 2 shows a simplified model of a digital antenna position control system using
servomechanism. Using MATLAB & SIMULINK,
a) Draw a SIMULINK simulation block diagram of the system.
b) Using MATLAB code, find the closed-loop digital transfer function for this system and
determine if the system is stable for 𝐾 = 20 and 𝐾 = 65 with a sampling interval of
𝑇 = 0.2 second.
c) Plot a curve to show variations in output position with time for 𝐾 = 20 and 𝐾 = 60.
Motor-gear-load
Sample Hold Amplifier system
10 Output position
Position + 1 − 𝑒 −𝑇𝑠
_ 𝐾
command 𝑠 𝑠(𝑠 + 10)
Sample
Fig. 2
3
EEE 2507 CONTROL ENGINEERING IV
Output
K[M-A]
-M -A A M Input
-K[M-A]
Fig. 3
Output
K
-M -A A M
Fig.4
4
EEE 2507 CONTROL ENGINEERING IV
Methodology/Procedure
Here, you are required to choose your own second-order and third systems to run through the steps
that have been highlighted using the second-order nonlinear pendulum system.
1. System Definition:
Choose a simple nonlinear system, for example, a second-order nonlinear system like a
pendulum:
Select a candidate Lyapunov function. For the pendulum system, a suitable Lyapunov
function is:
This function is chosen based on the energy of the system (kinetic and potential energy).
̇
3. Deriving the Time Derivative 𝑉(𝑥):
5
EEE 2507 CONTROL ENGINEERING IV
4. MATLAB Implementation:
Step 1: Define the Nonlinear System
Create a MATLAB script or function to define the system:
function dxdt = pendulum_system(t, x)
k = 0.5; % Damping coefficient
dxdt = [x(2); -sin(x(1)) - k*x(2)];
end
function V = lyapunov_function(x)
V = 0.5 * x(2)^2 + (1 - cos(x(1))); % Lyapunov function
end
Use MATLAB's ODE solver to simulate the system's response over time:
6
EEE 2507 CONTROL ENGINEERING IV
plot(t, V_values);
xlabel('Time (s)');
ylabel('Lyapunov Function V(x)');
title('Lyapunov Function over Time');
5. Analysis of Results
The plot of 𝑉(𝑥) should show that the Lyapunov function decreases over time, confirming
that the system is asymptotically stable.
The plot of 𝑉(𝑥) ̇ should show negative values, confirming that the system’s energy is
dissipating over time.
6. Discussion:
If the Lyapunov function remains positive and its derivative is negative definite, the system
is asymptotically stable.
If V˙(x) is negative semi-definite, the system is stable but not necessarily asymptotically
stable.
If no valid Lyapunov function can be found or V˙(x) is positive for some states, the system
is unstable.
Provide a detailed presentation and analysis of the results obtained from your two selected non-
linear systems.
Conclusion
Provide your conclusions here.
References
Provide your references here.
7
EEE 2507 CONTROL ENGINEERING IV
𝑥̇ 1 (𝑡) 0 5 𝑥1 (𝑡) 0
[ ]=[ ][ ] + [ ] 𝑢(𝑡)
𝑥̇ 2 (𝑡) 0 0 𝑥2 (𝑡) 1
The system is to be controlled using LQR method to minimize the performance index
1 2
𝐽(𝑥1 , 𝑥2 , 𝑢) = ∫ 𝑢2 (𝑡) 𝑑𝑡
2 0
with boundary conditions
𝑥1 (0) 1 𝑥 (2) 2
[ ] = [ ] and [ 1 ] = [ ]
𝑥2 (0) 1 𝑥2 (2) 1
a) Draw a SIMULINK simulation diagram required to implement the Optimal Tracking
System
b) Design an LQR controller by finding the optimal control law and optimal states, in
MATLAB.
c) Plot variations of the states 𝑥1 (𝑡) and 𝑥2 (𝑡)with time.
Objective:
This lab aims to solve an optimal control problem involving trajectory planning with constraints
using MATLAB's 'fmincon' function. The focus is on optimizing a trajectory while respecting the
given constraints on control inputs, states, and final conditions.
Theory Overview:
In optimal trajectory planning, the objective is to find the best possible path for a system to follow,
minimizing a given performance criterion such as energy consumption or time, while satisfying
system dynamics and constraints on the states and controls.
8
EEE 2507 CONTROL ENGINEERING IV
'fmincon' is a MATLAB function that finds the minimum of a constrained nonlinear multivariable
function. It is widely used for optimization problems with bounds, linear constraints, and nonlinear
constraints.
Problem Definition:
Consider a system described by simple kinematic equations, where the goal is to move an object
from an initial position to a target position in minimum time while satisfying velocity and
acceleration constraints.
The optimization problem is to minimize the objective function representing time, subject to the
constraints on control (acceleration) and state (velocity and position).
9
EEE 2507 CONTROL ENGINEERING IV
Methodology/Procedure
First use the system presented next and then choose your own system to demonstrate the
application of MATLAB's 'fmincon' for solving optimal control problems with constraints. By
using 'fmincon', optimize the trajectory of the selected system while adhering to the given state
and control limits. You may consider real-world applications like robotics, autonomous vehicles,
and aerospace systems.
1. Define the System Dynamics:
The dynamics of a simple point mass system can be defined as:
dx/dt = v (velocity)
dv/dt = u (acceleration, control input)
The state variables are position (x) and velocity (v), and the control input is acceleration (u).
For instance, in MATLAB, we will solve the optimal control problem using fmincon. The
fmincon function minimizes a nonlinear objective function with constraints. The function syntax
is:
10
EEE 2507 CONTROL ENGINEERING IV
matlab
Copy code
x_opt = fmincon(fun,x0,A,b,Aeq,beq,lb,ub,nonlcon)
Define the system dynamics in a separate function. This function will represent the evolution of
the state:
matlab
Copy code
function dxdt = system_dynamics(t, x, u)
dxdt = [x(2); u];
end
matlab
Copy code
function J = cost_function(tf)
J = tf;
end
Include the constraints for velocity and acceleration in a nonlinear constraint function:
matlab
Copy code
function [c, ceq] = nonlin_constraints(x, u, tf, x0, xf)
% Dynamics constraints
ceq = system_dynamics(0, x0, u) - x; % Initial conditions
% Control and state constraints
c = [abs(u) - u_max; abs(x(2)) - v_max];
end
matlab
Copy code
% Initial guess for control input and final time
u0 = zeros(N,1); % Initial guess for control input
tf_guess = 10; % Initial guess for final time
11
EEE 2507 CONTROL ENGINEERING IV
After solving the optimization problem, plot the results to visualize the optimal trajectory, control
inputs (acceleration), and the time taken to reach the target position. Verify that the solution
satisfies all the constraints and analyze the behavior of the system.
Once the fmincon function converges, analyze the optimal trajectory and control input. You can
use MATLAB to visualize the position, velocity, and control input as a function of time.
matlab
Copy code
% Simulate the system with the optimal control input
[t, x] = ode45(@(t,x) system_dynamics(t, x, u_opt), [0, tf_guess], x0);
% Plot results
figure;
subplot(3,1,1);
plot(t, x(:,1)); xlabel('Time (s)'); ylabel('Position (m)');
title('Optimal Position vs Time');
subplot(3,1,2);
plot(t, x(:,2)); xlabel('Time (s)'); ylabel('Velocity (m/s)');
title('Optimal Velocity vs Time');
subplot(3,1,3);
plot(t, u_opt); xlabel('Time (s)'); ylabel('Acceleration (m/s^2)');
title('Optimal Control Input (Acceleration) vs Time');
Conclusion
Provide your conclusions.
References
Provide your references here.
12