Archived OpenModelica forums. Posting is disabled.

Alternative forums include GitHub discussions or StackOverflow (make sure to read the Stack Overflow rules; you need to have well-formed questions)


Forgot password? | Forgot username? | Register

Over-Determined System Error (Motor Design)

Over-Determined System Error (Motor Design)

Hi everyone,

First off, I'm quite new to Modelica, so please forgive me if I use the wrong terminology or have glaring noob mistakes. The amount of information available online is overwhelming and given the time-sensitivity of this question I wanted to reach out to the community directly, but if my question has been answered already on another forum or if you know of a resource that pertains to my question directly, please link those!

Now for my issue. Like I said, I'm brand new to Modelica and I really only started using it a few days ago. I have a decent amount of experience with simulink, and this analysis was being done using that until last week when I ran into some issues with the modeling of a gearbox and discovered that Modelica was going to be a better platform for me to use in the long run. I'm currently trying to model a 3-phase stepper motor (which will be attached to the aforementioned gearbox as soon as I get the motor itself working), and I'm getting the error "Too many equations, over-determined system. The model has 176 equations and 174 variables." My code is attached, but for some reason I'm not able to import a screenshot of my model. I'll see if I can upload some screenshots shortly.

I suspect that the issue is related to the induced voltage sources that are attached to each phase, but I need to have those there to account for back-emf voltage due to the rotation of the rotor, and this method of arranging the circuit worked in Simulink (different software, I know, but that indicates that this method should work somehow). I know that there's no electrical ground in the circuit right now, but I've tried attaching one to the negative terminal of the power supply as well as to the wye-connection at the other end of the windings, and neither of those things made any difference.
Note: RL_params is a record file that holds the values for all of the variables in the model, so I won't share it here.


Code for motor model:

Code:


model MotorFull
  extends RL_params;
  extends Modelica.Blocks.Icons.Block;
  Modelica.Blocks.Sources.BooleanPulse PulseGen(period = 1 / F_step, startTime = 0.001, width = 99) annotation(
    Placement(visible = true, transformation(origin = {-94, 90}, extent = {{-6, -6}, {6, 6}}, rotation = 0)));
  Modelica.Electrical.Analog.Sources.ConstantVoltage PowerSupply(V = V_in) annotation(
    Placement(visible = true, transformation(origin = {-78, 40}, extent = {{-8, -8}, {8, 8}}, rotation = -90)));
  Modelica.Electrical.Analog.Ideal.IdealCommutingSwitch switchA(useHeatPort = false) annotation(
    Placement(visible = true, transformation(origin = {-22, 60}, extent = {{6, -6}, {-6, 6}}, rotation = 0)));
  Modelica.Electrical.Analog.Ideal.IdealCommutingSwitch switchB(useHeatPort = false) annotation(
    Placement(visible = true, transformation(origin = {-32, 40}, extent = {{6, -6}, {-6, 6}}, rotation = 0)));
  Modelica.Electrical.Analog.Ideal.IdealCommutingSwitch switchC(useHeatPort = false) annotation(
    Placement(visible = true, transformation(origin = {-42, 20}, extent = {{6, -6}, {-6, 6}}, rotation = 0)));
  Modelica.Electrical.Analog.Basic.HeatingResistor resistorA(R_ref = R_phase, T = T_test, T_ref = T0, alpha = C_res, i(start = 0), useHeatPort = true) annotation(
    Placement(visible = true, transformation(origin = {30, 60}, extent = {{6, -6}, {-6, 6}}, rotation = 0)));
  Modelica.Electrical.Analog.Basic.HeatingResistor resistorB(R_ref = R_phase, T = T_test, T_ref = T0, alpha = C_res, useHeatPort = true) annotation(
    Placement(visible = true, transformation(origin = {20, 40}, extent = {{6, -6}, {-6, 6}}, rotation = 0)));
  Modelica.Electrical.Analog.Basic.HeatingResistor resistorC(R_ref = R_phase, T = T_test, T_ref = T0, alpha = C_res, useHeatPort = true) annotation(
    Placement(visible = true, transformation(origin = {10, 20}, extent = {{6, -6}, {-6, 6}}, rotation = 0)));
  Modelica.Electrical.Analog.Basic.Inductor inductorA(L = L_phase, i(fixed = true, start = 0)) annotation(
    Placement(visible = true, transformation(origin = {46, 60}, extent = {{6, -6}, {-6, 6}}, rotation = 0)));
  Modelica.Electrical.Analog.Basic.Inductor inductorB(L = L_phase, i(fixed = true, start = 0)) annotation(
    Placement(visible = true, transformation(origin = {36, 40}, extent = {{6, -6}, {-6, 6}}, rotation = 0)));
  Modelica.Electrical.Analog.Basic.Inductor inductorC(L = L_phase, i(fixed = true, start = 0)) annotation(
    Placement(visible = true, transformation(origin = {26, 20}, extent = {{6, -6}, {-6, 6}}, rotation = 0)));
  ExcitationState excitationState1 annotation(
    Placement(visible = true, transformation(origin = {-56, 86}, extent = {{-6, -6}, {6, 6}}, rotation = 0)));
  Modelica.Electrical.Analog.Sources.SignalVoltage V_induced_A annotation(
    Placement(visible = true, transformation(origin = {10, 60}, extent = {{6, 6}, {-6, -6}}, rotation = 0)));
  Modelica.Electrical.Analog.Sources.SignalVoltage V_induced_B annotation(
    Placement(visible = true, transformation(origin = {0, 40}, extent = {{6, 6}, {-6, -6}}, rotation = 0)));
  Modelica.Electrical.Analog.Sources.SignalVoltage V_induced_C annotation(
    Placement(visible = true, transformation(origin = {-10, 20}, extent = {{6, 6}, {-6, -6}}, rotation = 0)));
  Modelica.Electrical.Analog.Sensors.CurrentSensor currentA annotation(
    Placement(visible = true, transformation(origin = {60, 60}, extent = {{4, -4}, {-4, 4}}, rotation = 0)));
  Modelica.Electrical.Analog.Sensors.CurrentSensor currentB annotation(
    Placement(visible = true, transformation(origin = {50, 40}, extent = {{4, -4}, {-4, 4}}, rotation = 0)));
  Modelica.Electrical.Analog.Sensors.CurrentSensor currentC annotation(
    Placement(visible = true, transformation(origin = {40, 20}, extent = {{4, -4}, {-4, 4}}, rotation = 0)));
  InducedVoltage inducedVoltage annotation(
    Placement(visible = true, transformation(origin = {-22, -24}, extent = {{-8, -8}, {8, 8}}, rotation = 0)));
  Modelica.Blocks.Interfaces.BooleanInput direction annotation(
    Placement(visible = true, transformation(origin = {-113, -49}, extent = {{-11, -11}, {11, 11}}, rotation = 0), iconTransformation(origin = {-112, 0}, extent = {{-12, -12}, {12, 12}}, rotation = 0)));
  Modelica.Blocks.Interfaces.RealInput phi annotation(
    Placement(visible = true, transformation(origin = {-114, -80}, extent = {{-12, -12}, {12, 12}}, rotation = 0), iconTransformation(origin = {-112, -60}, extent = {{-12, -12}, {12, 12}}, rotation = 0)));
  Modelica.Blocks.Interfaces.RealInput Temperature annotation(
    Placement(visible = true, transformation(origin = {-113, -19}, extent = {{-11, -11}, {11, 11}}, rotation = 0), iconTransformation(origin = {-112, 60}, extent = {{-12, -12}, {12, 12}}, rotation = 0)));
  phase_angle phase annotation(
    Placement(visible = true, transformation(origin = {-51, -49}, extent = {{-7, -7}, {7, 7}}, rotation = 0)));
  Detent detent annotation(
    Placement(visible = true, transformation(origin = {-37, -75}, extent = {{-9, -9}, {9, 9}}, rotation = 0)));
  GeneratedTorque generatedTorque annotation(
    Placement(visible = true, transformation(origin = {68, -44}, extent = {{-8, -8}, {8, 8}}, rotation = 0)));
  Modelica.Blocks.Math.Add add(k2 = -1) annotation(
    Placement(visible = true, transformation(origin = {92, -48}, extent = {{-6, -6}, {6, 6}}, rotation = 0)));
  Modelica.Blocks.Interfaces.RealOutput Tq_motor annotation(
    Placement(visible = true, transformation(origin = {114, -48}, extent = {{-10, -10}, {10, 10}}, rotation = 0), iconTransformation(origin = {110, 0}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
  Modelica.Blocks.Routing.Multiplex mux(n = 3) annotation(
    Placement(visible = true, transformation(origin = {58, -22}, extent = {{-6, -6}, {6, 6}}, rotation = -90)));
equation
  connect(currentC.p, currentB.p) annotation(
    Line(points = {{44, 20}, {68, 20}, {68, 40}, {54, 40}, {54, 40}, {54, 40}}, color = {0, 0, 255}));
  connect(currentA.p, currentB.p) annotation(
    Line(points = {{64, 60}, {68, 60}, {68, 40}, {54, 40}, {54, 40}}, color = {0, 0, 255}));
  connect(inductorA.p, currentA.n) annotation(
    Line(points = {{52, 60}, {56, 60}}, color = {0, 0, 255}));
  connect(currentA.i, mux.u[1]) annotation(
    Line(points = {{60, 56}, {60, -16}, {58, -16}}, color = {0, 0, 127}));
  connect(V_induced_B.p, resistorB.n) annotation(
    Line(points = {{6, 40}, {14, 40}, {14, 40}, {14, 40}}, color = {0, 0, 255}));
  connect(V_induced_A.p, resistorA.n) annotation(
    Line(points = {{16, 60}, {24, 60}, {24, 60}, {24, 60}}, color = {0, 0, 255}));
  connect(switchA.p, V_induced_A.n) annotation(
    Line(points = {{-16, 60}, {4, 60}, {4, 60}, {4, 60}}, color = {0, 0, 255}));
  connect(switchB.p, V_induced_B.n) annotation(
    Line(points = {{-26, 40}, {-6, 40}, {-6, 40}, {-6, 40}}, color = {0, 0, 255}));
  connect(switchC.p, V_induced_C.n) annotation(
    Line(points = {{-36, 20}, {-16, 20}, {-16, 20}, {-16, 20}}, color = {0, 0, 255}));
  connect(V_induced_C.p, resistorC.n) annotation(
    Line(points = {{-4, 20}, {4, 20}, {4, 20}, {4, 20}}, color = {0, 0, 255}));
  connect(V_induced_B.v, inducedVoltage.Vemf_B) annotation(
    Line(points = {{0, 33}, {0, -24}, {-13, -24}}, color = {0, 0, 127}));
  connect(inducedVoltage.Vemf_A, V_induced_A.v) annotation(
    Line(points = {{-13, -19}, {10, -19}, {10, 53}}, color = {0, 0, 127}));
  connect(inducedVoltage.T_motor, Temperature) annotation(
    Line(points = {{-32, -19}, {-113, -19}}, color = {0, 0, 127}));
  connect(V_induced_C.v, inducedVoltage.Vemf_C) annotation(
    Line(points = {{-10, 13}, {-10, -29}, {-13, -29}}, color = {0, 0, 127}));
  connect(phase.theta_x, inducedVoltage.theta_x) annotation(
    Line(points = {{-44, -49}, {-32, -49}, {-32, -29}}, color = {0, 0, 127}, thickness = 0.5));
  connect(currentC.i, mux.u[3]) annotation(
    Line(points = {{40, 16}, {40, 8}, {54, 8}, {54, -16}, {58, -16}}, color = {0, 0, 127}));
  connect(mux.y, generatedTorque.I_phase) annotation(
    Line(points = {{58, -29}, {58, -39}, {59, -39}}, color = {0, 0, 127}, thickness = 0.5));
  connect(currentB.i, mux.u[2]) annotation(
    Line(points = {{50, 36}, {50, 26}, {58, 26}, {58, -16}}, color = {0, 0, 127}));
  connect(resistorA.p, inductorA.n) annotation(
    Line(points = {{36, 60}, {40, 60}, {40, 60}, {40, 60}}, color = {0, 0, 255}));
  connect(inductorB.p, currentB.n) annotation(
    Line(points = {{42, 40}, {46, 40}}, color = {0, 0, 255}));
  connect(resistorB.p, inductorB.n) annotation(
    Line(points = {{26, 40}, {30, 40}, {30, 40}, {30, 40}}, color = {0, 0, 255}));
  connect(inductorC.p, currentC.n) annotation(
    Line(points = {{32, 20}, {36, 20}}, color = {0, 0, 255}));
  connect(resistorC.p, inductorC.n) annotation(
    Line(points = {{16, 20}, {20, 20}}, color = {0, 0, 255}));
  connect(switchA.n2, PowerSupply.n) annotation(
    Line(points = {{-28, 60}, {-54, 60}, {-54, 20}, {-78, 20}, {-78, 32}, {-78, 32}}, color = {0, 0, 255}));
  connect(switchB.n2, PowerSupply.n) annotation(
    Line(points = {{-38, 40}, {-54, 40}, {-54, 20}, {-78, 20}, {-78, 32}, {-78, 32}}, color = {0, 0, 255}));
  connect(switchC.n2, PowerSupply.n) annotation(
    Line(points = {{-48, 20}, {-78, 20}, {-78, 32}, {-78, 32}}, color = {0, 0, 255}));
  connect(generatedTorque.Tq_generated, add.u1) annotation(
    Line(points = {{76, -44}, {84, -44}, {84, -44}, {84, -44}}, color = {0, 0, 127}));
  connect(generatedTorque.theta_x, phase.theta_x) annotation(
    Line(points = {{58, -48}, {-44, -48}, {-44, -48}, {-44, -48}}, color = {0, 0, 127}, thickness = 0.5));
  connect(generatedTorque.T_motor, Temperature) annotation(
    Line(points = {{58, -44}, {-36, -44}, {-36, -18}, {-112, -18}, {-112, -18}}, color = {0, 0, 127}));
  connect(phase.phi, phi) annotation(
    Line(points = {{-60, -48}, {-68, -48}, {-68, -80}, {-110, -80}, {-110, -80}, {-114, -80}}, color = {0, 0, 127}));
  connect(PulseGen.y, excitationState1.Trigger) annotation(
    Line(points = {{-87, 90}, {-63, 90}}, color = {255, 0, 255}));
  connect(detent.Tq_Detent, add.u2) annotation(
    Line(points = {{-27, -75}, {79, -75}, {79, -52}, {85, -52}}, color = {0, 0, 127}));
  connect(add.y, Tq_motor) annotation(
    Line(points = {{99, -48}, {114, -48}}, color = {0, 0, 127}));
  connect(detent.phi, phi) annotation(
    Line(points = {{-47, -80}, {-114, -80}}, color = {0, 0, 127}));
  connect(detent.Temperature, Temperature) annotation(
    Line(points = {{-47, -70}, {-74, -70}, {-74, -19}, {-113, -19}}, color = {0, 0, 127}));
  connect(detent.Direction, direction) annotation(
    Line(points = {{-47, -75}, {-88, -75}, {-88, -49}, {-113, -49}}, color = {255, 0, 255}));
  connect(switchA.n1, PowerSupply.p) annotation(
    Line(points = {{-28, 62}, {-78, 62}, {-78, 48}}, color = {0, 0, 255}));
  connect(switchB.n1, PowerSupply.p) annotation(
    Line(points = {{-38, 42}, {-60, 42}, {-60, 62}, {-78, 62}, {-78, 48}}, color = {0, 0, 255}));
  connect(switchC.n1, PowerSupply.p) annotation(
    Line(points = {{-48, 22}, {-60, 22}, {-60, 62}, {-78, 62}, {-78, 48}}, color = {0, 0, 255}));
  connect(excitationState1.Direction, direction) annotation(
    Line(points = {{-63, 82}, {-88, 82}, {-88, -49}, {-113, -49}}, color = {255, 0, 255}));
  connect(excitationState1.SwitchC, switchC.control) annotation(
    Line(points = {{-49, 82}, {-42, 82}, {-42, 27}}, color = {255, 0, 255}));
  connect(excitationState1.SwitchB, switchB.control) annotation(
    Line(points = {{-49, 86}, {-32, 86}, {-32, 47}}, color = {255, 0, 255}));
  connect(excitationState1.SwitchA, switchA.control) annotation(
    Line(points = {{-49, 90}, {-22, 90}, {-22, 67}}, color = {255, 0, 255}));
  annotation(
    uses(Modelica(version = "3.2.3")),
    Icon(graphics = {Text(origin = {-71, 1}, extent = {{-13, 9}, {13, -11}}, textString = "Dir"), Text(origin = {-72, 72}, extent = {{-10, 6}, {30, -28}}, textString = "Temp"), Text(origin = {-78, -56}, extent = {{-12, 8}, {24, -12}}, textString = "phi"), Text(origin = {49, 9}, extent = {{-17, 9}, {37, -25}}, textString = "Torque Out")}, coordinateSystem(initialScale = 0.1)));
end MotorFull;

induced voltage:

Code:


block InducedVoltage
extends RL_params;
  extends Modelica.Blocks.Icons.Block;
 
  Real omega, K_motor;
  Modelica.Blocks.Interfaces.RealOutput Vemf_A annotation(
    Placement(visible = true, transformation(origin = {104, 48}, extent = {{-10, -10}, {10, 10}}, rotation = 0), iconTransformation(origin = {110, 60}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
  Modelica.Blocks.Interfaces.RealOutput Vemf_B annotation(
    Placement(visible = true, transformation(origin = {106, 0}, extent = {{-10, -10}, {10, 10}}, rotation = 0), iconTransformation(origin = {110, 0}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
  Modelica.Blocks.Interfaces.RealOutput Vemf_C annotation(
    Placement(visible = true, transformation(origin = {98, -42}, extent = {{-10, -10}, {10, 10}}, rotation = 0), iconTransformation(origin = {110, -60}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
  Modelica.Blocks.Interfaces.RealInput T_motor annotation(
    Placement(visible = true, transformation(origin = {-128, 58}, extent = {{-20, -20}, {20, 20}}, rotation = 0), iconTransformation(origin = {-120, 60}, extent = {{-20, -20}, {20, 20}}, rotation = 0)));
  Modelica.Blocks.Interfaces.RealVectorInput theta_x[N_phase] annotation(
    Placement(visible = true, transformation(origin = {-112, -58}, extent = {{-20, -20}, {20, 20}}, rotation = 0), iconTransformation(origin = {-120, -58}, extent = {{-20, -20}, {20, 20}}, rotation = 0)));
equation
  omega = Nrt*der(theta_x[1]);
  K_motor=Kt_amb*(1+C_mag*(T_motor-T0));
  Vemf_A=K_motor*omega*sin(theta_x[1]);
  Vemf_B=K_motor*omega*sin(theta_x[2]);
  Vemf_C=K_motor*omega*sin(theta_x[3]);
  annotation(
    uses(Modelica(version = "3.2.3")),
    Icon(graphics = {Text(origin = {-58, 62}, extent = {{-24, 12}, {20, -10}}, textString = "Temp"), Text(origin = {-56, -58}, extent = {{-24, 12}, {24, -12}}, textString = "theta_x"), Text(origin = {72, -60}, extent = {{-24, 12}, {24, -12}}, textString = "Vemf_C"), Text(origin = {74, 62}, extent = {{-24, 12}, {24, -12}}, textString = "Vemf_A"), Text(origin = {72, 2}, extent = {{-24, 12}, {24, -12}}, textString = "Vemf_B")}, coordinateSystem(initialScale = 0.1)));
end InducedVoltage;

phase angle:

Code:


block phase_angle
extends RL_params;
  extends Modelica.Blocks.Icons.Block;
  Modelica.Blocks.Interfaces.RealInput phi annotation(
    Placement(visible = true, transformation(origin = {-116, 0}, extent = {{-20, -20}, {20, 20}}, rotation = 0), iconTransformation(origin = {-120, 0}, extent = {{-20, -20}, {20, 20}}, rotation = 0)));
  Modelica.Blocks.Interfaces.RealVectorOutput theta_x[N_phase] annotation(
    Placement(visible = true, transformation(origin = {96, 6}, extent = {{-20, -20}, {20, 20}}, rotation = 0), iconTransformation(origin = {100, 0}, extent = {{-20, -20}, {20, 20}}, rotation = 0)));
  annotation(
    uses(Modelica(version = "3.2.3")),
    Icon(graphics = {Text(origin = {-74, 3}, extent = {{-34, 11}, {34, -11}}, textString = "phi"), Text(origin = {40, 0}, extent = {{-30, 10}, {30, -10}}, textString = "theta_x")}));
//Integer i;
equation
for i in 1:N_phase loop
theta_x[i] = Nrt*phi + (i - 1)*2*pi/N_phase;
end for;

end phase_angle;

detent:

Code:


block Detent
extends RL_params;
  extends Modelica.Blocks.Icons.Block;
  Modelica.Blocks.Interfaces.RealInput phi annotation(
    Placement(visible = true, transformation(origin = {-114, 58}, extent = {{-20, -20}, {20, 20}}, rotation = 0), iconTransformation(origin = {-112, -60}, extent = {{-12, -12}, {12, 12}}, rotation = 0)));
  Modelica.Blocks.Interfaces.RealInput Temperature annotation(
    Placement(visible = true, transformation(origin = {0, 0}, extent = {{-10, -10}, {10, 10}}, rotation = 0), iconTransformation(origin = {-112, 60}, extent = {{-12, -12}, {12, 12}}, rotation = 0)));
  Modelica.Blocks.Interfaces.RealOutput Tq_Detent annotation(
    Placement(visible = true, transformation(origin = {112, 4}, extent = {{-10, -10}, {10, 10}}, rotation = 0), iconTransformation(origin = {110, 0}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
  Modelica.Blocks.Interfaces.BooleanInput Direction annotation(
    Placement(visible = true, transformation(origin = {-156, 6}, extent = {{-20, -20}, {20, 20}}, rotation = 0), iconTransformation(origin = {-112, 0}, extent = {{-12, -12}, {12, 12}}, rotation = 0)));
  annotation(
    uses(Modelica(version = "3.2.3")),
    Icon(graphics = {Text(origin = {-65, 0}, extent = {{-23, 10}, {23, -10}}, textString = "Dir"), Text(origin = {-65, -58}, extent = {{-21, 10}, {21, -12}}, textString = "phi"), Text(origin = {-64, 63}, extent = {{-14, 11}, {28, -17}}, textString = "Temp"), Text(origin = {59, -1}, extent = {{-23, 11}, {15, -7}}, textString = "Detent")}));
Real D1, D2, theta, Coeff;
Integer dir;
equation
if Direction==true then dir=2;
else dir=1; end if;
theta = 2*phi*N_phase*Nrt;
Coeff=1+C_mag*(Temperature-T0);
D1=Coeff*(Tq_det[dir,1]+Tq_det[dir,2])/2;
D2=Coeff*abs(Tq_det[dir,1]-Tq_det[dir,2])/2;

Tq_Detent=D1*sin(theta)+D2*sin(phi*Nrt/2);
end Detent;

Generated Torque:

Code:


block GeneratedTorque
  extends RL_params;
  extends Modelica.Blocks.Icons.Block;
  Modelica.Blocks.Interfaces.RealOutput Tq_generated annotation(
    Placement(visible = true, transformation(origin = {106, 2}, extent = {{-10, -10}, {10, 10}}, rotation = 0), iconTransformation(origin = {112, -4.44089e-16}, extent = {{-12, -12}, {12, 12}}, rotation = 0)));
  Modelica.Blocks.Interfaces.RealInput T_motor annotation(
    Placement(visible = true, transformation(origin = {-134, 68}, extent = {{-20, -20}, {20, 20}}, rotation = 0), iconTransformation(origin = {-114, 0}, extent = {{-14, -14}, {14, 14}}, rotation = 0)));
  Real K_motor, Tq = 0;
//  Integer i;
  Modelica.Blocks.Interfaces.RealVectorInput theta_x[N_phase] annotation(
    Placement(visible = true, transformation(origin = {-98, -40}, extent = {{-20, -20}, {20, 20}}, rotation = 0), iconTransformation(origin = {-115, -59}, extent = {{-15, -15}, {15, 15}}, rotation = 0)));
  Modelica.Blocks.Interfaces.RealVectorInput I_phase[N_phase] annotation(
    Placement(visible = true, transformation(origin = {-114, 36}, extent = {{-20, -20}, {20, 20}}, rotation = 0), iconTransformation(origin = {-115, 61}, extent = {{-15, -15}, {15, 15}}, rotation = 0)));
equation
//Tq=0;
  K_motor = Kt_amb * (1 + C_mag * (T_motor - T0));
  for i in 1:N_phase loop
    Tq = Tq - K_motor * I_phase[i] * sin(theta_x[i]);
  end for;
  Tq_generated = Tq;
  annotation(
    uses(Modelica(version = "3.2.3")),
    Icon(graphics = {Text(origin = {-53, -59}, extent = {{-27, 11}, {27, -11}}, textString = "theta_x"), Text(origin = {-50, 58}, extent = {{-32, 14}, {20, -8}}, textString = "I_phase"), Text(origin = {-65, 2}, extent = {{-27, 10}, {27, -10}}, textString = "Temp"), Text(origin = {73, -1}, extent = {{-29, 15}, {17, -9}}, textString = "Tq_out")}, coordinateSystem(initialScale = 0.1)));
end GeneratedTorque;

and excitation state:

Code:


block ExcitationState
extends Modelica.Blocks.Icons.BooleanBlock;

Integer state;
Integer dir;

constant Real excite[6,3] = [0.5,  0.5,  -1; 1,  -0.5, -0.5; 0.5,  -1,   0.5; -0.5, -0.5,   1; -1,   0.5, 0.5; -0.5,  1,  -0.5];
  Modelica.Blocks.Interfaces.BooleanInput Direction annotation(
    Placement(visible = true, transformation(origin = {-96, 52}, extent = {{-20, -20}, {20, 20}}, rotation = 0), iconTransformation(origin = {-120, -60}, extent = {{-20, -20}, {20, 20}}, rotation = 0)));
  Modelica.Blocks.Interfaces.BooleanInput Trigger annotation(
    Placement(visible = true, transformation(origin = {-120, -32}, extent = {{-20, -20}, {20, 20}}, rotation = 0), iconTransformation(origin = {-120, 60}, extent = {{-20, -20}, {20, 20}}, rotation = 0)));
  Modelica.Blocks.Interfaces.BooleanOutput SwitchA annotation(
    Placement(visible = true, transformation(origin = {114, 56}, extent = {{-10, -10}, {10, 10}}, rotation = 0), iconTransformation(origin = {110, 60}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
  Modelica.Blocks.Interfaces.BooleanOutput SwitchB annotation(
    Placement(visible = true, transformation(origin = {106, 4}, extent = {{-10, -10}, {10, 10}}, rotation = 0), iconTransformation(origin = {110, 0}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
  Modelica.Blocks.Interfaces.BooleanOutput SwitchC annotation(
    Placement(visible = true, transformation(origin = {112, -66}, extent = {{-10, -10}, {10, 10}}, rotation = 0), iconTransformation(origin = {110, -60}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));

equation
when pre(Trigger)==false and Trigger==true then
state = pre(state) + dir;
end when;
if state==0 then state=6;
elseif state==7 then state=1;
end if;
if excite[state,1]>0 then
SwitchA=true;
else
SwitchA=false;
end if;

if excite[state,2]>0 then
SwitchB=true;
else
SwitchB=false;
end if;

if excite[state,3]>0 then
SwitchC=true;
else
SwitchC=false;
end if;

initial equation
if Direction==true then
dir=1;
else
dir=-1;
end if;
state = 1;

annotation(
    uses(Modelica(version = "3.2.3")),
    Icon(graphics = {Text(origin = {-57, -64}, extent = {{-41, 14}, {13, -4}}, textString = "Dir"), Text(origin = {-55, 58}, extent = {{-41, 14}, {13, -4}}, textString = "Trig"), Text(origin = {69, 54}, extent = {{-41, 14}, {13, -4}}, textString = "SwitchA"), Text(origin = {71, -2}, extent = {{-41, 14}, {13, -4}}, textString = "SwitchB"), Text(origin = {73, -64}, extent = {{-41, 14}, {13, -4}}, textString = "SwitchC")}));end ExcitationState;

Edited by: gtroberts - Jun-04-19 19:44:40
There are 0 guests and 0 other users also viewing this topic
You are here: