signal 3xh1 驱采

This commit is contained in:
xzb 2023-10-12 13:54:53 +08:00
parent 90e373d3fd
commit c23e141691
6 changed files with 140 additions and 68 deletions

View File

@ -72,16 +72,40 @@ type Signal3XH1Electronic struct {
Z3XH1_YXJ *ecs.Entry Z3XH1_YXJ *ecs.Entry
//开通正线信号继电器true-吸合 //开通正线信号继电器true-吸合
Z3XH1_ZXJ *ecs.Entry Z3XH1_ZXJ *ecs.Entry
// 物理黄灯true-亮 }
Z3XH1_U *ecs.Entry
// 物理绿灯true-亮 // Signal3XH1Lsq 联锁驱
Z3XH1_L *ecs.Entry type Signal3XH1Lsq struct {
// 物理红灯true-亮 //true-联锁施加励磁电流驱动继电器DDJ
Z3XH1_H *ecs.Entry Z3XH1_DDJ_Q bool
////true-联锁施加励磁电流驱动继电器LXJ
Z3XH1_LXJ_Q bool
////true-联锁施加励磁电流驱动继电器LXJ
Z3XH1_ZXJ_Q bool
////true-联锁施加励磁电流驱动继电器LXJ
Z3XH1_YXJ_Q bool
}
// Signal3XH1Lsc 联锁采
type Signal3XH1Lsc struct {
//true-继电器DJ吸起
Z3XH1_DJ_Xq bool
//true-继电器2DJ吸起
Z3XH1_2DJ_Xq bool
//true-继电器DDJ落下
Z3XH1_DDJ_Lx bool
//true-继电器LXJ吸起
Z3XH1_LXJ_Xq bool
//true-继电器ZXJ吸起
Z3XH1_ZXJ_Xq bool
//true-继电器YXJ吸起
Z3XH1_YXJ_Xq bool
} }
var ( var (
Signal3XH1ElectronicType = ecs.NewComponentType[Signal3XH1Electronic]() Signal3XH1ElectronicType = ecs.NewComponentType[Signal3XH1Electronic]()
Signal3XH1LsqType = ecs.NewComponentType[Signal3XH1Lsq]()
Signal3XH1LscType = ecs.NewComponentType[Signal3XH1Lsc]()
) )
///////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////

View File

@ -12,8 +12,11 @@ func loadSignal3xh1(w ecs.World, signal *repository.Signal, signalEntry *ecs.Ent
if len(elecs) == 6 { //3xh1组合类型包含6个继电器 if len(elecs) == 6 { //3xh1组合类型包含6个继电器
signalEntry.AddComponent(component.Signal3XH1ElectronicType) signalEntry.AddComponent(component.Signal3XH1ElectronicType)
signalEntry.AddComponent(component.Signal3XH1LsqType)
signalEntry.AddComponent(component.Signal3XH1LscType)
signalEntry.AddComponent(component.SignalLightsType)
// //
elecState := &component.Signal3XH1Electronic{Z3XH1_L: NewLightLEntity(w), Z3XH1_H: NewLightHEntity(w), Z3XH1_U: NewLightUEntity(w)} elecState := &component.Signal3XH1Electronic{}
for _, elec := range elecs { for _, elec := range elecs {
switch elec.Code() { switch elec.Code() {
case consts.SIGNAL_DDJ: case consts.SIGNAL_DDJ:
@ -34,6 +37,9 @@ func loadSignal3xh1(w ecs.World, signal *repository.Signal, signalEntry *ecs.Ent
} }
// //
component.Signal3XH1ElectronicType.Set(signalEntry, elecState) component.Signal3XH1ElectronicType.Set(signalEntry, elecState)
component.Signal3XH1LsqType.Set(signalEntry, &component.Signal3XH1Lsq{})
component.Signal3XH1LscType.Set(signalEntry, &component.Signal3XH1Lsc{})
component.SignalLightsType.Set(signalEntry, newSignalLights(w, component.HdTag, component.LdTag, component.UdTag))
} else { } else {
return fmt.Errorf("id=[%s]的信号机3xh1电子元器件数量须为6", signal.Id()) return fmt.Errorf("id=[%s]的信号机3xh1电子元器件数量须为6", signal.Id())
} }

View File

@ -11,6 +11,8 @@ import (
"joylink.club/rtsssimulation/repository" "joylink.club/rtsssimulation/repository"
"joylink.club/rtsssimulation/repository/model/proto" "joylink.club/rtsssimulation/repository/model/proto"
"log" "log"
"log/slog"
"os"
"time" "time"
) )
@ -20,6 +22,9 @@ const (
// 信号机测试 // 信号机测试
func main() { func main() {
logConfig := &slog.HandlerOptions{AddSource: false, Level: slog.LevelDebug}
slog.SetDefault(slog.New(slog.NewTextHandler(os.Stderr, logConfig)))
//
proto := &proto.Repository{} proto := &proto.Repository{}
proto.Id = "test-for-signal" proto.Id = "test-for-signal"
proto.Version = "v1.0" proto.Version = "v1.0"

View File

@ -4,7 +4,7 @@ import (
"joylink.club/ecs" "joylink.club/ecs"
"joylink.club/ecs/filter" "joylink.club/ecs/filter"
"joylink.club/rtsssimulation/component" "joylink.club/rtsssimulation/component"
"log" "log/slog"
) )
type SignalDebugSystem struct { type SignalDebugSystem struct {
@ -20,6 +20,10 @@ func (s *SignalDebugSystem) Update(w ecs.World) {
s.query.Each(w, func(entry *ecs.Entry) { s.query.Each(w, func(entry *ecs.Entry) {
uid := component.UidType.Get(entry) uid := component.UidType.Get(entry)
state := component.Signal3XH1ElectronicType.Get(entry) state := component.Signal3XH1ElectronicType.Get(entry)
lights := component.SignalLightsType.Get(entry)
Z3XH1_L := lights.GetLightByTag(component.LdTag)
Z3XH1_H := lights.GetLightByTag(component.HdTag)
Z3XH1_U := lights.GetLightByTag(component.UdTag)
// //
ddj := component.BitStateType.Get(state.Z3XH1_DDJ) ddj := component.BitStateType.Get(state.Z3XH1_DDJ)
lxj := component.BitStateType.Get(state.Z3XH1_LXJ) lxj := component.BitStateType.Get(state.Z3XH1_LXJ)
@ -27,11 +31,12 @@ func (s *SignalDebugSystem) Update(w ecs.World) {
edj := component.BitStateType.Get(state.Z3XH1_2DJ) edj := component.BitStateType.Get(state.Z3XH1_2DJ)
yxj := component.BitStateType.Get(state.Z3XH1_YXJ) yxj := component.BitStateType.Get(state.Z3XH1_YXJ)
zxj := component.BitStateType.Get(state.Z3XH1_ZXJ) zxj := component.BitStateType.Get(state.Z3XH1_ZXJ)
ld := component.BitStateType.Get(state.Z3XH1_L) ld := component.BitStateType.Get(Z3XH1_L)
hd := component.BitStateType.Get(state.Z3XH1_H) hd := component.BitStateType.Get(Z3XH1_H)
ud := component.BitStateType.Get(state.Z3XH1_U) ud := component.BitStateType.Get(Z3XH1_U)
//lsq := component.Signal3XH1LsqType.Get(entry)
//lsc := component.Signal3XH1LscType.Get(entry)
// //
log.Printf("===>> uid = %s | ddj = %t | lxj = %t zxj = %t yxj = %t | dj = %t 2dj = %t | 绿灯 = %t 红灯 = %t 黄灯 = %t,\n", slog.Debug(uid.Id, "ddj", ddj.Val, "lxj", lxj.Val, "zxj", zxj.Val, "yxj", yxj.Val, "dj", dj.Val, "2dj", edj.Val, "绿灯", ld.Val, "红灯", hd.Val, "黄灯", ud.Val)
uid.Id, ddj.Val, lxj.Val, zxj.Val, yxj.Val, dj.Val, edj.Val, ld.Val, hd.Val, ud.Val)
}) })
} }

View File

@ -15,11 +15,8 @@ func DriveSignal3XH1Dd(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.Signal3XH1ElectronicType.Get(signalEntry) lsq := component.Signal3XH1LsqType.Get(signalEntry)
driveDd := component.RelayDriveType.Get(state.Z3XH1_DDJ) lsq.Z3XH1_DDJ_Q = !dd
//点灯继电器落下时才点灯
driveDd.Td = !dd
driveDd.Xq = !dd
} }
}) })
} }
@ -31,16 +28,10 @@ func DriveSignal3XH1Lx(w ecs.World, signalId string, zx 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.Signal3XH1ElectronicType.Get(signalEntry) lsq := component.Signal3XH1LsqType.Get(signalEntry)
driveLx := component.RelayDriveType.Get(state.Z3XH1_LXJ) lsq.Z3XH1_LXJ_Q = true
driveLx.Td = true lsq.Z3XH1_ZXJ_Q = zx
driveLx.Xq = true lsq.Z3XH1_YXJ_Q = false
driveZx := component.RelayDriveType.Get(state.Z3XH1_ZXJ)
driveZx.Td = zx
driveZx.Xq = zx
driveYx := component.RelayDriveType.Get(state.Z3XH1_YXJ)
driveYx.Td = false
driveYx.Xq = false
} }
}) })
} }
@ -51,16 +42,10 @@ func DriveSignal3XH1Yx(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.Signal3XH1ElectronicType.Get(signalEntry) lsq := component.Signal3XH1LsqType.Get(signalEntry)
driveLx := component.RelayDriveType.Get(state.Z3XH1_LXJ) lsq.Z3XH1_LXJ_Q = false
driveLx.Td = false lsq.Z3XH1_ZXJ_Q = false
driveLx.Xq = false lsq.Z3XH1_YXJ_Q = true
driveZx := component.RelayDriveType.Get(state.Z3XH1_ZXJ)
driveZx.Td = false
driveZx.Xq = false
driveYx := component.RelayDriveType.Get(state.Z3XH1_YXJ)
driveYx.Td = true
driveYx.Xq = true
} }
}) })
} }
@ -71,16 +56,10 @@ func DriveSignal3XH1Non(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.Signal3XH1ElectronicType.Get(signalEntry) lsq := component.Signal3XH1LsqType.Get(signalEntry)
driveLx := component.RelayDriveType.Get(state.Z3XH1_LXJ) lsq.Z3XH1_LXJ_Q = false
driveLx.Td = false lsq.Z3XH1_ZXJ_Q = false
driveLx.Xq = false lsq.Z3XH1_YXJ_Q = false
driveZx := component.RelayDriveType.Get(state.Z3XH1_ZXJ)
driveZx.Td = false
driveZx.Xq = false
driveYx := component.RelayDriveType.Get(state.Z3XH1_YXJ)
driveYx.Td = false
driveYx.Xq = false
} }
}) })
} }

View File

@ -11,32 +11,85 @@ type Signal3XH1System struct {
} }
func NewSignal3XH1System() *Signal3XH1System { func NewSignal3XH1System() *Signal3XH1System {
return &Signal3XH1System{query: ecs.NewQuery(filter.Contains(component.Signal3XH1ElectronicType))} return &Signal3XH1System{query: ecs.NewQuery(filter.Contains(
component.Signal3XH1ElectronicType,
component.Signal3XH1LsqType,
component.Signal3XH1LscType,
component.SignalLightsType))}
} }
// Update world 执行 // Update world 执行
func (s *Signal3XH1System) Update(w ecs.World) { func (s *Signal3XH1System) Update(w ecs.World) {
s.query.Each(w, func(e *ecs.Entry) { s.query.Each(w, func(entry *ecs.Entry) {
signal3XH1State := component.Signal3XH1ElectronicType.Get(e) state := component.Signal3XH1ElectronicType.Get(entry)
lsq := component.Signal3XH1LsqType.Get(entry)
lsc := component.Signal3XH1LscType.Get(entry)
lights := component.SignalLightsType.Get(entry)
Z3XH1_L := lights.GetLightByTag(component.LdTag)
Z3XH1_H := lights.GetLightByTag(component.HdTag)
Z3XH1_U := lights.GetLightByTag(component.UdTag)
// //
s.calculateU(signal3XH1State) s.calculateLsq(state, lsq)
s.calculateL(signal3XH1State) s.calculateU(state, Z3XH1_U)
s.calculateH(signal3XH1State) s.calculateL(state, Z3XH1_L)
s.calculateDJ(signal3XH1State) s.calculateH(state, Z3XH1_H)
s.calculate2DJ(signal3XH1State) s.calculateDJ(state, Z3XH1_H, Z3XH1_L, Z3XH1_U)
s.calculate2DJ(state, Z3XH1_U)
s.calculateLsc(state, lsc)
}) })
} }
// 联锁驱
func (s *Signal3XH1System) calculateLsq(state *component.Signal3XH1Electronic, lsq *component.Signal3XH1Lsq) {
ddj := component.RelayDriveType.Get(state.Z3XH1_DDJ)
lxj := component.RelayDriveType.Get(state.Z3XH1_LXJ)
zxj := component.RelayDriveType.Get(state.Z3XH1_ZXJ)
yxj := component.RelayDriveType.Get(state.Z3XH1_YXJ)
//
ddjQ := lsq.Z3XH1_DDJ_Q
ddj.Td = ddjQ
ddj.Xq = ddjQ
//
lxjQ := lsq.Z3XH1_LXJ_Q
lxj.Td = lxjQ
lxj.Xq = lxjQ
//
zxjQ := lsq.Z3XH1_ZXJ_Q
zxj.Td = zxjQ
zxj.Xq = zxjQ
//
yxjQ := lsq.Z3XH1_YXJ_Q
yxj.Td = yxjQ
yxj.Xq = yxjQ
}
// 联锁采
func (s *Signal3XH1System) calculateLsc(state *component.Signal3XH1Electronic, lsc *component.Signal3XH1Lsc) {
ddj := component.BitStateType.Get(state.Z3XH1_DDJ)
lxj := component.BitStateType.Get(state.Z3XH1_LXJ)
dj := component.BitStateType.Get(state.Z3XH1_DJ)
edj := component.BitStateType.Get(state.Z3XH1_2DJ)
yxj := component.BitStateType.Get(state.Z3XH1_YXJ)
zxj := component.BitStateType.Get(state.Z3XH1_ZXJ)
//
lsc.Z3XH1_2DJ_Xq = edj.Val
lsc.Z3XH1_DJ_Xq = dj.Val
lsc.Z3XH1_DDJ_Lx = !ddj.Val
lsc.Z3XH1_LXJ_Xq = lxj.Val
lsc.Z3XH1_YXJ_Xq = yxj.Val
lsc.Z3XH1_ZXJ_Xq = zxj.Val
}
// 黄灯点灯电路 // 黄灯点灯电路
// 开放引导信号,黄灯亮且红灯亮 // 开放引导信号,黄灯亮且红灯亮
// 开放列车信号且开通侧向,只黄灯亮 // 开放列车信号且开通侧向,只黄灯亮
func (s *Signal3XH1System) calculateU(state *component.Signal3XH1Electronic) { func (s *Signal3XH1System) calculateU(state *component.Signal3XH1Electronic, Z3XH1_U *ecs.Entry) {
ddj := component.BitStateType.Get(state.Z3XH1_DDJ) ddj := component.BitStateType.Get(state.Z3XH1_DDJ)
lxj := component.BitStateType.Get(state.Z3XH1_LXJ) lxj := component.BitStateType.Get(state.Z3XH1_LXJ)
dj := component.BitStateType.Get(state.Z3XH1_DJ) dj := component.BitStateType.Get(state.Z3XH1_DJ)
yxj := component.BitStateType.Get(state.Z3XH1_YXJ) yxj := component.BitStateType.Get(state.Z3XH1_YXJ)
zxj := component.BitStateType.Get(state.Z3XH1_ZXJ) zxj := component.BitStateType.Get(state.Z3XH1_ZXJ)
driveU := component.LightDriveType.Get(state.Z3XH1_U) driveU := component.LightDriveType.Get(Z3XH1_U)
//引导信号 //引导信号
isY := !ddj.Val && !lxj.Val && dj.Val && yxj.Val isY := !ddj.Val && !lxj.Val && dj.Val && yxj.Val
//侧向行车信号 //侧向行车信号
@ -47,33 +100,33 @@ func (s *Signal3XH1System) calculateU(state *component.Signal3XH1Electronic) {
// 绿灯点灯电路 // 绿灯点灯电路
// 开放正线行车信号,只亮绿灯 // 开放正线行车信号,只亮绿灯
func (s *Signal3XH1System) calculateL(state *component.Signal3XH1Electronic) { func (s *Signal3XH1System) calculateL(state *component.Signal3XH1Electronic, Z3XH1_L *ecs.Entry) {
ddj := component.BitStateType.Get(state.Z3XH1_DDJ) ddj := component.BitStateType.Get(state.Z3XH1_DDJ)
lxj := component.BitStateType.Get(state.Z3XH1_LXJ) lxj := component.BitStateType.Get(state.Z3XH1_LXJ)
zxj := component.BitStateType.Get(state.Z3XH1_ZXJ) zxj := component.BitStateType.Get(state.Z3XH1_ZXJ)
driveL := component.LightDriveType.Get(state.Z3XH1_L) driveL := component.LightDriveType.Get(Z3XH1_L)
isL := !ddj.Val && lxj.Val && zxj.Val isL := !ddj.Val && lxj.Val && zxj.Val
driveL.Td = isL driveL.Td = isL
} }
// 红灯点灯电路 // 红灯点灯电路
// 列车信号禁止时,亮红灯 // 列车信号禁止时,亮红灯
func (s *Signal3XH1System) calculateH(state *component.Signal3XH1Electronic) { func (s *Signal3XH1System) calculateH(state *component.Signal3XH1Electronic, Z3XH1_H *ecs.Entry) {
ddj := component.BitStateType.Get(state.Z3XH1_DDJ) ddj := component.BitStateType.Get(state.Z3XH1_DDJ)
lxj := component.BitStateType.Get(state.Z3XH1_LXJ) lxj := component.BitStateType.Get(state.Z3XH1_LXJ)
driveH := component.LightDriveType.Get(state.Z3XH1_H) driveH := component.LightDriveType.Get(Z3XH1_H)
isH := !ddj.Val && !lxj.Val isH := !ddj.Val && !lxj.Val
driveH.Td = isH driveH.Td = isH
} }
// DJ 灯丝继电器电路 // DJ 灯丝继电器电路
func (s *Signal3XH1System) calculateDJ(state *component.Signal3XH1Electronic) { func (s *Signal3XH1System) calculateDJ(state *component.Signal3XH1Electronic, Z3XH1_H *ecs.Entry, Z3XH1_L *ecs.Entry, Z3XH1_U *ecs.Entry) {
ddj := component.BitStateType.Get(state.Z3XH1_DDJ) ddj := component.BitStateType.Get(state.Z3XH1_DDJ)
lxj := component.BitStateType.Get(state.Z3XH1_LXJ) lxj := component.BitStateType.Get(state.Z3XH1_LXJ)
zxj := component.BitStateType.Get(state.Z3XH1_ZXJ) zxj := component.BitStateType.Get(state.Z3XH1_ZXJ)
ld := component.BitStateType.Get(state.Z3XH1_L) ld := component.BitStateType.Get(Z3XH1_L)
hd := component.BitStateType.Get(state.Z3XH1_H) hd := component.BitStateType.Get(Z3XH1_H)
ud := component.BitStateType.Get(state.Z3XH1_U) ud := component.BitStateType.Get(Z3XH1_U)
isDj := ld.Val && !ddj.Val && lxj.Val && zxj.Val || //绿灯亮 isDj := ld.Val && !ddj.Val && lxj.Val && zxj.Val || //绿灯亮
ud.Val && !ddj.Val && lxj.Val && !zxj.Val || //黄灯亮 ud.Val && !ddj.Val && lxj.Val && !zxj.Val || //黄灯亮
hd.Val && !ddj.Val && !lxj.Val //红灯亮 hd.Val && !ddj.Val && !lxj.Val //红灯亮
@ -84,12 +137,12 @@ func (s *Signal3XH1System) calculateDJ(state *component.Signal3XH1Electronic) {
} }
// 2DJ 灯丝继电器电路 // 2DJ 灯丝继电器电路
func (s *Signal3XH1System) calculate2DJ(state *component.Signal3XH1Electronic) { func (s *Signal3XH1System) calculate2DJ(state *component.Signal3XH1Electronic, Z3XH1_U *ecs.Entry) {
ddj := component.BitStateType.Get(state.Z3XH1_DDJ) ddj := component.BitStateType.Get(state.Z3XH1_DDJ)
lxj := component.BitStateType.Get(state.Z3XH1_LXJ) lxj := component.BitStateType.Get(state.Z3XH1_LXJ)
dj := component.BitStateType.Get(state.Z3XH1_DJ) dj := component.BitStateType.Get(state.Z3XH1_DJ)
yxj := component.BitStateType.Get(state.Z3XH1_YXJ) yxj := component.BitStateType.Get(state.Z3XH1_YXJ)
ud := component.BitStateType.Get(state.Z3XH1_U) ud := component.BitStateType.Get(Z3XH1_U)
// //
is2DJ := ud.Val && !ddj.Val && !lxj.Val && dj.Val && yxj.Val is2DJ := ud.Val && !ddj.Val && !lxj.Val && dj.Val && yxj.Val
//通知继电器进行动作 //通知继电器进行动作