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
//开通正线信号继电器true-吸合
Z3XH1_ZXJ *ecs.Entry
// 物理黄灯true-亮
Z3XH1_U *ecs.Entry
// 物理绿灯true-亮
Z3XH1_L *ecs.Entry
// 物理红灯true-亮
Z3XH1_H *ecs.Entry
}
// Signal3XH1Lsq 联锁驱
type Signal3XH1Lsq struct {
//true-联锁施加励磁电流驱动继电器DDJ
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 (
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个继电器
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 {
switch elec.Code() {
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.Signal3XH1LsqType.Set(signalEntry, &component.Signal3XH1Lsq{})
component.Signal3XH1LscType.Set(signalEntry, &component.Signal3XH1Lsc{})
component.SignalLightsType.Set(signalEntry, newSignalLights(w, component.HdTag, component.LdTag, component.UdTag))
} else {
return fmt.Errorf("id=[%s]的信号机3xh1电子元器件数量须为6", signal.Id())
}

View File

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

View File

@ -4,7 +4,7 @@ import (
"joylink.club/ecs"
"joylink.club/ecs/filter"
"joylink.club/rtsssimulation/component"
"log"
"log/slog"
)
type SignalDebugSystem struct {
@ -20,6 +20,10 @@ func (s *SignalDebugSystem) Update(w ecs.World) {
s.query.Each(w, func(entry *ecs.Entry) {
uid := component.UidType.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)
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)
yxj := component.BitStateType.Get(state.Z3XH1_YXJ)
zxj := component.BitStateType.Get(state.Z3XH1_ZXJ)
ld := component.BitStateType.Get(state.Z3XH1_L)
hd := component.BitStateType.Get(state.Z3XH1_H)
ud := component.BitStateType.Get(state.Z3XH1_U)
ld := component.BitStateType.Get(Z3XH1_L)
hd := component.BitStateType.Get(Z3XH1_H)
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",
uid.Id, ddj.Val, lxj.Val, zxj.Val, yxj.Val, dj.Val, edj.Val, ld.Val, hd.Val, ud.Val)
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)
})
}

View File

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

View File

@ -11,32 +11,85 @@ type Signal3XH1System struct {
}
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 执行
func (s *Signal3XH1System) Update(w ecs.World) {
s.query.Each(w, func(e *ecs.Entry) {
signal3XH1State := component.Signal3XH1ElectronicType.Get(e)
s.query.Each(w, func(entry *ecs.Entry) {
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.calculateL(signal3XH1State)
s.calculateH(signal3XH1State)
s.calculateDJ(signal3XH1State)
s.calculate2DJ(signal3XH1State)
s.calculateLsq(state, lsq)
s.calculateU(state, Z3XH1_U)
s.calculateL(state, Z3XH1_L)
s.calculateH(state, Z3XH1_H)
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)
lxj := component.BitStateType.Get(state.Z3XH1_LXJ)
dj := component.BitStateType.Get(state.Z3XH1_DJ)
yxj := component.BitStateType.Get(state.Z3XH1_YXJ)
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
//侧向行车信号
@ -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)
lxj := component.BitStateType.Get(state.Z3XH1_LXJ)
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
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)
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
driveH.Td = isH
}
// 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)
lxj := component.BitStateType.Get(state.Z3XH1_LXJ)
zxj := component.BitStateType.Get(state.Z3XH1_ZXJ)
ld := component.BitStateType.Get(state.Z3XH1_L)
hd := component.BitStateType.Get(state.Z3XH1_H)
ud := component.BitStateType.Get(state.Z3XH1_U)
ld := component.BitStateType.Get(Z3XH1_L)
hd := component.BitStateType.Get(Z3XH1_H)
ud := component.BitStateType.Get(Z3XH1_U)
isDj := ld.Val && !ddj.Val && lxj.Val && zxj.Val || //绿灯亮
ud.Val && !ddj.Val && lxj.Val && !zxj.Val || //黄灯亮
hd.Val && !ddj.Val && !lxj.Val //红灯亮
@ -84,12 +137,12 @@ func (s *Signal3XH1System) calculateDJ(state *component.Signal3XH1Electronic) {
}
// 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)
lxj := component.BitStateType.Get(state.Z3XH1_LXJ)
dj := component.BitStateType.Get(state.Z3XH1_DJ)
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
//通知继电器进行动作