804 lines
25 KiB
Go
804 lines
25 KiB
Go
package system
|
||
|
||
import (
|
||
"fmt"
|
||
"github.com/yohamta/donburi/filter"
|
||
"joylink.club/ecs"
|
||
sysEvent "joylink.club/rtsssimulation/system/event"
|
||
)
|
||
|
||
// --------联锁驱动-----------------
|
||
|
||
// Switch2jZdj9DriveYc 联锁驱动YCJ
|
||
func Switch2jZdj9DriveYc(w ecs.World, switchId string, xh bool) bool {
|
||
return DriveRelay(w, switchId, SJZDJ9_TDC, SJZDJ9_YCJ, xh)
|
||
}
|
||
|
||
// Switch2jZdj9DriveFc 联锁驱动FCJ
|
||
func Switch2jZdj9DriveFc(w ecs.World, switchId string, xh bool) bool {
|
||
return DriveRelay(w, switchId, SJZDJ9_TDC, SJZDJ9_FCJ, xh)
|
||
}
|
||
|
||
// Switch2jZdj9DriveDc 联锁驱动DCJ
|
||
func Switch2jZdj9DriveDc(w ecs.World, switchId string, xh bool) bool {
|
||
return DriveRelay(w, switchId, SJZDJ9_TDC, SJZDJ9_DCJ, xh)
|
||
}
|
||
|
||
//////////////////////////////////////////////////////////////////
|
||
|
||
// Switch2jZdj9State 双机ZDJ9道岔电路系统状态定义
|
||
// 继电器: true-吸合;false-未吸合
|
||
type Switch2jZdj9State struct {
|
||
//定操继电器
|
||
DCJ bool
|
||
//反操继电器
|
||
FCJ bool
|
||
//允许操作继电器
|
||
YCJ bool
|
||
//总定表继电器
|
||
ZDBJ bool
|
||
//总反表继电器
|
||
ZFBJ bool
|
||
//道岔第一启动继电器
|
||
J1_1DQJ bool
|
||
//道岔保护继电器
|
||
J1_BHJ bool
|
||
//道岔第二启动继电器
|
||
//true-吸起即1-3通;false-打落即1-2通
|
||
J1_2DQJ bool
|
||
//true-2DQJ由落下转换到吸起,即定操
|
||
J1_2DQJ_ToD bool
|
||
//true-2DQJ由吸起转换到落下,即反操
|
||
J1_2DQJ_ToF bool
|
||
//道岔第一启动继电器复示继电器
|
||
J1_1DQJF bool
|
||
//断相保护器
|
||
J1_DBQ DBQState
|
||
//定位表示继电器
|
||
J1_DBJ bool
|
||
//true-当道岔转换到定位时,转辙机内端子9与电路接通;false-转辙机内端子9断开切断电路
|
||
J1_DB_K9 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_Traction int8
|
||
//反位表示继电器
|
||
J1_FBJ bool
|
||
//true-当道岔转换到反位时,转辙机内端子10与电路接通;false-转辙机内端子10断开切断电路
|
||
J1_FB_K10 bool
|
||
//道岔启动切断继电器
|
||
J1_QDJ bool
|
||
//道岔启动切断继电器的LC震荡电路保磁剩余时间,单位ms
|
||
//最长保持时长3000ms
|
||
J1_QDJ_LcTime int64
|
||
//总保护继电器
|
||
J1_ZBHJ bool
|
||
//道岔第一启动继电器
|
||
J2_1DQJ bool
|
||
//道岔保护继电器
|
||
J2_BHJ bool
|
||
//道岔第二启动继电器
|
||
//true-吸起即1-3通;false-打落即1-2通
|
||
J2_2DQJ bool
|
||
//true-2DQJ由落下转换到吸起,即定操
|
||
J2_2DQJ_ToD bool
|
||
//true-2DQJ由吸起转换到落下,即反操
|
||
J2_2DQJ_ToF bool
|
||
//道岔第一启动继电器复示继电器
|
||
J2_1DQJF bool
|
||
//断相保护器
|
||
J2_DBQ DBQState
|
||
//定位表示继电器
|
||
J2_DBJ bool
|
||
//true-当道岔转换到定位时,转辙机内端子9与电路接通;false-转辙机内端子9断开切断电路
|
||
J2_DB_K9 bool
|
||
//反位表示继电器
|
||
J2_FBJ bool
|
||
//true-当道岔转换到反位时,转辙机内端子10与电路接通;false-转辙机内端子10断开切断电路
|
||
J2_FB_K10 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_Traction int8
|
||
}
|
||
|
||
// IsTurning 道岔物理实际状态而非采集状态:道岔是否在转动过程中
|
||
func (me *Switch2jZdj9State) IsTurning() bool {
|
||
return !me.J1_DB_K9 && !me.J1_FB_K10 || !me.J2_DB_K9 && !me.J2_FB_K10
|
||
}
|
||
|
||
// IsNormal 道岔物理实际状态而非采集状态:道岔是否在定位
|
||
func (me *Switch2jZdj9State) IsNormal() bool {
|
||
return me.J1_DB_K9 && !me.J1_FB_K10 && me.J2_DB_K9 && !me.J2_FB_K10
|
||
}
|
||
|
||
// IsReverse 道岔物理实际状态而非采集状态:道岔是否在反位
|
||
func (me *Switch2jZdj9State) IsReverse() bool {
|
||
return !me.J1_DB_K9 && me.J1_FB_K10 && !me.J2_DB_K9 && me.J2_FB_K10
|
||
}
|
||
|
||
// NewSwitch2jZdj9State 创建ZDJ9道岔状态并初始化
|
||
func NewSwitch2jZdj9State() *Switch2jZdj9State {
|
||
return &Switch2jZdj9State{
|
||
DCJ: false,
|
||
FCJ: false,
|
||
YCJ: false,
|
||
ZDBJ: true,
|
||
ZFBJ: false,
|
||
J1_1DQJ: false,
|
||
J1_BHJ: false,
|
||
J1_2DQJ: true,
|
||
J1_2DQJ_ToD: false,
|
||
J1_2DQJ_ToF: false,
|
||
J1_1DQJF: false,
|
||
J1_DBQ: DBQState{PhaseLoss: true, LimitedTime: 0, Dc24Voltage: false},
|
||
J1_DBJ: true,
|
||
J1_DB_K9: true,
|
||
J1_AKB: true,
|
||
J1_Power: Switch380ACPower{Active: false, PhaseA: false, PhaseB: false, PhaseC: false},
|
||
J1_U1: ACPahseN,
|
||
J1_V1: ACPahseN,
|
||
J1_W1: ACPahseN,
|
||
J1_Traction: 0,
|
||
J1_FBJ: false,
|
||
J1_FB_K10: false,
|
||
J1_QDJ: true,
|
||
J1_QDJ_LcTime: 0,
|
||
J1_ZBHJ: false,
|
||
J2_1DQJ: false,
|
||
J2_BHJ: false,
|
||
J2_2DQJ: true,
|
||
J2_2DQJ_ToD: false,
|
||
J2_2DQJ_ToF: false,
|
||
J2_1DQJF: false,
|
||
J2_DBQ: DBQState{PhaseLoss: true, LimitedTime: 0, Dc24Voltage: false},
|
||
J2_DBJ: true,
|
||
J2_DB_K9: true,
|
||
J2_FBJ: false,
|
||
J2_FB_K10: false,
|
||
J2_AKB: true,
|
||
J2_Power: Switch380ACPower{Active: false, PhaseA: false, PhaseB: false, PhaseC: false},
|
||
J2_U1: ACPahseN,
|
||
J2_V1: ACPahseN,
|
||
J2_W1: ACPahseN,
|
||
J2_Traction: 0,
|
||
}
|
||
}
|
||
|
||
// DBQState 带限时功能断相保护器
|
||
// 限时13秒
|
||
type DBQState struct {
|
||
//是否缺相,true-缺相,false-三相电正常未缺相
|
||
PhaseLoss bool
|
||
//剩余限时时间,单位ms
|
||
LimitedTime int64
|
||
//当三相电正常时,断相保护器内的24V直流整流电路会正常输出24V直流电
|
||
//当三相电不正常如缺相时,断相保护器内的24V直流整流电路不会输出24V直流电
|
||
//BHJ道岔保护继电器的励磁线圈由该24V直流供电
|
||
Dc24Voltage bool
|
||
}
|
||
|
||
// SwitchBB 表示电路变压器,变压比2:1,将220V交流电变压后作为为道岔表示电路的电源
|
||
// 0-无电源;规定52端子为正,则,1-输出瞬时正电压;-1 - 输出瞬时负电压
|
||
type SwitchBB struct {
|
||
//true-变压器初级输入正常
|
||
InDj220V bool
|
||
//次级输出电压
|
||
//0-无电源;规定52端子为正,则,1-输出瞬时正电压;-1 - 输出瞬时负电压
|
||
OutBb int8
|
||
}
|
||
|
||
// Switch380ACPower 道岔380V动力交流电源
|
||
type Switch380ACPower struct {
|
||
//true-激活
|
||
Active bool
|
||
//true-A相电正常输出
|
||
PhaseA bool
|
||
//true-B相电正常输出
|
||
PhaseB bool
|
||
//true-C相电正常输出
|
||
PhaseC bool
|
||
}
|
||
|
||
// Switch380ACPhase 道岔380V动力交流电相位定义
|
||
type Switch380ACPhase int8
|
||
|
||
const (
|
||
ACPahseN Switch380ACPhase = iota //不存在相位交流电
|
||
ACPahseA //存在A相位交流电
|
||
ACPahseB //存在B相位交流电
|
||
ACPahseC //存在C相位交流电
|
||
)
|
||
|
||
// 继电器常量定义
|
||
const (
|
||
QDJ_LC_TIME int64 = 3000 //QDJ 电源切断继电器LC震荡电路有效震荡时间ms
|
||
DBQ_LIMITED_TIME = 13 * 1000 //断相保护器限时,单位ms
|
||
)
|
||
|
||
// Switch2jZdj9StateComponent 道岔ZDJ9电路状态组件
|
||
var Switch2jZdj9StateComponent = ecs.NewComponentType[Switch2jZdj9State]()
|
||
|
||
// zdj9查询
|
||
var zdj9Query = ecs.NewQuery(filter.Contains(EntityIdentityComponent, Switch2jZdj9StateComponent))
|
||
|
||
// Switch2jZdj9System 双机ZDJ9道岔系统
|
||
type Switch2jZdj9System struct {
|
||
}
|
||
|
||
// NewSwitch2jZdj9System 双机ZDJ9道岔系统
|
||
func NewSwitch2jZdj9System() *Switch2jZdj9System {
|
||
return &Switch2jZdj9System{}
|
||
}
|
||
|
||
// Update world 执行
|
||
func (me *Switch2jZdj9System) Update(w ecs.World) {
|
||
zdj9Query.Each(w, func(e *ecs.Entry) {
|
||
zdj9State := Switch2jZdj9StateComponent.Get(e)
|
||
//电机电源
|
||
me.calculateJPower(w, e, zdj9State)
|
||
//断相保护器电路
|
||
me.calculateDBQ(w, e, zdj9State)
|
||
//断相保护继电器励磁电路
|
||
me.calculateBHJ(w, e, zdj9State)
|
||
//总保护继电器励磁电路
|
||
me.calculateZBHJ(w, e, zdj9State)
|
||
//道岔转换启动切断继电器励磁电路
|
||
me.calculateQDJ(w, e, zdj9State)
|
||
//道岔第一启动继电器励磁电路
|
||
me.calculate1DQJ(w, e, zdj9State)
|
||
//道岔第一启动继电器复示继电器励磁电路
|
||
me.calculate1DQJF(w, e, zdj9State)
|
||
//道岔第二启动继电器励磁电路
|
||
me.calculate2DQJ(w, e, zdj9State)
|
||
//转辙机内自动开闭器
|
||
me.calculateAKB(w, e, zdj9State)
|
||
//道岔转辙机定表反表继电器励磁电路
|
||
me.calculateDBJ(w, e, zdj9State)
|
||
me.calculateFBJ(w, e, zdj9State)
|
||
//总定表/总反表继电器励磁电路
|
||
me.calculateZDBJ(w, e, zdj9State)
|
||
me.calculateZFBJ(w, e, zdj9State)
|
||
//道岔转辙机内电机驱动电路
|
||
me.calculateMotor(w, e, zdj9State)
|
||
me.calculateMove(w, e, zdj9State)
|
||
me.calculateK9K10(w, e, zdj9State)
|
||
})
|
||
}
|
||
|
||
// SJZDJ9双机zdj9
|
||
const (
|
||
SJZDJ9_TDC = "TDC" //继电器组合类型
|
||
SJZDJ9_TDFJ1 = "TDFJ1"
|
||
SJZDJ9_TDFJ2 = "TDFJ2"
|
||
|
||
SJZDJ9_1DQJ = "1DQJ" //继电器功能名称
|
||
SJZDJ9_BHJ = "BHJ"
|
||
SJZDJ9_2DQJ = "2DQJ"
|
||
SJZDJ9_1DQJF = "1DQJF"
|
||
SJZDJ9_DBJ = "DBJ"
|
||
SJZDJ9_FBJ = "FBJ"
|
||
SJZDJ9_QDJ = "QDJ"
|
||
SJZDJ9_ZBHJ = "ZBHJ"
|
||
SJZDJ9_DCJ = "DCJ"
|
||
SJZDJ9_FCJ = "FCJ"
|
||
SJZDJ9_YCJ = "YCJ"
|
||
SJZDJ9_ZDBJ = "ZDBJ"
|
||
SJZDJ9_ZFBJ = "ZFBJ"
|
||
)
|
||
|
||
func Switch2jzdj9AddListeners(w ecs.World) {
|
||
sysEvent.RelayActionEventBus.Subscribe(w, Switch2jzdj9RelayActionEventProcessor)
|
||
}
|
||
|
||
// Switch2jzdj9RelayActionEventProcessor 接收继电器动作事件
|
||
var Switch2jzdj9RelayActionEventProcessor = func(w ecs.World, event sysEvent.RelayActionEvent) {
|
||
//log.Println("==>>收到继电器动作事件:id = ", event.Id, " xh = ", event.Xh)
|
||
zdj9Query.Each(w, func(e *ecs.Entry) {
|
||
switchModel := FindModelStorage(w).FindById(EntityIdentityComponent.Get(e).Id)
|
||
roler, ok := switchModel.(IRelayCRole)
|
||
if ok {
|
||
if relayGroup, relayName, find := roler.FindCircuitRoleById(event.Id); find {
|
||
state := Switch2jZdj9StateComponent.Get(e)
|
||
switch relayGroup {
|
||
case SJZDJ9_TDC:
|
||
{
|
||
switch relayName {
|
||
case SJZDJ9_DCJ:
|
||
state.DCJ = event.Xh
|
||
case SJZDJ9_FCJ:
|
||
state.FCJ = event.Xh
|
||
case SJZDJ9_YCJ:
|
||
state.YCJ = event.Xh
|
||
case SJZDJ9_ZDBJ:
|
||
state.ZDBJ = event.Xh
|
||
case SJZDJ9_ZFBJ:
|
||
state.ZFBJ = event.Xh
|
||
default:
|
||
panic(fmt.Sprintf("SwitchZdj9的模型[%s]中继电器功能名称[%s]无法识别", switchModel.Id(), relayName))
|
||
}
|
||
}
|
||
case SJZDJ9_TDFJ1:
|
||
{
|
||
switch relayName {
|
||
case SJZDJ9_1DQJ:
|
||
state.J1_1DQJ = event.Xh
|
||
case SJZDJ9_BHJ:
|
||
state.J1_BHJ = event.Xh
|
||
case SJZDJ9_2DQJ:
|
||
{
|
||
state.J1_2DQJ_ToD = !state.J1_2DQJ && event.Xh
|
||
state.J1_2DQJ_ToF = state.J1_2DQJ && !event.Xh
|
||
state.J1_2DQJ = event.Xh
|
||
}
|
||
case SJZDJ9_1DQJF:
|
||
state.J1_1DQJF = event.Xh
|
||
case SJZDJ9_DBJ:
|
||
state.J1_DBJ = event.Xh
|
||
case SJZDJ9_FBJ:
|
||
state.J1_FBJ = event.Xh
|
||
case SJZDJ9_QDJ:
|
||
state.J1_QDJ = event.Xh
|
||
case SJZDJ9_ZBHJ:
|
||
state.J1_ZBHJ = event.Xh
|
||
default:
|
||
panic(fmt.Sprintf("SwitchZdj9的模型[%s]中继电器功能名称[%s]无法识别", switchModel.Id(), relayName))
|
||
}
|
||
}
|
||
case SJZDJ9_TDFJ2:
|
||
{
|
||
switch relayName {
|
||
case SJZDJ9_1DQJ:
|
||
state.J2_1DQJ = event.Xh
|
||
case SJZDJ9_BHJ:
|
||
state.J2_BHJ = event.Xh
|
||
case SJZDJ9_2DQJ:
|
||
{
|
||
state.J2_2DQJ_ToD = !state.J2_2DQJ && event.Xh
|
||
state.J2_2DQJ_ToF = state.J2_2DQJ && !event.Xh
|
||
state.J2_2DQJ = event.Xh
|
||
}
|
||
case SJZDJ9_1DQJF:
|
||
state.J2_1DQJF = event.Xh
|
||
case SJZDJ9_DBJ:
|
||
state.J2_DBJ = event.Xh
|
||
case SJZDJ9_FBJ:
|
||
state.J2_FBJ = event.Xh
|
||
default:
|
||
panic(fmt.Sprintf("SwitchZdj9的模型[%s]中继电器功能名称[%s]无法识别", switchModel.Id(), relayName))
|
||
}
|
||
}
|
||
default:
|
||
panic(fmt.Sprintf("SwitchZdj9的模型[%s]中继电器组合类型[%s]无法识别", switchModel.Id(), relayGroup))
|
||
}
|
||
|
||
}
|
||
} else {
|
||
panic("SwitchZdj9的模型未实现接口umi.IRelayCRoler")
|
||
}
|
||
})
|
||
}
|
||
|
||
// 发送继电器需要改变事件
|
||
func (me *Switch2jZdj9System) publishRelayNeedChangeEvent(w ecs.World, switchEntry *ecs.Entry, relayGroup string, relayName string, needXh bool) {
|
||
switchModel := FindModelStorage(w).FindById(EntityIdentityComponent.Get(switchEntry).Id)
|
||
relayRole, _ := switchModel.(IRelayCRole)
|
||
relayModel := relayRole.FindRelayModelByCRole(relayGroup, relayName)
|
||
sysEvent.RelayNeedChangeEventBus.Publish(w, &sysEvent.RelayNeedChangeEvent{Id: relayModel.(IDeviceModel).Id(), Xh: needXh})
|
||
}
|
||
|
||
// 断相保护电路运算
|
||
func (me *Switch2jZdj9System) calculateDBQ(w ecs.World, switchEntry *ecs.Entry, 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
|
||
}
|
||
|
||
// 转辙机内自动开闭器动作实现
|
||
// 暂时规定:自动开闭器跟随2DQJ
|
||
func (me *Switch2jZdj9System) calculateAKB(w ecs.World, switchEntry *ecs.Entry, state *Switch2jZdj9State) {
|
||
state.J1_AKB = state.J1_2DQJ
|
||
state.J2_AKB = state.J2_2DQJ
|
||
}
|
||
|
||
// 断相保护继电器运算
|
||
// BHJ JWXC-1700无极缓放继电器
|
||
func (me *Switch2jZdj9System) calculateBHJ(w ecs.World, switchEntry *ecs.Entry, state *Switch2jZdj9State) {
|
||
_J1_BHJ := state.J1_DBQ.Dc24Voltage
|
||
_J2_BHJ := state.J2_DBQ.Dc24Voltage
|
||
if _J1_BHJ != state.J1_BHJ {
|
||
me.publishRelayNeedChangeEvent(w, switchEntry, SJZDJ9_TDFJ1, SJZDJ9_BHJ, _J1_BHJ)
|
||
}
|
||
if _J2_BHJ != state.J2_BHJ {
|
||
me.publishRelayNeedChangeEvent(w, switchEntry, SJZDJ9_TDFJ2, SJZDJ9_BHJ, _J2_BHJ)
|
||
}
|
||
}
|
||
|
||
// 总保护继电器运算
|
||
// ZBHJ JWXC-1700无极缓放继电器
|
||
func (me *Switch2jZdj9System) calculateZBHJ(w ecs.World, switchEntry *ecs.Entry, state *Switch2jZdj9State) {
|
||
//励磁
|
||
method := state.J1_BHJ && state.J2_BHJ
|
||
//自闭
|
||
self := state.J1_ZBHJ && (state.J1_BHJ || state.J2_BHJ)
|
||
//
|
||
_J1_ZBHJ := method || self
|
||
//为总保护继电器励磁
|
||
if _J1_ZBHJ != state.J1_ZBHJ {
|
||
me.publishRelayNeedChangeEvent(w, switchEntry, SJZDJ9_TDFJ1, SJZDJ9_ZBHJ, _J1_ZBHJ)
|
||
}
|
||
}
|
||
|
||
// 道岔转换启动切断继电器运算
|
||
// QDJ JWXC-1700无极缓放继电器
|
||
func (me *Switch2jZdj9System) calculateQDJ(w ecs.World, switchEntry *ecs.Entry, 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
|
||
//为启动切断继电器励磁
|
||
_J1_QDJ := self || fullLc || state.J1_QDJ_LcTime > 0
|
||
if _J1_QDJ != state.J1_QDJ {
|
||
me.publishRelayNeedChangeEvent(w, switchEntry, SJZDJ9_TDFJ1, SJZDJ9_QDJ, _J1_QDJ)
|
||
}
|
||
}
|
||
|
||
// 道岔第一启动继电器运算
|
||
// 1DQJ JWJXC-H125/80无极加强缓放继电器
|
||
// J1先启动J2后启动
|
||
func (me *Switch2jZdj9System) calculate1DQJ(w ecs.World, switchEntry *ecs.Entry, state *Switch2jZdj9State) {
|
||
//自闭电路
|
||
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
|
||
//为J2第一启动继电器励磁
|
||
if j2DqjIs != state.J2_1DQJ {
|
||
me.publishRelayNeedChangeEvent(w, switchEntry, SJZDJ9_TDFJ2, SJZDJ9_1DQJ, j2DqjIs)
|
||
}
|
||
// ---------------
|
||
//励磁电路
|
||
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
|
||
//为J1第一启动继电器励磁
|
||
if j1DqjIs != state.J1_1DQJ {
|
||
me.publishRelayNeedChangeEvent(w, switchEntry, SJZDJ9_TDFJ1, SJZDJ9_1DQJ, j1DqjIs)
|
||
}
|
||
}
|
||
|
||
// 道岔第一启动继电器复示继电器运算
|
||
// 1DQJF JWJXC-480无极继电器
|
||
func (me *Switch2jZdj9System) calculate1DQJF(w ecs.World, switchEntry *ecs.Entry, state *Switch2jZdj9State) {
|
||
_J1_1DQJF := state.J1_1DQJ
|
||
_J2_1DQJF := state.J2_1DQJ
|
||
if _J1_1DQJF != state.J1_1DQJF {
|
||
me.publishRelayNeedChangeEvent(w, switchEntry, SJZDJ9_TDFJ1, SJZDJ9_1DQJF, _J1_1DQJF)
|
||
}
|
||
if _J2_1DQJF != state.J2_1DQJF {
|
||
me.publishRelayNeedChangeEvent(w, switchEntry, SJZDJ9_TDFJ2, SJZDJ9_1DQJF, _J2_1DQJF)
|
||
}
|
||
}
|
||
|
||
// 道岔第二启动继电器运算
|
||
// 2DQJ JYJXC-160/260有极加强继电器
|
||
// 2DQJ为有极继电器,根据线圈中电流极性不同具有 定位和反位 两种稳定状态,这两种稳定状态当线圈中电流消失时仍能继续保持;
|
||
// 在线圈中通以规定极性的电流时,继电器吸起,断电后仍保持在吸起位置;通以反方向电流时,继电器打落,断电后保持在打落位置;
|
||
// 断电保持由磁路系统中的一块长条形永久磁铁取代了大部分轭铁来实现;
|
||
// 电流3->4吸起,电流2->1打落,如果21和34同时通过电流时磁场相互抵消则继电器保持原来状态不变
|
||
func (me *Switch2jZdj9System) calculate2DQJ(w ecs.World, switchEntry *ecs.Entry, 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 {
|
||
_J1_2DQJ := j12dqj > 0
|
||
if _J1_2DQJ != state.J1_2DQJ {
|
||
me.publishRelayNeedChangeEvent(w, switchEntry, SJZDJ9_TDFJ1, SJZDJ9_2DQJ, _J1_2DQJ)
|
||
}
|
||
}
|
||
//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 {
|
||
_J2_2DQJ := j22dqj > 0
|
||
if _J2_2DQJ != state.J2_2DQJ {
|
||
me.publishRelayNeedChangeEvent(w, switchEntry, SJZDJ9_TDFJ2, SJZDJ9_2DQJ, _J2_2DQJ)
|
||
}
|
||
}
|
||
}
|
||
|
||
// 道岔总定表继电器运算
|
||
// ZDBJ JPXC-1000 偏极继电器是为了鉴别信号电路中的电流极性而设计
|
||
// 继电器在磁路中增加一个偏极磁钢,使衔铁受永磁力的作用而偏于落下位置。衔铁的吸起与线圈中的电流的极性有关,
|
||
// 通过线圈的电流为规定的方向时,衔铁才吸起,而电流的方向相反时,衔铁保持不动。
|
||
// 它只具有一种稳定状态,即衔铁靠电磁力吸起后,断电即落下,始终偏向落下的定位状态
|
||
func (me *Switch2jZdj9System) calculateZDBJ(w ecs.World, switchEntry *ecs.Entry, state *Switch2jZdj9State) {
|
||
_ZDBJ := state.J1_DBJ && state.J2_DBJ
|
||
if _ZDBJ != state.ZDBJ {
|
||
me.publishRelayNeedChangeEvent(w, switchEntry, SJZDJ9_TDC, SJZDJ9_ZDBJ, _ZDBJ)
|
||
}
|
||
}
|
||
func (me *Switch2jZdj9System) calculateZFBJ(w ecs.World, switchEntry *ecs.Entry, state *Switch2jZdj9State) {
|
||
_ZFBJ := state.J1_FBJ && state.J2_FBJ
|
||
if _ZFBJ != state.ZFBJ {
|
||
me.publishRelayNeedChangeEvent(w, switchEntry, SJZDJ9_TDC, SJZDJ9_ZFBJ, _ZFBJ)
|
||
}
|
||
}
|
||
|
||
// 道岔定表继电器运算
|
||
// DBJ JPXC-1000 偏极继电器
|
||
// BB的负半周期提供DBJ的励磁电流
|
||
func (me *Switch2jZdj9System) calculateDBJ(w ecs.World, switchEntry *ecs.Entry, state *Switch2jZdj9State) {
|
||
//j1 DBJ励磁
|
||
j1DbjLc := state.J1_2DQJ && state.J1_AKB && state.J1_DB_K9 && !state.J1_1DQJ
|
||
if j1DbjLc != state.J1_DBJ {
|
||
me.publishRelayNeedChangeEvent(w, switchEntry, SJZDJ9_TDFJ1, SJZDJ9_DBJ, j1DbjLc)
|
||
}
|
||
//j2 DBJ励磁
|
||
j2DbjLc := state.J2_2DQJ && state.J2_AKB && state.J2_DB_K9 && !state.J2_1DQJ
|
||
if j2DbjLc != state.J2_DBJ {
|
||
me.publishRelayNeedChangeEvent(w, switchEntry, SJZDJ9_TDFJ2, SJZDJ9_DBJ, j2DbjLc)
|
||
}
|
||
}
|
||
|
||
// 道岔反表继电器运算
|
||
// FBJ JPXC-1000 偏极继电器
|
||
// BB的正半周期提供FBJ的励磁流
|
||
func (me *Switch2jZdj9System) calculateFBJ(w ecs.World, switchEntry *ecs.Entry, state *Switch2jZdj9State) {
|
||
//j1 FBJ励磁
|
||
j1FbjLc := !state.J1_2DQJ && !state.J1_AKB && state.J1_FB_K10 && !state.J1_1DQJ
|
||
if j1FbjLc != state.J1_FBJ {
|
||
me.publishRelayNeedChangeEvent(w, switchEntry, SJZDJ9_TDFJ1, SJZDJ9_FBJ, j1FbjLc)
|
||
}
|
||
//j2
|
||
j2FbjLc := !state.J2_2DQJ && !state.J2_AKB && state.J2_FB_K10 && !state.J2_1DQJ
|
||
if j2FbjLc != state.J2_FBJ {
|
||
me.publishRelayNeedChangeEvent(w, switchEntry, SJZDJ9_TDFJ2, SJZDJ9_FBJ, j2FbjLc)
|
||
}
|
||
}
|
||
|
||
// 道岔转动运算
|
||
// j1 完全转动须4000ms -> v=25/ms
|
||
// j2 完全转动须5000ms -> v=20/ms
|
||
// j.Value 0-反位 jRange-定位
|
||
func (me *Switch2jZdj9System) calculateMove(w ecs.World, switchEntry *ecs.Entry, state *Switch2jZdj9State) {
|
||
j1 := PercentageDeviceState1Component.Get(switchEntry)
|
||
j1.V = int64(state.J1_Traction) * 25
|
||
//
|
||
j2 := PercentageDeviceState2Component.Get(switchEntry)
|
||
j2.V = int64(state.J2_Traction) * 20
|
||
}
|
||
|
||
// 转辙机对外端子9、10运算
|
||
func (me *Switch2jZdj9System) calculateK9K10(w ecs.World, switchEntry *ecs.Entry, state *Switch2jZdj9State) {
|
||
j1 := PercentageDeviceState1Component.Get(switchEntry)
|
||
j2 := PercentageDeviceState2Component.Get(switchEntry)
|
||
//
|
||
state.J1_DB_K9 = j1.isToM()
|
||
state.J1_FB_K10 = j1.isToL()
|
||
//
|
||
state.J2_DB_K9 = j2.isToM()
|
||
state.J2_FB_K10 = j2.isToL()
|
||
}
|
||
|
||
// 转辙机电源控制
|
||
// 1DQj启动继电器吸合时接通电源
|
||
func (me *Switch2jZdj9System) calculateJPower(w ecs.World, switchEntry *ecs.Entry, state *Switch2jZdj9State) {
|
||
//超时断电
|
||
j1csdd := state.J1_Power.Active && state.J1_DBQ.LimitedTime <= 0
|
||
//转换到位断电
|
||
j1zhdwdd := state.J1_2DQJ_ToD && state.J1_DB_K9 || state.J1_2DQJ_ToF && state.J1_FB_K10
|
||
if j1csdd || j1zhdwdd {
|
||
state.J1_Power.PhaseA = false
|
||
state.J1_Power.PhaseB = false
|
||
state.J1_Power.PhaseC = false
|
||
state.J1_2DQJ_ToD = false
|
||
state.J1_2DQJ_ToF = false
|
||
}
|
||
//第一启动继电器落下
|
||
if !state.J1_1DQJ {
|
||
state.J1_Power.Active = false
|
||
}
|
||
//接通电源
|
||
if state.J1_1DQJ && !state.J1_Power.Active {
|
||
state.J1_Power.Active = true
|
||
state.J1_Power.PhaseA = true
|
||
state.J1_Power.PhaseB = true
|
||
state.J1_Power.PhaseC = true
|
||
state.J1_DBQ.LimitedTime = DBQ_LIMITED_TIME
|
||
}
|
||
//----------------
|
||
//超时断电
|
||
j2csdd := state.J2_Power.Active && state.J2_DBQ.LimitedTime <= 0
|
||
//转换到位断电
|
||
j2zhdwdd := state.J2_2DQJ_ToD && state.J2_DB_K9 || state.J2_2DQJ_ToF && state.J2_FB_K10
|
||
if j2csdd || j2zhdwdd {
|
||
state.J2_Power.PhaseA = false
|
||
state.J2_Power.PhaseB = false
|
||
state.J2_Power.PhaseC = false
|
||
state.J2_2DQJ_ToD = false
|
||
state.J2_2DQJ_ToF = false
|
||
}
|
||
//第一启动继电器落下
|
||
if !state.J2_1DQJ {
|
||
state.J2_Power.Active = false
|
||
}
|
||
//接通电源
|
||
if state.J2_1DQJ && !state.J2_Power.Active {
|
||
state.J2_Power.Active = true
|
||
state.J2_Power.PhaseA = true
|
||
state.J2_Power.PhaseB = true
|
||
state.J2_Power.PhaseC = true
|
||
state.J2_DBQ.LimitedTime = DBQ_LIMITED_TIME
|
||
}
|
||
}
|
||
|
||
// 道岔转辙机电机内线圈电路运算
|
||
// 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 (me *Switch2jZdj9System) calculateMotor(w ecs.World, switchEntry *ecs.Entry, state *Switch2jZdj9State) {
|
||
//电机1
|
||
state.J1_U1 = ACPahseN
|
||
state.J1_V1 = ACPahseN
|
||
state.J1_W1 = ACPahseN
|
||
state.J1_Traction = 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_Traction = 1
|
||
}
|
||
}
|
||
case state.J1_V1 == ACPahseC: //U-A W-B V-C
|
||
{
|
||
if state.J1_W1 == ACPahseB {
|
||
state.J1_Traction = -1
|
||
}
|
||
}
|
||
}
|
||
}
|
||
/////////////
|
||
//电机2
|
||
state.J2_U1 = ACPahseN
|
||
state.J2_V1 = ACPahseN
|
||
state.J2_W1 = ACPahseN
|
||
state.J2_Traction = 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_Traction = 1
|
||
}
|
||
}
|
||
case state.J2_V1 == ACPahseC: //U-A W-B V-C
|
||
{
|
||
if state.J2_W1 == ACPahseB {
|
||
state.J2_Traction = -1
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}
|