package system import ( "github.com/yohamta/donburi/filter" "joylink.club/ecs" ) // 双机ZDJ9道岔电路系统状态定义 // 继电器: true-吸合;false-未吸合 type Switch2jZdj9State struct { //定操继电器 DCJ bool //定操联锁条件触发 //true-联锁条件满足,按下按钮触发定操 DC_Pressed bool //缓放剩余时间,单位ms DCJ_ReleaseTime int64 //反操继电器 FCJ bool //反操联锁条件触发 //true-联锁条件满足,按下按钮触发反操 FC_Pressed bool //缓放剩余时间,单位ms FCJ_ReleaseTime int64 //允许操作继电器 YCJ bool //允操联锁条件触发 //true-联锁条件满足,按下按钮触发允操 YC_Pressed bool //缓放剩余时间,单位ms YCJ_ReleaseTime int64 //总定表继电器 ZDBJ bool //总反表继电器 ZFBJ bool //表示电路变压器,将220V交流电变压后作为为道岔表示电路的电源 //0-无电源;规定52端子为正,则,1-输出瞬时正电压;-1 - 输出瞬时负电压 J1_BB SwitchBB //道岔第一启动继电器 J1_1DQJ bool //道岔转辙机启动脉冲 J1_1DQJ_Pulse bool //缓放剩余时间,单位ms J1_1DQJ_ReleaseTime int64 //道岔保护继电器 J1_BHJ bool //缓放剩余时间,单位ms J1_BHJ_ReleaseTime int64 //道岔第二启动继电器 //true-吸起即1-3通;false-打落即1-2通 J1_2DQJ bool //道岔第一启动继电器复示继电器 J1_1DQJF bool //断相保护器 J1_DBQ DBQState //定位表示继电器 J1_DBJ bool //缓放剩余时间,单位ms J1_DBJ_ReleaseTime int64 //true-当道岔转换到定位时,转辙机内端子9与电路接通;false-转辙机内端子9断开切断电路 J1_DB_K9 bool //道岔由反位转换到定位时产生的脉冲 J1_DB_K9_Pulse bool //转辙机内部自动开闭器 //true-接通1、3排表示电路,用于定操;false-接通2、4排表示电路,用于反操 J1_AKB bool //道岔电机1的电源 J1_Power Switch380ACPower //电机线圈相电流 J1_U1 Switch380ACPhase J1_V1 Switch380ACPhase J1_W1 Switch380ACPhase //电机转速,大于0表示正转即定操,小于0表示反转即反操,等于0表示不转 J1_Speed int8 //反位表示继电器 J1_FBJ bool //缓放剩余时间,单位ms J1_FBJ_ReleaseTime int64 //true-当道岔转换到反位时,转辙机内端子10与电路接通;false-转辙机内端子10断开切断电路 J1_FB_K10 bool //道岔由定位转换到反位时产生的脉冲 J1_FB_K10_Pulse bool //道岔启动切断继电器 J1_QDJ bool //缓放剩余时间,单位ms J1_QDJ_ReleaseTime int64 //道岔启动切断继电器的LC震荡电路保磁剩余时间,单位ms //最长保持时长3000ms J1_QDJ_LcTime int64 //总保护继电器 J1_ZBHJ bool //缓放剩余时间,单位ms J1_ZBHJ_ReleaseTime int64 //表示电路变压器,将220V交流电变压后作为为道岔表示电路的电源 //0-无电源;规定52端子为正,则,1-输出瞬时正电压;-1 - 输出瞬时负电压 J2_BB SwitchBB //道岔第一启动继电器 J2_1DQJ bool //道岔转辙机启动脉冲 J2_1DQJ_Pulse bool //缓放剩余时间,单位ms J2_1DQJ_ReleaseTime int64 //道岔保护继电器 J2_BHJ bool //缓放剩余时间,单位ms J2_BHJ_ReleaseTime int64 //道岔第二启动继电器 //true-吸起即1-3通;false-打落即1-2通 J2_2DQJ bool //道岔第一启动继电器复示继电器 J2_1DQJF bool //断相保护器 J2_DBQ DBQState //定位表示继电器 J2_DBJ bool //缓放剩余时间,单位ms J2_DBJ_ReleaseTime int64 //true-当道岔转换到定位时,转辙机内端子9与电路接通;false-转辙机内端子9断开切断电路 J2_DB_K9 bool //道岔由反位转换到定位时产生的脉冲 J2_DB_K9_Pulse bool //反位表示继电器 J2_FBJ bool //缓放剩余时间,单位ms J2_FBJ_ReleaseTime int64 //true-当道岔转换到反位时,转辙机内端子10与电路接通;false-转辙机内端子10断开切断电路 J2_FB_K10 bool //道岔由定位转换到反位时产生的脉冲 J2_FB_K10_Pulse bool //转辙机内部自动开闭器 //true-接通1、3排表示电路,用于定操;false-接通2、4排表示电路,用于反操 J2_AKB bool //道岔电机2的电源 J2_Power Switch380ACPower //电机线圈相电流 J2_U1 Switch380ACPhase J2_V1 Switch380ACPhase J2_W1 Switch380ACPhase //电机转速,大于0表示正转即定操,小于0表示反转即反操,等于0表示不转 J2_Speed int8 } // 创建ZDJ9道岔状态并初始化 func NewSwitch2jZdj9State() *Switch2jZdj9State { return &Switch2jZdj9State{ DCJ: false, DC_Pressed: false, DCJ_ReleaseTime: 0, FCJ: false, FC_Pressed: false, FCJ_ReleaseTime: 0, YCJ: false, YC_Pressed: false, YCJ_ReleaseTime: 0, ZDBJ: true, ZFBJ: false, J1_BB: SwitchBB{InDj220V: true, OutBb: 1}, J1_1DQJ: false, J1_1DQJ_Pulse: false, J1_1DQJ_ReleaseTime: 0, J1_BHJ: false, J1_BHJ_ReleaseTime: 0, J1_2DQJ: true, J1_1DQJF: false, J1_DBQ: DBQState{PhaseLoss: true, LimitedTime: 0, Dc24Voltage: false}, J1_DBJ: true, J1_DBJ_ReleaseTime: 0, J1_DB_K9: true, J1_DB_K9_Pulse: false, J1_AKB: true, J1_Power: Switch380ACPower{PhaseA: false, PhaseB: false, PhaseC: false}, J1_U1: ACPahseN, J1_V1: ACPahseN, J1_W1: ACPahseN, J1_Speed: 0, J1_FBJ: false, J1_FBJ_ReleaseTime: 0, J1_FB_K10: false, J1_FB_K10_Pulse: false, J1_QDJ: true, J1_QDJ_ReleaseTime: 0, J1_QDJ_LcTime: 0, J1_ZBHJ: false, J1_ZBHJ_ReleaseTime: 0, J2_BB: SwitchBB{InDj220V: true, OutBb: 1}, J2_1DQJ: false, J2_1DQJ_Pulse: false, J2_1DQJ_ReleaseTime: 0, J2_BHJ: false, J2_BHJ_ReleaseTime: 0, J2_2DQJ: true, J2_1DQJF: false, J2_DBQ: DBQState{PhaseLoss: true, LimitedTime: 0, Dc24Voltage: false}, J2_DBJ: true, J2_DBJ_ReleaseTime: 0, J2_DB_K9: true, J2_DB_K9_Pulse: false, J2_FBJ: false, J2_FBJ_ReleaseTime: 0, J2_FB_K10: false, J2_FB_K10_Pulse: false, J2_AKB: true, J2_Power: Switch380ACPower{PhaseA: false, PhaseB: false, PhaseC: false}, J2_U1: ACPahseN, J2_V1: ACPahseN, J2_W1: ACPahseN, J2_Speed: 0, } } // 带限时功能断相保护器 // 限时13秒 type DBQState struct { //是否缺相,true-缺相,false-三相电正常未缺相 PhaseLoss bool //剩余限时时间,单位ms LimitedTime int64 //当三相电正常时,断相保护器内的24V直流整流电路会正常输出24V直流电 //当三相电不正常如缺相时,断相保护器内的24V直流整流电路不会输出24V直流电 //BHJ道岔保护继电器的励磁线圈由该24V直流供电 Dc24Voltage bool } // 表示电路变压器,变压比2:1,将220V交流电变压后作为为道岔表示电路的电源 // 0-无电源;规定52端子为正,则,1-输出瞬时正电压;-1 - 输出瞬时负电压 type SwitchBB struct { //true-变压器初级输入正常 InDj220V bool //次级输出电压 //0-无电源;规定52端子为正,则,1-输出瞬时正电压;-1 - 输出瞬时负电压 OutBb int8 } // 道岔380V动力交流电源 type Switch380ACPower struct { //true-A相电正常输出 PhaseA bool //true-B相电正常输出 PhaseB bool //true-C相电正常输出 PhaseC bool } // 道岔380V动力交流电相位定义 type Switch380ACPhase int8 const ( //不存在相位交流电 ACPahseN Switch380ACPhase = iota //存在A相位交流电 ACPahseA //存在B相位交流电 ACPahseB //存在C相位交流电 ACPahseC ) // 继电器常量定义 const ( //QDJ 电源切断继电器LC震荡电路有效震荡时间ms QDJ_LC_TIME int64 = 3000 //断相保护器限时,单位ms DBQ_LIMITED_TIME = 13 * 1000 ) // 道岔ZDJ9电路状态组件 var Switch2jZdj9StateComponent = ecs.NewComponentType[Switch2jZdj9State]() // ZDJ9道岔系统 type SwitchZdj9System struct { zdj9Query *ecs.Query } func NewSwitchZdj9System() *SwitchZdj9System { return &SwitchZdj9System{zdj9Query: ecs.NewQuery(filter.Contains(Switch2jZdj9StateComponent))} } // world 执行 func (me *SwitchZdj9System) Update(w ecs.World) { me.zdj9Query.Each(w, func(e *ecs.Entry) { zdj9State := Switch2jZdj9StateComponent.Get(e) //联锁条件操作 calculateDCFCYCJ(w, zdj9State) //断相保护器电路 calculateDBQ(w, zdj9State) //断相保护继电器励磁电路 calculateBHJ(w, zdj9State) //总保护继电器励磁电路 calculateZBHJ(w, zdj9State) //道岔转换启动切断继电器励磁电路 calculateQDJ(w, zdj9State) //道岔第一启动继电器励磁电路 calculate1DQJ(w, zdj9State) //转辙机接通380V交流电源 calculate380VPower(w, zdj9State) //道岔第一启动继电器复示继电器励磁电路 calculate1DQJF(w, zdj9State) //道岔第二启动继电器励磁电路 calculate2DQJ(w, zdj9State) //转辙机内自动开闭器 calculateAKB(w, zdj9State) //表示变压器电路 calculateBB(w, zdj9State) //道岔转辙机定表反表继电器励磁电路 calculateDBJ(w, zdj9State) calculateFBJ(w, zdj9State) //总定表/总反表继电器励磁电路 calculateZDBJ(w, zdj9State) calculateZFBJ(w, zdj9State) //道岔转辙机内电机驱动电路 calculateMotor(w, zdj9State) }) } // 断相保护电路运算 func calculateDBQ(w ecs.World, state *Switch2jZdj9State) { if state.J1_DBQ.LimitedTime > 0 { state.J1_DBQ.LimitedTime -= int64(w.Tick()) if state.J1_DBQ.LimitedTime < 0 { state.J1_DBQ.LimitedTime = 0 } } // state.J1_DBQ.PhaseLoss = !state.J1_Power.PhaseA || !state.J1_Power.PhaseB || !state.J1_Power.PhaseC // state.J1_DBQ.Dc24Voltage = !state.J1_DBQ.PhaseLoss /////////////////////////////////////////////////// if state.J2_DBQ.LimitedTime > 0 { state.J2_DBQ.LimitedTime -= int64(w.Tick()) if state.J2_DBQ.LimitedTime < 0 { state.J2_DBQ.LimitedTime = 0 } } // state.J2_DBQ.PhaseLoss = !state.J2_Power.PhaseA || !state.J2_Power.PhaseB || !state.J2_Power.PhaseC // state.J2_DBQ.Dc24Voltage = !state.J2_DBQ.PhaseLoss } // 定操、反操、允操继电器励磁电路运算 // JWXC-1700无极缓放继电器 func calculateDCFCYCJ(w ecs.World, state *Switch2jZdj9State) { //允操------- ycInterlock := state.YC_Pressed //缓放 if ycInterlock { state.YCJ_ReleaseTime = JWXC_1700_RELEASE_TIME } else { if state.YCJ_ReleaseTime > 0 { state.YCJ_ReleaseTime -= int64(w.Tick()) if state.YCJ_ReleaseTime < 0 { state.YCJ_ReleaseTime = 0 } } } //励磁 state.YCJ = ycInterlock || state.YCJ_ReleaseTime > 0 //定操------- dcInterlock := state.DC_Pressed //缓放 if dcInterlock { state.DCJ_ReleaseTime = JWXC_1700_RELEASE_TIME } else { if state.DCJ_ReleaseTime > 0 { state.DCJ_ReleaseTime -= int64(w.Tick()) if state.DCJ_ReleaseTime < 0 { state.DCJ_ReleaseTime = 0 } } } //励磁 state.DCJ = dcInterlock || state.DCJ_ReleaseTime > 0 //反操------- fcInterlock := state.FC_Pressed //缓放 if fcInterlock { state.FCJ_ReleaseTime = JWXC_1700_RELEASE_TIME } else { if state.FCJ_ReleaseTime > 0 { state.FCJ_ReleaseTime -= int64(w.Tick()) if state.FCJ_ReleaseTime < 0 { state.FCJ_ReleaseTime = 0 } } } //励磁 state.FCJ = fcInterlock || state.FCJ_ReleaseTime > 0 } // 转辙机内自动开闭器动作实现 // 暂时规定:自动开闭器跟随2DQJ func calculateAKB(w ecs.World, state *Switch2jZdj9State) { state.J1_AKB = state.J1_2DQJ state.J2_AKB = state.J2_2DQJ } // 转辙机380V三相交流电源 func calculate380VPower(w ecs.World, state *Switch2jZdj9State) { //接通电源 if state.J1_1DQJ_Pulse { state.J1_DBQ.LimitedTime = DBQ_LIMITED_TIME state.J1_Power.PhaseA = true state.J1_Power.PhaseB = true state.J1_Power.PhaseC = true } if state.J2_1DQJ_Pulse { state.J2_DBQ.LimitedTime = DBQ_LIMITED_TIME state.J2_Power.PhaseA = true state.J2_Power.PhaseB = true state.J2_Power.PhaseC = true } //转换超时切断电源 或 转到位切断电源 if state.J1_DBQ.LimitedTime == 0 || state.J1_DB_K9_Pulse || state.J1_FB_K10_Pulse { state.J1_Power.PhaseA = false state.J1_Power.PhaseB = false state.J1_Power.PhaseC = false } if state.J2_DBQ.LimitedTime == 0 || state.J2_DB_K9_Pulse || state.J2_FB_K10_Pulse { state.J2_Power.PhaseA = false state.J2_Power.PhaseB = false state.J2_Power.PhaseC = false } } // 断相保护继电器运算 // BHJ JWXC-1700无极缓放继电器 func calculateBHJ(w ecs.World, state *Switch2jZdj9State) { if state.J1_DBQ.Dc24Voltage { state.J1_BHJ_ReleaseTime = JWXC_1700_RELEASE_TIME } else { if state.J1_BHJ_ReleaseTime > 0 { state.J1_BHJ_ReleaseTime -= int64(w.Tick()) if state.J1_BHJ_ReleaseTime < 0 { state.J1_BHJ_ReleaseTime = 0 } } } state.J1_BHJ = state.J1_DBQ.Dc24Voltage || state.J1_BHJ_ReleaseTime > 0 // if state.J2_DBQ.Dc24Voltage { state.J2_BHJ_ReleaseTime = JWXC_1700_RELEASE_TIME } else { if state.J2_BHJ_ReleaseTime > 0 { state.J2_BHJ_ReleaseTime -= int64(w.Tick()) if state.J2_BHJ_ReleaseTime < 0 { state.J2_BHJ_ReleaseTime = 0 } } } state.J2_BHJ = state.J2_DBQ.Dc24Voltage || state.J2_BHJ_ReleaseTime > 0 } // 总保护继电器运算 // ZBHJ JWXC-1700无极缓放继电器 func calculateZBHJ(w ecs.World, state *Switch2jZdj9State) { //励磁 method := state.J1_BHJ && state.J2_BHJ //自闭 self := state.J1_ZBHJ && (state.J1_BHJ || state.J2_BHJ) // is := method || self //缓放 if is { state.J1_ZBHJ_ReleaseTime = JWXC_1700_RELEASE_TIME } else { if state.J1_ZBHJ_ReleaseTime > 0 { state.J1_ZBHJ_ReleaseTime -= int64(w.Tick()) if state.J1_ZBHJ_ReleaseTime < 0 { state.J1_ZBHJ_ReleaseTime = 0 } } } //为总保护继电器励磁 state.J1_ZBHJ = is || state.J1_ZBHJ_ReleaseTime > 0 } // 道岔转换启动切断继电器运算 // QDJ JWXC-1700无极缓放继电器 func calculateQDJ(w ecs.World, state *Switch2jZdj9State) { //LC震荡电路运算 fullLc := (!state.J1_BHJ && !state.J2_BHJ) || state.J1_ZBHJ if fullLc { state.J1_QDJ_LcTime = QDJ_LC_TIME } else { if state.J1_QDJ_LcTime > 0 { state.J1_QDJ_LcTime -= int64(w.Tick()) if state.J1_QDJ_LcTime < 0 { state.J1_QDJ_LcTime = 0 } } } //自闭励磁电路 self := state.J1_QDJ && state.J1_ZBHJ //缓放 if self { state.J1_QDJ_ReleaseTime = JWXC_1700_RELEASE_TIME } else { if state.J1_QDJ_ReleaseTime > 0 { state.J1_QDJ_ReleaseTime -= int64(w.Tick()) if state.J1_QDJ_ReleaseTime < 0 { state.J1_QDJ_ReleaseTime = 0 } } } //为启动切断继电器励磁 state.J1_QDJ = self || fullLc || state.J1_QDJ_LcTime > 0 || state.J1_QDJ_ReleaseTime > 0 } // 道岔第一启动继电器运算 // 1DQJ JWJXC-H125/80无极加强缓放继电器 // J1先启动J2后启动 func calculate1DQJ(w ecs.World, state *Switch2jZdj9State) { _J1_1DQJ := state.J1_1DQJ _J2_1DQJ := state.J2_1DQJ // //自闭电路 j2DqjSelf := state.J1_QDJ && state.J2_BHJ && state.J2_1DQJ //励磁电路 j2DqjMethod1 := state.YCJ && state.J1_1DQJ && (!state.J2_2DQJ && state.DCJ || state.J2_2DQJ && state.FCJ) //缓放 j2DqjIs := j2DqjMethod1 || j2DqjSelf if j2DqjIs { state.J2_1DQJ_ReleaseTime = JWJXC_H125_80_RELEASE_TIME } else { if state.J2_1DQJ_ReleaseTime > 0 { state.J2_1DQJ_ReleaseTime -= int64(w.Tick()) if state.J2_1DQJ_ReleaseTime < 0 { state.J2_1DQJ_ReleaseTime = 0 } } } //为J2第一启动继电器励磁 state.J2_1DQJ = j2DqjIs || state.J2_1DQJ_ReleaseTime > 0 //暂时规定:产生上升沿脉冲来接通380V交流电源 state.J2_1DQJ_Pulse = !_J2_1DQJ && state.J2_1DQJ // --------------- //励磁电路 j1DqjMethod1 := state.YCJ && (!state.J1_2DQJ && state.DCJ || state.J1_2DQJ && state.FCJ) //自闭电路 j1DqjSelf := state.J1_QDJ && state.J1_BHJ && state.J1_1DQJ //缓放 j1DqjIs := j1DqjMethod1 || j1DqjSelf if j1DqjIs { state.J1_1DQJ_ReleaseTime = JWJXC_H125_80_RELEASE_TIME } else { if state.J1_1DQJ_ReleaseTime > 0 { state.J1_1DQJ_ReleaseTime -= int64(w.Tick()) if state.J1_1DQJ_ReleaseTime < 0 { state.J1_1DQJ_ReleaseTime = 0 } } } //为J1第一启动继电器励磁 state.J1_1DQJ = j1DqjIs || state.J1_1DQJ_ReleaseTime > 0 //暂时规定:产生上升沿脉冲来接通380V交流电源 state.J1_1DQJ_Pulse = !_J1_1DQJ && state.J1_1DQJ } // 道岔第一启动继电器复示继电器运算 // 1DQJF JWJXC-480无极继电器 func calculate1DQJF(w ecs.World, state *Switch2jZdj9State) { state.J1_1DQJF = state.J1_1DQJ state.J2_1DQJF = state.J2_1DQJ } // 道岔第二启动继电器运算 // 2DQJ JYJXC-160/260有极加强继电器 // 2DQJ为有极继电器,根据线圈中电流极性不同具有 定位和反位 两种稳定状态,这两种稳定状态当线圈中电流消失时仍能继续保持; // 在线圈中通以规定极性的电流时,继电器吸起,断电后仍保持在吸起位置;通以反方向电流时,继电器打落,断电后保持在打落位置; // 断电保持由磁路系统中的一块长条形永久磁铁取代了大部分轭铁来实现; // 电流3->4吸起,电流2->1打落,如果21和34同时通过电流时磁场相互抵消则继电器保持原来状态不变 func calculate2DQJ(w ecs.World, state *Switch2jZdj9State) { //J1-2DQJ j1_2dqj_21 := state.J1_1DQJF && state.FCJ j1_2dqj_34 := state.J1_1DQJF && state.DCJ //磁通量,矢量 var j12dqj int8 = 0 if j1_2dqj_34 { j12dqj++ } if j1_2dqj_21 { j12dqj-- } if j12dqj != 0 { state.J1_2DQJ = j12dqj > 0 } //J2-2DQJ j2_2dqj_21 := state.J2_1DQJF && state.FCJ j2_2dqj_34 := state.J2_1DQJF && state.DCJ //磁通量,矢量 var j22dqj int8 = 0 if j2_2dqj_34 { j22dqj++ } if j2_2dqj_21 { j22dqj-- } if j22dqj != 0 { state.J2_2DQJ = j22dqj > 0 } } // 表示变压器电路运算 // 实际频率50HZ,简化处理每一个world tick改变一次BB二次输出电压正负值 // 表示电路变压器,将220V交流电变压后作为为道岔表示电路的电源 // 0-无电源;规定52端子为正,则,1-输出瞬时正电压;-1 - 输出瞬时负电压 func calculateBB(w ecs.World, state *Switch2jZdj9State) { //j1 if state.J1_BB.InDj220V { if state.J1_BB.OutBb >= 0 { state.J1_BB.OutBb = -1 } else { state.J1_BB.OutBb = 1 } } else { state.J1_BB.OutBb = 0 } //j2 if state.J2_BB.InDj220V { if state.J2_BB.OutBb >= 0 { state.J2_BB.OutBb = -1 } else { state.J2_BB.OutBb = 1 } } else { state.J2_BB.OutBb = 0 } } // 道岔总定表继电器运算 // ZDBJ JPXC-1000 偏极继电器是为了鉴别信号电路中的电流极性而设计 // 继电器在磁路中增加一个偏极磁钢,使衔铁受永磁力的作用而偏于落下位置。衔铁的吸起与线圈中的电流的极性有关, // 通过线圈的电流为规定的方向时,衔铁才吸起,而电流的方向相反时,衔铁保持不动。 // 它只具有一种稳定状态,即衔铁靠电磁力吸起后,断电即落下,始终偏向落下的定位状态 func calculateZDBJ(w ecs.World, state *Switch2jZdj9State) { state.ZDBJ = state.J1_DBJ && state.J2_DBJ } func calculateZFBJ(w ecs.World, state *Switch2jZdj9State) { state.ZFBJ = state.J1_FBJ && state.J2_FBJ } // 道岔定表继电器运算 // DBJ JPXC-1000 偏极继电器 // BB的负半周期提供DBJ的励磁电流 func calculateDBJ(w ecs.World, state *Switch2jZdj9State) { //j1 DBJ励磁 j1DbjLc := state.J1_BB.OutBb < 0 && state.J1_2DQJ && state.J1_AKB && state.J1_DB_K9 && !state.J1_1DQJ //缓放 if j1DbjLc { state.J1_DBJ_ReleaseTime = JPXC_1000_RELEASE_TIME } else { if state.J1_DBJ_ReleaseTime > 0 { state.J1_DBJ_ReleaseTime -= int64(w.Tick()) if state.J1_DBJ_ReleaseTime < 0 { state.J1_DBJ_ReleaseTime = 0 } } } state.J1_DBJ = j1DbjLc || state.J1_DBJ_ReleaseTime > 0 //j2 DBJ励磁 j2DbjLc := state.J2_BB.OutBb < 0 && state.J2_2DQJ && state.J2_AKB && state.J2_DB_K9 && !state.J2_1DQJ //缓放 if j2DbjLc { state.J2_DBJ_ReleaseTime = JPXC_1000_RELEASE_TIME } else { if state.J2_DBJ_ReleaseTime > 0 { state.J2_DBJ_ReleaseTime -= int64(w.Tick()) if state.J2_DBJ_ReleaseTime < 0 { state.J2_DBJ_ReleaseTime = 0 } } } state.J2_DBJ = j2DbjLc || state.J2_DBJ_ReleaseTime > 0 } // 道岔反表继电器运算 // FBJ JPXC-1000 偏极继电器 // BB的正半周期提供FBJ的励磁流 func calculateFBJ(w ecs.World, state *Switch2jZdj9State) { //j1 FBJ励磁 j1FbjLc := state.J1_BB.OutBb > 0 && !state.J1_2DQJ && !state.J1_AKB && state.J1_FB_K10 && !state.J1_1DQJ //缓放 if j1FbjLc { state.J1_FBJ_ReleaseTime = JPXC_1000_RELEASE_TIME } else { if state.J1_FBJ_ReleaseTime > 0 { state.J1_FBJ_ReleaseTime -= int64(w.Tick()) if state.J1_FBJ_ReleaseTime < 0 { state.J1_FBJ_ReleaseTime = 0 } } } state.J1_FBJ = j1FbjLc || state.J1_FBJ_ReleaseTime > 0 //j2 j2FbjLc := state.J2_BB.OutBb > 0 && !state.J2_2DQJ && !state.J2_AKB && state.J2_FB_K10 && !state.J2_1DQJ if j2FbjLc { state.J2_FBJ_ReleaseTime = JPXC_1000_RELEASE_TIME } else { if state.J2_FBJ_ReleaseTime > 0 { state.J2_FBJ_ReleaseTime -= int64(w.Tick()) if state.J2_FBJ_ReleaseTime < 0 { state.J2_FBJ_ReleaseTime = 0 } } } state.J2_FBJ = j2FbjLc || state.J2_FBJ_ReleaseTime > 0 } // 道岔转辙机电机内线圈电路运算 // ABC三相电,电机线圈UVW, // 定位到反位U-A V-C W-B 即U->W->V电机反转,反操接通2、4排表示电路 // 反位到定位U-A V-B W-C 即U->V->W电机正转,定操接通1、3排表示电路 func calculateMotor(w ecs.World, state *Switch2jZdj9State) { //电机1 state.J1_U1 = ACPahseN state.J1_V1 = ACPahseN state.J1_W1 = ACPahseN state.J1_Speed = 0 //A相电 if state.J1_Power.PhaseA && state.J1_1DQJ { state.J1_U1 = ACPahseA } //B相电 if state.J1_Power.PhaseB && state.J1_1DQJF { if state.J1_2DQJ { if state.J1_AKB { state.J1_V1 = ACPahseB } } else { if !state.J1_AKB { state.J1_W1 = ACPahseB } } } //C相电 if state.J1_Power.PhaseC && state.J1_1DQJF { if state.J1_2DQJ { if state.J1_AKB { state.J1_W1 = ACPahseC } } else { if !state.J1_AKB { state.J1_V1 = ACPahseC } } } //转速 if state.J1_U1 == ACPahseA { switch { case state.J1_V1 == ACPahseB: //U-A V-B W-C { if state.J1_W1 == ACPahseC { state.J1_Speed = 1 } } case state.J1_V1 == ACPahseC: //U-A W-B V-C { if state.J1_W1 == ACPahseB { state.J1_Speed = -1 } } } } ///////////// //电机2 state.J2_U1 = ACPahseN state.J2_V1 = ACPahseN state.J2_W1 = ACPahseN state.J2_Speed = 0 //A相电 if state.J2_Power.PhaseA && state.J2_1DQJ { state.J2_U1 = ACPahseA } //B相电 if state.J2_Power.PhaseB && state.J2_1DQJF { if state.J2_2DQJ { if state.J2_AKB { state.J2_V1 = ACPahseB } } else { if !state.J2_AKB { state.J2_W1 = ACPahseB } } } //C相电 if state.J2_Power.PhaseC && state.J2_1DQJF { if state.J2_2DQJ { if state.J2_AKB { state.J2_W1 = ACPahseC } } else { if !state.J2_AKB { state.J2_V1 = ACPahseC } } } //转速 if state.J2_U1 == ACPahseA { switch { case state.J2_V1 == ACPahseB: //U-A V-B W-C { if state.J2_W1 == ACPahseC { state.J2_Speed = 1 } } case state.J2_V1 == ACPahseC: //U-A W-B V-C { if state.J2_W1 == ACPahseB { state.J2_Speed = -1 } } } } }