0% found this document useful (0 votes)
11 views25 pages

MBB 410 Practicals

Uploaded by

gomotinashe85
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views25 pages

MBB 410 Practicals

Uploaded by

gomotinashe85
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 25

MBB 410 – Mechatronics and Control Practicals

MECHATRONICS AND CONTROL


PRACTICAL 1: PYTHON TUTORIAL

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

[4] 2% settling time, ts


[5] Estimated damping ratio, zetae
[6] Estimated damped natural frequency, we
[7] Estimated undamped natural frequency, wne

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

[1] the peak resonance, Mp


[2] the -3dB bandwidth, bw

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:

[2] Overshoot, ospid


[3] 2% settling time, tspid

Solution

Figure 5

6
MBB 410 – Mechatronics and Control Practicals

2
3

7
MBB 410 – Mechatronics and Control Practicals

MECHATRONICS AND CONTROL


PRACTICAL 2: FFT

Part A: FFT [12 Marks]


Calculate the FFT of a time domain signal.

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)

 Apply windowing before calculating the FFT


 Apply windowing after calculating the FFT
 Do not apply windowing

 Normalize the FFT by multiplying it by 2/N


 Do not normalize the FFT

 Perform FFT correction by multiplying the FFT with the window correction factor
 Perform FFT correction by dividing the FFT with the window correction factor

 Do not perform FFT correction

 Other: ……………………………………………………………………………………………………………………

Enter the frequency of the 1st positive frequency peak (1 mark)

9 Hz

Enter the frequency of the 2nd positive frequency peak (1 mark)

41 Hz

Enter the frequency of the 3rd positive frequency peak (1 mark)

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

Part B: RC Filter Design [10 Marks]


Design a first order RC low-pass filter with a cut-off frequency of 100 Hz.
Python code:

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

Refer to the PDF document titled "Standard_Capacitor_Values.pdf". Using 3 standard capacitors,


what is the closest you can get to the value of C as reported in the previous question? (2 marks)

Cact = 1.5915 μF

C = 0.022 + 0.068 + 1.5 = 1.59 μ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)

 The Bode plot magnitude graphs are different

 The Bode plot magnitude graphs are identical

 The Bode plot phase angle graphs are different

 The Bode plot phase angle graphs are identical


 Other: ……………………………………………………………………………………………………………………

Part C: Python Filter Implementation [8 Marks]


Apply your first order Butterworth low-pass filter to your time domain signal and calculate the FFT
of the filtered signal. Compare the peak frequency amplitudes with those you calculated in

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)

 Nothing, the filter is effective

 Reduce the cut-off frequency (also works, impacts 2nd peak as well though)

 Increase the filter order


 Other: ……………………………………………………………………………………………………………………

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

 Random errors characteristic of the FFT algorithm

19
MBB 410 – Mechatronics and Control Practicals

MECHATRONICS AND CONTROL


PRACTICAL 3: PIC32 POGRAMMING

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

Question 1 [10 Marks]


TIMER2 is currently used to flash the LED connected to pin RC13 at a rate of 7 Hz

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:

Changed Line 74: T2CONbits.TCKPS = 0b110; //prescaler

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

Question 2 [10 Marks]


The pushbutton connected to pin RB9 is currently used to switch off the LED at pin RD3. Change line
202 so that the pushbutton connected to pin RC4 to switch on the LED at pin RC13 (Hint: You also
need to update line 187).

22
MBB 410 – Mechatronics and Control Practicals

Original Line 187: TRISBbits.TRISB9 = 1; //Set switch pin RB9 as input

Original Line 202: LATDbits.LATD3 = PORTBbits.RB9;

Changed Line 187: TRISCbits.TRISC4 = 1; //Set switch pin RC4 as input


Explanation on changes: originally, RB9 is set as the input (0 for output, 1 for input), therefore, the input needs to be changed to take RC4
as the input switch – the port also needs to be changed from port B to port C.

Changed Line 202: LATCbits.LATC13 = !PORTCbits.RC4;


Explanation on changes: originally, RB9 switches off the LED at pin RD3, but now RC4 must switch on the LED at pin RC13. The LED needs
to be changed from RD3 to RC13 and the port needs to be changed from port D to port C (LAT section). The pin needs to be changed
from RB9 to RC4 and the port needs to be changed from port B to port C (PORT section). Originally, RD3 is off when RB9 is pressed, hence
why “=” is used, now RC13 needs to be on when RC4 is pressed, hence why the “= !” or not equal to is used. Line 202 is in a while loop,
so initially the code is always running until the input is pressed (=), now the code is always off until the input is pressed because of the not
equal to (= !).

Question 3 [10 Marks]


TIMER1 is currently set up to let the ADC sample at a rate of 1000 Hz.

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:

Changed Line 135: T1CONbits.TCKPS = 0b10; //1:64

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

Prescaler PR <= Prmax?


1 3199 Y
2 1599 Y
4 799 Y
8 399 Y
16 199 Y
32 99 Y
64 49 Y
128 24 Y
256 11.5 Y
Changed Line 137: PR = 49; //Set timer overflow value

23
MBB 410 – Mechatronics and Control Practicals

Question 4 [10 Marks]


PWM is currently applied to the blue (RC15) and red (RD1) LEDs. You must change the code so that
PWM is now applied only to the green (RC3) and red (RD1) LEDs.

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

Changed Code (from FDS pp 10, OCM2B/RC3):


CCP2CON1 = 0; // initialise all values as 0
CCP2CON2 = 0; // initialise all values as 0
CCP2CON3 = 0; // initialise all values as 0
CCP2CON1bits.CCSEL = 0; // PWM mode
CCP2CON1bits.CLKSEL = 0; // clock source = system clock
CCP2CON1bits.TMRPS = 0b00; // 1:1 prescaler
CCP2CON1bits.MOD = 0b0100; // Dual Edge Compare mode State
CCP2CON2bits.OCBEN = 1; // enable OCM2B/RC3 (green)
CCP2TMR = 0; // start timer at 0
CCP2RA = 4095; // Value to go to HIGH
CCP2RB = 4095; // Value to go to LOW
CCP2PR = 4095; // Value to overflow, start from 0
CCP2CON1bits.ON = 1; // enable module
Explanation on changes: originally 3 is used for OCM3E/RC15 for the blue LED, now 2 is used for OCM2B/RC3 for the green LED.
Additionally, originally E is used for OCM3E/RC15 for the blue LED (OCEEN), now B is used for OCM2B/RC3 for the green LED (OCBEN)

b. Update line 57 accordingly. [5]


Original Line 57: CCP3RA = ADC14Val;
Changed Line 57: CCP2RA = ADC14Val;
Explanation on changes: originally 3 is used for OCM3E/RC15 for the blue LED, now 2 is used for OCM2B/RC3 for the green LED.

25

You might also like