signal 3xh1

This commit is contained in:
xzb 2023-10-11 16:57:48 +08:00
parent 1a809f1af4
commit 819f157f23
6 changed files with 58 additions and 64 deletions

View File

@ -16,25 +16,14 @@ type Signal3XH1Electronic struct {
Z3XH1_YXJ *ecs.Entry
//开通正线信号继电器true-吸合
Z3XH1_ZXJ *ecs.Entry
}
// Signal3XH1Filament 信号机3XH-1 灯丝状态
type Signal3XH1Filament struct {
// 物理黄灯true-灯丝正常
Uf bool
// 物理绿灯true-灯丝正常
Lf bool
// 物理红灯true-灯丝正常
Hf bool
// 物理黄灯true-亮
U bool
Z3XH1_U *ecs.Entry
// 物理绿灯true-亮
L bool
Z3XH1_L *ecs.Entry
// 物理红灯true-亮
H bool
Z3XH1_H *ecs.Entry
}
var (
Signal3XH1ElectronicType = ecs.NewComponentType[Signal3XH1Electronic]()
Signal3XH1FilamentType = ecs.NewComponentType[Signal3XH1Filament]()
)

View File

@ -12,9 +12,8 @@ func loadSignal3xh1(w ecs.World, signal *repository.Signal, signalEntry *ecs.Ent
if len(elecs) == 6 { //3xh1组合类型包含6个继电器
signalEntry.AddComponent(component.Signal3XH1ElectronicType)
signalEntry.AddComponent(component.Signal3XH1FilamentType)
//
elecState := &component.Signal3XH1Electronic{}
elecState := &component.Signal3XH1Electronic{Z3XH1_L: NewLightLEntity(w), Z3XH1_H: NewLightHEntity(w), Z3XH1_U: NewLightUEntity(w)}
for _, elec := range elecs {
switch elec.Code() {
case consts.SIGNAL_DDJ:
@ -35,7 +34,6 @@ func loadSignal3xh1(w ecs.World, signal *repository.Signal, signalEntry *ecs.Ent
}
//
component.Signal3XH1ElectronicType.Set(signalEntry, elecState)
component.Signal3XH1FilamentType.Set(signalEntry, &component.Signal3XH1Filament{Uf: true, Lf: true, Hf: true, U: false, L: false, H: false})
} else {
return fmt.Errorf("id=[%s]的信号机3xh1电子元器件数量须为6", signal.Id())
}

View File

@ -29,7 +29,7 @@ func main() {
repo := repository.BuildRepositoryForSignalTest(proto)
sim := rtss_simulation.NewSimulation(repo)
loadEntities(sim, repo)
sim.SetSpeed(0.1)
sim.SetSpeed(1)
sim.AddSystem(sigSys.NewSignalDebugSystem())
sim.AddSystem(device_sys.NewRelaySys())
sim.AddSystem(circuit_sys.NewSignal3XH1System())
@ -50,7 +50,7 @@ func main() {
worldLog(sim, "===>>开通列车信号 .....")
fi.DriveSignal3XH1Lx(sim, IdSignal3XH1, true)
//
time.Sleep(3 * time.Second)
time.Sleep(5 * time.Second)
sim.Close()
}
func worldLog(w ecs.World, logInfo string) {

View File

@ -12,7 +12,7 @@ type SignalDebugSystem struct {
}
func NewSignalDebugSystem() *SignalDebugSystem {
return &SignalDebugSystem{query: ecs.NewQuery(filter.Contains(component.Signal3XH1ElectronicType, component.Signal3XH1FilamentType))}
return &SignalDebugSystem{query: ecs.NewQuery(filter.Contains(component.Signal3XH1ElectronicType))}
}
// Update world 执行
@ -20,7 +20,6 @@ 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)
filament := component.Signal3XH1FilamentType.Get(entry)
//
ddj := component.BitStateType.Get(state.Z3XH1_DDJ)
lxj := component.BitStateType.Get(state.Z3XH1_LXJ)
@ -28,8 +27,11 @@ 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)
//
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, filament.L, filament.H, filament.U)
uid.Id, ddj.Val, lxj.Val, zxj.Val, yxj.Val, dj.Val, edj.Val, ld.Val, hd.Val, ud.Val)
})
}

View File

@ -46,9 +46,9 @@ func (s *Signal2XH1System) calculateDJ(state *component.Signal2XH1Electronic) {
ddj := component.BitStateType.Get(state.Z2XH1_DDJ)
lxj := component.BitStateType.Get(state.Z2XH1_LXJ)
dj := component.BitStateType.Get(state.Z2XH1_DJ)
lf := true
hf := true
isDJ := !ddj.Val && lxj.Val && lf || !ddj.Val && !lxj.Val && hf
ld := component.BitStateType.Get(state.Z2XH1_L)
hd := component.BitStateType.Get(state.Z2XH1_H)
isDJ := !ddj.Val && lxj.Val && ld.Val || !ddj.Val && !lxj.Val && hd.Val
//通知继电器进行动作
if dj.Val != isDJ {
drive := component.RelayDriveType.Get(state.Z2XH1_DJ)

View File

@ -11,90 +11,95 @@ type Signal3XH1System struct {
}
func NewSignal3XH1System() *Signal3XH1System {
return &Signal3XH1System{query: ecs.NewQuery(filter.Contains(component.Signal3XH1ElectronicType, component.Signal3XH1FilamentType))}
return &Signal3XH1System{query: ecs.NewQuery(filter.Contains(component.Signal3XH1ElectronicType))}
}
// Update world 执行
func (s *Signal3XH1System) Update(w ecs.World) {
s.query.Each(w, func(e *ecs.Entry) {
signal3XH1State := component.Signal3XH1ElectronicType.Get(e)
filament := component.Signal3XH1FilamentType.Get(e)
//
s.calculateU(signal3XH1State, filament)
s.calculateL(signal3XH1State, filament)
s.calculateH(signal3XH1State, filament)
s.calculateDJ(signal3XH1State, filament)
s.calculate2DJ(signal3XH1State, filament)
s.calculateU(signal3XH1State)
s.calculateL(signal3XH1State)
s.calculateH(signal3XH1State)
s.calculateDJ(signal3XH1State)
s.calculate2DJ(signal3XH1State)
})
}
// 黄灯点灯电路
// 开放引导信号,黄灯亮且红灯亮
// 开放列车信号且开通侧向,只黄灯亮
func (s *Signal3XH1System) calculateU(state *component.Signal3XH1Electronic, filament *component.Signal3XH1Filament) {
func (s *Signal3XH1System) calculateU(state *component.Signal3XH1Electronic) {
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)
//引导信号
isY := !ddj.Val && !lxj.Val && dj.Val && yxj.Val
//侧向行车信号
isLC := !ddj.Val && lxj.Val && !zxj.Val
filament.U = filament.Uf && (isY || isLC)
isU := isY || isLC
if driveU.Td != isU {
driveU.Td = isU
}
}
// 绿灯点灯电路
// 开放正线行车信号,只亮绿灯
func (s *Signal3XH1System) calculateL(state *component.Signal3XH1Electronic, filament *component.Signal3XH1Filament) {
func (s *Signal3XH1System) calculateL(state *component.Signal3XH1Electronic) {
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)
isL := !ddj.Val && lxj.Val && zxj.Val
filament.L = filament.Lf && isL
if driveL.Td != isL {
driveL.Td = isL
}
}
// 红灯点灯电路
// 列车信号禁止时,亮红灯
func (s *Signal3XH1System) calculateH(state *component.Signal3XH1Electronic, filament *component.Signal3XH1Filament) {
func (s *Signal3XH1System) calculateH(state *component.Signal3XH1Electronic) {
ddj := component.BitStateType.Get(state.Z3XH1_DDJ)
lxj := component.BitStateType.Get(state.Z3XH1_LXJ)
driveH := component.LightDriveType.Get(state.Z3XH1_H)
isH := !ddj.Val && !lxj.Val
filament.H = filament.Hf && isH
if driveH.Td != isH {
driveH.Td = isH
}
}
// DJ 灯丝继电器电路
func (s *Signal3XH1System) calculateDJ(state *component.Signal3XH1Electronic, filament *component.Signal3XH1Filament) {
func (s *Signal3XH1System) calculateDJ(state *component.Signal3XH1Electronic) {
ddj := component.BitStateType.Get(state.Z3XH1_DDJ)
lxj := component.BitStateType.Get(state.Z3XH1_LXJ)
dj := component.BitStateType.Get(state.Z3XH1_DJ)
zxj := component.BitStateType.Get(state.Z3XH1_ZXJ)
_DJ := dj.Val
isDj := filament.Lf && !ddj.Val && lxj.Val && zxj.Val ||
filament.Uf && !ddj.Val && lxj.Val && !zxj.Val ||
filament.Hf && !ddj.Val && !lxj.Val
ld := component.BitStateType.Get(state.Z3XH1_L)
hd := component.BitStateType.Get(state.Z3XH1_H)
ud := component.BitStateType.Get(state.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 //红灯亮
//通知继电器进行动作
if _DJ != isDj {
drive := component.RelayDriveType.Get(state.Z3XH1_DJ)
drive.Td = isDj
drive.Xq = isDj
}
}
// 2DJ 灯丝继电器电路
func (s *Signal3XH1System) calculate2DJ(state *component.Signal3XH1Electronic, filament *component.Signal3XH1Filament) {
func (s *Signal3XH1System) calculate2DJ(state *component.Signal3XH1Electronic) {
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)
edj := component.BitStateType.Get(state.Z3XH1_2DJ)
_2DJ := edj.Val
ud := component.BitStateType.Get(state.Z3XH1_U)
//
is2DJ := filament.Uf && !ddj.Val && !lxj.Val && dj.Val && yxj.Val
is2DJ := ud.Val && !ddj.Val && !lxj.Val && dj.Val && yxj.Val
//通知继电器进行动作
if _2DJ != is2DJ {
drive := component.RelayDriveType.Get(state.Z3XH1_2DJ)
drive.Td = is2DJ
drive.Xq = is2DJ
}
}