+ All Categories
Home > Documents > Lab2 DC NXT motor control - web page for staffwebstaff.kmutt.ac.th/~sarawan.won/INC451/Lab2.pdfS...

Lab2 DC NXT motor control - web page for staffwebstaff.kmutt.ac.th/~sarawan.won/INC451/Lab2.pdfS...

Date post: 08-May-2018
Category:
Upload: dangtuong
View: 216 times
Download: 2 times
Share this document with a friend
14
S WONGSA INC451: 2-1 UNIT 2: DC MOTOR POSITION CONTROL 2.1 INTRODUCTION This experiment aims to show the mathematical model of a DC motor and how to determine the physical parameters of a DC motor model. Once the model is verified, it is used to design a closed-loop control system that regulates the position of the DC motor. 2.2 EXPERIMENTAL SETUP The block diagram ofthe setupis as shown in Fig. 2.1 (a). OneFiOLite board from Aimagin (www.aimagin.com ), one dc motor driver and interface board, oneLego DC motor with built-in encoder, one external power supply, and one USB isolator will be given to each group. Connect up these components to the FiOLite Board and PC according to the setup shown in Figure 2.2 (b). The given NXT parts are connected with the motor as shown in Fig. 2.2. (a) (b) Fig. 2.1 Block diagram (a) and motor control lab setup (b) FiO Lite Board USB Isolator DC Adapter FiOLite Board Lego Motor Motor Driver Board Port B
Transcript
Page 1: Lab2 DC NXT motor control - web page for staffwebstaff.kmutt.ac.th/~sarawan.won/INC451/Lab2.pdfS WONGSA INC451: 2-1 UNIT 2: DC MOTOR POSITION CONTROL 2.1 INTRODUCTION This experiment

S WONGSA INC451: 2-1

UNIT 2: DC MOTOR POSITION CONTROL

2.1 INTRODUCTION This experiment aims to show the mathematical model of a DC motor and how to determine the

physical parameters of a DC motor model. Once the model is verified, it is used to design a closed-loop

control system that regulates the position of the DC motor.

2.2 EXPERIMENTAL SETUP

The block diagram ofthe setupis as shown in Fig. 2.1 (a). OneFiOLite board from

Aimagin (www.aimagin.com), one dc motor driver and interface board, oneLego DC motor

with built-in encoder, one external power supply, and one USB isolator will be given to each

group. Connect up these components to the FiOLite Board and PC according to the setup

shown in Figure 2.2 (b). The given NXT parts are connected with the motor as shown in Fig.

2.2.

(a)

(b)

Fig. 2.1 Block diagram (a) and motor control lab setup (b)

FiO Lite Board

USB Isolator

DC Adapter

FiOLite

Board

Lego Motor

Motor

Driver Board

Port B

Page 2: Lab2 DC NXT motor control - web page for staffwebstaff.kmutt.ac.th/~sarawan.won/INC451/Lab2.pdfS WONGSA INC451: 2-1 UNIT 2: DC MOTOR POSITION CONTROL 2.1 INTRODUCTION This experiment

S WONGSA

Fig. 2.2

2.2.1 LEGO MINDSTORMS

The motor has a built

rotation. The encoder generates two shifted rectangular pulses

TACH01, and the shift represents one

the direction and speed of the motor. Fig. 2.

forward, and Fig. 2.4 (b) is for reverse.

(a)

Fig. 2.4 Quadrature signals for motor running forward (a) and reverse (b)

Fig. 2.2 How to build the Lego Motor in this experiment

INDSTORMS NXT MOTOR

built-in gear reduction and an optical encoder with

rotation. The encoder generates two shifted rectangular pulses from ports TACH00 and

, and the shift represents one quarter of a cycle. These signals allow us to determine

the direction and speed of the motor. Fig. 2.4 (a) illustrates the signals for a motor turning

is for reverse.

Fig. 2.3 Lego Mindstorms NXT motor

(b)

Quadrature signals for motor running forward (a) and reverse (b)

(Gasperi and Hurbain 2009)

INC451: 2-2

in this experiment

in gear reduction and an optical encoder with 180 pulsesper

from ports TACH00 and

quarter of a cycle. These signals allow us to determine

illustrates the signals for a motor turning

(b)

Quadrature signals for motor running forward (a) and reverse (b)

Page 3: Lab2 DC NXT motor control - web page for staffwebstaff.kmutt.ac.th/~sarawan.won/INC451/Lab2.pdfS WONGSA INC451: 2-1 UNIT 2: DC MOTOR POSITION CONTROL 2.1 INTRODUCTION This experiment

S WONGSA INC451: 2-3

2.2.2 DC MOTOR DRIVER BOARD

The motor driver board is based on H-bridge IC drivers LB1836M which

can drive up to 2 DC motors, connected through Ports A and B, at 9V-1A per

channel. You need three signals to drive each motor. Two digital signals provide

appropriate logics to control the motor’s directions and one Pulse Width

Modulation (PWM) signal for controlling the motor’s speed. The speed of a motor

depends on the average voltage applied to it, and the PWM method is a way of

controlling this average voltage. Pins used for driving motors A and B are

summarised in Table 1.1.

Fig. 2.5 Motor driver board

Table 2.1 Pin connections for driving motors A and B

Control signal Motor driver port

(direction 1 for motor A) Da1 C1

(direction 2 for motor A) Da2 C2

(PWM for motor A) Pa C6

(direction 1 for motor B) Db1 C3

(direction 2 for motor B) Db2 C4

(PWM for motor B) Pb C7

2.2.3 FIOLITE BOARD

FiOLite board is based on ARM 33-bits processor (STM32F103R8),

supporting on-chip peripherals, for instance digital IOs, ADC, PWM, USART, and

USB. One of the most appealing features of this board is that it supports C code

generation of a custom user program for STM32 from a Simulink model.

Therefore, it is suitable for those who are familiar with MATLAB programming.

The interested reader is referred to www.aimgin.com for required software and

tutorials on how to program the board with many example projects.

Page 4: Lab2 DC NXT motor control - web page for staffwebstaff.kmutt.ac.th/~sarawan.won/INC451/Lab2.pdfS WONGSA INC451: 2-1 UNIT 2: DC MOTOR POSITION CONTROL 2.1 INTRODUCTION This experiment

S WONGSA INC451: 2-4

2.3 MOTOR MODELLING

2.3.1 MODEL OF A SIMPLE SERVO SYSTEM

Fig. 2.6 Armature-controller DC motor

Table 2.2Definitions of parameters of the servo DC motor

J Moment of inertia (kg m2)

b Viscous friction coefficient of the motor (N⋅m⋅s)

tK Motor torque constant (N⋅m/A)

L Motor armature inductance (H)

R Motor armature resistance (Ω)

bK Back emf coefficient V/(rad/s)

A servo DC motor system, as shown in Fig. 2.6, in the armature-control mode of operation

is composed of the armature circuit and the mechanical parts, leading to the two following

dynamic equations(Nise 2008):

iKbJ t=+ θθ &&& (2.1)

vdt

dKRi

dt

diL b =++

θ (2.2)

wherev is the input voltage applied to the motor’s armature, θ is the angular displacement

of the shaft, and the definition of all constant parameters is summarized in Table 2.2.

It is usual to assume that the armature inductance, L, is small compared to the armature

resistance, R. By applying the Laplace transform to the above differential equations with L

being eliminated from (2.2), we can obtain the following transfer function:

Page 5: Lab2 DC NXT motor control - web page for staffwebstaff.kmutt.ac.th/~sarawan.won/INC451/Lab2.pdfS WONGSA INC451: 2-1 UNIT 2: DC MOTOR POSITION CONTROL 2.1 INTRODUCTION This experiment

S WONGSA INC451: 2-5

++

R

KKb

Jss

RJK

sV

s

bt

t

1

/

)(

)(

(2.3)

In this experimental setup, however, instead of controlling the voltage we will control a

PWM signal with varying duty cycle with amplitude of 3.3 V. Also, the output shaft position

will be considered in degrees.Based on this setup, the servo system model can be put in the

following transfer function form:

)1()(

)()(

+==

ss

K

sU

sYsG

τ (2.4)

where U(s) is the input PWM duty cycle and Y(s) is the shaft position in degrees, K is the

system gain and τ is the time constant.

2.3.2 MOTOR DEADBAND

The linear model described above is the basis of the design of servo controller.

However, a real servo has nonlinear components that influence its dynamic behavior. Examples

of these nonlinearities are the saturation voltage of the motor drive amplifier, Coulumb friction

in the moving parts, and the deadbandor deadzone in the motor amplifier. Deadband is the

region where the applied input has no effect, preventing motor from turning when small inputs

are applied.

ω

Fig. 2.7 Motor deadband

The deadband can be included to the servo system at the system input for moreaccurate

approximation of the system model. The nonsymmetricdeadband nonlinearity shown in Fig.

2.8 is given by

<−

≤≤

>−

=−−

+−

++

uuuu

uuu

uuuu

um

,

,0

,

(2.5)

Page 6: Lab2 DC NXT motor control - web page for staffwebstaff.kmutt.ac.th/~sarawan.won/INC451/Lab2.pdfS WONGSA INC451: 2-1 UNIT 2: DC MOTOR POSITION CONTROL 2.1 INTRODUCTION This experiment

S WONGSA INC451: 2-6

The parameters u-,u

+ characterise the width of the system deadband.

Fig. 2.8 Friction modeling with deadband

2.4 LAB EXPERIMENTS

2.4.1 MOTOR MANUAL CONTROL

We will get started by learning how to make your motor rotate. Three

topics will be covered in this section:

Using the motor driver board to control motor speed and direction

Reading the incremental quadrature encoder

The nonlinearities Coulomb & viscous friction effects

This lab consists of two Simulink models, one for the target and another

for the host PC. The target Simulinkmodel is configured such that the FiO board

receives3 command signals, including

PWM duty cycle (to pin C6)

DIR1 (to pin C3)

DIR2 (to pin C4),

from a Simulink model running on the host PC to control the motor speed

anddirection. The target alsoreturns two output signals, rotation direction and

encoder counts, to the host PC.

On the host PC Simulink model, you can use a slider gain block to vary

PWM duty cycle and sign(between -100 and +100) to control the motor speed and

direction in real-time. The received encoder countsare converted to positions 0 -

360 degrees. You should also observe the nonlinear effects due to mechanical

frictions.

2.4.1.1 EXPERIMENTAL SETUP

To drive the motor and to read the encoder signals, connect the driver motor

board with the FiO board as shown in Fig. 2.9. Pins C3 and C4 are for controlling

the motor’s direction. PWM signals generated from pin A3 of FiO board is

connected to the PWM pin (C7) of the motor driver board to control the motor’s

speed. The two encoder signals, A8 and A9, from the motor driver board are read

by the target Simulink model to calculate the corresponding angular displacement

of the motor.

Page 7: Lab2 DC NXT motor control - web page for staffwebstaff.kmutt.ac.th/~sarawan.won/INC451/Lab2.pdfS WONGSA INC451: 2-1 UNIT 2: DC MOTOR POSITION CONTROL 2.1 INTRODUCTION This experiment

S WONGSA INC451: 2-7

Fig. 2.9 Pin connections between the motor driver board and the FiOLite board

2.4.1.2 TARGET SIMULINK MODEL

Fig. 2.10 Target Simulink model

Build a Target Simulink as shown in Fig. 2.10. Notice that

The sample time is 0.005 sec.

Page 8: Lab2 DC NXT motor control - web page for staffwebstaff.kmutt.ac.th/~sarawan.won/INC451/Lab2.pdfS WONGSA INC451: 2-1 UNIT 2: DC MOTOR POSITION CONTROL 2.1 INTRODUCTION This experiment

S WONGSA INC451: 2-8

PWM frequency is 20 kHz

PinsC3 and C4of Digital Output Block are configured asOpen-Drainoutput. Table

2.3summarises required signals to control the motor in different modes.In Break mode,

the motor will stop right away. In Standby mode, the motor will slowly come to a stop

depending on the inertia of the load.

Table 2.3 Truth table for motor control

C3 C4 Mode

H L Forward

L H Reverse

H H Brake

L L Standby

Position (POS) port of Incremental Quadrature Encoder Interface Block is the count of

number of edges of the encoder output signals from both channels A and B. The decoder is set to

count at every rising and falling edge of both channel A and B to provide maximum resolution.

Therefore, for our encoder which has 180 pulses per revolution (PPS), the maximum count is 720

per revolution (4x180 = 720), i.e. from 0 to 719.Given the number of edges of encoder signals, we

can calculate the corresponding angular displacement in degrees as (POS+1)/2. The Data Type

Conversion Block, connected to the POS port, is used to convert POS (unit16) to the 64-bit

double-precision format for floating-point computation.

2.4.1.3 HOST SIMULINK MODEL

Fig. 2.11 Host Simulink model

Page 9: Lab2 DC NXT motor control - web page for staffwebstaff.kmutt.ac.th/~sarawan.won/INC451/Lab2.pdfS WONGSA INC451: 2-1 UNIT 2: DC MOTOR POSITION CONTROL 2.1 INTRODUCTION This experiment

S WONGSA INC451: 2-9

function [pwmout, dir1, dir2] = fcn(pwm)

if (pwm>0)%forward pwmout = pwm; dir1 = uint8(1); dir2 = uint8(0); elseif (pwm<0)%reverse pwmout = pwm; dir1 = uint8(0); dir2 = uint8(1); else%break pwmout = 0; dir1 = uint8(1); dir2 = uint8(1); end

Fig. 2.12 MATLAB function for manual speed control (Speed Control Block of Fig. 2.11)

In the Host Simulink model, the angular displacement from Target model is read in the

Host model by using the Host HID Receiver Block. In the driver side, we need to send the Target

model the PWM percent duty cycle and the right logics to control the motor’s direction.Given the

PWM value, ranging from -100% to 100%, the Speed Control Block, which is created by the

MATLAB Function Block Editor, converts the PWM value to the corresponding logics for pins

C3 and C4, according to the truth table in Table 2.3. The function script is shown in Fig. 2.12.

2.4.1.4 LET’S GET IT RUN

i) Set FiO board in USB In Application Programming (IAP) Mode then

Build Model. Do not forget to update the diagram until all blocks display

correct sample time before building the model. The source code should be

automatically generated, compiled, and downloaded to the FiO Lite board

ii) Set FiO board in Run Custom User Program Mode and run the Host

model by double clicking the HID Force Output Block.

iii) Double click the Slider Gain to control PWM duty cycle. Because of the

friction effects, a certain minimum percent of duty cycle is required to

make the motor start to run from rest. This nonlinear behaviour is known as

the deadband. Record the deadbandvalues of your motor in both directions.

- Deadband of forward direction: u+ = ……………………… %

- Deadband of reverse direction: u- = ……………………… %

2.4.2 IDENTIFICATION OF MOTOR MODEL

2.4.2.1 CLOSED-LOOP IDENTIFICATION AND DEADBAND COMPENSATION

We will identify the motor transfer function G(s) by using the closed-loop

identification and a deadband compensation techniques. To compensate for the deadband

in closed-loop, we can introduce a deadbandprecompensator as in Fig. 2.13. The rule of

deadband compensator depends on the region within which u~ occurs and can be normally

described as follows:

Page 10: Lab2 DC NXT motor control - web page for staffwebstaff.kmutt.ac.th/~sarawan.won/INC451/Lab2.pdfS WONGSA INC451: 2-1 UNIT 2: DC MOTOR POSITION CONTROL 2.1 INTRODUCTION This experiment

S WONGSA INC451: 2-10

<−

>+

= −

+

otherwise ,~0~,~0~,~

u

uuu

uuu

u (2.6)

Fig. 2.13 Feedback control with deadband compensation

If the deadband is well determined and constant, we can use the same value in the

deadbandprecompensation as described in (2.5). Unfortunately, the deadband approximation is

normally not perfect. If you attempt to cancel the deadband completely, we could therefore end up

with overcompensation that causes unwanted jitter and limit cycles. Therefore, to avoid these

undesired outcomes, in practice the precompensator magnitude is chosen smaller than the width of

the deadzone.

After applying the deadbandprecompensation, we can hopefully significant reduce the

effects of Coulomb friction. If this is the case, we could consider the closed-loop system as if all

components are linear. Consequently, the closed-loop system after the deadband is compensated

can be considered as shown in Fig. 2.14.

)(sU

Fig. 2.14 Closed-loop motor control system

If C(s) is a proportional compensator with a constant gain, say C(s) = 1, the closed-loop

transfer function of the system in Fig. 2.14 becomes

22

2

2 2

/

)(

)()(

nn

n

ssKss

K

sR

sYsT

ωζωω

ττ

τ++

=++

== (2.7)

)(~

sU )(sU

Page 11: Lab2 DC NXT motor control - web page for staffwebstaff.kmutt.ac.th/~sarawan.won/INC451/Lab2.pdfS WONGSA INC451: 2-1 UNIT 2: DC MOTOR POSITION CONTROL 2.1 INTRODUCTION This experiment

S WONGSA INC451: 2-11

Note that the closed-loop transfer function of motor can be written in the standard form of

second order transfer function )2/( 222

nnn ss ωζωω ++ . The parameters K and τ of the open-loop

transfer function G(s) in (2.3) can therefore be identified from T(s).

2.4.2.2 IDENTIFICATION EXPERIMENT

1. Modify the Host Simulink model in Fig. 2.11 to perform the closed-loop

identification with deadbandprecompensator in Fig. 2.13. Set the controller

C(s) = 1 and the desired angle r(t) to be a square wave with

amplitudes[170°, 190°] and period 6 sec as shown in Fig. 2.15.

Fig. 2.15 Squarewave input r(t) used for closed-loop identification experiment

2. Try to use the deadband constants obtained in Section 2.4.1.4 for your

deadband compensator. But if this causes jitter, slightly reduce them until

the jitter disappears. Your response should look like asecond-order step

response. For example, it may look like Fig. 2.16.

Fig. 2.16 Second-order step response of the servo motor system

Save the desired angle r(t) and the motor angle y(t) as variables r and y,

respectively, in Workspace.

Approximate the overshoot, the rise time, and the settling time of your

second order step response and define the corresponding nω and ζ .

Overshoot = …………………………………. %

0 5 10 15 20165

170

175

180

185

190

195

Time(sec)

Angle

r(t

), d

eg.

0 2 4 6 8 10 12 14 16 18150

160

170

180

190

200

Time(sec)

Angle

y(t

), d

eg.

Page 12: Lab2 DC NXT motor control - web page for staffwebstaff.kmutt.ac.th/~sarawan.won/INC451/Lab2.pdfS WONGSA INC451: 2-1 UNIT 2: DC MOTOR POSITION CONTROL 2.1 INTRODUCTION This experiment

S WONGSA INC451: 2-12

Rise time = …………………………………... sec

Settling time = ………………………………… sec

nω = …………………………. rad/sec

ζ = ………………………………

Given the approximated nω and ζ , calculate the corresponding K and τ by

using (2.6).

K = ……………………………

τ = ……………………………

3. Alternatively, you can use the MATLAB identification Toolbox to identify

T(s).

% Assuming you already have r(input), y(output), and t(time vector) in Workspace

dat=iddata(y,r,0.005); % Create a data object to be used for system identification

% Identify a predicted model of the system using the assumed form ofunderdamped system m = pem(dat,'p2u');

% The obtained model m is in the form % Kp % G(s) = ---------------------- % 1+2*Zeta*Tw*s+(Tw*s)^2

% Extract parameters Kp, Tw and Zeta from m Kp = m.Kp.value; Zeta = m.Zeta.value; Tw = m.Tw.value;

% Create the corresponding closed-loop transfer function object T T = tf(Kp,[Tw^2 2*Zeta*Tw 1]);

% Simulate response from the model and compare with experiment [ysim,t]=lsim(T,r,t); figure plot(t,ysim,t,y) legend('Simulated angle','Actual angle')

Fig. 2.17Closed-loop identification results

3 4 5 6 7 8 9150

160

170

180

190

200

Simulated angle

Actual angle

Page 13: Lab2 DC NXT motor control - web page for staffwebstaff.kmutt.ac.th/~sarawan.won/INC451/Lab2.pdfS WONGSA INC451: 2-1 UNIT 2: DC MOTOR POSITION CONTROL 2.1 INTRODUCTION This experiment

S WONGSA

Given the approximated T(s), calculate the parameters of G(s) :

K = ……………………………

τ = ……………………………

Comment on the identification results, c

rough approximations in

2.4.3 DESIGN ASSIGNMENT

Design a discrete

- Overshoot less than

- Settling less than0.5

- Steady state error less than 1 degree.

for step inputs.

Simulate your design closed

experimental results

190°], [135°, 225°], and [90

Your simulated model should include

[-100 %,100%] ) and the deadband. Also include the deadband compensation as used in

the real experiments. The saturation and deadband can be modelled by using the

Saturation and Dead Zone

Fig. 2.18

Given the approximated T(s), calculate the parameters of G(s) :

= ……………………………

= ……………………………

Comment on the identification results, compared with those obtained from your

rough approximations in 2.

SSIGNMENT

Design a discrete PD compensator which satisfies the following specifications:

Overshoot less than 5%

less than0.5 sec.

Steady state error less than 1 degree.

Simulate your design closed-loop systems and compare them with the real

forthe desired angle r(t) to be a square wave

], and [90°, 270°].

Your simulated model should include the saturation of controller output (duty cycle

100 %,100%] ) and the deadband. Also include the deadband compensation as used in

the real experiments. The saturation and deadband can be modelled by using the

Dead Zone Blocks of Simulink.

Fig. 2.18 Saturation and Dead Zone Blocks of Simulink

INC451: 2-13

Given the approximated T(s), calculate the parameters of G(s) :

those obtained from your

compensator which satisfies the following specifications:

loop systems and compare them with the real

square wave with amplitudes[170°,

controller output (duty cycle

100 %,100%] ) and the deadband. Also include the deadband compensation as used in

the real experiments. The saturation and deadband can be modelled by using the

Saturation and Dead Zone Blocks of Simulink

Page 14: Lab2 DC NXT motor control - web page for staffwebstaff.kmutt.ac.th/~sarawan.won/INC451/Lab2.pdfS WONGSA INC451: 2-1 UNIT 2: DC MOTOR POSITION CONTROL 2.1 INTRODUCTION This experiment

S WONGSA INC451: 2-14

REFERENCES

Gasperi, Michael, and Phillippe Philo Hurbain. Extreme NXT: Extending the LEGO MINDSTORMS NXT

to the Next Level. 2009.

Nise, Norman S. Control Systems Engineering. John Wiley & Sons, 2008.


Recommended