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. FiO Lite Board (a) DC Adapter FiOLite Board USB Isolator Lego Motor Port B Motor Driver Board (b) Fig. 2.1 Block diagram (a) and motor control lab setup (b) S WONGSA INC451: 2-1
Fig. 2.2 How to build the Lego Motor in this experiment 2.2.1 LEGO MINDSTORMS NXT MOTOR The motor has a built-in gear reduction and an optical encoder with 180 pulsesper rotation. The encoder generates two shifted rectangular pulses from ports TACH00 and TACH01, 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 forward, and Fig. 2.4 (b) is for reverse. Fig. 2.3 Lego Mindstorms NXT motor (a) (b) Fig. 2.4 Quadrature signals for motor running forward (a) and reverse (b) (Gasperi and Hurbain 2009) S WONGSA INC451: 2-2
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 (direction 1 for motor A) Da1 (direction 2 for motor A) Da2 (PWM for motor A) Pa (direction 1 for motor B) Db1 (direction 2 for motor B) Db2 (PWM for motor B) Pb Motor driver port C1 C2 C6 C3 C4 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. S WONGSA INC451: 2-3
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 m 2 ) b Viscous friction coefficient of the motor (N m s) K t L R K b Motor torque constant (N m/a) Motor armature inductance (H) Motor armature resistance (Ω) 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): J& θ + b & θ = K ti (2.1) di dθ L + Ri+ K b = v dt dt (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: S WONGSA INC451: 2-4
Θ( s) V ( s) = s s+ K t / RJ 1 K t K b+ J R b (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: Y ( s) G( s) = U ( s) = K s( τs+ 1) (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 + u u, u > u u m = 0, u u u u u, u< u + + (2.5) S WONGSA INC451: 2-5
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. S WONGSA INC451: 2-6
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. S WONGSA INC451: 2-7
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 S WONGSA INC451: 2-8
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: S WONGSA INC451: 2-9
+ u~ + u, u~ > 0 u = u ~ u, u~ < 0 (2.6) ~ u, otherwise ~ U ( s ) U (s) 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. U (s) 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 Y ( s) T ( s) = R( s) = s K / τ = s K + + τ τ 2 2 s + 2 ω 2 n ζω s+ ω n 2 n (2.7) S WONGSA INC451: 2-10
Note that the closed-loop transfer function of motor can be written in the standard form of 2 2 2 second order transfer function ω /( s + 2ζω s+ ω ). The parameters K and τ of the open-loop n transfer function G(s) in (2.3) can therefore be identified from T(s). 2.4.2.2 IDENTIFICATION EXPERIMENT n n 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. 195 190 Angle r(t), deg. 185 180 175 170 165 0 5 10 15 20 Time(sec) 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. 200 190 Angle y(t), deg. 180 170 160 150 0 2 4 6 8 10 12 14 16 18 Time(sec) 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 =. % S WONGSA INC451: 2-11
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') 200 190 Simulated angle Actual angle 180 170 160 150 3 4 5 6 7 8 9 Fig. 2.17Closed-loop identification results S WONGSA INC451: 2-12
Given the approximated T(s), calculate the parameters of G(s) : K = τ = Comment on the identification results, compared with those obtained from your rough approximations in 2. 2.4.3 DESIGN ASSIGNMENT Design a discretee PD compensator which satisfies the following specifications: - Overshoot less than 5% - Settling less than0.5 sec. - Steady state error less than 1 degree. for step inputs. Simulate your design closed-loop systems and compare them with the real experimental results forthe desired angle r(t) to be a square wave with amplitudes[170, 190 ], [135, 225 ], 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 Saturation and Dead Zone Blocks of Simulink. Fig. 2.18 Saturation and Dead Zone Blocks of Simulink S WONGSA INC451: 2-13
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. S WONGSA INC451: 2-14