道岔zdj9电源控制

This commit is contained in:
xzb 2023-09-14 13:52:36 +08:00
parent 5fe73f8a55
commit 84f79d9c45
4 changed files with 175 additions and 94 deletions

View File

@ -6,14 +6,19 @@ import (
)
// 双机zdj9
// 默认定位
func CreateSwitch2jzdj9Entity(w ecs.World, switchId string) *ecs.Entry {
e := w.Create(system.EntityIdentityComponent, system.Switch2jZdj9StateComponent, system.TimeMovableObject1Component, system.TimeMovableObject2Component)
e := w.Create(system.EntityIdentityComponent, system.Switch2jZdj9StateComponent, system.MovableObject1Component, system.MovableObject2Component)
system.EntityIdentityComponent.Set(e, &system.EntityIdentity{Id: switchId})
//电路
system.Switch2jZdj9StateComponent.Set(e, system.NewSwitch2jZdj9State())
//J1
system.TimeMovableObject1Component.Set(e, system.NewTimeMovableObject())
j1 := system.NewMovableObject()
j1.Value = system.J1Range
system.MovableObject1Component.Set(e, j1)
//J2
system.TimeMovableObject2Component.Set(e, system.NewTimeMovableObject())
j2 := system.NewMovableObject()
j2.Value = system.J2Range
system.MovableObject2Component.Set(e, j2)
return e
}

75
system/move_system.go Normal file
View File

@ -0,0 +1,75 @@
package system
import (
"github.com/yohamta/donburi/filter"
"joylink.club/ecs"
)
// 时间维度上移动的物体
type MovableObject struct {
Value int64
//移动方向0-不动1-变大,-1 -变小
direction int8
}
func NewMovableObject() *MovableObject {
return &MovableObject{Value: 0, direction: 0}
}
// 时间维度上移动物体组件
var MovableObjectComponent = ecs.NewComponentType[MovableObject]()
var MovableObject1Component = ecs.NewComponentType[MovableObject]()
var MovableObject2Component = ecs.NewComponentType[MovableObject]()
type TimeMovableSystem struct {
query *ecs.Query
}
func NewTimeMovableSystem() *TimeMovableSystem {
return &TimeMovableSystem{
query: ecs.NewQuery(filter.Or(filter.Contains(MovableObjectComponent), filter.Contains(MovableObject1Component), filter.Contains(MovableObject2Component))),
}
}
// world 执行
func (me *TimeMovableSystem) Update(w ecs.World) {
me.query.Each(w, func(e *ecs.Entry) {
if e.HasComponent(MovableObjectComponent) {
MovableObjectComponent.Get(e).move(w.Tick())
}
if e.HasComponent(MovableObject1Component) {
MovableObject1Component.Get(e).move(w.Tick())
}
if e.HasComponent(MovableObject2Component) {
MovableObject2Component.Get(e).move(w.Tick())
}
})
}
////////////////////////////////////////////////
func (me *MovableObject) move(tick int) {
if me.direction != 0 {
if me.direction > 0 {
me.Value += int64(tick)
} else {
me.Value -= int64(tick)
}
}
}
// 暂停
func (me *MovableObject) Pause() {
me.direction = 0
}
// 前进
func (me *MovableObject) Forward() {
me.direction = 1
}
// 后退
func (me *MovableObject) Retreat() {
me.direction = -1
}

View File

@ -29,6 +29,10 @@ type Switch2jZdj9State struct {
//道岔第二启动继电器
//true-吸起即1-3通false-打落即1-2通
J1_2DQJ bool
//true-2DQJ由落下转换到吸起即定操
J1_2DQJ_ToD bool
//true-2DQJ由吸起转换到落下即反操
J1_2DQJ_ToF bool
//道岔第一启动继电器复示继电器
J1_1DQJF bool
//断相保护器
@ -66,6 +70,10 @@ type Switch2jZdj9State struct {
//道岔第二启动继电器
//true-吸起即1-3通false-打落即1-2通
J2_2DQJ bool
//true-2DQJ由落下转换到吸起即定操
J2_2DQJ_ToD bool
//true-2DQJ由吸起转换到落下即反操
J2_2DQJ_ToF bool
//道岔第一启动继电器复示继电器
J2_1DQJF bool
//断相保护器
@ -102,12 +110,14 @@ func NewSwitch2jZdj9State() *Switch2jZdj9State {
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{PhaseA: false, PhaseB: false, PhaseC: false},
J1_Power: Switch380ACPower{Active: false, PhaseA: false, PhaseB: false, PhaseC: false},
J1_U1: ACPahseN,
J1_V1: ACPahseN,
J1_W1: ACPahseN,
@ -120,6 +130,8 @@ func NewSwitch2jZdj9State() *Switch2jZdj9State {
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,
@ -127,7 +139,7 @@ func NewSwitch2jZdj9State() *Switch2jZdj9State {
J2_FBJ: false,
J2_FB_K10: false,
J2_AKB: true,
J2_Power: Switch380ACPower{PhaseA: false, PhaseB: false, PhaseC: false},
J2_Power: Switch380ACPower{Active: false, PhaseA: false, PhaseB: false, PhaseC: false},
J2_U1: ACPahseN,
J2_V1: ACPahseN,
J2_W1: ACPahseN,
@ -160,6 +172,8 @@ type SwitchBB struct {
// 道岔380V动力交流电源
type Switch380ACPower struct {
//true-激活
Active bool
//true-A相电正常输出
PhaseA bool
//true-B相电正常输出
@ -209,6 +223,8 @@ func NewSwitch2jZdj9System() *Switch2jZdj9System {
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)
//断相保护继电器励磁电路
@ -294,7 +310,11 @@ var Switch2jzdj9RelayActionEventProcessor = func(w ecs.World, event sysEvent.Rel
case SJZDJ9_BHJ:
state.J1_BHJ = event.Xh
case SJZDJ9_2DQJ:
state.J1_2DQJ = event.Xh
{
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:
@ -317,7 +337,11 @@ var Switch2jzdj9RelayActionEventProcessor = func(w ecs.World, event sysEvent.Rel
case SJZDJ9_BHJ:
state.J2_BHJ = event.Xh
case SJZDJ9_2DQJ:
state.J2_2DQJ = event.Xh
{
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:
@ -568,8 +592,8 @@ func (me *Switch2jZdj9System) calculateFBJ(w ecs.World, switchEntry *ecs.Entry,
// j1 完全转动须4000ms
// j2 完全转动须5000ms
const (
j1Range int64 = 4000
j2Range int64 = 5000
J1Range int64 = 4000
J2Range int64 = 5000
)
// 道岔转动运算
@ -577,37 +601,89 @@ const (
// j2 完全转动须5000ms
// j.Value 0-反位 jRange-定位
func (me *Switch2jZdj9System) calculateMove(w ecs.World, switchEntry *ecs.Entry, state *Switch2jZdj9State) {
j1 := TimeMovableObject1Component.Get(switchEntry)
j1 := MovableObject1Component.Get(switchEntry)
//
if j1.Value < 0 {
j1.Value = 0
} else if j1.Value > j1Range {
j1.Value = j1Range
} else if j1.Value > J1Range {
j1.Value = J1Range
}
j1.direction = state.J1_Traction
//
j2 := TimeMovableObject2Component.Get(switchEntry)
j2 := MovableObject2Component.Get(switchEntry)
//
if j2.Value < 0 {
j2.Value = 0
} else if j2.Value > j2Range {
j2.Value = j2Range
} else if j2.Value > J2Range {
j2.Value = J2Range
}
j2.direction = state.J2_Traction
}
// 转辙机对外端子9、10运算
func (me *Switch2jZdj9System) calculateK9K10(w ecs.World, switchEntry *ecs.Entry, state *Switch2jZdj9State) {
j1 := TimeMovableObject1Component.Get(switchEntry)
j2 := TimeMovableObject2Component.Get(switchEntry)
j1 := MovableObject1Component.Get(switchEntry)
j2 := MovableObject2Component.Get(switchEntry)
//
state.J1_DB_K9 = j1.Value >= j1Range
state.J1_DB_K9 = j1.Value >= J1Range
state.J1_FB_K10 = j1.Value <= 0
//
state.J2_DB_K9 = j2.Value >= j2Range
state.J2_DB_K9 = j2.Value >= J2Range
state.J2_FB_K10 = j2.Value <= 0
}
// 转辙机电源控制
// 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排表示电路

View File

@ -1,75 +0,0 @@
package system
import (
"github.com/yohamta/donburi/filter"
"joylink.club/ecs"
)
// 时间维度上移动的物体
type TimeMovableObject struct {
Value int64
//移动方向0-不动1-变大,-1 -变小
direction int8
}
func NewTimeMovableObject() *TimeMovableObject {
return &TimeMovableObject{Value: 0, direction: 0}
}
// 时间维度上移动物体组件
var TimeMovableObjectComponent = ecs.NewComponentType[TimeMovableObject]()
var TimeMovableObject1Component = ecs.NewComponentType[TimeMovableObject]()
var TimeMovableObject2Component = ecs.NewComponentType[TimeMovableObject]()
type TimeMovableSystem struct {
query *ecs.Query
}
func NewTimeMovableSystem() *TimeMovableSystem {
return &TimeMovableSystem{
query: ecs.NewQuery(filter.Or(filter.Contains(TimeMovableObjectComponent), filter.Contains(TimeMovableObject1Component), filter.Contains(TimeMovableObject2Component))),
}
}
// world 执行
func (me *TimeMovableSystem) Update(w ecs.World) {
me.query.Each(w, func(e *ecs.Entry) {
if e.HasComponent(TimeMovableObjectComponent) {
TimeMovableObjectComponent.Get(e).move(w.Tick())
}
if e.HasComponent(TimeMovableObject1Component) {
TimeMovableObject1Component.Get(e).move(w.Tick())
}
if e.HasComponent(TimeMovableObject2Component) {
TimeMovableObject2Component.Get(e).move(w.Tick())
}
})
}
////////////////////////////////////////////////
func (me *TimeMovableObject) move(tick int) {
if me.direction != 0 {
if me.direction > 0 {
me.Value += int64(tick)
} else {
me.Value -= int64(tick)
}
}
}
// 暂停
func (me *TimeMovableObject) Pause() {
me.direction = 0
}
// 前进
func (me *TimeMovableObject) Forward() {
me.direction = 1
}
// 后退
func (me *TimeMovableObject) Retreat() {
me.direction = -1
}