Salta al contenuto
Note per Studenti Lab Activity - DC Servomotor Simulink Modeling Report

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 RaR_a, inductance LaL_a and BEMF source ueu_e) and by the rotor inertia JmJ_m. The rotor inertia is moved by the motor torque τm\tau_m. A gearbox transfers the motion to an external inertial load with moment of inertia JdJ_d, with a rigid connection between gearbox and load (no elasticity). The armature voltage uau_a is supplied by a voltage driver. A shunt resistor RsR_s is connected between the driver output and the armature circuit: by sensing the voltage drop across it (udrv−uau_{drv}-u_a) and knowing its nominal value it is possible to infer the current through it, which is the armature current iai_a.

Symbols (Table 1):

symbol meaning
JmJ_m, BmB_m rotor moment of inertia and viscous friction coefficient
JlJ_l, BlB_l load moment of inertia and viscous friction coefficient
RaR_a, LaL_a resistance and inductance of the armature circuit
uau_a, iai_a supply voltage and current to the armature circuit
ueu_e back electromotive force (BEMF)
ktk_t, kek_e torque and electric (BEMF) constants
τm\tau_m, ωm\omega_m, ϑm\vartheta_m motor side torque, speed and position
τl\tau_l, ωl\omega_l, ϑl\vartheta_l load side torque, speed and position
τd\tau_d disturbance torque applied to the load inertia
NN planetary gearbox reduction ratio
RsR_s shunt resistance
uu, udrvu_{drv} voltage driver input and output voltages
kdrvk_{drv}, fc,drvf_{c,drv} voltage driver attenuation gain and cut-off frequency

Load inertia and equations

The load inertia is Jl=Jd+3 J72J_l = J_d + 3\,J_{72}, where JdJ_d is the moment of inertia of the extra disc on the output shaft and J72J_{72} 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 τl′\tau'_l and τl\tau_l exchanged between rotor, gearbox and load) the lumped-parameter LTI model is

{Ladiadt+(Ra+Rs) ia=udrv−ue(1) electrical dynamicsJmdωmdt+Bm ωm=τm−τl′(2) rotor mechanical dynamicsJldωldt+Bl ωl=τl−τd(3) load mechanical dynamics\begin{cases} L_a\dfrac{di_a}{dt} + (R_a+R_s)\,i_a = u_{drv} - u_e & \text{(1) electrical dynamics}\\[2mm] J_m\dfrac{d\omega_m}{dt} + B_m\,\omega_m = \tau_m - \tau'_l & \text{(2) rotor mechanical dynamics}\\[2mm] J_l\dfrac{d\omega_l}{dt} + B_l\,\omega_l = \tau_l - \tau_d & \text{(3) load mechanical dynamics}\end{cases}

with

{ue=ke ωm(4) law of generatorsτm=kt ia(5) law of motors{ωl=ωm/N(6) gearbox speed transformationτl=N τl′(7) gearbox torque transformation\begin{cases} u_e = k_e\,\omega_m & \text{(4) law of generators}\\ \tau_m = k_t\,i_a & \text{(5) law of motors}\end{cases}\qquad \begin{cases} \omega_l = \omega_m/N & \text{(6) gearbox speed transformation}\\ \tau_l = N\,\tau'_l & \text{(7) gearbox torque transformation}\end{cases}

Equation (7) comes from the power balance of an ideal gearbox with 100%100\% efficiency: the input power Pm=τl′ ωmP_m=\tau'_l\,\omega_m equals the output power Pl=τl ωlP_l=\tau_l\,\omega_l. The torque τd\tau_d 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:

τd=τsf sign(ωl),τsf>0(8) Coulomb friction at load side\tau_d = \tau_{sf}\,\mathrm{sign}(\omega_l),\qquad \tau_{sf}>0\qquad\text{(8) Coulomb friction at load side}

Combining (2), (3) with (6), (7) gives the overall mechanical dynamics at motor side:

Jeqdωmdt+Beq ωm=τm−1N τd(9),Jeq=Jm+JlN2,Beq=Bm+BlN2(10)J_{eq}\frac{d\omega_m}{dt} + B_{eq}\,\omega_m = \tau_m - \frac1N\,\tau_d\quad(9),\qquad J_{eq} = J_m + \frac{J_l}{N^2},\quad B_{eq} = B_m + \frac{B_l}{N^2}\quad(10)

Alternatively, at load side:

N2Jeqdωldt+N2Beq ωl=N τm−τd(11)N^2 J_{eq}\frac{d\omega_l}{dt} + N^2 B_{eq}\,\omega_l = N\,\tau_m - \tau_d\qquad(11)

where N2JeqN^2J_{eq} and N2BeqN^2B_{eq} 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

τf′=Beq ωm+τsfN sign(ωm)  (12),τf=N τf′=N2Beq ωl+τsf sign(ωl)  (13)\tau'_f = B_{eq}\,\omega_m + \frac{\tau_{sf}}{N}\,\mathrm{sign}(\omega_m)\ \ (12),\qquad \tau_f = N\,\tau'_f = N^2B_{eq}\,\omega_l + \tau_{sf}\,\mathrm{sign}(\omega_l)\ \ (13)

Voltage driver

The voltage udrvu_{drv} is provided by a power operational amplifier in non-inverting configuration:

udrv=(1+R3R4)u+(14)u_{drv} = \Big(1+\frac{R_3}{R_4}\Big)u_+\qquad(14)

where u+u_+ is the voltage at the non-inverting input. The currents through C1C_1 and R2R_2 are i1=C1 du+/dti_1 = C_1\,du_+/dt and i2=u+/R2i_2 = u_+/R_2, and u+=u−R1(i1+i2)u_+ = u - R_1(i_1+i_2). After some algebra:

(R1R2C1R1+R2)du+dt+u+=R2R1+R2 u(15)\Big(\frac{R_1R_2C_1}{R_1+R_2}\Big)\frac{du_+}{dt} + u_+ = \frac{R_2}{R_1+R_2}\,u\qquad(15)

and combining (14) and (15):

(R1R2C1R1+R2)dudrvdt+udrv=(1+R3R4)R2R1+R2 u(16)\Big(\frac{R_1R_2C_1}{R_1+R_2}\Big)\frac{du_{drv}}{dt} + u_{drv} = \Big(1+\frac{R_3}{R_4}\Big)\frac{R_2}{R_1+R_2}\,u\qquad(16)

kdrv=(1+R3R4)R2R1+R2,Tdrv=R1R2C1R1+R2(17)k_{drv} = \Big(1+\frac{R_3}{R_4}\Big)\frac{R_2}{R_1+R_2},\qquad T_{drv} = \frac{R_1R_2C_1}{R_1+R_2}\qquad(17)

Tdrvdudrvdt+udrv=kdrv u(18) voltage driver dynamicsT_{drv}\frac{du_{drv}}{dt} + u_{drv} = k_{drv}\,u\qquad\text{(18) voltage driver dynamics}

which is a first-order low-pass filter with time constant TdrvT_{drv} (cut-off frequency ωc=1/Tdrv\omega_c = 1/T_{drv} in rad/s or fc=1/(2πTdrv)f_c = 1/(2\pi T_{drv}) in Hz) and DC gain kdrvk_{drv}.

Complete model, Laplace form, block diagram

Using (4) in (1), (5) in (9) and (18):

{Ladiadt+Req ia=udrv−ke ωm(19)Jeqdωmdt+Beq ωm=kt ia−1N τd(20)Tdrvdudrvdt+udrv=kdrv u(21)Req=Ra+Rs  (22)\begin{cases} L_a\dfrac{di_a}{dt} + R_{eq}\,i_a = u_{drv} - k_e\,\omega_m & (19)\\[2mm] J_{eq}\dfrac{d\omega_m}{dt} + B_{eq}\,\omega_m = k_t\,i_a - \dfrac1N\,\tau_d & (20)\\[2mm] T_{drv}\dfrac{du_{drv}}{dt} + u_{drv} = k_{drv}\,u & (21)\end{cases}\qquad R_{eq} = R_a + R_s\ \ (22)

Laplace transform of (19)-(21):

{(Las+Req) Ia(s)=Udrv(s)−ke Ωm(s)(23)(Jeqs+Beq) Ωm(s)=kt Ia(s)−1N Td(s)(24)(Tdrvs+1) Udrv(s)=kdrv U(s)(25)\begin{cases} (L_a s + R_{eq})\,I_a(s) = U_{drv}(s) - k_e\,\Omega_m(s) & (23)\\ (J_{eq}s + B_{eq})\,\Omega_m(s) = k_t\,I_a(s) - \tfrac1N\,T_d(s) & (24)\\ (T_{drv}s+1)\,U_{drv}(s) = k_{drv}\,U(s) & (25)\end{cases}

This is the block diagram of Fig. 4: driver kdrv/(Tdrvs+1)k_{drv}/(T_{drv}s+1), then the electrical block 1/(Las+Ra+Rs)1/(L_as+R_a+R_s) with output iai_a, the gain ktk_t giving τm\tau_m, a summing node subtracting τd/N\tau_d/N, the mechanical block 1/((Jm+Jl/N2)s+(Bm+Bl/N2))1/\big((J_m+J_l/N^2)s + (B_m+B_l/N^2)\big) with output ωm\omega_m, the integrator 1/s1/s giving ϑm\vartheta_m, the gain 1/N1/N giving ωl\omega_l and another integrator giving ϑl\vartheta_l, and the BEMF feedback ωm→ke→ue\omega_m\to k_e\to u_e subtracted from udrvu_{drv}. After algebraic manipulation:

Pu→ωm(s)=Ωm(s)U(s)=kdrvTdrvs+1⋅kt(Las+Req)(Jeqs+Beq)+ktke(26)P_{u\to\omega_m}(s) = \frac{\Omega_m(s)}{U(s)} = \frac{k_{drv}}{T_{drv}s+1}\cdot\frac{k_t}{(L_as+R_{eq})(J_{eq}s+B_{eq})+k_tk_e}\qquad(26)

Since ωl=ωm/N\omega_l=\omega_m/N and ωl=dϑl/dt\omega_l = d\vartheta_l/dt, so that Θl(s)=Ωm(s)/(Ns)\Theta_l(s)=\Omega_m(s)/(Ns):

Pu→ϑl(s)=Θl(s)U(s)=kdrvTdrvs+1⋅kt(Las+Req)(Jeqs+Beq)+ktke⋅1Ns(27)P_{u\to\vartheta_l}(s) = \frac{\Theta_l(s)}{U(s)} = \frac{k_{drv}}{T_{drv}s+1}\cdot\frac{k_t}{(L_as+R_{eq})(J_{eq}s+B_{eq})+k_tk_e}\cdot\frac1{Ns}\qquad(27)

Typically the time constants of the voltage driver and of the armature circuit are both very small:

La/Req≪1,Tdrv≪1(28)L_a/R_{eq}\ll1,\qquad T_{drv}\ll1\qquad(28)

so that (27) simplifies to

P(s)=kdrvktReq(Jeqs+Beq)+ktke⋅1Ns=kmTms+1⋅1Ns  (29),km=kdrvktReqBeq+ktke,Tm=ReqJeqReqBeq+ktke  (30)P(s) = \frac{k_{drv}k_t}{R_{eq}(J_{eq}s+B_{eq})+k_tk_e}\cdot\frac1{Ns} = \frac{k_m}{T_ms+1}\cdot\frac1{Ns}\ \ (29),\qquad k_m = \frac{k_{drv}k_t}{R_{eq}B_{eq}+k_tk_e},\quad T_m = \frac{R_{eq}J_{eq}}{R_{eq}B_{eq}+k_tk_e}\ \ (30)

3. Nominal parameters (Table 2)

quantity symbol value
Armature resistance RaR_a 2.6 Ω2.6\ \Omega
Armature inductance LaL_a 180 μH180\ \mu\text{H}
Electric (BEMF) constant kek_e 7.68×10−37.68\times10^{-3} V s/rad
Torque constant ktk_t 7.682×10−37.682\times10^{-3} N m/A
Rotor inertia JmJ_m 3.90×10−73.90\times10^{-7} kg m2^2
Rotor viscous friction coefficient BmB_m not available
Gearbox ratio NN 14
Moment of inertia of external 72-tooth gear J72J_{72} 1.4×10−61.4\times10^{-6} kg m2^2
Moment of inertia of extra disc JdJ_d 3.0×10−53.0\times10^{-5} kg m2^2
Load viscous friction coefficient BlB_l to be estimated
Voltage driver static gain kdrvk_{drv} about 0.6
Voltage driver cut-off frequency fc,drvf_{c,drv} about 1.2 kHz
Shunt resistance RsR_s 0.5 Ω0.5\ \Omega

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:

Beq=1.28×10−6 N m/(rad/s),τsf=1.0×10−2 N m(31)B_{eq} = 1.28\times10^{-6}\ \text{N m/(rad/s)},\qquad \tau_{sf} = 1.0\times10^{-2}\ \text{N m}\qquad(31)

Remember Jl=Jd+3J72J_l = J_d + 3J_{72}. 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

Hdrv(s)=kdrvTdrvs+1(32)H_{drv}(s) = \frac{k_{drv}}{T_{drv}s+1}\qquad(32)

(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 ±12\pm12 V.

S3. DAC. The DAC provides the reference voltage uu 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 Ts=1T_s = 1 ms (the sampling time used in all experiments) and the saturation to ±10\pm10 V (positive/negative full scale). Since the DAC resolution is 16 bits, set the quantization interval to

q=20216−1 Vq = \frac{20}{2^{16}-1}\ \text{V}

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 Ts=1T_s=1 ms and the quantization interval qq according to the encoder of the unit:

  • for all the units except "MOTORE 8" and "MOTORE 10": q=360/(500×4)q = 360/(500\times4) deg
  • for the "MOTORE 8" and "MOTORE 10" units: q=360/(1024×4)q = 360/(1024\times4) 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 1/q1/q.

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:

H1(s)=sTcs+1,Tc=12π 50(33)H_1(s) = \frac{s}{T_cs+1},\qquad T_c = \frac1{2\pi\,50}\qquad(33)

b) continuous-time second-order high-pass filter:

H2(s)=ωc2 ss2+2δωcs+ωc2,ωc=2π 50,δ=12(34)H_2(s) = \frac{\omega_c^2\,s}{s^2+2\delta\omega_cs+\omega_c^2},\qquad \omega_c = 2\pi\,50,\quad \delta = \frac1{\sqrt2}\qquad(34)

c) discrete-time difference:

H3(z)=1−z−NN Ts,N=10,Ts=1 ms(35)H_3(z) = \frac{1-z^{-N}}{N\,T_s},\qquad N=10,\quad T_s = 1\ \text{ms}\qquad(35)

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 z−dz^{-d} subtracted from the input, followed by a gain 1/(Ts⋅N)1/(T_s\cdot N); 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 uu; 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, where ppr is the number of encoder pulses per rotation (500×4500\times4 for all units except "MOTORE 8" and "MOTORE 10", 1024×41024\times4 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 uu applied to the DAC, with main period:

u(t)={6 V0 s≤t<1.5 s−6 V1.5 s≤t<3 s(36)u(t) = \begin{cases} 6\ \text{V} & 0\ \text{s}\le t<1.5\ \text{s}\\ -6\ \text{V} & 1.5\ \text{s}\le t<3\ \text{s}\end{cases}\qquad(36)

Set the final simulation time to 1818 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 20002000 deg in the first half period then returns; the speed reaches a plateau of the order of 250250 rpm in absolute value (with a first-order rise, read from the plot); the current iai_a shows a transient peak at each reversal of uu 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

matlab
%% 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);     %   quantization

Note: 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 (oz⋅in\text{oz}\cdot\text{in} 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. Lai˙a+Reqia=udrv−keωmL_a\dot i_a + R_{eq}i_a = u_{drv}-k_e\omega_m, Jeqω˙m+Beqωm=ktia−τd/NJ_{eq}\dot\omega_m + B_{eq}\omega_m = k_ti_a - \tau_d/N, Tdrvu˙drv+udrv=kdrvuT_{drv}\dot u_{drv}+u_{drv}=k_{drv}u, with Req=Ra+RsR_{eq}=R_a+R_s, Jeq=Jm+Jl/N2J_{eq}=J_m+J_l/N^2, Beq=Bm+Bl/N2B_{eq}=B_m+B_l/N^2, Jl=Jd+3J72J_l = J_d+3J_{72}, τd=τsf sign(ωl)\tau_d=\tau_{sf}\,\mathrm{sign}(\omega_l), ωl=ωm/N\omega_l=\omega_m/N. Simplified (28):

P(s)=kmTms+1⋅1NsP(s) = \frac{k_m}{T_ms+1}\cdot\frac1{Ns}

Parameters. Ra=2.6 ΩR_a=2.6\ \Omega, La=180 μL_a=180\ \muH, ke=7.68×10−3k_e=7.68\times10^{-3}, kt=7.682×10−3k_t=7.682\times10^{-3}, Jm=3.9×10−7J_m=3.9\times10^{-7}, N=14N=14, J72=1.4×10−6J_{72}=1.4\times10^{-6}, Jd=3×10−5J_d=3\times10^{-5}, kdrv≈0.6k_{drv}\approx0.6, fc,drv≈1.2f_{c,drv}\approx1.2 kHz, Rs=0.5 ΩR_s=0.5\ \Omega. Tentative friction: Beq=1.28×10−6B_{eq}=1.28\times10^{-6}, τsf=10−2\tau_{sf}=10^{-2} N m.

Tasks.

  • S1 gearmotor from Fig. 4 plus gains rad2deg=180/pi, rads2rpm=60/2/pi.
  • S2 driver: Transfer Fcn kdrv/(Tdrvs+1)k_{drv}/(T_{drv}s+1) and Saturation ±12\pm12 V.
  • S3 DAC: ZOH Ts=1T_s=1 ms, Quantizer q=20/(216−1)q=20/(2^{16}-1) V, Saturation ±10\pm10 V.
  • S4 encoder: ZOH Ts=1T_s=1 ms, Quantizer q=360/(500×4)q=360/(500\times4) deg (1024×41024\times4 for units 8 and 10), gain 1/q1/q.
  • S5 speed filters: H1=s/(Tcs+1)H_1=s/(T_cs+1), Tc=1/(2π50)T_c=1/(2\pi50); H2=ωc2s/(s2+2δωcs+ωc2)H_2=\omega_c^2s/(s^2+2\delta\omega_cs+\omega_c^2), ωc=2π50\omega_c=2\pi50, δ=1/2\delta=1/\sqrt2; H3=(1−z−N)/(NTs)H_3=(1-z^{-N})/(NT_s), N=10N=10. 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 ±6\pm6 V, period 3 s, 18 s total. Variable step: ode45, disable zero-crossing detection in the Sign block. Fixed step: ode3, step at most Ts/10T_s/10, rate transition error to warning. Filter (33) is noisier than (34) and (35).

Typical error: forgetting the 1/q1/q gain after the encoder quantizer, or a solver step not smaller than TsT_s.

Equazioni del modello completo (numerazione del testo):

  • Elettrica (1): Ladiadt+(Ra+Rs) ia=udrv−ueL_a\dfrac{di_a}{dt} + (R_a+R_s)\,i_a = u_{drv} - u_e, con ue=keωmu_e = k_e\omega_m (4) e τm=ktia\tau_m = k_t i_a (5).
  • Meccanica del rotore (2) e del carico (3): Jmω˙m+Bmωm=τm−τl′J_m\dot\omega_m + B_m\omega_m = \tau_m - \tau_l' e Jlω˙l+Blωl=τl−τdJ_l\dot\omega_l + B_l\omega_l = \tau_l - \tau_d.
  • Riduttore (6)-(7): ωl=ωm/N\omega_l = \omega_m/N, τl=Nτl′\tau_l = N\tau_l' (potenza conservata, rendimento 100%).
  • Attrito di Coulomb (8): τd=τsf sign(ωl)\tau_d = \tau_{sf}\,\mathrm{sign}(\omega_l).
  • Dinamica equivalente lato motore (9)-(10): Jeqω˙m+Beqωm=τm−1NτdJ_{eq}\dot\omega_m + B_{eq}\omega_m = \tau_m - \dfrac{1}{N}\tau_d, con Jeq=Jm+Jl/N2J_{eq} = J_m + J_l/N^2 e Beq=Bm+Bl/N2B_{eq} = B_m + B_l/N^2.
  • Attrito totale lato motore (12): τf′=Beqωm+τsfN sign(ωm)\tau_f' = B_{eq}\omega_m + \dfrac{\tau_{sf}}{N}\,\mathrm{sign}(\omega_m).

Driver (14)-(18):

  1. Non invertente: udrv=(1+R3/R4) u+u_{drv} = (1 + R_3/R_4)\,u_+.
  2. Costante di tempo: Tdrv=R1R2C1R1+R2T_{drv} = \dfrac{R_1R_2C_1}{R_1+R_2}; guadagno: kdrv=(1+R3/R4)R2R1+R2k_{drv} = (1+R_3/R_4)\dfrac{R_2}{R_1+R_2}.
  3. Passa-basso del primo ordine: Tdrvu˙drv+udrv=kdrv uT_{drv}\dot u_{drv} + u_{drv} = k_{drv}\,u, con ωc=1/Tdrv\omega_c = 1/T_{drv}.

Modello di Laplace e funzione di trasferimento: Pu→ωm(s)=kdrvTdrvs+1⋅kt(Las+Req)(Jeqs+Beq)+ktkeP_{u\to\omega_m}(s) = \frac{k_{drv}}{T_{drv}s+1}\cdot\frac{k_t}{(L_as+R_{eq})(J_{eq}s+B_{eq})+k_tk_e} Con La/Req≪1L_a/R_{eq} \ll 1 e Tdrv≪1T_{drv} \ll 1 (28): P(s)=kmTms+1⋅1Ns,km=kdrvktReqBeq+ktke,Tm=ReqJeqReqBeq+ktke.P(s) = \frac{k_m}{T_ms+1}\cdot\frac{1}{Ns}, \qquad k_m = \frac{k_{drv}k_t}{R_{eq}B_{eq}+k_tk_e}, \quad T_m = \frac{R_{eq}J_{eq}}{R_{eq}B_{eq}+k_tk_e}. L'integratore 1/(Ns)1/(Ns) viene da ωl=ωm/N\omega_l = \omega_m/N e ωl=ϑ˙l\omega_l = \dot\vartheta_l.

Valori nominali: Ra=2.6 ΩR_a = 2.6\ \Omega, La=180 μL_a = 180\ \muH, ke=7.68×10−3k_e = 7.68\times10^{-3}, kt=7.682×10−3k_t = 7.682\times10^{-3}, Jm=3.90×10−7J_m = 3.90\times10^{-7} kg m2^2, J72=1.4×10−6J_{72} = 1.4\times10^{-6} kg m2^2, Jd=3.0×10−5J_d = 3.0\times10^{-5} kg m2^2, N=14N = 14, Rs=0.5 ΩR_s = 0.5\ \Omega. Non noti: BmB_m, BlB_l (da stimare). Attrito provvisorio: Beq=1.28×10−6B_{eq} = 1.28\times10^{-6}, τsf=10−2\tau_{sf} = 10^{-2} N m.

S1 e S2 (motore e driver): Jl=Jd+3J72J_l = J_d + 3J_{72} (il fattore 3 sul gruppo ingranaggi è nel listato). Conversioni: rad2deg = 180/pi sulla posizione, rads2rpm = 60/2/pi sulla velocità. Driver: funzione di trasferimento kdrv/(Tdrvs+1)k_{drv}/(T_{drv}s+1) e saturazione a ±12\pm 12 V.

S3 (DAC): ZOH con Ts=1T_s = 1 ms, quantizzatore con q=20216−1q = \dfrac{20}{2^{16}-1} V (risoluzione 16 bit), saturazione a ±10\pm 10 V.

S4 (encoder): ZOH con Ts=1T_s = 1 ms, quantizzatore con q=360500×4q = \dfrac{360}{500\times4} deg, oppure 3601024×4\dfrac{360}{1024\times4} deg per MOTORE 8 e MOTORE 10. Dopo il quantizzatore un guadagno 1/q1/q: 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:

  • H1(s)=sTcs+1H_1(s) = \dfrac{s}{T_cs+1}, Tc=12π⋅50T_c = \dfrac{1}{2\pi\cdot 50};
  • H2(s)=ωc2ss2+2δωcs+ωc2H_2(s) = \dfrac{\omega_c^2 s}{s^2+2\delta\omega_c s+\omega_c^2}, ωc=2π⋅50\omega_c = 2\pi\cdot 50, δ=1/2\delta = 1/\sqrt{2};
  • H3(z)=1−z−NNTsH_3(z) = \dfrac{1-z^{-N}}{NT_s}, N=10N = 10, Ts=1T_s = 1 ms.

S6 (modello completo): Repeating Sequence →\to DAC →\to driver →\to motore con riduttore →\to encoder →\to pulse2deg →\to filtro di velocità. Costanti:

matlab
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*4

S7 (test): onda quadra u=±6u = \pm 6 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 ≤Ts/10\le T_s/10, 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 iai_a a ogni inversione di uu.

Errori tipici:

  • Dimenticare che JlJ_l include 3J723J_{72}, non J72J_{72}.
  • Usare qq dell'encoder da 500 ppr per MOTORE 8 o 10 (si usa 1024).
  • Passo del solver non minore di Ts/10T_s/10 con passo fisso: il modello perde il comportamento tra i campioni.

Teoria collegata