Salta al contenuto
Note per Studenti Experimental Setup and Simulink Desktop Real-Time Report

Experimental Setup and Simulink Desktop Real-Time

In questa pagina 3

This note describes the hardware and software used in the laboratory activities on the DC servomotor. The practical procedure to configure a Simulink model and to wire the unit is in Lab Guide 1 - Getting Started with the DC ServomotorStep-by-step guide to the first laboratory activity: components and nominal data of the SRV-02 setup, how to configure a Simulink model for Simulink Desktop Real-Time, how to set up the Analog Output, Encoder Input and Analog Input blocks, log data to the workspace, wire the unit to the BNC-2110 board and run the real-time simulation.Lab Guide 1 - Getting Started with the DC Servomotor →; the mathematical model of the motor is 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 →; the activities that use the setup are Lab Activity - DC Servomotor Simulink ModelingLaboratory activity to build a Simulink model of the laboratory DC servomotor that includes voltage saturation, DAC and encoder quantization, Coulomb friction and three alternative speed filters, with nominal parameters, step-by-step tasks S1 to S7 and a Matlab parameter script.Lab Activity - DC Servomotor Simulink Modeling → and Lab Activity - Speed P and PI Control Loop SimulationSimulation tasks to close a speed loop around the Simulink servomotor model, first with a proportional controller that cannot give zero steady-state error and then with a PI controller that does, using a square-wave speed reference of plus and minus 250 rpm and the three speed filters.Lab Activity - Speed P and PI Control Loop Simulation →. The slides give an outline of three blocks of the setup (DC Servomotor Unit, Real-Time Control Unit, Simulink Desktop Real-Time toolbox, SLDRT) followed by the preparation of a Simulink model for real-time simulation.

1. DC servomotor unit

The plant is a Quanser SRV-02 servomotor unit (customized). Parts, from the photographs of the slides:

  • DC motor: Faulhaber 2338S006S (brushed DC motor);
  • planetary gearbox attached to the motor;
  • transmission gears and the output shaft on top of the unit (three gears on the top plate; the mechanical load considered in the course is a simple disc inertia mounted on the output shaft);
  • incremental optical encoder (HP HEDS-5540#A06);
  • linear voltage driver (LM1875 power op-amp);
  • a 24 V DC input on the front panel together with the BNC connectors described below.

The exploded view of the Faulhaber SR motor shows its parts: (1) end cap, (2) terminals, (3) brushes with brush cover, (4) commutator, (5) winding, (6) shaft, (7) housing, (8) magnet with sintered bearing and retaining ring. It is a brushed motor, in which brushes and commutator feed the winding on the rotor, and the permanent magnet is fixed.

Front panel connectors (BNC): Pot 2 Out, V Reference, Pot 1 Out, Motor INPUT, Encoder, Encoder 90°, Motor Current A, Motor Current B, plus the 24 Vdc supply connector.

1.1 Voltage driver

The driver is a power operational amplifier (LM1875, supplies +12 V+12\,\text{V} and −12 V-12\,\text{V}) with the following schematic: the Motor Input goes through R1=7.5 kΩR_1=7.5\,\text{k}\Omega to the non-inverting input, with C1=100 nFC_1=100\,\text{nF} and R2=1.6 kΩR_2=1.6\,\text{k}\Omega to ground; the inverting input has a feedback resistor R3=1.2 kΩR_3=1.2\,\text{k}\Omega from the output and R4=500 ΩR_4=500\,\Omega to ground; the output drives the motor MM through a shunt resistor Rs=0.5 Ω (3 W)R_s=0.5\,\Omega\ (3\,\text{W}). Motor Current A is the amplifier output node (the motor-side voltage before the shunt), Motor Current B is the node between the shunt resistor and the motor, so the voltage between A and B is the drop on the shunt, proportional to the armature current.

 Motor Input --R1--+----+--(+)\
              7.5k |    |     >---+----------------+--- Motor Current A
                  C1   R2  (-)/   |                |
                100nF 1.6k   |    R3 1.2k          Rs 0.5 ohm (3 W)
                  |    |     +----+                +--- Motor Current B
                 gnd  gnd    R4 500 ohm             |
                              |                    (M)
                             gnd                    |
                                                   gnd

Static gain (non-inverting amplifier times the input divider R1,R2R_1,R_2):

kdrv=R2R1+R2(1+R3R4)≈0.6,k_{drv}=\frac{R_2}{R_1+R_2}\left(1+\frac{R_3}{R_4}\right)\approx0.6,

(numerical check: 1.69.1×3.4≈0.598\tfrac{1.6}{9.1}\times3.4\approx0.598) and the divider R1//R2R_1//R_2 with C1C_1 is a first-order low-pass, with cut-off frequency

fc=12π (R1//R2) C1≈1.2 kHz.f_c=\frac{1}{2\pi\,(R_1//R_2)\,C_1}\approx1.2\ \text{kHz}.

The driver is therefore a first-order low-pass filter with DC gain 0.60.6 and a bandwidth far above the dynamics of the motor, and it is the kdrvk_{drv} that appears in the models of 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 →.

1.2 Incremental optical encoder

The encoder has a disc with a regular pattern of slits, a mask, lamps and two detectors A and B, mounted on the shaft. As the disc rotates, the light intensity at each detector changes and two square waves are produced; the two detectors are positioned so that the signals are in quadrature (shifted by a quarter period). The slide figure shows the disc seen against the mask, rotated slightly between pictures (A)-(E), and the corresponding signals of detector A and detector B. The outputs are on the connectors Encoder (channel A) and Encoder 90° (channel B). (Source of the figure: J. Trevelyan, Mechatronics Control Devices.) Counting the edges of both signals (quadrature decoding) multiplies the resolution by four with respect to the pulses per rotation (see Lab Guide 1 - Getting Started with the DC ServomotorStep-by-step guide to the first laboratory activity: components and nominal data of the SRV-02 setup, how to configure a Simulink model for Simulink Desktop Real-Time, how to set up the Analog Output, Encoder Input and Analog Input blocks, log data to the workspace, wire the unit to the BNC-2110 board and run the real-time simulation.Lab Guide 1 - Getting Started with the DC Servomotor → for the counter configuration).

2. Real-time control unit

2.1 Architecture

 PC workstation                                         Quanser SRV-02 servomotor unit
 +-------------------------------+   Terminal board     +----------------------------------+
 | MATLAB/Simulink               |   (BNC-2110)         |                                  |
 |   .                           |                      |                                  |
 | Simulink Desktop Real-Time    |                      |                                  |
 | Kernel   .                    |                      |                                  |
 |   .      +-------------+      |                      |                                  |
 |   .      | DAQ board   |      |                      |                                  |
 |   .      | DAC  ------------------ AO0   -----------------> Motor Input -> driver -> M    |
 |   .      | ADC  <----------------- AI0   <----------------- Motor Current A             |
 |   .      |      <----------------- AI1   <----------------- Motor Current B             |
 |   ......>| Encoder     <----------- USER1 <---------------- Encoder                     |
 |          | counter     <----------- USER2 <---------------- Encoder 90 deg              |
 |          +-------------+      |                      |                                  |
 +-------------------------------+                      +----------------------------------+
  • The PC workstation runs MATLAB/Simulink; the SLDRT real-time kernel (dotted link in the diagram) talks directly to the data acquisition (DAQ) board.
  • The DAQ board contains a DAC (analog output AO0), an ADC (analog inputs AI0, AI1) and an encoder counter (inputs USER1, USER2).
  • The terminal board connects the DAQ board to the servomotor unit with BNC cables: AO0 to Motor Input; AI0 to Motor Current A; AI1 to Motor Current B; USER1 to Encoder; USER2 to Encoder 90°.

2.2 Data acquisition boards

  • National Instruments NI-DAQ PCI-6221 on the workstations PCFA05 to PCFA12;
  • National Instruments NI-DAQ PCIe-6321 on the workstations PCFA01 to PCFA04.

2.3 Wiring

The terminal board is a National Instruments BNC-2110; the photograph shows the servomotor unit and the BNC-2110 connected by coloured BNC cables (a 5-channel cable and single-channel cables): red to the motor input, yellow and black for the two motor currents, green and blue for the two encoder channels. The AI 0 and AI 1 BNC inputs of the terminal board take the two motor-current signals, the AO 0 output drives the motor, and the encoder signals go to USER 1 and USER 2.

3.1 What it is

The Simulink Desktop Real-Time toolbox allows to:

  • execute Simulink models on Windows or Mac computers (laptop or desktop) in real time;
  • connect Simulink models with a wide range of I/O devices (multipurpose acquisition boards, communication ports and networks, etc.).

Key features:

  • real-time execution of Simulink models with up to 1 kHz1\,\text{kHz} sample rate in Normal Mode, or 20 kHz20\,\text{kHz} in External Mode;
  • blocks supporting more than 250 I/O devices (analog I/O, digital I/O, counters, encoders, frequency output) and communication protocols (including UDP, Serial, and CAN);
  • run-time signal visualization and parameter tuning.

To support real-time execution the SLDRT installs a real-time kernel that interfaces with the operating system of the host computer. The SLDRT kernel allows the Simulink model to:

  • run at the highest priority, without interference from other OS processes, so the model is updated at the selected sample rate;
  • access the hardware resources (I/O devices).

3.2 Normal mode

 USER SPACE      +------------------------+
                 | Simulink (user process)|
                 |  Solver + Model methods|
                 +-----------^------------+
                             |
                 +------------------------+
                 | Shared memory area     |
                 |  input buffer / output buffer |
                 +-----------^------------+
 - - - - - - - - - - - - - - | - - - - - - - - - - -
 KERNEL SPACE     +----------v-----------+
                  | I/O driver (kernel)  |
                  +----------------------+
  • Simulink runs the model simulation in user space.
  • A separate process runs the drivers for the I/O device in kernel space.
  • Data (block parameters and model signals) is exchanged via a shared memory area (an input data buffer and an output data buffer).
  • Only the I/O drivers are synchronized with a real-time clock (RTC). If the model uses some I/O blocks, its execution is indirectly synchronized with the same RTC.
  • RTC ticks may be missed when the Simulink model is too complex to be run at the RTC pace, or when other OS processes contend the CPU usage.

3.3 Accelerator mode

Like normal mode, except that the Simulink model is compiled into a MEX (MATLAB executable) to speed up the execution; the structure (Simulink in user space, shared memory, kernel I/O driver) is unchanged and only the model methods are compiled.

3.4 External mode

  • The Simulink Coder is invoked to convert the model into a set of C-code source files.
  • The source files are compiled and linked with the I/O drivers to obtain a standalone application running in real time in kernel space.
  • The "external mode" application running the model algorithm is fully synchronized with the RTC.
  • Simulink only acts as a user interface for the data exchange (through the shared memory area) with the simulation running in kernel space.
 USER SPACE      +------------------------+
                 | Simulink (user interface only) |
                 +-----------^------------+
                 | Shared memory area (input/output buffers) |
 - - - - - - - - - - - - - - | - - - - - - - - - - -
 KERNEL SPACE     +----------v--------------------------+
                  | Solver + Model methods + I/O driver |   <- standalone app, in real time
                  +-------------------------------------+

Summary of the three modes:

Mode Where the model runs Synchronization Max sample rate (slides)
Normal Simulink, user space only the I/O drivers use the RTC; model indirectly up to 1 kHz
Accelerator Simulink, user space, compiled as MEX as normal not stated, same structure as normal
External standalone C application, kernel space fully synchronized with the RTC up to 20 kHz

The lab guide uses the external-mode flow ("Run in Kernel", build, connect, start), see Lab Guide 1 - Getting Started with the DC ServomotorStep-by-step guide to the first laboratory activity: components and nominal data of the SRV-02 setup, how to configure a Simulink model for Simulink Desktop Real-Time, how to set up the Analog Output, Encoder Input and Analog Input blocks, log data to the workspace, wire the unit to the BNC-2110 board and run the real-time simulation.Lab Guide 1 - Getting Started with the DC Servomotor →.

Versione ripasso

Plant: Quanser SRV-02 unit (customized): Faulhaber 2338S006S brushed DC motor, planetary gearbox, transmission gears, output shaft with disc inertia, HP HEDS-5540#A06 incremental optical encoder, LM1875 linear voltage driver.

Voltage driver (R1=7.5 kΩR_1=7.5\,\text{k}\Omega, R2=1.6 kΩR_2=1.6\,\text{k}\Omega, R3=1.2 kΩR_3=1.2\,\text{k}\Omega, R4=500 ΩR_4=500\,\Omega, C1=100 nFC_1=100\,\text{nF}, shunt Rs=0.5 ΩR_s=0.5\,\Omega, supplies ±12 V\pm12\,\text{V}) kdrv=R2R1+R2(1+R3R4)≈0.6,fc=12π(R1//R2)C1≈1.2 kHzk_{drv}=\frac{R_2}{R_1+R_2}\left(1+\frac{R_3}{R_4}\right)\approx0.6,\qquad f_c=\frac1{2\pi(R_1//R_2)C_1}\approx1.2\,\text{kHz}

  • Motor Current A and B are the two ends of the shunt (drop proportional to armature current).

Encoder: disc, mask, two detectors A and B giving quadrature square waves (Encoder, Encoder 90°).

Real-time unit: PC with MATLAB/Simulink and SLDRT kernel; DAQ board (DAC, ADC, encoder counter): NI PCI-6221 (PCFA05 to PCFA12) or PCIe-6321 (PCFA01 to PCFA04); BNC-2110 terminal board.

  • Wiring: AO0 to Motor Input; AI0 to Motor Current A; AI1 to Motor Current B; USER1 to Encoder; USER2 to Encoder 90°.

SLDRT

  • Runs Simulink models in real time on Windows or Mac, with I/O blocks for more than 250250 devices (UDP, Serial, CAN). Up to 1 kHz1\,\text{kHz} in normal mode, 20 kHz20\,\text{kHz} in external mode. Real-time kernel at highest priority, access to hardware.
  • Normal mode: model in user space, drivers in kernel space, data in shared memory; only the I/O drivers sync with the real-time clock (RTC); RTC ticks can be missed (model too heavy, CPU contention).
  • Accelerator mode: as normal, with the model compiled into a MEX.
  • External mode: Simulink Coder generates C code, compiled and linked with the drivers into a standalone application in kernel space, fully synchronized with the RTC; Simulink is only the user interface.

Typical error: assuming the model is always executed at the nominal sample rate in normal mode, forgetting that missed RTC ticks are possible.

Calcolo del guadagno del driver:

  1. Divisore d'ingresso R1,R2R_1, R_2 con il guadagno non invertente 1+R3/R41 + R_3/R_4: kdrv=R2R1+R2(1+R3R4)k_{drv} = \dfrac{R_2}{R_1+R_2}\left(1+\dfrac{R_3}{R_4}\right).
  2. Numeri: 1.69.1⋅3.4≈0.598\dfrac{1.6}{9.1}\cdot 3.4 \approx 0.598, cioè circa 0.60.6.
  3. Il parallelo R1//R2R_1 // R_2 con C1C_1 dà un passa-basso del primo ordine: fc=12π(R1//R2)C1≈1.2f_c = \dfrac{1}{2\pi (R_1//R_2) C_1} \approx 1.2 kHz, molto oltre la dinamica del motore.

Corrente d'armatura: le due estremità della resistenza di shunt RsR_s sono Motor Current A e Motor Current B; la differenza di tensione è proporzionale alla corrente.

Encoder in quadratura: i due canali sono sfasati di un quarto di periodo; contando i fronti di entrambi la risoluzione si moltiplica per quattro rispetto agli impulsi per giro.

Cablaggio: AO0 →\to Motor Input; AI0 →\to Motor Current A; AI1 →\to Motor Current B; USER1 →\to Encoder; USER2 →\to Encoder 90°. Schede: NI PCI-6221 sulle postazioni PCFA05-PCFA12, PCIe-6321 su PCFA01-PCFA04.

Modalità di esecuzione:

Modalità Dove gira il modello Sincronizzazione Frequenza massima
Normal Simulink, spazio utente solo i driver I/O sono sincronizzati con il RTC 1 kHz
Accelerator Simulink, compilato in MEX come normal non indicata
External applicazione C standalone, spazio kernel pienamente sincronizzata con il RTC 20 kHz

In normal mode i tick del RTC possono saltare se il modello è troppo pesante o la CPU è occupata. In external mode Simulink è solo l'interfaccia: il flusso del lab guide è Run in Kernel, build, connessione, avvio.

Errori tipici:

  • Confondere R1//R2R_1//R_2 (parallelo) con R1+R2R_1 + R_2 (serie) nella frequenza di taglio.
  • Leggere il guadagno del driver come R3/R4R_3/R_4 invece che 1+R3/R41 + R_3/R_4.
  • Usare la normal mode per frequenze elevate: il limite indicato è 1 kHz, la external mode arriva a 20 kHz.

Teoria collegata