mech 473 project manual - concordia...

48
CONCORDIA UNIVERSITY DEPARTMENT OF MECHANICAL AND INDUSTRIAL ENGINEERING Control System Design MECH 473 Project Manual Written by H. Hong, T. Wen, G. Huard 2011

Upload: others

Post on 13-Jul-2021

5 views

Category:

Documents


0 download

TRANSCRIPT

Control System Design MECH 473
Project Manual
Written by
MECH 473 Project Manual
Table of Contents
GENERAL LABORATORY SAFTY RULES………………………………………3 LABORATORY RULES .................................................................................................. 9 Session #1 Introduction to DC Motor Control System .............................................. 10
Session #2 Introduction to Matlab/Simulink with QuaRC, and Senor Calibration . 17
Session #3 Motor Dynamical Modeling ........................................................................ 24
Session #4 DC Motor Transfer Function Estimation .................................................. 28
Session #5 Motor Controller Implement— Matlab/Simulink (QuaRC) ................... 31
Session #6 Motor Controller Implement— C program .............................................. 35
Appendix A ...................................................................................................................... 36 Pittman Motor Data Sheet.............................................................................................. 36 Appendix B Motor Controller Design .......................................................................... 39
Appendix C: Guide for VC 2008 with Quanser HIL C API configuration .............. 44
MECH 473 Project Manual
• Before attempting to install, commission or operate equipment, all relevant suppliers’/manufacturers’ instructions and local regulations should be understood and implemented.
• It is irresponsible and dangerous to misuse equipment or ignore instructions, regulations or warnings.
• Do not exceed specified maximum operating conditions (e.g. temperature, pressure, speed etc.).
Installation/Commissioning • Use lifting table where possible to install heavy equipment. Where manual lifting
is necessary beware of strained backs and crushed toes. Get help from an assistant if necessary. Wear safety shoes appropriate.
• Extreme care should be exercised to avoid damage to the equipment during handling and unpacking. When using slings to lift equipment, ensure that the slings are attached to structural framework and do not foul adjacent pipe work, glassware etc.
• Locate heavy equipment at low level.
• Equipment involving inflammable or corrosive liquids should be sited in a containment area or bund with a capacity 50% greater that the maximum equipment contents.
• Ensure that all services are compatible with equipment and that independent isolators are always provided and labeled. Use reliable connections in all instances, do not improvise.
• Ensure that all equipment is reliably grounded and connected to an electrical supply at the correct voltage.
• Potential hazards should always be the first consideration when deciding on a suitable location for equipment. Leave sufficient space between equipment and between walls and equipment.
• Ensure that equipment is commissioned and checked by a competent member of staff permitting students to operate it.
MECH 473 Project Manual
4
Operation • Ensure the students are fully aware of the potential hazards when operating
equipment.
• Students should be supervised by a competent member of staff at all times when in the laboratory. No one should operate equipment alone. Do not leave equipment running unattended.
• Do not allow students to derive their own experimental procedures unless they are competent to do so.
Maintenance • Badly maintained equipment is a potential hazard. Ensure that a competent
member of staff is responsible for organizing maintenance and repairs on a planned basis.
• Do not permit faulty equipment to be operated. Ensure that repairs are carried out competently and checked before students are permitted to operate the equipment.
Electricity • Electricity is the most common cause of accidents in the laboratory. Ensure that all
members of staff and students respect it.
• Ensure that the electrical supply has been disconnected from the equipment before attempting repairs or adjustments.
• Water and electricity are not compatible and can cause serious injury if they come into contact. Never operate portable electric appliances adjacent to equipment involving water unless some form of constraint or barrier is incorporated to prevent accidental contact.
• Always disconnect equipment from the electrical supply when not in use.
Avoiding Fires or Explosion • Ensure that the laboratory is provided with adequate fire extinguishers appropriate
to the potential hazards.
• Smoking must be forbidden. Notices should be displayed to enforce this.
• Beware since fine powders or dust can spontaneously ignite under certain conditions. Empty vessels having contained inflammable liquid can contain vapor and explode if ignited.
• Bulk quantities of inflammable liquids should be stored outside the laboratory in accordance with local regulations.
MECH 473 Project Manual
5
• Storage tanks on equipment should not be overfilled. All spillages should be immediately cleaned up, carefully disposing of any contaminated cloths etc. Beware of slippery floors.
• When liquids giving off inflammable vapors are handled in the laboratory, the area should be properly ventilated.
• Students should not be allowed to prepare mixtures for analysis or other purposes without competent supervision.
Handling Poisons, Corrosive or Toxic Materials • Certain liquids essential to the operation of equipment, for example, mercury, are
poisonous or can give off poisonous vapors. Wear appropriate protective clothing when handling such substances.
• Do not allow food to be brought into or consumed in the laboratory. Never use chemical beakers as drinking vessels
• Smoking must be forbidden. Notices should be displayed to enforce this.
• Poisons and very toxic materials must be kept in a locked cupboard or store and checked regularly. Use of such substances should be supervised.
Avoid Cuts and Burns • Take care when handling sharp edged components. Do not exert undue force on
glass or fragile items.
• Hot surfaces cannot, in most cases, be totally shielded and can produce severe burns even when not visibly hot. Use common sense and think which parts of the equipment are likely to be hot.
Eye/Ear Protection • Goggles must be worn whenever there is risk to the eyes. Risk may arise from
powders, liquid splashes, vapors or splinters. Beware of debris from fast moving air streams.
• Never look directly at a strong source of light such as a laser or Xenon arc lamp. Ensure the equipment using such a source is positioned so that passers-by cannot accidentally view the source or reflected ray.
• Facilities for eye irrigation should always be available.
• Ear protectors must be worn when operating noisy equipment.
MECH 473 Project Manual
6
Clothing • Suitable clothing should be worn in the laboratory. Loose garments can cause
serious injury if caught in rotating machinery. Ties, rings on fingers etc. should be removed in these situations.
• Additional protective clothing should be available for all members of staff and students as appropriate.
Guards and Safety Devices • Guards and safety devices are installed on equipment to protect the operator. The
equipment must not be operated with such devices removed.
• Safety valves, cut-outs or other safety devices will have been set to protect the equipment. Interference with these devices may create a potential hazard.
• It is not possible to guard the operator against all contingencies. Use commons sense at all times when in the laboratory.
• Before staring a rotating machine, make sure staff are aware how to stop it in an emergency.
• Ensure that speed control devices are always set to zero before starting equipment.
First Aid • If an accident does occur in the laboratory it is essential that first aid equipment is
available and that the supervisor knows how to use it.
• A notice giving details of a proficient first-aider should be prominently displayed.
• A short list of the antidotes for the chemicals used in the particular laboratory should be prominently displayed.
MECH 473 Project Manual
LABORATORY RULES
Considering the large number of students attending the labs and in order for the lab to operate properly, the students are asked to abide by the following rules:
1. No smoking, eating, or drinking is permitted in the laboratory. 2. No students are allowed access to the instruments of the other course. 3. No equipment is allowed to be exchanged from one bench to another. 4. Upon entering and when leaving the laboratory students should check equipment
against the list posted at each station. 5. All damaged or missing equipment and cables must be reported immediately to the
demonstrator. Failure to do so will result in students being charged for damages or losses.
6. All data must be recorded in the laboratory paper and must be signed by the demonstrator.
7. Laboratory demonstrators are not permitted to admit any students other than those on their class list.
8. Any student who is more than 30 minutes late will not be permitted into the laboratory. Furthermore, repeated tardiness will not be tolerated.
9. After your laboratory session is completed all components, connecting jumpers, and cables must be returned to their respective places.
10. No students are allowed access to parts in the cabinets. Your laboratory demonstrator will provide you with all necessary parts.
MECH 473 Project Manual
Session #1 Introduction to DC Motor Control System Objective:
The objective of this lab is to give an introduction to the DC motor Control system, familiarize students with motor control system hardware, and measurement instruments. System Introduction The DC motor control system (as shown in Fig.1.1) consists of the computer (as the system management and controller), I/O board (A/D, D/A, Timer), power amplifier (OP amp), DC motor, generator and inertial loads, and sensor (tachometer, encoder).
1. Computer and controller:
The computer is a PC compatible computer. The controller is implemented by C, or Matlab program.
Computer Controller A/D, D/A
2. I/O Board:
Q4 DAQ board will be used in this Experiment and project. The Q4 is a versatile and powerful measurement and control board with an extensive range of input and output support. A wide variety of devices with analog and digital sensors as well as quadrature encoders are easily connected to the Q4. The Q4 provides: • 4 x 14-bit analog inputs: The Q4 has one analog-to-digital (A/D) converter on board. The
A/D converter handles four single-ended analog inputs. The A/D samples all four channels simultaneously and holds the sampled signals while it converts the analog value to a 14-bit digital code. Up to 350 kS/s sampling frequency on 1 A/D channel (100 kHz on all 4 channels)
• 4x 12-bit D/A voltage outputs: The Q4 has one 12-bit digital-to-analog (D/A) converter on board. The D/A converter outputs four analog outputs. Each analog output channel can be individually programmed to be in the range 0V to 10V, -5V to 5V, or -10V to +10V. Internal output amplifiers in the D/A converters allow the outputs to sink 5mA and to drive up to a 500pF load.
• 4 quadrature encoder inputs: The Q4 contains two encoder chips, each handling two channels, for a total of 4 encoder inputs. Both encoder chips can be accessed in a single 32-bit operation, and both channels can be accessed at the same time per chip. Hence, all four encoder inputs may be processed simultaneously.
• 16 programmable digital I/O channels • Simultaneous sampling of both analog, digital and encoder sections • 2x 32-bit dedicated counter/timers, including watchdog functionality • 4x 24-bit reconfigurable encoder counter/timers • 2x on-board PWM outputs • 32-bit, 33 MHz PCI bus interface • Supports Quanser real-time control software QuarC
Figure 1.2 Q4 Data Acquisition Card
MECH 473 Project Manual
12
The Q4 terminal board is illustrated in Figure 1.3. The terminal board is designed to sit on top of a tower unit, if desired.
Figure 1.3 Q4 Terminal Board 3. Power Module: The power module consists of a regulated dual output DC Power Supply set and a linear Power Operational Amplifier. DC Power Supply has three biding posts labeled +12V, GND and –12V. These may be used to power active components on the breadboard as well as to bias the sensors. Power Operational Amplifier has four binding posts. It can be used in any standard op-amp configuration (summer, inverter, buffer etc…). Its two inputs are labeled (-) for the inverting input and (+) for non-inverting input. The output is also labeled.
To Motor Encoder
To power in ( -)
Figure 1.5 DC motor System
From analog out ch0 All ground here
To drive Motor +enc
Connect together
14
DC motor is a Pittman Series GM9000 LO-COG® Brush-Commutated Gearmotor. For more detailed information about Pittman DC motors, check the site at: http://www.pittmannet.com for GM9000 series product specific data and technical article and application notes. 5. Sensors: The sensors used in this lab are tachometer for velocity feedback and an encoder for position or velocity feedback. The pot is also used for position sensor.
Tachometers are rated to provide a specific voltage per unit of velocity. Some units in which tachometers are rated are:
• V/Rad/Sec Volts per Radian per Second • V/Krpm Volts per thousand Revolutions Per Minute
Encoders provide incremental motor position information via two channels, referred to as the A Channel and B Channel. These channels output a specific number of pulses for a unit of shaft motion. These pulses are typically generated within the encoder using an optical disk directly connected to the motor shaft. 6. Experiment Procedure:
1) Analog an output signal using a attenuator to drive motor as shown in Figure 1.6, adjust knob of attenuator to vary voltage 4,8v. Using second attenuator to get +5V to encoder, and check tachometer output by DMM. Check encoder out A, B( frequency and time) by scope ch1, ch2. From tachometer reading and scope wave form, can you get speeds of motor for 4v input and 8v input.
Figure 1.6 Analog computer output to drive motor
MECH 473 Project Manual
15
2) As shown in Figure 1.6, disconnect to motor, adjust knob to get +5V from first attenuator, and connect to Pot. Turn motor shaft by hand 360 degree(One turn) ,Use scope Ch1 to measure pot output, ch2 to measure encoder out A. can you find the position by reading ch1from pot and ch2 from encoder. Please note: don’t turn on power module at the following step 3 and step 4. Let your lab instructor to check your connection, make sure connections are all right.
3) As shown in Figure 1.4, make a voltage follower using built in Op. connect terminal board analog output ch0 to Op (-), connect Op out to drive motor (motor+enc post).
4) As shown in Figure 1.3, connect encoder cable to terminal board enc ch0, connect tachometer post to analog input ch0. All above connections should be checked by your Lab Demonstrator and will be used for next lab.
Project Overview:
1) Provide a mathematical model for the DC motor and loads (inertia and generator), for the driving circuit, and for the feedback. Note that the motor is GM9236, and the generator is GM9413. Two inertial disks will be used in the project. J1=1.4 e-4 kg m2, J2=2.6 e-4 kg m2. Both motor and generator have a reduction gear ratio of 5.9.
2) Assuming a continuous model with no controller (ie: unity forward proportional
gain only), select a generator load (resistance = 5W) so the system feedback response to a position step input is highly oscillatory (underdamped). Using SIMULINK, show the system step response. Provide a Bode diagram and show/discuss the correlation between the phase margin and damping ratio.
It should be noted that for any generator load, the open-loop system is always overdamped and thus an underdamped system can never be obtained.
Do not forget to include the amplifier gain Ka = 2.5 V/V used to drive the DC motor/load system.
3) According to the frequency domain method, design a cascade controller for 20%
overshoot. Show/discuss the differences in system response between a lead and a lag compensator. For each controller, simulate the position step response and correlate with its Bode diagram.
Since the system is overdamped, it should be noted that conventional lead or lag compensation methods cannot achieve an underdamped system. You must use a
MECH 473 Project Manual
16
“lag-type” controller to “shape” your Bode diagram to achieve an underdamped system.
Vary the load resistance between 0 and 10W to see its effect.
4) Once the proper controller has been selected in 3, convert the continuous controller
into a digital controller (see text: Chapter 13, up to page 526). Using SIMULINK, simulate the lag digital controller and continuous plant. Provide responses and discussions for a variety of proper and improper sampling times.
5) For the variety of sampling times, convert the controllers found in 4 into a
difference equation (see text: Section 12.4 p. 481). Implement the difference equation in C-language on the digital computer controller and store the step response on the oscilloscope. Compare the experimental results with those found in 4. The project coordinator will show you how to implement your program within the interface software provided, and will show you how to change the sampling time on the computer.
6) After obtaining the system model from step 2 above, convert the continuous model
into an equivalent digital model (see text: Section 13.4 p. 526). Using the frequency domain method of Section 13.6, p. 540, design a digital lag controller for 20% overshoot. A variety of properly and improperly selected sampling times should be performed for SIMULINK simulation (see text: Section 12.4.1 p.484, Section 13.4.1 p. 528).
7) Convert the digital controllers into difference equations and repeat step 5.
MECH 473 Project Manual
Session #2 Introduction to Matlab/Simulink with QuaRC, and Senor Calibration
Objective:
The objective of this lab is to give an introduction to Simulink, DAQ interface with QuaRC and familiarize students with DC motor control system hardware integration. Introduction In this project, the MATLAB/SIMULINK is used to simulate the motor control system. QuaRC is used integrate Simulink with DAQ and hardware interface.
1. Matlab/Simulink: Start up Matlab and type simulink, or from the toolbar click New simulink model, or from the menu File, New, Model to start a Simulink session. A window with a library of building blocks appears:
Fig 2.1 library of building blocks and Simulink worksheet
The Following example is only a demo simulation for a simplified motor control system. For more information on Matlab/Simulink, check the following web site: Mathworks: www.mathworks.com
MECH 473 Project Manual
19
2. QuaRC integration: Here are the basic steps to apply a voltage to the DC motor using QuaRC: Design a Simulink model that interacts with DAQ device using block from QuaRC library, build and compile the code from the simulink model, and execute the code.
2.1 Designing the Simulink model as shown in Figure 2.4:
Figure 2.4 Sample Simulink model to apply voltage to DC motor
1) Create a new simulink diagram, open the simulink Library Browser window.
Figure 2.5 QuaRC Configuration fold in Simulink Library Browser Window
MECH 473 Project Manual
20
2) From QuaRC Targets\Data Acquistion\Generic\Configuration fold, Click-and- drag the HIL Initialize block to blank Simulink model. Double click the block in your Simulink model, choose Q4 as your hardware-in-the-loop board.
3) In the Library Browser, go to the Generic\Immediate I/O category. This contains various blocks used to interact with actuator and sensor:
Figure 2.6 QuaRC Targets Library Brower
4) Choose HIL Write Analog, click and drag it to blank Simulink model. Save your model as DC_out_xx . choose constant(value as 1), slide gain (set slide gain between -5 to +5), and connect them as Figure 2.4.
5) Connect a DMM to terminal board: analog out ch0 to check voltage
2.2 Compiling the model to generate code from a Simulink diagram: 1) Open your saved DC_out_xx model: set the simulink model for external (as
opposed to the Simulation mode). 2) To view the compiler options, go to QuaRC|Options in the Simulink model tool
bar. Check solver pane, start time: 0, stop time: inf, solver: discrete, Type: fixed step, sample time: 0.002 sec. You can change sample time as you needed late. As shown in figure 2.
3) Click Real time workshop pane, System target file: quarc_windows.tlc, Language: C. in the Makefole configuration section: Make command: make_rtw, Template makefile: quarc_default_tmf. As shown in Figure 2.8. Click OK to close the Configuration Parameter window.
4) Select The QuaRC|Build item. Various lines in the Matlab Command Window should be displayed as the model is being compiled.
MECH 473 Project Manual
Figure 2.8 Configuration parameter: Real-Time Workshop
MECH 473 Project Manual
22
2.3 Running QuaRC code Once the Simulink Model has been compiled, the code can be executed and the voltage set in the Simulink model can be sent to DC motor. Go though these steps:
1) Connection as shown in Figure 1.4, lab#1 step 3): Analog out ch0 voltage follower in, voltage follower out drive DC motor.
2) Click to Connect Target, turn on Power module then click to run, set slide gain to 4, the DC motor will turn at a constant speed in one direction, Change the slide gain to -4, the DC Motor will turn to other direction.
3. Sensor calibration:
3.1 Position sensor:
1) Potentiometer and Encoder: Build a model save as positionSesor.mdl as shown
in Figure 2.9:
Figure 2.9 Position sensor model
2) Using attenuator to supply +5 and 0v voltage to potentiometer. Connect back pot signal to terminal board analog in ch0, connect encoder to terminal board encoder ch0.
3) Turn motor shaft by hand, mark the position, from 0, 45, 90, 135, 180, 235, 270,315,360, record digital readings.
4) Find the sensitivity (or convert factor) of Pot and encoder in degree/v or degree/conter, or rad/v, rad/conter.
3.2 Speed sensor: 1) Modify above PositionSensor model to get tachometer signal, connect
tachometer signal by an attenuator gain of 0.5, then to analog in ch1. Add analog out as in Figure 2.4 to drive motor, set slide gain to 2, add a digital
MECH 473 Project Manual
23
differentiator to convert encoder position to speed. Put a saturate block before HIL analog write. Save your model as DC_speed.mdl.
2) Refer to Figure 1.4, 1.5 and 1.6, make your connection. Please ask your lab demonstrator to check the connection before turn on power supply.
3) Compile and Run the model, when motor is stable, record speed from tachometer and encoder. Using a hand held tachometer to verify the speed.
4) Then increase slide gain to 4 and repeat step #3. 5) Find out the sensitivity of tachometer and encoder.
MECH 473 Project Manual
Objective:
The objective of this lab is to give an introduction to the mathematical modeling and software simulation and familiarize students with motor control system hardware, software, and measurement instruments.
1. DC motor dynamic modeling:
The controller design and the system response are dependent on the DC motor dynamical model. The first requirement is to model the DC motor dynamic system.
Jm
Stator (Field Circuit) Rotor (Armature Circuit)
Fig. 1.1 shows the model of the DC motor system. Since this is the armature-controlled DC motor, the field current fi is kept constant.
atm iKT = (1)
where mT is the motor torque, tK is the torque constant, ai is the armature current.
Fig B 1 DC Motor
MECH 473 Project Manual
25
When the motor is driving a load, a back electromotive force (back EMF) voltage bV will be developed in the armature circuit. The back EMF voltage tends to oppose the voltage which produced the original current. ωeb KV = (2) where eK is the back-EMF constant, ω is the angular velocity of the motor system. The armature circuit equation is thus:
abaa a
Lmm TT dt df
2
(4)
where
mJ is the total inertia of the motor system, f is the damping constant (KD in the
data sheet), and LT is the load torque.
The electrical and mechanical transfer function can be derived by the above equations using Laplace transforms. The electrical transfer function is:
aaba RsLsVsV
1 --------- Ls+R
Fig. B 2 Electronical Block Diagram
MECH 473 Project Manual
fsJsT s
1 -----------
Fig. 4 Mechanical Block Diagram
The mechanical and electrical subsystems can be coupled through the electromagnetic field, and the total motor system transfer function can be got. The above total motor system becomes the plant in the overall system:
Plant Va ω
Or θ
2. Questions:
sV s
a
θ .
2) Consider generator as a load, derive the open loop transfer function: )( )(
sV s
Fig B 4 Total Motor as a Plant
MECH 473 Project Manual
27
3) Consider inertial disk as a load, derive the open loop transfer function: )( )(
sV s
a
θ .
4) Combining generator and inertial disk, derive a open loop transfer function for )( )( sV s
a
θ .
5) Can the electrical time constant be omitted? Explain why?
6) Using Simulink to get step response for open loop modeling, without load generator
load, with inertial load, and with both load.
7) Using Simulink to get step response for close loop unit feedback systems, adjust proportional gain if it is necessary.
MECH 473 Project Manual
Objective:
The objective of this lab is to verify DC motor system modeling, and identify the unknown system parameters in different system setup by step-response method. Introduction Transfer Function Estimation by Step Response The transfer function of a DC motor can be obtained by analyzing its step response. As seen in Appendix B, the motor’s Voltage to Angular Velocity transfer function can be approximated by a first order transfer function,
1)(
τ ω 3.1
The goal of this test will be to estimate the values for Km and τm by analyzing the response of the motor to a step input voltage. A step function will be input to the motor, and the signal from the tachometer will be observed. Remember that the voltage of the tachometer is proportional to the angular velocity of the motor. The above first order transfer function can be solved for time response if Va is a constant when t>0:
)1()( e m t
maKVt τω −−= 3.2 Note that the motor parameter value Km can be estimated by: when time t= ∞, and τm can be estimated by 63.2% of method. Transfer Function Estimation by Frequency Response A very powerful tool for identifying systems is the frequency response method. The key idea behind frequency response techniques is to input sinusoids into the linear system and study the response. A well-known result of linear theory establishes that the steady-state response of a linear system to a sinusoid is a sinusoid, with the same frequency as the input sinusoid, but, possibly, with a different amplitude and phase. The change in amplitude is equal to )( ωjG and the phase shift is ))j(G(Arg ω , where G(s) is the transfer function of the system, evaluated at the input frequency. Figure 1 shows a graphical representation of this idea. The goal of this test will be to input sine waves of varying frequencies and measure the ratio of amplitudes of output to input sines and the phase shift between the two waveforms. That will provide enough information to identify the linear system G(s).
MECH 473 Project Manual
29
Figure 3.1 Steady-State response of a linear system to a sinusoid
Test Procedure Transfer Function Estimation by Step Response:
1. Using the set of DC motor leads, universal power module, and the terminal board of the Q4 data acquisition card, complete the wiring diagram shown in Figure 1.2, 1.3, and 1.4.
2. Start MATLAB/SIMULINK. Build a model similar as you did in speed sensor test shown in Figure 3.2.
3. Now you can perform various steps of the DC-motor identification. However, before proceeding, you must request your laboratory Demonstrator or technician to check your connection and bock diagram. 1) DC motor only, no inertial load, no power resistor. Run program, and save
data. 2) DC motor with on big inertial disk. 3) DC motor with resistor load (50 power resistor). 4) DC motor with inertial and resistor load.
Figure 3.2 Model for transfer function estimation with time response method
G(s)
4. Compare your estimated parameters with your mathematical modeling parameters. 5. Simulate the experimental transfer functions and compare with you theoretical
results. Transfer Function Estimation by Frequency Response
1. Same connection as time response method. Start MATLAB/SIMULINK. Build a
model as shown in Figure 3.3.
Figure 3.3 Model for transfer function estimation with Frequency response method
2. Only using DC motor, no inertial disk, no resistor needed in this test. Run and save data, using Matlab/System Identification tool box to estimation the DC motor transfer function.
3. Compare the result with the one from time response, and with theoretical modeling.
MECH 473 Project Manual
Session #5 Motor Controller Implement— Matlab/Simulink (QuaRC)
Objectives The objectives of this lab are to implement a compensator for DC motor position control. Familiar students with different control approach—Simulink/QuaRC Introduction
When the computer reacts to external events as they occur, it is referred to as real-time control. An important consideration in real-time control is the update rate. During one controller cycle, three things must happen before the next cycle can begin: 1) Sensors are read (ADC inputs). 2) The microprocessor computes updated commands. 3) The commands are converted to analog signals (DAC outputs). Between cycles, the commands outputs are held constant. If the controller is updated every 0.01 seconds, the output of the controller would look like a staircase with steps 0.01 seconds wide. As expected, the faster the dynamics of the system being controlled), the faster the update rate must be. A real-time system reads inputs from the plant and sends control signals to the plant at
times determined by plant operational considerations- not at times limited by the capabilities of the computer system. Modern real-time control systems use computer aided software engineering (CASE) such as MATLAB's Real-Time Workshop to automatically generate C code from a graphical control model (like Simulink). Often the sensors or other components of the DAQ system are proprietary. Quanser provide Simulink blocks along with their hardware in order to ease the graphical modeling of their product(QuaRC). In this lab, we will focus on gaining familiarity with the HIL Q4 Data Acquisition Card and the QuaRC software and C or C++ program under Visual C++ environment. Procedure 1. Matlab/Simulink (QuaRC) Implementation: The PID control Block diagram window as following:
MECH 473 Project Manual
32
Fig. 4.1 Real Time Control Block Diagram Window In above close loop motor position control diagram, there is no plant transfer function. The plant is the real motor system. The analog output to power amplifier and then drive motor through HIL Q4 board. The encoder feedback through Q4 board and then compare with the set point. The building of block diagram is same as Lab #2. Under Simulink Library BrowserSimulink ExtrasAdditional Linear: choose PID controller block. The final block diagram is shown in above Fig 4.1. Before running the real time control, we have to choose external in the block diagram. Then, Simulation Configuration parameters solver option: choose fixed-step, step size and mode …, as shown in Fig 4.2. we can change fixed-step size according our simulation results. We will see how step size affects our control results.
MECH 473 Project Manual
33
Fig 4.2 Configuration of PID control Window After the setting of simulation parameters, we need to compile and build the program:
Next step is to connect to target by click the icon . Now it is ready to run the real time control. Make sure the power supply is on, and motor is in the initial zero position. The response is shown in Fig 4.3. If the model is changed, the Building and connect to target need to be redone.
Fig 4.3 Step Response of DC Motor Position Control
MECH 473 Project Manual
34
Questions
1. Compare the real time control step response with the theoretical Simulink
response by using different Motor setting and sample time.
MECH 473 Project Manual
Session #6 Motor Controller Implement— C Program
Objectives The objectives of this lab are to implement a compensator for DC motor position control. Familiar students with C program control approach. Introduction The general form of a real-time control program is: MODULE RealTimeControl; BEGIN Initialization; Loop{ Synchronization; Get plant data; Control calculation (Control Algorithm); EXIT condition check; Put control data to plant; }END loop; END RealTimeControl. In this lab, we will focus on gaining familiarity with the HIL Q4 Data Acquisition Card and C or C++ program under Visual C++ environment. Procedure Read and understand the Pcontrol.c code, especial the section of P controller. Refer to Appendix C and Appendix D, get your PID controller or other compensator,
Convert the Z transform formula into difference equations and implement them by C program. In this lab we will run the program Pcontrol.c. Open Pcontrol.c. Save Pcontrol.c as
Pcontrol 01.c, add your controller C code into this program, compile it. Run it and get the response plot, save them. Repeat the above procedure for different digital controllers. Questions
1. For C program implement, using Matlab plot, get the experimental step response
from the saved data file and plot it. Compare them with the theoretical Simulink response.
MECH 473 Project Manual
Appendix B Motor Controller Design
Objectives The objectives of this lab are to design a lead and a lag compensator for DC motor position control, to study the effect of lead and lag compensation, and other advanced controller. Introduction
The controller performs the intelligent tasks of the motor system. The most fundamental function of the controller is to close the loop, decode the motor position or velocity from the feedback signal, and compare it with the desired, reference position or velocity, with the objective to reduce the error to a minimum while controlling the system transient. To achieve this, the controller often includes a compensator (filter) whose output is then applied via the DAC to the amplifier.
Techniques used for controller design: If the specifications are given in terms of the transfer function, relating the output to the disturbance, it is natural to apply the methods that admit control of this transfer function. One of these methods is the Root Locus design method. Another method is the pole placement, which includes the State Space Approach and the Polynomial Approach. If the requirements are expressed as an optimization criterion, the optimization design techniques are often used. Another possible controller design method is to use the frequency response method. This design method is based on Bode and Nichols plots which are useful for designing compensators for linear systems described by transfer functions. In this project, the Lag/ Lead Compensation: Frequency Response Design method will be used. The simplest and most common form of compensation is a filter with one zero and one pole:
bs
)(1
It is a lead compensator if the zero occurs before the pole, i.e., 0<a<b, and a lag compensator if the pole occurs before the zero, i.e., a>b>0. The maximum phase contribution occurs, lead or lag, at ab=ω . (1) Lead Compensation- Frequency Response Design: The basic idea in lead compensation frequency response design is to shape the open-loop transfer function so that it will have:
MECH 473 Project Manual
Desirable low frequency gain (for steady-state error or disturbance rejection properties)
Desirable gain crossover frequency gcω (for speed of response) Adequate stability margins
The form for this compensator design is as follows:
)]1/()1[()(1 TsbTsKsG c ++= First choose the gain cK to satisfy steady-state error requirements. Then satisfy the phase margin requirements and attempt to achieve the desired gain crossover frequency, gcω . The outline of this lead compensation design technique is as following:
Select cK to satisfy the required steady-state error. Draw Bode plots for )( ωjGKc (uncompensated system), and determine the phase
& gain margin for )( ωjGKc . Determined additional phase lead required; εφφφ +−= sl where: lφ -- additional phase-lead required sφ -- specified phase margin φ -- phase margin of )( ωjGKc , uncompensated system ε -- safety factor, 5° Compute b, let maximum phase lead lm φφ =
m
− +
=
Find the frequency at which the gain of bjGKc log10)( −=ω . This frequency mω is the new crossover frequency for the compensated system.
Compute T, zω pω from:
b T
mω 1
1 =ω
where, zω and pω are two corner frequency. Draw Bode plots for the compensated system to confirm design, if the phase
margin is still low, increase ε and repeat the design. Simulate the close loop response.
MECH 473 Project Manual
(2) Lag compensation- Frequency Response Design:
A lag compensator reduces the gain of the system and adds phase lag. It is usually used when we wish to reduce plant gain. The most useful form of the lag compensator is )]1/()1[()(1 TsaTsKsG c ++= (0<a<1) As with lead compensation, we first choose cK to satisfy the steady-state error requirement. The parameters α and T are then found to meet the required phase-margin. The maximum gain reduction is αlog20 . The minimal phase contribution from the lag compensator occurs at Tαω /10= . The lag compensation- frequency response design is outlined as following:
Determine cK to satisfy error requirements. Draw Bode plots of )( ωiGKc . Find the new crossover frequency gω at which the phase margin is
satisfied. ( εφφ += sg ) Measure the gain at gω , and let it equal to αlog20 , then α is found.
Choose upper corner frequency, 10 ~
2 gg
ωω ω = , then Tz α
ω 1 = , the T can
be found. Check if the desired phase margin is obtained. If yes, draw Bode plot for the
compensated system. If not, choose another value for T and repeat the design step.
Simulate the closed-loop system.
For more detailed information about Lead/Lag compensation- Frequency response techniques, refer to the textbook Chapter 8, Frequency-Domain Techniques, and Lecture Notes, Lead Compensators/Lag Compensators.
Digital control system design A digital control system is one in which at least one element on the control loop is a digital component. One of the primary differences between an analog and digital system is in the update time of the controller. An analog controller has continuous feedback of the output signal and continuously applies corrective action to the plant. A digital system samples the output of the plant and applies a control action at discrete points in time. There are two different approaches for the design of digital control system: Continuous Design and Digitization: Perform a continuous design, then digitize the resulting compensation.
MECH 473 Project Manual
42
Direct Digital Design: Digitize the plant, then perform a design using discrete analysis methods.
1. Continuous design and digitization: the problem is: given a continuous controller
D(s), find the best digital implementation of that compensator. A digital implementation requires that the output be sampled at some sampling rate and that the computer output samples be smoothed in some manner (most of the time a zero- order hold is used) so as to provide a continuous input to the plant. There are three methods used for this approach:
Forward-Difference Method: T zs 1−
=
+ −
We can also use Time-Domain Invariance Methods: Impulse-Invariance Method or
Step-Invariance Method. 2. Direct Digital Design: The first step in performing a control design or analysis of a

s sGzzG )()1()( 1
The analysis and design of discrete systems is very similar to the analysis and design of continuous systems: in fact, all the same rules apply. For more detailed information, please refer to text Chapter 12, 13.
Procedures Try to design a lead compensator and a lag compensator for the DC motor position control system to obtain 20% overshoot. You will notice that neither compensators can achieve the system specification because the system is overdamped. Thus, you must apply a “lag- type” controller to “shape” your Bode diagram to achieve an underdamped response. Also design a PID control and simulate them for comparison. Convert the continuous compensator into digital one by trapezoidal approximation method. Simulate them. Convert the continuous model into an equivalent digital model, design a digital lag controller, and simulate the system by SIMULINK.
MECH 473 Project Manual
43
Questions:
1. Use Matlab/Simulink to get the step response of , the lag compensated and PID controlled system. Analyze the results.
2. Use Matlab/Simulink to get step responses of digital lag compensator and PID
controller with continuous model (plant). Analyze the results using different sample time.
3. Simulate the digital compensator with digital motor/load plant model and compare
them with question #2.
MECH 473 Project Manual
44
Appendix C: Guide for VC 2008 with Quanser HIL C API configuration
To create a new project
1. From the File menu, point to New, and then click Project….
2. In the Project Types area, click Win32. Then, in the Visual Studio installed
templates pane, click Win32 Console Application. 3. Type a name for the project. In this example, we'll use game.
When you create a new project, Visual Studio puts the project in a solution. Accept the default name for the solution, which is the same name as the project. You can accept the default location, type a different location, or browse to a directory where you want to save the project. Press OK to start the Win32 Application Wizard.
4. On the Overview page of the Win32 Application Wizard dialog box, click Next.
MECH 473 Project Manual
45
5. On the Application Settings page under Application type, select Console
Application. Select the Empty Project setting under Additional options and click Finish. You now have a project without source code files.
Using Solution Explorer Solution Explorer makes it easy for you to work with files and other resources in your solution. In this step, you add a class to the project and Visual Studio adds the .h and .cpp files to your project. You then add a new source code file to the project for the main program that tests the class.
Adding a Source File In this step, you add a source code file for the main program that tests the class.
To add a new source file 1. From the Project menu, click Add New Item.
Alternatively, to use Solution Explorer to add a new file to the project, right-click the Head Files, folder in Solution Explorer and point to Add. Then click Existing Item. Choose the Head file from your location.
2. Then add the source files to the project: Source Files folder in Solution Explorer and point to Add. Then click Existing Item. Choose the c file from your location
MECH 473 Project Manual
46
Setting up the C/C++ Application to use the HIL C API
The user needs to follow a set of steps to setup the C/C++ application to use the HIL C API. We assume that Microsoft Visual Studio 2005 or later version is being used to develop the application. Please perform the following procedure to setup your application, once in the Microsoft Visual Studio environment:
1. Open the Property Pages window by right-clicking on the project containing your application and choosing the Properties menu item in the context menu. The following figure illustrates this window.
MECH 473 Project Manual
47
2. In the Property Pages window, click on the C/C++ pane. The first parameter in this pane is called Additional Include Directories. Type in $(HIL_DIR)include in its field as shown in the figure below. Note that HIL_DIR is an environment variable referring to the directory in which the HIL API has been installed.
3. Click on the Linker pane and expand its treeview. In the General section of this pane, there is a parameter called Additional Library Directories. Type in $(HIL_DIR)lib\windows in its field as shown in the figure below.
MECH 473 Project Manual
48
4. While in the Linker pane, click on the Input section. The first parameter in this section is called Additional Dependencies. Type in hil.lib quanser_runtime.lib quanser_common.lib in this field as illustrated in the following figure. Note that the entries in this field should each be separated by a single space
5. Once all these changes are made, click on Apply and then OK. 6. Now, you can build and debug your solution
Follow Relevant Instructions
Avoid Cuts and Burns
Session #1 Introduction to DC Motor Control System
The objective of this lab is to give an introduction to the DC motor Control system, familiarize students with motor control system hardware, and measurement instruments.
System Introduction
1) Provide a mathematical model for the DC motor and loads (inertia and generator), for the driving circuit, and for the feedback. Note that the motor is GM9236, and the generator is GM9413. Two inertial disks will be used in the project. J1=1.4 e-4 k...
2) Assuming a continuous model with no controller (ie: unity forward proportional gain only), select a generator load (resistance = 5W) so the system feedback response to a position step input is highly oscillatory (underdamped). Using SIMULINK, show ...
It should be noted that for any generator load, the open-loop system is always overdamped and thus an underdamped system can never be obtained.
Do not forget to include the amplifier gain Ka = 2.5 V/V used to drive the DC motor/load system.
3) According to the frequency domain method, design a cascade controller for 20% overshoot. Show/discuss the differences in system response between a lead and a lag compensator. For each controller, simulate the position step response and correlate wi...
Since the system is overdamped, it should be noted that conventional lead or lag compensation methods cannot achieve an underdamped system. You must use a “lag-type” controller to “shape” your Bode diagram to achieve an underdamped system.
Vary the load resistance between 0 and 10W to see its effect.
4) Once the proper controller has been selected in 3, convert the continuous controller into a digital controller (see text: Chapter 13, up to page 526). Using SIMULINK, simulate the lag digital controller and continuous plant. Provide responses and d...
5) For the variety of sampling times, convert the controllers found in 4 into a difference equation (see text: Section 12.4 p. 481). Implement the difference equation in C-language on the digital computer controller and store the step response on the ...
6) After obtaining the system model from step 2 above, convert the continuous model into an equivalent digital model (see text: Section 13.4 p. 526). Using the frequency domain method of Section 13.6, p. 540, design a digital lag controller for 20% ov...
7) Convert the digital controllers into difference equations and repeat step 5.
Session #2 Introduction to Matlab/Simulink with QuaRC, and Senor Calibration
Fig 2.2 Block Diagram of Motor Control System
Session #3 Motor Dynamical Modeling
where is the motor torque, is the torque constant, is the armature current.
Fig B 1 DC Motor
When the motor is driving a load, a back electromotive force (back EMF) voltage will be developed in the armature circuit. The back EMF voltage tends to oppose the voltage which produced the original current.
Fig. B 2 Electronical Block Diagram
Session #4 DC Motor Transfer Function Estimation
Transfer Function Estimation by Step Response
Transfer Function Estimation by Frequency Response
Transfer Function Estimation by Frequency Response
Session #5 Motor Controller Implement— Matlab/Simulink (QuaRC)
Objectives
Procedure
Fig 4.2 Configuration of PID control Window
Questions
Objectives
Questions
Objectives
Procedures
Questions:
Appendix C: Guide for VC 2008 with Quanser HIL C API configuration
To create a new project
Using Solution Explorer