Lab Activity - DC Servomotor Simulink Modeling
In questa pagina 5
1. Activity goal
Implement an accurate Simulink model of the DC servomotor available in the laboratory, to verify the control design before the experimental tests. The model includes all the nonlinear effects that are relevant for the analysis and design of a control system: the saturation of the voltage command, the quantization of the encoder and of the digital-to-analog converter (DAC), and the Coulomb (static) friction of the gearbox. The analytical model is derived in Modeling a DC ServomotorA permanent-magnet DC motor is modeled by an electrical equation with a back-EMF term and a mechanical equation with inertia and viscous friction, a gearbox just adds the load inertia and friction divided by N squared on the motor side, and for the laboratory servomotor (voltage driver plus gearmotor plus disc) this gives a transfer function from input voltage to load angle that reduces to a first-order lag times an integrator.Modeling a DC Servomotor →.
2. Analytical model of the DC gearmotor
The permanent-magnet DC motor produces a rotation as the result of the interaction between the magnetic field generated by the armature current and the field of the stator magnets. A device called commutator keeps the armature current flowing always in the same direction within the stator field: maximum torque is obtained by always supplying the armature current to the armature coil facing perpendicularly the stator field. Electrical contacts called brushes (typically spring-loaded carbon contacts) supply the current to the commutator and, in turn, to the armature coils.
The lumped-element diagram of the SRV-02 gearmotor is the one of the experimental unit: the DC motor is represented by the equivalent circuit of its armature (series connection of resistance , inductance and BEMF source ) and by the rotor inertia . The rotor inertia is moved by the motor torque . A gearbox transfers the motion to an external inertial load with moment of inertia , with a rigid connection between gearbox and load (no elasticity). The armature voltage is supplied by a voltage driver. A shunt resistor is connected between the driver output and the armature circuit: by sensing the voltage drop across it () and knowing its nominal value it is possible to infer the current through it, which is the armature current .
Symbols (Table 1):
| symbol | meaning |
|---|---|
| , | rotor moment of inertia and viscous friction coefficient |
| , | load moment of inertia and viscous friction coefficient |
| , | resistance and inductance of the armature circuit |
| , | supply voltage and current to the armature circuit |
| back electromotive force (BEMF) | |
| , | torque and electric (BEMF) constants |
| , , | motor side torque, speed and position |
| , , | load side torque, speed and position |
| disturbance torque applied to the load inertia | |
| planetary gearbox reduction ratio | |
| shunt resistance | |
| , | voltage driver input and output voltages |
| , | voltage driver attenuation gain and cut-off frequency |
Load inertia and equations
The load inertia is , where is the moment of inertia of the extra disc on the output shaft and that of the external 72-tooth gear (the handout counts this gear contribution three times, as in gbox.J = 3*gbox.J72 in the listing). From the free-body diagram (internal torques and exchanged between rotor, gearbox and load) the lumped-parameter LTI model is
with
Equation (7) comes from the power balance of an ideal gearbox with efficiency: the input power equals the output power . The torque in (3) is a generic disturbance torque at the load side; here it models the Coulomb (static) friction of the mechanical transmission, a constant resistant torque opposing the motion:
Combining (2), (3) with (6), (7) gives the overall mechanical dynamics at motor side:
Alternatively, at load side:
where and are the total inertia and viscous friction seen at the load side. The total friction torque (viscous plus static) generated at the motor side, and the one at the load side, are
Voltage driver
The voltage is provided by a power operational amplifier in non-inverting configuration:
where is the voltage at the non-inverting input. The currents through and are and , and . After some algebra:
and combining (14) and (15):
which is a first-order low-pass filter with time constant (cut-off frequency in rad/s or in Hz) and DC gain .
Complete model, Laplace form, block diagram
Using (4) in (1), (5) in (9) and (18):
Laplace transform of (19)-(21):
This is the block diagram of Fig. 4: driver , then the electrical block with output , the gain giving , a summing node subtracting , the mechanical block with output , the integrator giving , the gain giving and another integrator giving , and the BEMF feedback subtracted from . After algebraic manipulation:
Since and , so that :
Typically the time constants of the voltage driver and of the armature circuit are both very small:
so that (27) simplifies to
3. Nominal parameters (Table 2)
| quantity | symbol | value |
|---|---|---|
| Armature resistance | ||
| Armature inductance | ||
| Electric (BEMF) constant | V s/rad | |
| Torque constant | N m/A | |
| Rotor inertia | kg m | |
| Rotor viscous friction coefficient | not available | |
| Gearbox ratio | 14 | |
| Moment of inertia of external 72-tooth gear | kg m | |
| Moment of inertia of extra disc | kg m | |
| Load viscous friction coefficient | to be estimated | |
| Voltage driver static gain | about 0.6 | |
| Voltage driver cut-off frequency | about 1.2 kHz | |
| Shunt resistance |
4. Laboratory assignments: numerical simulations (section 3.1, DC servomotor modelling)
S1. DC gearmotor model. Implement a Simulink model of the gearmotor according to the block diagram of Fig. 4, with the parameters of Table 2. Since the friction parameters are not yet known (they are estimated in Lab Activity - Friction and Inertia EstimationLaboratory activity that estimates the viscous friction, the Coulomb friction and the total rotor inertia of the DC servomotor from experimental data, using the torque balance at constant speed and at constant acceleration, a linear least squares fit and filtered current and speed measurements.Lab Activity - Friction and Inertia Estimation →), use these tentative values:
Remember . Position and speed in the model are in rad and rad/s, but for analysis it is preferred to use degrees and rpm, so insert two conversion gains: rad2deg=180/pi at the motor position output, and rads2rpm=60/2/pi at the motor speed output. A possible implementation is Fig. 5a, with parameters defined in the Matlab listing below.
S2. Voltage driver. Model it as in Fig. 5b: a Continuous > Transfer Function block for
(the low-pass dynamics) and a Discontinuities > Saturation block for the voltage limitation of the power amplifier. The amplifier output cannot exceed the supply levels, so set the saturation bounds to V.
S3. DAC. The DAC provides the reference voltage to the voltage driver (Fig. 5c). It contains a Discrete > Zero-Order Hold block that simulates the holding of the DAC output within each sampling period, a Discontinuities > Quantizer block for the quantization of the DAC output due to the finite resolution, and a Discontinuities > Saturation block for the finite output range. Set the ZOH sampling time to ms (the sampling time used in all experiments) and the saturation to V (positive/negative full scale). Since the DAC resolution is 16 bits, set the quantization interval to
S4. Incremental optical encoder. It measures the load position (Fig. 5d). The model contains a Discrete > Zero-Order Hold block that simulates the ideal sampling of the load-side position measurement (note: Simulink has no specific ideal-sampler block; the conventional way is a ZOH block, which as its name says is also the zero-order discrete-to-continuous interpolator), and a Discontinuities > Quantizer block for the finite resolution of the position transducer. Set the ZOH sampling time to ms and the quantization interval according to the encoder of the unit:
- for all the units except "MOTORE 8" and "MOTORE 10": deg
- for the "MOTORE 8" and "MOTORE 10" units: deg
The encoder output is the "pulse count", not a position in degrees, so insert a Math > Gain block at the quantizer output with gain .
S5. Speed filter. The speed is ideally obtained by differentiating the position, but the ideal derivative cannot be implemented: it violates causality (its transfer function is not proper) and it amplifies excessively the measurement noise (the encoder quantization) at high frequency. One therefore uses a "real derivative": a high-pass filter, i.e. the series of an ideal derivative and a low-pass filter of suitable order. Three speed filters are to be implemented:
a) continuous-time first-order high-pass filter:
b) continuous-time second-order high-pass filter:
c) discrete-time difference:
Fig. 5e shows a possible implementation: three subsystems (1) CT 1st order HPF with a Transfer Fcn block, (2) CT 2nd order HPF with a Transfer Fcn block, (3) DT HPF built with an N-samples delay subtracted from the input, followed by a gain ; a Multiport Switch (control input: a constant 1, 2 or 3) selects the filter, and a final gain degs2rpm converts the output to rpm.
S6. Whole servomotor. Combine the models of S1-S5 as in Fig. 5f: a Repeating Sequence source gives ; it goes through DAC, Voltage driver, "DC motor + gearbox" (outputs thl and wl), then the Encoder (output thl [pulses]), the gain pulse2deg (thl_meas) and the Speed filter (output wl_meas in rpm). Position measured in degrees, speed in rpm, with the conversion gains:
pulse2deg=360/ppr, whereppris the number of encoder pulses per rotation ( for all units except "MOTORE 8" and "MOTORE 10", for those)degs2rpm=60/360
S7. Test in simulation. Use either a Variable-step or a Fixed-step solver.
- Variable-step: select
ode45 (Dormand-Prince)(in Configuration Parameters > Solver > Type and Solver). With a variable step the simulation may hang when the speed becomes very small, because the solver cannot find a step where the speed does not change sign (a "too many zero crossings" error). To avoid it, deselect Enable zero-crossing detection in the Block Parameters of the Sign block used for the static friction torque. - Fixed-step: select
ode3 (Bogacki-Shampine). To simulate the continuous plant dynamics between consecutive sampling times (inter-sample behaviour) the maximum step of the solver must be smaller than the DAC and encoder sampling time; at most one tenth of the sampling time is recommended, so that the plant is evaluated at ten instants within each sampling period. A "rate transition" error may be issued when simulating a sampled-data system with a step smaller than the controller sampling time; it can be avoided by changing Configuration parameters > Diagnostics > Sample Time > Multitask rate transition from error to warning.
Test with a square-wave input voltage applied to the DAC, with main period:
Set the final simulation time to s (six complete periods). Compare the speed response obtained with the three speed filters; verify that filter (33) gives a noisier speed estimate than (34) and (35), and motivate the result by comparing the high-frequency attenuation of the three filters on a Bode plot (see Frequency Response of BIBO Stable SystemsFor a BIBO stable system W(s) driven by a sinusoid of angular frequency w, the output converges to a sinusoid of the same frequency whose amplitude is multiplied by |W(jw)| and whose phase is shifted by the angle of W(jw); the result extends to cosines and to sums of sinusoids.Frequency Response of BIBO Stable Systems →).
Typical results (Fig. 6): the load position grows linearly up to about deg in the first half period then returns; the speed reaches a plateau of the order of rpm in absolute value (with a first-order rise, read from the plot); the current shows a transient peak at each reversal of and then a small value. The measured speed with filter (a) is visibly noisy, while with (b) and (c) the measured trace is clean and overlaps the real one.
5. Matlab listing: load_params_inertial_case.m
%% General parameters and conversion gains
% conversion gains
rpm2rads = 2*pi/60; % [rpm] -> [rad/s]
rads2rpm = 60/2/pi; % [rad/s] -> [rpm]
rpm2degs = 360/60; % [rpm] -> [deg/s]
degs2rpm = 60/360; % [deg/s] -> [rpm]
deg2rad = pi/180; % [deg] -> [rad]
rad2deg = 180/pi; % [rad] -> [deg]
ozin2Nm = 0.706e-2; % [oz*inch] -> [N*m]
%% DC motor nominal parameters
% brushed DC-motor Faulhaber 2338S006S
mot.R = 2.6; % armature resistance
mot.L = 180e-6; % armature inductance
mot.Kt = 1.088 * ozin2Nm; % torque constant
mot.Ke = 0.804e-3 * rads2rpm; % back-EMF constant
mot.J = 5.523e-5 * ozin2Nm; % rotor inertia
mot.B = 0.0; % viscous friction coeff (n.a.)
mot.eta = 0.69; % motor efficiency
mot.PN = 3.23/mot.eta; % nominal output power
mot.UN = 6; % nominal voltage
mot.IN = mot.PN/mot.UN; % nominal current
mot.tauN = mot.Kt*mot.IN; % nominal torque
mot.taus = 2.42 * ozin2Nm; % stall torque
mot.w0 = 7200 * rpm2rads; % no-load speed
%% Gearbox nominal parameters
% planetary gearbox Micromotor SA 23/1
gbox.N1 = 14; % 1st reduction ratio (planetary gearbox)
gbox.eta1 = 0.80; % gearbox efficiency
% external transmission gears
gbox.N2 = 1; % 2nd reduction ratio (external trasmission gears)
gbox.J72 = 1.4e-6; % inertia of a single external 72 tooth gear
gbox.eta2 = 1; % external trasmission efficiency (n.a.)
% overall gearbox data
gbox.N = gbox.N1*gbox.N2; % total reduction ratio
gbox.eta = gbox.eta1*gbox.eta2; % total efficiency
gbox.J = 3*gbox.J72; % total inertia (at gearbox output)
%% Mechanical load nominal parameters
% inertia disc params
mld.JD = 3e-5; % load disc inertia
mld.BD = 0.0; % load viscous coeff (n.a.)
% overall mech load params
mld.J = mld.JD + gbox.J; % total inertia
mld.B = 2.5e-4; % total viscous fric coeff (estimated)
mld.tausf = 1.0e-2; % total static friction (estimated)
%% Voltage driver nominal parameters
% op-amp circuit params
drv.R1 = 7.5e3; % op-amp input resistor (dac to non-inverting in)
drv.R2 = 1.6e3; % op-amp input resistor (non-inverting in to gnd)
drv.R3 = 1.2e3; % op-amp feedback resistor (output to inverting in)
drv.R4 = 0.5e3; % op-amp feedback resistor (inverting in to gnd)
drv.C1 = 100e-9; % op-amp input capacitor
drv.outmax = 12; % op-amp max output voltage
% voltage driver dc-gain
drv.dcgain = drv.R2/(drv.R1+drv.R2) * (1 + drv.R3/drv.R4);
% voltage driver time constant
drv.Tc = drv.C1 * drv.R1*drv.R2/(drv.R1+drv.R2);
%% Sensors data
% shunt resistor
sens.curr.Rs = 0.5;
% Hewlett-Packard HEDS-5540#A06 optical encoder
sens.enc.ppr = 500*4; % pulses per rotation
sens.enc.pulse2deg = 360/sens.enc.ppr; % [pulses] -> [deg]
sens.enc.pulse2rad = 2*pi/sens.enc.ppr; % [pulses] -> [rad]
sens.enc.deg2pulse = sens.enc.ppr/360; % [deg] -> [pulses]
sens.enc.rad2pulse = sens.enc.ppr/2/pi; % [rad] -> [pulses]
% potentiometer 1 (Spectrol 138-0-0-103) - installed on motor box
sens.pot1.range.R = 10e3; % ohmic value range
sens.pot1.range.V = 5; % voltage range
sens.pot1.range.th_deg = 345; % angle range [deg]
sens.pot1.range.th = sens.pot1.range.th_deg * deg2rad; % angle range [rad]
sens.pot1.deg2V = sens.pot1.range.V / sens.pot1.range.th_deg; % sensitivity [V/deg]
sens.pot1.rad2V = sens.pot1.range.V / sens.pot1.range.th; % sensitivity [V/rad]
sens.pot1.V2deg = 1/sens.pot1.deg2V; % conversion gain [V] -> [deg]
sens.pot1.V2rad = 1/sens.pot1.rad2V; % conversion gain [V] -> [rad]
%% Data acquisition board (daq) data
% NI PCI-6221 DAC data
daq.dac.bits = 16; % resolution (bits)
daq.dac.fs = 10; % full scale
daq.dac.q = 2*daq.dac.fs/(2^daq.dac.bits-1); % quantization
% NI PCI-6221 ADC data
daq.adc.bits = 16; % resolution (bits)
daq.adc.fs = 10; % full scale (as set in SLDRT Analog Input block)
daq.adc.q = 2*daq.adc.fs/(2^daq.adc.bits-1); % quantizationNote: mld.B = 2.5e-4 and mld.tausf = 1.0e-2 are labelled "estimated" in the listing, and the motor constants are given in the datasheet units ( and V per rpm) and converted with ozin2Nm and rads2rpm. The listing was transcribed from the small printed text of the handout.
Versione ripasso
Goal. Simulink model of the servomotor with voltage saturation, DAC and encoder quantization, Coulomb friction; see Modeling a DC ServomotorA permanent-magnet DC motor is modeled by an electrical equation with a back-EMF term and a mechanical equation with inertia and viscous friction, a gearbox just adds the load inertia and friction divided by N squared on the motor side, and for the laboratory servomotor (voltage driver plus gearmotor plus disc) this gives a transfer function from input voltage to load angle that reduces to a first-order lag times an integrator.Modeling a DC Servomotor →.
Model. , , , with , , , , , . Simplified (28):
Parameters. , H, , , , , , , , kHz, . Tentative friction: , N m.
Tasks.
- S1 gearmotor from Fig. 4 plus gains
rad2deg=180/pi,rads2rpm=60/2/pi. - S2 driver: Transfer Fcn and Saturation V.
- S3 DAC: ZOH ms, Quantizer V, Saturation V.
- S4 encoder: ZOH ms, Quantizer deg ( for units 8 and 10), gain .
- S5 speed filters: , ; , , ; , . The ideal derivative is non-causal and amplifies noise.
- S6 top model: Repeating Sequence, DAC, Driver, Motor+gearbox, Encoder,
pulse2deg=360/ppr, Speed filter,degs2rpm=60/360. - S7 test: square wave V, period 3 s, 18 s total. Variable step:
ode45, disable zero-crossing detection in the Sign block. Fixed step:ode3, step at most , rate transition error to warning. Filter (33) is noisier than (34) and (35).
Typical error: forgetting the gain after the encoder quantizer, or a solver step not smaller than .
Equazioni del modello completo (numerazione del testo):
- Elettrica (1): , con (4) e (5).
- Meccanica del rotore (2) e del carico (3): e .
- Riduttore (6)-(7): , (potenza conservata, rendimento 100%).
- Attrito di Coulomb (8): .
- Dinamica equivalente lato motore (9)-(10): , con e .
- Attrito totale lato motore (12): .
Driver (14)-(18):
- Non invertente: .
- Costante di tempo: ; guadagno: .
- Passa-basso del primo ordine: , con .
Modello di Laplace e funzione di trasferimento: Con e (28): L'integratore viene da e .
Valori nominali: , H, , , kg m, kg m, kg m, , . Non noti: , (da stimare). Attrito provvisorio: , N m.
S1 e S2 (motore e driver): (il fattore 3 sul gruppo ingranaggi è nel listato). Conversioni: rad2deg = 180/pi sulla posizione, rads2rpm = 60/2/pi sulla velocità. Driver: funzione di trasferimento e saturazione a V.
S3 (DAC): ZOH con ms, quantizzatore con V (risoluzione 16 bit), saturazione a V.
S4 (encoder): ZOH con ms, quantizzatore con deg, oppure deg per MOTORE 8 e MOTORE 10. Dopo il quantizzatore un guadagno : l'uscita è un conteggio di impulsi, non gradi.
S5 (filtri di velocità): la derivata ideale non è propria e amplifica il rumore di quantizzazione. Tre filtri:
- , ;
- , , ;
- , , ms.
S6 (modello completo): Repeating Sequence DAC driver motore con riduttore encoder pulse2deg filtro di velocità. Costanti:
drv.dcgain = drv.R2/(drv.R1+drv.R2) * (1 + drv.R3/drv.R4);
drv.Tc = drv.C1 * drv.R1*drv.R2/(drv.R1+drv.R2);
sens.enc.pulse2deg = 360/sens.enc.ppr; % ppr = 500*4S7 (test): onda quadra V con semiperiodo 1.5 s, tempo finale 18 s (sei periodi completi).
- Passo variabile (
ode45): se la velocità si azzera si può bloccare; disattivare Enable zero-crossing detection nel blocco Sign. - Passo fisso (
ode3): passo massimo , cioè dieci valutazioni del modello per periodo di campionamento. - Confronto: il filtro (33) dà una velocità più rumorosa di (34) e (35).
Risultati attesi: posizione che cresce linearmente fino a circa 2000 deg nel primo semiperiodo; velocità in plateau di circa 250 rpm in valore assoluto; picco transitorio di a ogni inversione di .
Errori tipici:
- Dimenticare che include , non .
- Usare dell'encoder da 500 ppr per MOTORE 8 o 10 (si usa 1024).
- Passo del solver non minore di con passo fisso: il modello perde il comportamento tra i campioni.