MBB 410 Practicals
MBB 410 Practicals
Question 1 [3 Marks]
Create a model of a mass-spring-damper system with the mass (m in kg), undamped natural
frequency (ωn in rad/s) and damping coefficient (zeta) as defined by your dataset, using b0 = 1 so
that
ω2n
Gmck (s) =
s2 + 2ζωn s + ω2n
[1] Store the transfer function of the mass-spring-damper system in the variable Gmck
[2] Calculate the damped natural frequency w in rad/s
[3] Calculate the poles of Gmck, poles
Solution
2
3
Question 2 [7 Marks]
Calculate and plot the response for Gmck with a unit force step. Using this graph, return the
following parameters using the specified variables:
[1] Overshoot, OS
[2] Steady-state value, xss
[3] Rise time, tr
1
MBB 410 – Mechatronics and Control Practicals
Solution
2
MBB 410 – Mechatronics and Control Practicals
Figure 1
1
2
3
4
5
6
7
Question 3 [2 Marks]
Plot the bode diagram of Gmck. From the bode diagram, determine
Solution
3
MBB 410 – Mechatronics and Control Practicals
Figure 3
1
2
Question 4 [5 Marks]
Using the Process Reaction Method, calculate the gains for a PID controller using P = 6% step input.
Return the following variables:
[1] Lag, L
[2] Maximum gradient, R
[3] Proportional constant, Kp
[4] Integral constant, Ki
[5] Derivative constant, Kd
Solution
4
MBB 410 – Mechatronics and Control Practicals
Figure 4
1
2
3
4
5
5
MBB 410 – Mechatronics and Control Practicals
Question 5 [3 Marks]
[1] Calculate and store the transfer function of the closed-loop control loop in the variable T
Calculate and plot the response for T with a unit step input. Using this graph, return the following
parameters:
Solution
Figure 5
6
MBB 410 – Mechatronics and Control Practicals
2
3
7
MBB 410 – Mechatronics and Control Practicals
Python code:
8
MBB 410 – Mechatronics and Control Practicals
Figure 1
Figure 2
Figure 3
9
MBB 410 – Mechatronics and Control Practicals
Figure 4
Figure 5
10
MBB 410 – Mechatronics and Control Practicals
Figure 6
Figure 7
Figure 8
11
MBB 410 – Mechatronics and Control Practicals
Figure 9
Figure 10
12
MBB 410 – Mechatronics and Control Practicals
Figure 11
Questions:
From the time signal that you are given, you must calculate the FFT. Indicate the steps that you
followed. (3 marks)
Perform FFT correction by multiplying the FFT with the window correction factor
Perform FFT correction by dividing the FFT with the window correction factor
Other: ……………………………………………………………………………………………………………………
9 Hz
41 Hz
190 Hz
Enter the amplitude of the 1st positive frequency peak (accurate to 3 significant figures (1 mark)
1.00
Enter the amplitude of the 2nd positive frequency peak (accurate to 3 significant figures) (1 mark)
0.975
Enter the amplitude of the 2nd positive frequency peak (accurate to 3 significant figures) (1 mark)
1.00
13
MBB 410 – Mechatronics and Control Practicals
Enter the phase angle (in degrees) of the 1st positive frequency peak (accurate to 3 significant
figures) (1 mark)
-90.0
Enter the phase angle (in degrees) of the 2nd positive frequency peak (accurate to 3 significant
figures) (1 mark)
-54.1
Enter the phase angle (in degrees) of the 3rd positive frequency peak (accurate to 3 significant
figures) (1 mark)
45.0
Figure
14
MBB 410 – Mechatronics and Control Practicals
Questions:
By setting R = 1000 Ohm, calculate the value of C in microFarad (μF), accurate to 4 significant
figures. (2 marks)
1
vR = iR, i = Cv̇ C, vC = ∫i, vR = RCv̇ C
C
1
vin = vR + vC = RCv̇ C + vC → G(s) = RCs + 1
1 1 1
ωC = RC
= 2πfc → RC = ωc
= ,f
2πfc c
= 100 Hz
1 1
C= 2πfc × R
= 2π × 100 × 1000
1.592 μF
Cact = 1.5915 μF
15
MBB 410 – Mechatronics and Control Practicals
Create a first order Butterworth low-pass filter in Python with a cut-off frequency of 100 Hz, using
scipy.signal.butter.
Compare the Bode plots of your RC filter and your Butterworth filter, and complete the following (6
marks)
Python code:
Figure 12
16
MBB 410 – Mechatronics and Control Practicals
Figure 13
17
MBB 410 – Mechatronics and Control Practicals
Figure 14
Figure 15
Figure 16
18
MBB 410 – Mechatronics and Control Practicals
Questions:
Enter the amplitude of the 1st positive frequency peak of the filtered signal (accurate to 3 significant
figures) (1 mark)
0.997
Enter the amplitude of the 2nd positive frequency peak of the filtered signal (accurate to 3
significant figures) (1 mark)
0.915
Enter the amplitude of the 3rd positive frequency peak of the filtered signal (accurate to 3
significant figures) (1 mark)
0.289
According to you, is the low-pass filter effective in filtering out the 3rd peak frequency? (1 mark)
Yes
No
Somewhat
Other: ……………………………………………………………………………………………………………………
What can be done to increase the effectiveness of the low-pass filter (2 marks)
Reduce the cut-off frequency (also works, impacts 2nd peak as well though)
Compare the phase angles of the frequency components of the filtered signal to that of the
unfiltered signal (as reported in Section 2). The differences are caused by (2 marks):
Phase angle distortion from using the low-pass filter (influenced by order)
Aliasing
19
MBB 410 – Mechatronics and Control Practicals
You are provided with the file main.c based on lectures 26-31.
20
MBB 410 – Mechatronics and Control Practicals
21
MBB 410 – Mechatronics and Control Practicals
a. Change the value for T2CONbits.TCKPS (line 74) to correspond to a prescale value of 1:64 (see
FDS pp134). [5]
Original Line 74: T2CONbits.TCKPS = 0b101; //prescaler
FDS pp 134:
b. Change the value for PR2 (line 76) accordingly to generate an interrupt at a rate of 4 Hz. Use
the stopwatch function and a suitable breakpoint to verify the interrupt rate. [5]
Original Line 76: PR2 = 35713; //set reset/overflow value < 2^16-1
Fsource
(prescaler )
PR Formula: PR = -1
F
PR Calculator: (use prescaler value from 1a)
Changed Line 76: PR2 = 31249; //set reset/overflow value < 2^16-1
c. Change line 49 so that TIMER2 flashes the LED connected to pin RD3.
Original Line 49: LATCbits.LATC13 = !PORTCbits.RC13;
Changed Line 49: LATDbits.LATD3 = !PORTDbits.RD3;
Explanation on changes: originally, TIMER2 flashes the LED connected to pin RC13, therefore, need to change the port to D, and the
pin to RD13
22
MBB 410 – Mechatronics and Control Practicals
a. Change the value of T1CONbits.TCKPS (line 135) to correspond to a prescale value of 1:64 (see
FDS pp129). [5]
Original Line 135: T1CONbits.TCKPS = 0b01; //1:1
FDS pp 129:
b. Change the value of PR1 (line 137) accordingly so that the sample rate is 2500 Hz. Use the
stopwatch function and a suitable breakpoint to verify the interrupt rate. [5]
Original Line 137: PR = 999; //Set timer overflow value
Fsource
(prescaler )
PR Formula: PR = F
-1
PR Calculator: (use prescaler value from 3a)
Fsource 8000000 Hz
F 2500 Hz
Bit 16
Prmax 65535
23
MBB 410 – Mechatronics and Control Practicals
a. Change lines 146 – 158 to apply PWM to the green LED on pin RC3 based on the ADC value
read from the potentiometer [5]
Original Code:
CCP3CON1 = 0; // initialise all values as 0
CCP3CON2 = 0; // initialise all values as 0
CCP3CON3 = 0; // initialise all values as 0
CCP3CON1bits.CCSEL = 0; // PWM mode
CCP3CON1bits.CLKSEL = 0; // clock source = system clock
CCP3CON1bits.TMRPS = 0b00; // 1:1 prescaler
CCP3CON1bits.MOD = 0b0100; // Dual Edge Compare mode State
CCP3CON2bits.OCEEN = 1; // enable OCM3E/RC15 (blue)
CCP3TMR = 0; // start timer at 0
CCP3RA = 4095; // Value to go to HIGH
CCP3RB = 4095; // Value to go to LOW
CCP3PR = 4095; // Value to overflow, start from 0
CCP3CON1bits.ON = 1; // enable module
Change Lines 146 – 158 from blue (RC15) to green (RC3) (FDS pp 10):
24
MBB 410 – Mechatronics and Control Practicals
25