双机zdj9

This commit is contained in:
xzb 2023-09-13 18:03:55 +08:00
parent 0a5df829a2
commit 5fe73f8a55
3 changed files with 161 additions and 33 deletions

View File

@ -7,7 +7,13 @@ import (
// 双机zdj9
func CreateSwitch2jzdj9Entity(w ecs.World, switchId string) *ecs.Entry {
e := w.Create(system.EntityIdentityComponent, system.Switch2jZdj9StateComponent)
e := w.Create(system.EntityIdentityComponent, system.Switch2jZdj9StateComponent, system.TimeMovableObject1Component, system.TimeMovableObject2Component)
system.EntityIdentityComponent.Set(e, &system.EntityIdentity{Id: switchId})
//电路
system.Switch2jZdj9StateComponent.Set(e, system.NewSwitch2jZdj9State())
//J1
system.TimeMovableObject1Component.Set(e, system.NewTimeMovableObject())
//J2
system.TimeMovableObject2Component.Set(e, system.NewTimeMovableObject())
return e
}

View File

@ -46,8 +46,8 @@ type Switch2jZdj9State struct {
J1_U1 Switch380ACPhase
J1_V1 Switch380ACPhase
J1_W1 Switch380ACPhase
//电机转速大于0表示正转即定操小于0表示反转即反操等于0表示不转
J1_Speed int8
//电机输出牵引力大于0表示正转即定操小于0表示反转即反操等于0表示不转
J1_Traction int8
//反位表示继电器
J1_FBJ bool
//true-当道岔转换到反位时转辙机内端子10与电路接通false-转辙机内端子10断开切断电路
@ -88,7 +88,7 @@ type Switch2jZdj9State struct {
J2_V1 Switch380ACPhase
J2_W1 Switch380ACPhase
//电机转速大于0表示正转即定操小于0表示反转即反操等于0表示不转
J2_Speed int8
J2_Traction int8
}
// 创建ZDJ9道岔状态并初始化
@ -111,7 +111,7 @@ func NewSwitch2jZdj9State() *Switch2jZdj9State {
J1_U1: ACPahseN,
J1_V1: ACPahseN,
J1_W1: ACPahseN,
J1_Speed: 0,
J1_Traction: 0,
J1_FBJ: false,
J1_FB_K10: false,
J1_QDJ: true,
@ -131,7 +131,7 @@ func NewSwitch2jZdj9State() *Switch2jZdj9State {
J2_U1: ACPahseN,
J2_V1: ACPahseN,
J2_W1: ACPahseN,
J2_Speed: 0,
J2_Traction: 0,
}
}
@ -196,16 +196,17 @@ var Switch2jZdj9StateComponent = ecs.NewComponentType[Switch2jZdj9State]()
// zdj9查询
var zdj9Query = ecs.NewQuery(filter.Contains(EntityIdentityComponent, Switch2jZdj9StateComponent))
// ZDJ9道岔系统
type SwitchZdj9System struct {
// 双机ZDJ9道岔系统
type Switch2jZdj9System struct {
}
func NewSwitchZdj9System() *SwitchZdj9System {
return &SwitchZdj9System{}
// 双机ZDJ9道岔系统
func NewSwitch2jZdj9System() *Switch2jZdj9System {
return &Switch2jZdj9System{}
}
// world 执行
func (me *SwitchZdj9System) Update(w ecs.World) {
func (me *Switch2jZdj9System) Update(w ecs.World) {
zdj9Query.Each(w, func(e *ecs.Entry) {
zdj9State := Switch2jZdj9StateComponent.Get(e)
//断相保护器电路
@ -232,6 +233,8 @@ func (me *SwitchZdj9System) Update(w ecs.World) {
me.calculateZFBJ(w, e, zdj9State)
//道岔转辙机内电机驱动电路
me.calculateMotor(w, e, zdj9State)
me.calculateMove(w, e, zdj9State)
me.calculateK9K10(w, e, zdj9State)
})
}
@ -337,7 +340,7 @@ var Switch2jzdj9RelayActionEventProcessor = func(w ecs.World, event sysEvent.Rel
}
// 发送继电器需要改变事件
func (me *SwitchZdj9System) publishRelayNeedChangeEvent(w ecs.World, switchEntry *ecs.Entry, relayGroup string, relayName string, needXh bool) {
func (me *Switch2jZdj9System) publishRelayNeedChangeEvent(w ecs.World, switchEntry *ecs.Entry, relayGroup string, relayName string, needXh bool) {
switchModel := FindModelStorage(w).FindById(EntityIdentityComponent.Get(switchEntry).Id)
relayRole, _ := switchModel.(umi.IRelayCRole)
relayModel := relayRole.FindRelayModelByCRole(relayGroup, relayName)
@ -345,7 +348,7 @@ func (me *SwitchZdj9System) publishRelayNeedChangeEvent(w ecs.World, switchEntry
}
// 断相保护电路运算
func (me *SwitchZdj9System) calculateDBQ(w ecs.World, switchEntry *ecs.Entry, state *Switch2jZdj9State) {
func (me *Switch2jZdj9System) calculateDBQ(w ecs.World, switchEntry *ecs.Entry, state *Switch2jZdj9State) {
if state.J1_DBQ.LimitedTime > 0 {
state.J1_DBQ.LimitedTime -= int64(w.Tick())
if state.J1_DBQ.LimitedTime < 0 {
@ -371,14 +374,14 @@ func (me *SwitchZdj9System) calculateDBQ(w ecs.World, switchEntry *ecs.Entry, st
// 转辙机内自动开闭器动作实现
// 暂时规定自动开闭器跟随2DQJ
func (me *SwitchZdj9System) calculateAKB(w ecs.World, switchEntry *ecs.Entry, state *Switch2jZdj9State) {
func (me *Switch2jZdj9System) calculateAKB(w ecs.World, switchEntry *ecs.Entry, state *Switch2jZdj9State) {
state.J1_AKB = state.J1_2DQJ
state.J2_AKB = state.J2_2DQJ
}
// 断相保护继电器运算
// BHJ JWXC-1700无极缓放继电器
func (me *SwitchZdj9System) calculateBHJ(w ecs.World, switchEntry *ecs.Entry, state *Switch2jZdj9State) {
func (me *Switch2jZdj9System) calculateBHJ(w ecs.World, switchEntry *ecs.Entry, state *Switch2jZdj9State) {
_J1_BHJ := state.J1_DBQ.Dc24Voltage
_J2_BHJ := state.J2_DBQ.Dc24Voltage
if _J1_BHJ != state.J1_BHJ {
@ -391,7 +394,7 @@ func (me *SwitchZdj9System) calculateBHJ(w ecs.World, switchEntry *ecs.Entry, st
// 总保护继电器运算
// ZBHJ JWXC-1700无极缓放继电器
func (me *SwitchZdj9System) calculateZBHJ(w ecs.World, switchEntry *ecs.Entry, state *Switch2jZdj9State) {
func (me *Switch2jZdj9System) calculateZBHJ(w ecs.World, switchEntry *ecs.Entry, state *Switch2jZdj9State) {
//励磁
method := state.J1_BHJ && state.J2_BHJ
//自闭
@ -406,7 +409,7 @@ func (me *SwitchZdj9System) calculateZBHJ(w ecs.World, switchEntry *ecs.Entry, s
// 道岔转换启动切断继电器运算
// QDJ JWXC-1700无极缓放继电器
func (me *SwitchZdj9System) calculateQDJ(w ecs.World, switchEntry *ecs.Entry, state *Switch2jZdj9State) {
func (me *Switch2jZdj9System) calculateQDJ(w ecs.World, switchEntry *ecs.Entry, state *Switch2jZdj9State) {
//LC震荡电路运算
fullLc := (!state.J1_BHJ && !state.J2_BHJ) || state.J1_ZBHJ
if fullLc {
@ -431,7 +434,7 @@ func (me *SwitchZdj9System) calculateQDJ(w ecs.World, switchEntry *ecs.Entry, st
// 道岔第一启动继电器运算
// 1DQJ JWJXC-H125/80无极加强缓放继电器
// J1先启动J2后启动
func (me *SwitchZdj9System) calculate1DQJ(w ecs.World, switchEntry *ecs.Entry, state *Switch2jZdj9State) {
func (me *Switch2jZdj9System) calculate1DQJ(w ecs.World, switchEntry *ecs.Entry, state *Switch2jZdj9State) {
//自闭电路
j2DqjSelf := state.J1_QDJ && state.J2_BHJ && state.J2_1DQJ
//励磁电路
@ -457,7 +460,7 @@ func (me *SwitchZdj9System) calculate1DQJ(w ecs.World, switchEntry *ecs.Entry, s
// 道岔第一启动继电器复示继电器运算
// 1DQJF JWJXC-480无极继电器
func (me *SwitchZdj9System) calculate1DQJF(w ecs.World, switchEntry *ecs.Entry, state *Switch2jZdj9State) {
func (me *Switch2jZdj9System) calculate1DQJF(w ecs.World, switchEntry *ecs.Entry, state *Switch2jZdj9State) {
_J1_1DQJF := state.J1_1DQJ
_J2_1DQJF := state.J2_1DQJ
if _J1_1DQJF != state.J1_1DQJF {
@ -474,7 +477,7 @@ func (me *SwitchZdj9System) calculate1DQJF(w ecs.World, switchEntry *ecs.Entry,
// 在线圈中通以规定极性的电流时,继电器吸起,断电后仍保持在吸起位置;通以反方向电流时,继电器打落,断电后保持在打落位置;
// 断电保持由磁路系统中的一块长条形永久磁铁取代了大部分轭铁来实现;
// 电流3->4吸起电流2->1打落如果21和34同时通过电流时磁场相互抵消则继电器保持原来状态不变
func (me *SwitchZdj9System) calculate2DQJ(w ecs.World, switchEntry *ecs.Entry, state *Switch2jZdj9State) {
func (me *Switch2jZdj9System) calculate2DQJ(w ecs.World, switchEntry *ecs.Entry, state *Switch2jZdj9State) {
//J1-2DQJ
j1_2dqj_21 := state.J1_1DQJF && state.FCJ
j1_2dqj_34 := state.J1_1DQJF && state.DCJ
@ -516,13 +519,13 @@ func (me *SwitchZdj9System) calculate2DQJ(w ecs.World, switchEntry *ecs.Entry, s
// 继电器在磁路中增加一个偏极磁钢,使衔铁受永磁力的作用而偏于落下位置。衔铁的吸起与线圈中的电流的极性有关,
// 通过线圈的电流为规定的方向时,衔铁才吸起,而电流的方向相反时,衔铁保持不动。
// 它只具有一种稳定状态,即衔铁靠电磁力吸起后,断电即落下,始终偏向落下的定位状态
func (me *SwitchZdj9System) calculateZDBJ(w ecs.World, switchEntry *ecs.Entry, state *Switch2jZdj9State) {
func (me *Switch2jZdj9System) calculateZDBJ(w ecs.World, switchEntry *ecs.Entry, state *Switch2jZdj9State) {
_ZDBJ := state.J1_DBJ && state.J2_DBJ
if _ZDBJ != state.ZDBJ {
me.publishRelayNeedChangeEvent(w, switchEntry, SJZDJ9_TDC, SJZDJ9_ZDBJ, _ZDBJ)
}
}
func (me *SwitchZdj9System) calculateZFBJ(w ecs.World, switchEntry *ecs.Entry, state *Switch2jZdj9State) {
func (me *Switch2jZdj9System) calculateZFBJ(w ecs.World, switchEntry *ecs.Entry, state *Switch2jZdj9State) {
_ZFBJ := state.J1_FBJ && state.J2_FBJ
if _ZFBJ != state.ZFBJ {
me.publishRelayNeedChangeEvent(w, switchEntry, SJZDJ9_TDC, SJZDJ9_ZFBJ, _ZFBJ)
@ -532,7 +535,7 @@ func (me *SwitchZdj9System) calculateZFBJ(w ecs.World, switchEntry *ecs.Entry, s
// 道岔定表继电器运算
// DBJ JPXC-1000 偏极继电器
// BB的负半周期提供DBJ的励磁电流
func (me *SwitchZdj9System) calculateDBJ(w ecs.World, switchEntry *ecs.Entry, state *Switch2jZdj9State) {
func (me *Switch2jZdj9System) calculateDBJ(w ecs.World, switchEntry *ecs.Entry, state *Switch2jZdj9State) {
//j1 DBJ励磁
j1DbjLc := state.J1_2DQJ && state.J1_AKB && state.J1_DB_K9 && !state.J1_1DQJ
if j1DbjLc != state.J1_DBJ {
@ -548,7 +551,7 @@ func (me *SwitchZdj9System) calculateDBJ(w ecs.World, switchEntry *ecs.Entry, st
// 道岔反表继电器运算
// FBJ JPXC-1000 偏极继电器
// BB的正半周期提供FBJ的励磁流
func (me *SwitchZdj9System) calculateFBJ(w ecs.World, switchEntry *ecs.Entry, state *Switch2jZdj9State) {
func (me *Switch2jZdj9System) calculateFBJ(w ecs.World, switchEntry *ecs.Entry, state *Switch2jZdj9State) {
//j1 FBJ励磁
j1FbjLc := !state.J1_2DQJ && !state.J1_AKB && state.J1_FB_K10 && !state.J1_1DQJ
if j1FbjLc != state.J1_FBJ {
@ -561,16 +564,60 @@ func (me *SwitchZdj9System) calculateFBJ(w ecs.World, switchEntry *ecs.Entry, st
}
}
// 道岔转动运算
// j1 完全转动须4000ms
// j2 完全转动须5000ms
const (
j1Range int64 = 4000
j2Range int64 = 5000
)
// 道岔转动运算
// j1 完全转动须4000ms
// j2 完全转动须5000ms
// j.Value 0-反位 jRange-定位
func (me *Switch2jZdj9System) calculateMove(w ecs.World, switchEntry *ecs.Entry, state *Switch2jZdj9State) {
j1 := TimeMovableObject1Component.Get(switchEntry)
//
if j1.Value < 0 {
j1.Value = 0
} else if j1.Value > j1Range {
j1.Value = j1Range
}
j1.direction = state.J1_Traction
//
j2 := TimeMovableObject2Component.Get(switchEntry)
//
if j2.Value < 0 {
j2.Value = 0
} 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)
//
state.J1_DB_K9 = j1.Value >= j1Range
state.J1_FB_K10 = j1.Value <= 0
//
state.J2_DB_K9 = j2.Value >= j2Range
state.J2_FB_K10 = j2.Value <= 0
}
// 道岔转辙机电机内线圈电路运算
// ABC三相电电机线圈UVW,
// 定位到反位U-A V-C W-B 即U->W->V电机反转反操接通2、4排表示电路
// 反位到定位U-A V-B W-C 即U->V->W电机正转定操接通1、3排表示电路
func (me *SwitchZdj9System) calculateMotor(w ecs.World, switchEntry *ecs.Entry, state *Switch2jZdj9State) {
func (me *Switch2jZdj9System) calculateMotor(w ecs.World, switchEntry *ecs.Entry, state *Switch2jZdj9State) {
//电机1
state.J1_U1 = ACPahseN
state.J1_V1 = ACPahseN
state.J1_W1 = ACPahseN
state.J1_Speed = 0
state.J1_Traction = 0
//A相电
if state.J1_Power.PhaseA && state.J1_1DQJ {
state.J1_U1 = ACPahseA
@ -599,19 +646,19 @@ func (me *SwitchZdj9System) calculateMotor(w ecs.World, switchEntry *ecs.Entry,
}
}
}
//转速
//牵引力
if state.J1_U1 == ACPahseA {
switch {
case state.J1_V1 == ACPahseB: //U-A V-B W-C
{
if state.J1_W1 == ACPahseC {
state.J1_Speed = 1
state.J1_Traction = 1
}
}
case state.J1_V1 == ACPahseC: //U-A W-B V-C
{
if state.J1_W1 == ACPahseB {
state.J1_Speed = -1
state.J1_Traction = -1
}
}
}
@ -621,7 +668,7 @@ func (me *SwitchZdj9System) calculateMotor(w ecs.World, switchEntry *ecs.Entry,
state.J2_U1 = ACPahseN
state.J2_V1 = ACPahseN
state.J2_W1 = ACPahseN
state.J2_Speed = 0
state.J2_Traction = 0
//A相电
if state.J2_Power.PhaseA && state.J2_1DQJ {
state.J2_U1 = ACPahseA
@ -650,19 +697,19 @@ func (me *SwitchZdj9System) calculateMotor(w ecs.World, switchEntry *ecs.Entry,
}
}
}
//转速
//牵引力
if state.J2_U1 == ACPahseA {
switch {
case state.J2_V1 == ACPahseB: //U-A V-B W-C
{
if state.J2_W1 == ACPahseC {
state.J2_Speed = 1
state.J2_Traction = 1
}
}
case state.J2_V1 == ACPahseC: //U-A W-B V-C
{
if state.J2_W1 == ACPahseB {
state.J2_Speed = -1
state.J2_Traction = -1
}
}
}

View File

@ -0,0 +1,75 @@
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
}