signal 3xh2 驱采

This commit is contained in:
xzb 2023-10-12 14:19:00 +08:00
parent da8485c036
commit 691a4efdc9
5 changed files with 104 additions and 52 deletions

View File

@ -123,16 +123,36 @@ type Signal3XH2Electronic struct {
Z3XH2_LXJ *ecs.Entry Z3XH2_LXJ *ecs.Entry
//引导信号继电器true-吸合 //引导信号继电器true-吸合
Z3XH2_YXJ *ecs.Entry Z3XH2_YXJ *ecs.Entry
// 物理黄灯true-亮 }
Z3XH2_U *ecs.Entry
// 物理绿灯true-亮 // Signal3XH2Lsq 联锁驱
Z3XH2_L *ecs.Entry type Signal3XH2Lsq struct {
// 物理红灯true-亮 //true-联锁施加励磁电流驱动继电器DDJ
Z3XH2_H *ecs.Entry Z3XH2_DDJ_Q bool
////true-联锁施加励磁电流驱动继电器LXJ
Z3XH2_LXJ_Q bool
////true-联锁施加励磁电流驱动继电器LXJ
Z3XH2_YXJ_Q bool
}
// Signal3XH2Lsc 联锁采
type Signal3XH2Lsc struct {
//true-继电器DJ吸起
Z3XH2_DJ_Xq bool
//true-继电器2DJ吸起
Z3XH2_2DJ_Xq bool
//true-继电器DDJ落下
Z3XH2_DDJ_Lx bool
//true-继电器LXJ吸起
Z3XH2_LXJ_Xq bool
//true-继电器YXJ吸起
Z3XH2_YXJ_Xq bool
} }
var ( var (
Signal3XH2ElectronicType = ecs.NewComponentType[Signal3XH2Electronic]() Signal3XH2ElectronicType = ecs.NewComponentType[Signal3XH2Electronic]()
Signal3XH2LsqType = ecs.NewComponentType[Signal3XH2Lsq]()
Signal3XH2LscType = ecs.NewComponentType[Signal3XH2Lsc]()
) )
////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////

View File

@ -12,8 +12,11 @@ func loadSignal3xh2(w ecs.World, signal *repository.Signal, signalEntry *ecs.Ent
if len(elecs) == 5 { //3xh2组合类型包含5个继电器 if len(elecs) == 5 { //3xh2组合类型包含5个继电器
signalEntry.AddComponent(component.Signal3XH2ElectronicType) signalEntry.AddComponent(component.Signal3XH2ElectronicType)
signalEntry.AddComponent(component.Signal3XH2LsqType)
signalEntry.AddComponent(component.Signal3XH2LscType)
signalEntry.AddComponent(component.SignalLightsType)
// //
elecState := &component.Signal3XH2Electronic{Z3XH2_L: NewLightLEntity(w), Z3XH2_H: NewLightHEntity(w), Z3XH2_U: NewLightUEntity(w)} elecState := &component.Signal3XH2Electronic{}
for _, elec := range elecs { for _, elec := range elecs {
switch elec.Code() { switch elec.Code() {
case consts.SIGNAL_DDJ: case consts.SIGNAL_DDJ:
@ -32,6 +35,9 @@ func loadSignal3xh2(w ecs.World, signal *repository.Signal, signalEntry *ecs.Ent
} }
// //
component.Signal3XH2ElectronicType.Set(signalEntry, elecState) component.Signal3XH2ElectronicType.Set(signalEntry, elecState)
component.Signal3XH2LsqType.Set(signalEntry, &component.Signal3XH2Lsq{})
component.Signal3XH2LscType.Set(signalEntry, &component.Signal3XH2Lsc{})
component.SignalLightsType.Set(signalEntry, newSignalLights(w, component.HdTag, component.LdTag, component.UdTag))
} else { } else {
return fmt.Errorf("id=[%s]的信号机3xh2电子元器件数量须为5", signal.Id()) return fmt.Errorf("id=[%s]的信号机3xh2电子元器件数量须为5", signal.Id())
} }

View File

@ -15,11 +15,8 @@ func DriveSignal3XH2Dd(w ecs.World, signalId string, dd bool) {
wd := entity.GetWorldData(w) wd := entity.GetWorldData(w)
signalEntry, ok := wd.EntityMap[signalId] signalEntry, ok := wd.EntityMap[signalId]
if ok { if ok {
state := component.Signal3XH2ElectronicType.Get(signalEntry) lsq := component.Signal3XH2LsqType.Get(signalEntry)
driveDd := component.RelayDriveType.Get(state.Z3XH2_DDJ) lsq.Z3XH2_DDJ_Q = !dd
//点灯继电器落下时才点灯
driveDd.Td = !dd
driveDd.Xq = !dd
} }
}) })
} }
@ -30,13 +27,9 @@ func DriveSignal3XH2Lx(w ecs.World, signalId string) {
wd := entity.GetWorldData(w) wd := entity.GetWorldData(w)
signalEntry, ok := wd.EntityMap[signalId] signalEntry, ok := wd.EntityMap[signalId]
if ok { if ok {
state := component.Signal3XH2ElectronicType.Get(signalEntry) lsq := component.Signal3XH2LsqType.Get(signalEntry)
driveLx := component.RelayDriveType.Get(state.Z3XH2_LXJ) lsq.Z3XH2_LXJ_Q = true
driveLx.Td = true lsq.Z3XH2_YXJ_Q = false
driveLx.Xq = true
driveYx := component.RelayDriveType.Get(state.Z3XH2_YXJ)
driveYx.Td = false
driveYx.Xq = false
} }
}) })
} }
@ -47,13 +40,9 @@ func DriveSignal3XH2Yx(w ecs.World, signalId string) {
wd := entity.GetWorldData(w) wd := entity.GetWorldData(w)
signalEntry, ok := wd.EntityMap[signalId] signalEntry, ok := wd.EntityMap[signalId]
if ok { if ok {
state := component.Signal3XH2ElectronicType.Get(signalEntry) lsq := component.Signal3XH2LsqType.Get(signalEntry)
driveLx := component.RelayDriveType.Get(state.Z3XH2_LXJ) lsq.Z3XH2_LXJ_Q = false
driveLx.Td = false lsq.Z3XH2_YXJ_Q = true
driveLx.Xq = false
driveYx := component.RelayDriveType.Get(state.Z3XH2_YXJ)
driveYx.Td = true
driveYx.Xq = true
} }
}) })
} }
@ -64,13 +53,9 @@ func DriveSignal3XH2Non(w ecs.World, signalId string) {
wd := entity.GetWorldData(w) wd := entity.GetWorldData(w)
signalEntry, ok := wd.EntityMap[signalId] signalEntry, ok := wd.EntityMap[signalId]
if ok { if ok {
state := component.Signal3XH2ElectronicType.Get(signalEntry) lsq := component.Signal3XH2LsqType.Get(signalEntry)
driveLx := component.RelayDriveType.Get(state.Z3XH2_LXJ) lsq.Z3XH2_LXJ_Q = false
driveLx.Td = false lsq.Z3XH2_YXJ_Q = false
driveLx.Xq = false
driveYx := component.RelayDriveType.Get(state.Z3XH2_YXJ)
driveYx.Td = false
driveYx.Xq = false
} }
}) })
} }

@ -1 +1 @@
Subproject commit 74c02116147b7b4e86b56c790c9075e039e6fe82 Subproject commit af605020f1bccf1f1b2ab5a4ae4966d1c6c9776c

View File

@ -16,47 +16,88 @@ func NewSignal3XH2System() *Signal3XH2System {
// Update world 执行 // Update world 执行
func (s *Signal3XH2System) Update(w ecs.World) { func (s *Signal3XH2System) Update(w ecs.World) {
s.query.Each(w, func(e *ecs.Entry) { s.query.Each(w, func(entry *ecs.Entry) {
state := component.Signal3XH2ElectronicType.Get(e) state := component.Signal3XH2ElectronicType.Get(entry)
s.calculateU(state) lsq := component.Signal3XH2LsqType.Get(entry)
s.calculateL(state) lsc := component.Signal3XH2LscType.Get(entry)
s.calculateH(state) lights := component.SignalLightsType.Get(entry)
s.calculateDJ(state) Z3XH2_L := lights.GetLightByTag(component.LdTag)
s.calculate2DJ(state) Z3XH2_H := lights.GetLightByTag(component.HdTag)
Z3XH2_U := lights.GetLightByTag(component.UdTag)
s.calculateLsq(state, lsq)
s.calculateU(state, Z3XH2_U)
s.calculateL(state, Z3XH2_L)
s.calculateH(state, Z3XH2_H)
s.calculateDJ(state, Z3XH2_L, Z3XH2_H)
s.calculate2DJ(state, Z3XH2_U)
s.calculateLsc(state, lsc)
}) })
} }
func (s *Signal3XH2System) calculateU(state *component.Signal3XH2Electronic) { // 联锁驱
func (s *Signal3XH2System) calculateLsq(state *component.Signal3XH2Electronic, lsq *component.Signal3XH2Lsq) {
ddj := component.RelayDriveType.Get(state.Z3XH2_DDJ)
lxj := component.RelayDriveType.Get(state.Z3XH2_LXJ)
yxj := component.RelayDriveType.Get(state.Z3XH2_YXJ)
//
ddjQ := lsq.Z3XH2_DDJ_Q
ddj.Td = ddjQ
ddj.Xq = ddjQ
//
lxjQ := lsq.Z3XH2_LXJ_Q
lxj.Td = lxjQ
lxj.Xq = lxjQ
//
yxjQ := lsq.Z3XH2_YXJ_Q
yxj.Td = yxjQ
yxj.Xq = yxjQ
}
// 联锁采
func (s *Signal3XH2System) calculateLsc(state *component.Signal3XH2Electronic, lsc *component.Signal3XH2Lsc) {
ddj := component.BitStateType.Get(state.Z3XH2_DDJ)
lxj := component.BitStateType.Get(state.Z3XH2_LXJ)
dj := component.BitStateType.Get(state.Z3XH2_DJ)
edj := component.BitStateType.Get(state.Z3XH2_2DJ)
yxj := component.BitStateType.Get(state.Z3XH2_YXJ)
//
lsc.Z3XH2_2DJ_Xq = edj.Val
lsc.Z3XH2_DJ_Xq = dj.Val
lsc.Z3XH2_DDJ_Lx = !ddj.Val
lsc.Z3XH2_LXJ_Xq = lxj.Val
lsc.Z3XH2_YXJ_Xq = yxj.Val
}
func (s *Signal3XH2System) calculateU(state *component.Signal3XH2Electronic, Z3XH2_U *ecs.Entry) {
ddj := component.BitStateType.Get(state.Z3XH2_DDJ) ddj := component.BitStateType.Get(state.Z3XH2_DDJ)
lxj := component.BitStateType.Get(state.Z3XH2_LXJ) lxj := component.BitStateType.Get(state.Z3XH2_LXJ)
dj := component.BitStateType.Get(state.Z3XH2_DJ) dj := component.BitStateType.Get(state.Z3XH2_DJ)
yxj := component.BitStateType.Get(state.Z3XH2_YXJ) yxj := component.BitStateType.Get(state.Z3XH2_YXJ)
driveU := component.LightDriveType.Get(state.Z3XH2_U) driveU := component.LightDriveType.Get(Z3XH2_U)
isU := !ddj.Val && !lxj.Val && dj.Val && yxj.Val isU := !ddj.Val && !lxj.Val && dj.Val && yxj.Val
driveU.Td = isU driveU.Td = isU
} }
func (s *Signal3XH2System) calculateL(state *component.Signal3XH2Electronic) { func (s *Signal3XH2System) calculateL(state *component.Signal3XH2Electronic, Z3XH2_L *ecs.Entry) {
ddj := component.BitStateType.Get(state.Z3XH2_DDJ) ddj := component.BitStateType.Get(state.Z3XH2_DDJ)
lxj := component.BitStateType.Get(state.Z3XH2_LXJ) lxj := component.BitStateType.Get(state.Z3XH2_LXJ)
driveL := component.LightDriveType.Get(state.Z3XH2_L) driveL := component.LightDriveType.Get(Z3XH2_L)
isL := !ddj.Val && lxj.Val isL := !ddj.Val && lxj.Val
driveL.Td = isL driveL.Td = isL
} }
func (s *Signal3XH2System) calculateH(state *component.Signal3XH2Electronic) { func (s *Signal3XH2System) calculateH(state *component.Signal3XH2Electronic, Z3XH2_H *ecs.Entry) {
ddj := component.BitStateType.Get(state.Z3XH2_DDJ) ddj := component.BitStateType.Get(state.Z3XH2_DDJ)
lxj := component.BitStateType.Get(state.Z3XH2_LXJ) lxj := component.BitStateType.Get(state.Z3XH2_LXJ)
driveH := component.LightDriveType.Get(state.Z3XH2_H) driveH := component.LightDriveType.Get(Z3XH2_H)
isH := !ddj.Val && !lxj.Val isH := !ddj.Val && !lxj.Val
driveH.Td = isH driveH.Td = isH
} }
func (s *Signal3XH2System) calculateDJ(state *component.Signal3XH2Electronic) { func (s *Signal3XH2System) calculateDJ(state *component.Signal3XH2Electronic, Z3XH2_L *ecs.Entry, Z3XH2_H *ecs.Entry) {
ddj := component.BitStateType.Get(state.Z3XH2_DDJ) ddj := component.BitStateType.Get(state.Z3XH2_DDJ)
lxj := component.BitStateType.Get(state.Z3XH2_LXJ) lxj := component.BitStateType.Get(state.Z3XH2_LXJ)
ld := component.BitStateType.Get(state.Z3XH2_L) ld := component.BitStateType.Get(Z3XH2_L)
hd := component.BitStateType.Get(state.Z3XH2_H) hd := component.BitStateType.Get(Z3XH2_H)
isDJ := ld.Val && !ddj.Val && lxj.Val || hd.Val && !ddj.Val && !lxj.Val isDJ := ld.Val && !ddj.Val && lxj.Val || hd.Val && !ddj.Val && !lxj.Val
//通知继电器进行动作 //通知继电器进行动作
drive := component.RelayDriveType.Get(state.Z3XH2_DJ) drive := component.RelayDriveType.Get(state.Z3XH2_DJ)
@ -64,12 +105,12 @@ func (s *Signal3XH2System) calculateDJ(state *component.Signal3XH2Electronic) {
drive.Xq = isDJ drive.Xq = isDJ
} }
func (s *Signal3XH2System) calculate2DJ(state *component.Signal3XH2Electronic) { func (s *Signal3XH2System) calculate2DJ(state *component.Signal3XH2Electronic, Z3XH2_U *ecs.Entry) {
ddj := component.BitStateType.Get(state.Z3XH2_DDJ) ddj := component.BitStateType.Get(state.Z3XH2_DDJ)
lxj := component.BitStateType.Get(state.Z3XH2_LXJ) lxj := component.BitStateType.Get(state.Z3XH2_LXJ)
dj := component.BitStateType.Get(state.Z3XH2_DJ) dj := component.BitStateType.Get(state.Z3XH2_DJ)
yxj := component.BitStateType.Get(state.Z3XH2_YXJ) yxj := component.BitStateType.Get(state.Z3XH2_YXJ)
ud := component.BitStateType.Get(state.Z3XH2_U) ud := component.BitStateType.Get(Z3XH2_U)
is2DJ := ud.Val && !ddj.Val && !lxj.Val && dj.Val && yxj.Val is2DJ := ud.Val && !ddj.Val && !lxj.Val && dj.Val && yxj.Val
//通知继电器进行动作 //通知继电器进行动作
drive := component.RelayDriveType.Get(state.Z3XH2_2DJ) drive := component.RelayDriveType.Get(state.Z3XH2_2DJ)