%% Speed Regulation of a 6/4 Switched Reluctance Motor
%
% This example shows the speed regulation of a three-phase 6/4 switched reluctance motor (SRM).  

% Copyright 2020 Hydro-Quebec, and The MathWorks, Inc.
%%

open_system('SpeedRegulatedSwitchedReluctanceMotor')

%% Description
% Switched reluctance motors are AC motors that run by reluctance torque. Their rotors have no windings or permanent magnets. Common SRM types are three-phase 6/4 (where 6 is the number of stator poles and 4 is the number of rotor poles), four-phase 8/6, and five-phase 10/8. SRM are connected to power electronic converters that energize appropriate stator phases based on the rotor position.

%% Electrical Model
% A DC bus, modeled as an ideal DC source of 240 V, is connected to a power electronics converter feeding a three-phase 6/4 SRM. The converter is modeled using three single-phase, full-bridge converters. Full-bridge converters apply positive or negative voltage to the stator windings to energize or de-energize them, respectively.
%
% The example uses the generic model type of SRM model. The electrical part
% is represented by a nonlinear model based on the magnetization
% characteristic composed of several magnetizing curves and on the torque characteristic computed from the magnetization curves. The magnetization characteristic is calculated using nonlinear functions and the specified motor parameters. You can visualize the magnetization curves (including the linkage flux as a function of stator currents and rotor position) by checking the *Plot magnetization curves* parameter of the Switched Reluctance Motor block and click Apply.

%% Control System
% The main components of the SRM control system are:
%%
% 
% # Speed Regulator - The regulator compares the actual motor speed to the speed reference. If the motor needs to be accelerated, the regulator increases the current reference (Iref) to create more torque. On the contrary, if the motor speed is higher than the reference, the regulator reduces Iref.
% # Commutation Logic block - Based on the rotor position (represented by the theta signal from the SRM model) and the turn-on and turn-off angles, this block generates the control signals to produce the appropriate commutation sequence for torque production. 
% # Current Regulator - Based on the desired reference current, Iref, and the commutation logic signals, a current reference is created for each of the three phases. Each current reference is then compared with the corresponding measured stator current. When the resulting error crosses the positive hysteresis band value, a conduction order is sent to the appropriate full-bridge converter. The converter then applies a positive voltage to the stator winding in order to drive a positive current into the winding. During the free-wheeling period (when there is no pulse), a negative voltage is applied to the windings and the stored energy is returned to the power DC source through the diodes.
%
% The next figure illustrates the commutation sequence for three rotor positions.
% 
% <<../SRMRotorPositions.png>>
% 
% In rotor position 1, a positive voltage is applied to windings A1 and A2. The resulting magnetic field creates a reluctance torque that forces the rotor pole to align with the newly energized stator poles. 
%
% When the motor reaches rotor position 2, the A1 and A2 windings are de-energized and windings B1 and B2 are energized to keep the rotor turning clockwise. This action keeps the rotor turning clockwise, because the rotor tries to align with B1 and B2 windings.
% 
% Finally, when the motor reaches position 3, the B1 and B2 windings are de-energized and windings C1 and C2 are energized. Because the rotor has four poles, this sequence is repeated every 90 degrees.
%
% In this example, the turn-on and turn-off angles (relative to stator windings A1 and A2) are kept constant at 45 degrees and 75 degrees, respectively. The rotor angles when phases A, B, and C are energized are then respectively 45, 75, and 105 degrees with respect to phase A axis.

%% Simulation
% Run the simulation and observe waveforms on the block named Scope1.
% The motor moves from zero speed to 1500 rpm with a load torque of 15 N.m. At 0.15 s, the load torque is increased to 75 N.m. The control system increases the reference current in order to maintain the motor speed at 1500 rpm. At 0.3 s, the speed reference is stepped to 2500 rpm. To reach the desired speed, the control system momentarily produces a large torque by increasing the motor currents.

%% Real-Time Simulation
% If you have Simulink Real-Time and a Speedgoat target computer, you can run this model in real time.
%%
% 
% # Open the Configuration Parameters window (or press *Ctrl+E* ), click *Code Generation*, and set *System target file* to an STF for a Simulink Real-Time model.
% # Connect to the target and, in the *Real-Time* tab, click *Run on Target*.
% 
% Your model will then be automatically built, deployed, and executed on the target. Depending on your target streaming bandwidth, you may have to reduce the number of signals transferred in real-time from the target to the host computer.

%% Reference
% Knight, Andy. Electrical Machines Switched Reluctance Motors. University of Calgary.

%% External Website
% Wikipedia. "Switched reluctance motor." Accessed October 28,2020.

