mirror of
https://github.com/metrostroi-repo/MetrostroiAddon.git
synced 2026-05-02 00:42:29 +00:00
120 lines
4.5 KiB
Lua
120 lines
4.5 KiB
Lua
--------------------------------------------------------------------------------
|
|
-- DK-108D DC engine
|
|
--------------------------------------------------------------------------------
|
|
-- Copyright (C) 2013-2018 Metrostroi Team & FoxWorks Aerospace s.r.o.
|
|
-- Contains proprietary code. See license.txt for additional information.
|
|
--------------------------------------------------------------------------------
|
|
Metrostroi.DefineSystem("DK_108D")
|
|
|
|
function TRAIN_SYSTEM:Initialize()
|
|
-- Speed of train in km/h
|
|
self.Speed = 0
|
|
|
|
-- Winding resistance
|
|
self.Rwa = 0.0859 -- Ohms, anchor
|
|
self.Rws = 0.0350 -- Ohms, stator
|
|
|
|
-- Voltage generated by engine
|
|
self.E13 = 0.0 -- Volts
|
|
self.E24 = 0.0 -- Volts
|
|
|
|
-- Rotation rate
|
|
self.RotationRate = 0.0
|
|
|
|
-- Magnetic flux in the engine
|
|
self.MagneticFlux13 = 0.0
|
|
self.MagneticFlux24 = 0.0
|
|
|
|
-- Field reduction (how much current goes through stator)
|
|
self.FieldReduction13 = 0.0
|
|
self.FieldReduction24 = 0.0
|
|
|
|
-- Moment generated by the engine
|
|
self.Moment13 = 0.0
|
|
self.Moment24 = 0.0
|
|
self.BogeyMoment = 0.0 -- Moment on front and rear bogey is equal
|
|
|
|
-- Need many iterations for engine simulation to converge
|
|
self.SubIterations = 16
|
|
end
|
|
|
|
function TRAIN_SYSTEM:Inputs()
|
|
return { "Speed" }
|
|
end
|
|
|
|
function TRAIN_SYSTEM:Outputs()
|
|
return { "BogeyMoment", "E24" }
|
|
end
|
|
|
|
function TRAIN_SYSTEM:TriggerInput(name,value)
|
|
if name == "Speed" then
|
|
self.Speed = value
|
|
end
|
|
end
|
|
|
|
function TRAIN_SYSTEM:Think(dT)
|
|
local Train = self.Train
|
|
|
|
-- Get rate of engine rotation
|
|
local currentRotationRate = 3000 * (self.Speed/80)
|
|
self.RotationRate = self.RotationRate + 5.0 * (currentRotationRate - self.RotationRate) * dT
|
|
|
|
--self.Rws = 0.0356 -- Ohms, stator
|
|
self.Rws = 0.0396 -- Ohms, stator
|
|
self.Rwa = 0.2215-self.Rws -- Ohms, anchor
|
|
|
|
-- Calculate magnetic flux in the engine
|
|
local a = 0.1204
|
|
local b = 1.2075
|
|
local c = 0.3461
|
|
local RotRate = math.max(0,(Train.Engines.RotationRate-500)/2500)
|
|
local RotRateMF = 0.2+math.max(0,math.min(1,(Train.Engines.RotationRate-375)/1700))*0.8
|
|
local Is13 = math.abs(Train.Electric.Istator13)--)
|
|
local Is24 = math.abs(Train.Electric.Istator24)--+self.Magnetic)
|
|
--print(Is13,Is24)
|
|
local X1 = (Train.Electric.I13 > 0 and 1 or 0)
|
|
local X2 = (Train.Electric.I24 > 0 and 1 or 0)
|
|
self.MagneticFlux13 = (Is13/(204.7+(1-math.min(1,self.RotationRate/375))*30))*math.min(1.0,a+b*math.exp(-c*Is13/(98.56)))
|
|
self.MagneticFlux24 = (Is24/(204.7+(1-math.min(1,self.RotationRate/375))*30))*math.min(1.0,a+b*math.exp(-c*Is24/(98.56)))
|
|
self.Magnetic = self.Magnetic or 0
|
|
local MG = Train.Electric.Aux750V/16*Train.Electric.Magnetization*RotRate
|
|
if MG==0 then
|
|
self.Magnetic = self.Magnetic+(MG-self.Magnetic)*dT*100
|
|
elseif self.Magnetic > MG then
|
|
self.Magnetic = self.Magnetic-dT*100
|
|
else
|
|
self.Magnetic = self.Magnetic+dT*50
|
|
end
|
|
--print(math.max(0,(40+self.Magnetic/5)*0.007*(150-Is13)/150),Train.Electric.Magnetization)
|
|
self.MagneticFlux13 = math.min(8.0,math.max(0.01,self.MagneticFlux13+RotRateMF*Train.Electric.Magnetization*math.max(0,(40+self.Magnetic/5)*0.007*(150-Is13)/150)))
|
|
self.MagneticFlux24 = math.min(8.0,math.max(0.01,self.MagneticFlux24+RotRateMF*Train.Electric.Magnetization*math.max(0,(40+self.Magnetic/5)*0.007*(150-Is13)/150)))
|
|
|
|
-- Calculate voltage generated by engines from magnetic flux
|
|
self.E13 = self.RotationRate * self.MagneticFlux13
|
|
self.E24 = self.RotationRate * self.MagneticFlux24
|
|
|
|
self.E13 = math.max(-4000,math.min(4000,self.E13))
|
|
self.E24 = math.max(-4000,math.min(4000,self.E24))
|
|
|
|
-- Calculate engine force (moment)
|
|
local b = 3.4539 --1.4539
|
|
local c = 16.1975e-3
|
|
local I13 = math.abs(Train.Electric.I13)
|
|
local I24 = math.abs(Train.Electric.I24)
|
|
local S13 = (Train.Electric.I13 > 0) and 1 or -1
|
|
local S24 = (Train.Electric.I24 > 0) and 1 or -1
|
|
self.Moment13 = S13*(b*I13 + c*(I13^2))*(1/850.0)*self.MagneticFlux13
|
|
self.Moment24 = S24*(b*I24 + c*(I24^2))*(1/850.0)*self.MagneticFlux24 --1/800
|
|
|
|
-- Apply moment to bogeys
|
|
if (math.abs(Train.Electric.I13) > 1.0) or (math.abs(Train.Electric.I24) > 1.0) then
|
|
self.BogeyMoment = (self.Moment13 + self.Moment24) / 2
|
|
else
|
|
self.BogeyMoment = 0.0
|
|
end
|
|
|
|
-- Calculate reduction in magnetic field
|
|
self.FieldReduction13 = math.abs(100 * Is13 / (I13+1e-9))
|
|
self.FieldReduction24 = math.abs(100 * Is24 / (I24+1e-9))
|
|
end
|