This commit is contained in:
xzb 2023-09-28 09:25:35 +08:00
commit af36695fdf
22 changed files with 393 additions and 198 deletions

View File

@ -5,13 +5,20 @@ import (
"joylink.club/rtsssimulation/consts"
)
// 两位置转换组件
// 唯一ID组件
type Uid struct {
Id string
}
var UidType = ecs.NewComponentType[Uid]()
// 两个稳态位置转换组件
type TwoPositionTransform struct {
Pos int // 当前位置百分比,[0, 10000],两位小数
Speed int
}
// 百分比值
// 当前位置百分比值
func (tp *TwoPositionTransform) Percentage() float32 {
return float32(tp.Pos) / consts.TwoPosMax
}

18
component/singleton.go Normal file
View File

@ -0,0 +1,18 @@
package component
import (
"joylink.club/ecs"
"joylink.club/rtsssimulation/repository"
)
// 世界数据单例组件
type WorldData struct {
Repo *repository.Repository
// 世界时间,时间戳,单位ms
Time int64
EntityMap map[string]*ecs.Entry
}
// 世界公共数据
var WorldDataType = ecs.NewComponentType[WorldData]()

View File

@ -5,9 +5,17 @@ import "joylink.club/ecs"
// 道岔标签
var TurnoutTag = ecs.NewTag()
// ZDJ9单机电路元器件
// 道岔的实际位置
type TurnoutPosition struct {
Dw bool // 是否定位
Fw bool // 是否反位
}
type Zdj9_1_Electronic struct {
// 实际道岔的实际位置组件类型
var TurnoutPositionType = ecs.NewComponentType[TurnoutPosition]()
// ZDJ9单机电路元器件
type Zdj9OneElectronic struct {
TDC_YCJ *ecs.Entry // 运行操作继电器
TDC_DCJ *ecs.Entry // 定操继电器
TDC_FCJ *ecs.Entry // 反操继电器
@ -24,9 +32,9 @@ type Zdj9_1_Electronic struct {
}
// ZDJ9单机电路元器件组件类型
var Zdj9_1_ElectronicType = ecs.NewComponentType[Zdj9_1_Electronic]()
var Zdj9OneElectronicType = ecs.NewComponentType[Zdj9OneElectronic]()
type Zdj9_2_Electronic struct {
type Zdj9TwoElectronic struct {
TDC_DCJ *ecs.Entry // 定操继电器
TDC_FCJ *ecs.Entry // 反操继电器
TDC_YCJ *ecs.Entry // 允许操作继电器
@ -59,8 +67,9 @@ type Zdj9_2_Electronic struct {
}
// ZDJ9双机电路元器件组件类型
var Zdj9_2_ElectronicType = ecs.NewComponentType[Zdj9_2_Electronic]()
var Zdj9TwoElectronicType = ecs.NewComponentType[Zdj9TwoElectronic]()
// 转辙机状态
type Zzj struct {
// 自动开闭器接点位置默认定位接通1/3排反位接通2/4排
// 由定位转反位1DQJ和1DQJF励磁吸起2DQJ在反位——即落下三相电路导通电机开始反转转辙机将第3排接点接通第4排到位锁闭后转辙机的自动开闭器拉簧将第1排接点拉到第2排接点到2排后三相电路断路

View File

@ -7,5 +7,5 @@ const (
// 断相保护器超时时间,单位ms
DBQTimeout = 13 * 1000
// 继电器缓放时间单位ms
RelayHf = 0.5 * 1000
RelayHfTime = int(0.5 * 1000)
)

View File

@ -3,9 +3,15 @@ package entities
import (
"joylink.club/ecs"
"joylink.club/rtsssimulation/repository"
"joylink.club/rtsssimulation/simulation"
"joylink.club/rtsssimulation/system"
)
type RelayState struct {
Id string
Xh bool
}
// CreateRelayEntity 创建继电器实体
func CreateRelayEntity(w ecs.World, relayId string) *ecs.Entry {
e := w.Create(system.EntityIdentityComponent, system.RelayStateComponent)
@ -19,3 +25,13 @@ func CreateRelayEntries(world ecs.World, relays []*repository.Relay) {
CreateRelayEntity(world, relay.Id())
}
}
func GetRelayState(worldId ecs.WorldId, relayId string) *RelayState {
sim := simulation.FindSimulation(worldId)
entry := sim.GetEntry(relayId)
if entry == nil {
return nil
}
state := system.RelayStateComponent.Get(entry)
return &RelayState{Id: relayId, Xh: state.Xh}
}

View File

@ -76,7 +76,7 @@ func TurnToReverse(worldId ecs.WorldId, turnoutId string) {
}()
}
func GetState(worldId ecs.WorldId, turnoutId string) *TurnoutState {
func GetTurnoutState(worldId ecs.WorldId, turnoutId string) *TurnoutState {
sim := simulation.FindSimulation(worldId)
entry := sim.GetEntry(turnoutId)
if entry == nil {

26
entity/relay.go Normal file
View File

@ -0,0 +1,26 @@
package entity
import (
"github.com/yohamta/donburi"
"joylink.club/ecs"
"joylink.club/rtsssimulation/component"
)
// 创建继电器实体(无uid)
func NewRelayEntity(w ecs.World, comps ...*donburi.IComponentType) *ecs.Entry {
entry := w.Create(component.RelayTag, component.RelayDriveType)
for _, comp := range comps {
entry.AddComponent(*comp)
}
return entry
}
// 创建继电器实体(有uid)
func NewRelayEntityWithUid(w ecs.World, uid string, entityMap map[string]*ecs.Entry) *ecs.Entry {
entry, ok := entityMap[uid]
if !ok {
entry = w.Create(component.RelayTag, component.UidType, component.RelayDriveType)
entityMap[uid] = entry
}
return entry
}

25
entity/singleton.go Normal file
View File

@ -0,0 +1,25 @@
package entity
import (
"time"
"joylink.club/ecs"
"joylink.club/rtsssimulation/component"
"joylink.club/rtsssimulation/repository"
)
// 初始化世界数据
func InitWorldData(w ecs.World, repo *repository.Repository) {
entry := w.Create(component.WorldDataType)
component.WorldDataType.Set(entry, &component.WorldData{
Repo: repo,
Time: time.Now().UnixMilli(),
EntityMap: make(map[string]*ecs.Entry),
})
}
// 获取世界数据
func GetWorldData(w ecs.World) *component.WorldData {
entry := component.WorldDataType.MustFirst(w)
return component.WorldDataType.Get(entry)
}

53
entity/turnout.go Normal file
View File

@ -0,0 +1,53 @@
package entity
import (
"fmt"
"joylink.club/ecs"
"joylink.club/rtsssimulation/component"
"joylink.club/rtsssimulation/repository"
"joylink.club/rtsssimulation/repository/model/proto"
)
// 加载道岔实体
func LoadTurnouts(w ecs.World) error {
data := GetWorldData(w)
turnouts := data.Repo.TurnoutList()
for _, turnout := range turnouts {
entry := NewTurnoutEntity(w, turnout.Id(), data)
var err error
switch turnout.SwitchMachineType() {
case proto.Turnout_ZDJ9_Single:
err = LoadTurnoutZdj9One(w, turnout, entry)
case proto.Turnout_ZDJ9_Double:
err = LoadTurnoutZdj9Two(w, turnout, entry)
default:
fmt.Println("id=", turnout.Id(), "的道岔没有转辙机类型")
}
if err != nil {
return err
}
}
return nil
}
// 加载道岔ZDJ9单机转辙机
func LoadTurnoutZdj9One(w ecs.World, turnout *repository.Turnout, entry *ecs.Entry) error {
panic("unimplemented")
}
// 加载道岔ZDJ9双机转辙机
func LoadTurnoutZdj9Two(w ecs.World, turnout *repository.Turnout, entry *ecs.Entry) error {
panic("unimplemented")
}
// 新建道岔实体
func NewTurnoutEntity(w ecs.World, uid string, worldData *component.WorldData) *ecs.Entry {
entry, ok := worldData.EntityMap[uid]
if !ok {
entry = w.Create(component.TurnoutTag, component.UidType, component.TurnoutPositionType)
component.UidType.Set(entry, &component.Uid{Id: uid})
worldData.EntityMap[uid] = entry
}
return entry
}

49
fi/turnout.go Normal file
View File

@ -0,0 +1,49 @@
package fi
import (
"fmt"
"joylink.club/ecs"
"joylink.club/rtsssimulation/component"
"joylink.club/rtsssimulation/entity"
)
// 道岔功能接口
// 驱动道岔定操相关继电器
func DriveTurnoutDCRelay(w ecs.World, id string, on bool) {
w.Execute(func() {
wd := entity.GetWorldData(w)
entry, ok := wd.EntityMap[id]
if ok {
if entry.HasComponent(component.Zdj9TwoElectronicType) {
zdj9 := component.Zdj9TwoElectronicType.Get(entry)
ycj := component.RelayDriveType.Get(zdj9.TDC_YCJ)
dcj := component.RelayDriveType.Get(zdj9.TDC_DCJ)
ycj.Td = on
dcj.Td = on
}
} else {
fmt.Println("未找到id=", id, "的道岔")
}
})
}
// 驱动道岔反操相关继电器
func DriveTurnoutFCRelay(w ecs.World, id string, on bool) {
w.Execute(func() {
wd := entity.GetWorldData(w)
entry, ok := wd.EntityMap[id]
if ok {
if entry.HasComponent(component.Zdj9TwoElectronicType) {
zdj9 := component.Zdj9TwoElectronicType.Get(entry)
ycj := component.RelayDriveType.Get(zdj9.TDC_YCJ)
fcj := component.RelayDriveType.Get(zdj9.TDC_FCJ)
ycj.Td = on
fcj.Td = on
}
} else {
fmt.Println("未找到id=", id, "的道岔")
}
})
}

3
init.go Normal file
View File

@ -0,0 +1,3 @@
package rtss_simulation
// 初始化仿真

View File

@ -3,6 +3,7 @@ package repository
import (
"errors"
"fmt"
"joylink.club/rtsssimulation/repository/model/proto"
)
@ -155,6 +156,10 @@ func (repo *Repository) FindTurnout(id string) *Turnout {
return repo.turnoutMap[id]
}
func (repo *Repository) FindPhysicalSection(id string) *PhysicalSection {
return repo.physicalSectionMap[id]
}
func (repo *Repository) AddPhysicalSection(section *PhysicalSection) {
repo.physicalSectionMap[section.Id()] = section
}

16
sys/bind.go Normal file
View File

@ -0,0 +1,16 @@
package sys
import (
"joylink.club/ecs"
"joylink.club/rtsssimulation/sys/circuit_sys"
"joylink.club/rtsssimulation/sys/common_sys"
"joylink.club/rtsssimulation/sys/device_sys"
)
// 添加系统到World
func BindSystem(w ecs.World) {
w.AddSystem(NewWorldTimeSys(),
common_sys.NewCounterDownSys(), common_sys.NewTwoPositionMovementSys(),
device_sys.NewRelaySys(), device_sys.NewDBQSys(), device_sys.NewZzjSys(),
circuit_sys.NewZdj9TwoDragSys())
}

View File

@ -10,20 +10,21 @@ import (
)
// ZDJ9双机牵引道岔电路系统
type ZDJ9_2 struct {
type ZDJ9TwoDragSys struct {
query *ecs.Query
}
func NewZdj9_2() *ZDJ9_2 {
return &ZDJ9_2{
query: ecs.NewQuery(filter.Contains(component.Zdj9_2_ElectronicType, component.TwoPositionTransformType)),
func NewZdj9TwoDragSys() *ZDJ9TwoDragSys {
return &ZDJ9TwoDragSys{
query: ecs.NewQuery(filter.Contains(component.Zdj9TwoElectronicType, component.TwoPositionTransformType)),
}
}
func (zdj9 *ZDJ9_2) Update(w ecs.World) {
// 电路更新
func (zdj9 *ZDJ9TwoDragSys) Update(w ecs.World) {
fmt.Println("ZDJ9双机牵引道岔电路系统")
zdj9.query.Each(w, func(entry *ecs.Entry) {
elec := component.Zdj9_2_ElectronicType.Get(entry)
elec := component.Zdj9TwoElectronicType.Get(entry)
// 转辙机一机电路相关动作
// 1DQJ励磁状态控制
zdj9.exciteM1_TDFJ_1DQJ(elec)
@ -40,7 +41,7 @@ func (zdj9 *ZDJ9_2) Update(w ecs.World) {
// 切断继电器
zdj9.exciteM1_TDFJ_QDJ(w, entry, elec)
// 定表/反表继电器
zdj9.exciteM1_TDFJ1_DFBJ(entry, elec)
zdj9.exciteM1_TDFJ1_DFBJ(elec)
// 转辙机二机电路相关动作
// 1DQJ励磁状态控制
@ -54,56 +55,112 @@ func (zdj9 *ZDJ9_2) Update(w ecs.World) {
// TDFJ1_BHJ励磁状态控制
zdj9.exciteM2_TDFJ_BHJ(elec)
// 定表/反表继电器
zdj9.exciteM2_TDFJ1_DFBJ(entry, elec)
zdj9.exciteM2_TDFJ1_DFBJ(elec)
// 总定表/反表继电器
zdj9.exciteZDFBJ(elec)
})
}
// 总定表、反表继电器控制
func (zdj9 *ZDJ9TwoDragSys) exciteZDFBJ(elec *component.Zdj9TwoElectronic) {
tdfj1_dbj := component.BitStateType.Get(elec.TDFJ1_DBJ)
tdfj2_dbj := component.BitStateType.Get(elec.TDFJ2_DBJ)
tdfj1_fbj := component.BitStateType.Get(elec.TDFJ1_FBJ)
tdfj2_fbj := component.BitStateType.Get(elec.TDFJ2_FBJ)
zdbj_drive := component.RelayDriveType.Get(elec.TDC_ZDBJ)
zfbj_drive := component.RelayDriveType.Get(elec.TDC_ZDBJ)
// 总定表
if zdbj_drive.Td { // 总定表继电器通电,监测电路是否断开
if !(tdfj1_dbj.Val && tdfj2_dbj.Val) {
zdbj_drive.Td = false
}
} else {
if tdfj1_dbj.Val && tdfj2_dbj.Val {
zdbj_drive.Td = true
}
}
// 总反表
if zfbj_drive.Td {
if !(tdfj1_fbj.Val && tdfj2_fbj.Val) {
zfbj_drive.Td = false
}
} else {
if tdfj1_fbj.Val && tdfj2_fbj.Val {
zfbj_drive.Td = true
}
}
}
// 二极管整流电路为继电器励磁电路提供半波整流电源
// 转辙机一定表/反表继电器控制
func (zdj9 *ZDJ9_2) exciteM1_TDFJ1_DFBJ(entry *ecs.Entry, elec *component.Zdj9_2_Electronic) {
func (zdj9 *ZDJ9TwoDragSys) exciteM1_TDFJ1_DFBJ(elec *component.Zdj9TwoElectronic) {
_1dqj := component.BitStateType.Get(elec.TDFJ1_1DQJ)
_2dqj := component.BitStateType.Get(elec.TDFJ1_2DQJ)
zzj := component.ZzjType.Get(elec.Zzj1)
dbj := component.BitStateType.Get(elec.TDFJ1_DBJ)
dbj_drive := component.RelayDriveType.Get(elec.TDFJ1_DBJ)
fbj := component.BitStateType.Get(elec.TDFJ1_FBJ)
fbj_drive := component.RelayDriveType.Get(elec.TDFJ1_DBJ)
fbj_drive := component.RelayDriveType.Get(elec.TDFJ1_FBJ)
// 默认BB道岔表示变压器正常
if !dbj.Val { // 定表继电器落下状态
if !_1dqj.Val && _2dqj.Val && !zzj.JD12 { // 1DQJ落下2DQJ定位开闭器接点在1排
if !dbj_drive.Td { // 定表继电器未通电
if !_1dqj.Val && _2dqj.Val && !zzj.JD12 && !zzj.JD34 { // 1DQJ落下2DQJ定位开闭器接点在1/3
dbj_drive.Td = true
}
} else { // 吸起状态
if !(!_1dqj.Val && _2dqj.Val && !zzj.JD12) { // 励磁电路断开
} else { // 定表继电器通电
if !(!_1dqj.Val && _2dqj.Val && !zzj.JD12 && !zzj.JD34) { // 励磁电路断开
dbj_drive.Td = false
}
}
if !fbj.Val { // 反表继电器落下状态
if !_1dqj.Val && !_2dqj.Val && zzj.JD34 {
if !fbj_drive.Td { // 反表继电器未通电
if !_1dqj.Val && !_2dqj.Val && zzj.JD12 && zzj.JD34 { // 2DQJ反位,开闭器在2/4排
fbj_drive.Td = true
}
} else { //
} else { // 反表继电器通电
if !(!_1dqj.Val && !_2dqj.Val && zzj.JD12 && zzj.JD34) { // 电路断开
fbj_drive.Td = false
}
}
}
// 转辙机二定表/反表继电器控制
func (zdj9 *ZDJ9_2) exciteM2_TDFJ1_DFBJ(entry *ecs.Entry, elec *component.Zdj9_2_Electronic) {
func (zdj9 *ZDJ9TwoDragSys) exciteM2_TDFJ1_DFBJ(elec *component.Zdj9TwoElectronic) {
_1dqj := component.BitStateType.Get(elec.TDFJ2_1DQJ)
_2dqj := component.BitStateType.Get(elec.TDFJ2_2DQJ)
zzj := component.ZzjType.Get(elec.Zzj2)
dbj_drive := component.RelayDriveType.Get(elec.TDFJ2_DBJ)
fbj_drive := component.RelayDriveType.Get(elec.TDFJ2_FBJ)
// 默认BB道岔表示变压器正常
if !dbj_drive.Td { // 定表继电器未通电
if !_1dqj.Val && _2dqj.Val && !zzj.JD12 && !zzj.JD34 { // 1DQJ落下2DQJ定位开闭器接点在1/3排
dbj_drive.Td = true
}
} else { // 定表继电器通电
if !(!_1dqj.Val && _2dqj.Val && !zzj.JD12 && !zzj.JD34) { // 励磁电路断开
dbj_drive.Td = false
}
}
if !fbj_drive.Td { // 反表继电器未通电
if !_1dqj.Val && !_2dqj.Val && zzj.JD12 && zzj.JD34 { // 2DQJ反位,开闭器在2/4排
fbj_drive.Td = true
}
} else { // 反表继电器通电
if !(!_1dqj.Val && !_2dqj.Val && zzj.JD12 && zzj.JD34) { // 电路断开
fbj_drive.Td = false
}
}
}
// 切断继电器延时缓放电路缓放时间单位ms
const QDJ_DELAY = 3 * 1000
// 切断继电器控制
func (zdj9 *ZDJ9_2) exciteM1_TDFJ_QDJ(w ecs.World, entry *ecs.Entry, elec *component.Zdj9_2_Electronic) {
func (zdj9 *ZDJ9TwoDragSys) exciteM1_TDFJ_QDJ(w ecs.World, entry *ecs.Entry, elec *component.Zdj9TwoElectronic) {
tdfj1_bhj := component.BitStateType.Get(elec.TDFJ1_BHJ)
tdfj2_bhj := component.BitStateType.Get(elec.TDFJ2_BHJ)
tdfj1_zbhj := component.BitStateType.Get(elec.TDFJ1_ZBHJ)
tdfj1_qdj := component.BitStateType.Get(elec.TDFJ1_QDJ)
drive := component.RelayDriveType.Get(elec.TDFJ1_QDJ)
if !tdfj1_qdj.Val { // 落下状态
if (!tdfj1_bhj.Val && !tdfj2_bhj.Val) || tdfj1_zbhj.Val { // 励磁电路导通
if (!tdfj1_bhj.Val && !tdfj2_bhj.Val) || tdfj1_zbhj.Val { // 电路导通
drive.Td = true
if entry.HasComponent(component.CounterDownType) {
entry.RemoveComponent(component.CounterDownType)
@ -129,7 +186,7 @@ func (zdj9 *ZDJ9_2) exciteM1_TDFJ_QDJ(w ecs.World, entry *ecs.Entry, elec *compo
}
// 总保护继电器控制
func (zdj9 *ZDJ9_2) exciteM1_TDFJ_ZBHJ(elec *component.Zdj9_2_Electronic) {
func (zdj9 *ZDJ9TwoDragSys) exciteM1_TDFJ_ZBHJ(elec *component.Zdj9TwoElectronic) {
tdfj1_bhj := component.BitStateType.Get(elec.TDFJ1_BHJ)
tdfj2_bhj := component.BitStateType.Get(elec.TDFJ2_BHJ)
tdfj1_zbhj := component.RelayDriveType.Get(elec.TDFJ1_ZBHJ)
@ -145,7 +202,7 @@ func (zdj9 *ZDJ9_2) exciteM1_TDFJ_ZBHJ(elec *component.Zdj9_2_Electronic) {
}
// 转辙机一断相保护器控制
func (zdj9 *ZDJ9_2) exciteM1_TDFJ_DBQ(w ecs.World, entry *ecs.Entry, elec *component.Zdj9_2_Electronic) {
func (zdj9 *ZDJ9TwoDragSys) exciteM1_TDFJ_DBQ(w ecs.World, entry *ecs.Entry, elec *component.Zdj9TwoElectronic) {
_1dqj := component.BitStateType.Get(elec.TDFJ1_1DQJ)
_1dqjf := component.BitStateType.Get(elec.TDFJ1_1DQJF)
_2dqj := component.BitStateType.Get(elec.TDFJ1_2DQJ)
@ -167,7 +224,7 @@ func (zdj9 *ZDJ9_2) exciteM1_TDFJ_DBQ(w ecs.World, entry *ecs.Entry, elec *compo
}
// 转辙机二断相保护器控制
func (zdj9 *ZDJ9_2) exciteM2_TDFJ_DBQ(w ecs.World, entry *ecs.Entry, elec *component.Zdj9_2_Electronic) {
func (zdj9 *ZDJ9TwoDragSys) exciteM2_TDFJ_DBQ(w ecs.World, entry *ecs.Entry, elec *component.Zdj9TwoElectronic) {
_1dqj := component.BitStateType.Get(elec.TDFJ2_1DQJ)
_1dqjf := component.BitStateType.Get(elec.TDFJ2_1DQJF)
_2dqj := component.BitStateType.Get(elec.TDFJ2_2DQJ)
@ -189,7 +246,7 @@ func (zdj9 *ZDJ9_2) exciteM2_TDFJ_DBQ(w ecs.World, entry *ecs.Entry, elec *compo
}
// 转辙机一TDFJ_BHJ保护继电器励磁状态控制
func (zdj9 *ZDJ9_2) exciteM1_TDFJ_BHJ(elec *component.Zdj9_2_Electronic) {
func (zdj9 *ZDJ9TwoDragSys) exciteM1_TDFJ_BHJ(elec *component.Zdj9TwoElectronic) {
dbq := component.DBQType.Get(elec.TDFJ1_DBQ)
bhj := component.RelayDriveType.Get(elec.TDFJ1_BHJ)
if !bhj.Td && dbq.Dzkg { // BHJ励磁电路导通
@ -200,7 +257,7 @@ func (zdj9 *ZDJ9_2) exciteM1_TDFJ_BHJ(elec *component.Zdj9_2_Electronic) {
}
// 转辙机二TDFJ_BHJ保护继电器励磁状态控制
func (zdj9 *ZDJ9_2) exciteM2_TDFJ_BHJ(elec *component.Zdj9_2_Electronic) {
func (zdj9 *ZDJ9TwoDragSys) exciteM2_TDFJ_BHJ(elec *component.Zdj9TwoElectronic) {
dbq := component.DBQType.Get(elec.TDFJ2_DBQ)
bhj := component.RelayDriveType.Get(elec.TDFJ2_BHJ)
if !bhj.Td && dbq.Dzkg { // BHJ励磁电路导通
@ -211,7 +268,7 @@ func (zdj9 *ZDJ9_2) exciteM2_TDFJ_BHJ(elec *component.Zdj9_2_Electronic) {
}
// 转辙机一TDFJ_1DQJF励磁电路逻辑
func (zdj9 *ZDJ9_2) exciteM1_TDFJ_1DQJF(elec *component.Zdj9_2_Electronic) {
func (zdj9 *ZDJ9TwoDragSys) exciteM1_TDFJ_1DQJF(elec *component.Zdj9TwoElectronic) {
tdfj_1dqj := component.BitStateType.Get(elec.TDFJ1_1DQJ)
tdfj_1dqjf_drive := component.RelayDriveType.Get(elec.TDFJ1_1DQJF)
if tdfj_1dqjf_drive.Td { // 通电
@ -226,7 +283,7 @@ func (zdj9 *ZDJ9_2) exciteM1_TDFJ_1DQJF(elec *component.Zdj9_2_Electronic) {
}
// 转辙机二TDFJ_1DQJF励磁电路逻辑
func (zdj9 *ZDJ9_2) exciteM2_TDFJ_1DQJF(elec *component.Zdj9_2_Electronic) {
func (zdj9 *ZDJ9TwoDragSys) exciteM2_TDFJ_1DQJF(elec *component.Zdj9TwoElectronic) {
tdfj_1dqj := component.BitStateType.Get(elec.TDFJ2_1DQJ)
tdfj_1dqjf_drive := component.RelayDriveType.Get(elec.TDFJ2_1DQJF)
if tdfj_1dqjf_drive.Td { // 通电
@ -241,7 +298,7 @@ func (zdj9 *ZDJ9_2) exciteM2_TDFJ_1DQJF(elec *component.Zdj9_2_Electronic) {
}
// 转辙机一TDFJ_1DQJ励磁电路逻辑
func (zdj9 *ZDJ9_2) exciteM1_TDFJ_1DQJ(elec *component.Zdj9_2_Electronic) {
func (zdj9 *ZDJ9TwoDragSys) exciteM1_TDFJ_1DQJ(elec *component.Zdj9TwoElectronic) {
// 暂时先实现非应急按钮操作
ycj := component.BitStateType.Get(elec.TDC_YCJ)
dcj := component.BitStateType.Get(elec.TDC_DCJ)
@ -262,7 +319,7 @@ func (zdj9 *ZDJ9_2) exciteM1_TDFJ_1DQJ(elec *component.Zdj9_2_Electronic) {
}
// 转辙机二TDFJ_1DQJ励磁电路逻辑
func (zdj9 *ZDJ9_2) exciteM2_TDFJ_1DQJ(elec *component.Zdj9_2_Electronic) {
func (zdj9 *ZDJ9TwoDragSys) exciteM2_TDFJ_1DQJ(elec *component.Zdj9TwoElectronic) {
// 暂时先实现非应急按钮操作
ycj := component.BitStateType.Get(elec.TDC_YCJ)
dcj := component.BitStateType.Get(elec.TDC_DCJ)
@ -283,7 +340,7 @@ func (zdj9 *ZDJ9_2) exciteM2_TDFJ_1DQJ(elec *component.Zdj9_2_Electronic) {
}
// 转辙机一TDFJ_2DQJ励磁电路逻辑(暂时未考虑应急盘操作按钮电路)
func (zdj9 *ZDJ9_2) exciteM1_TDFJ_2DQJ(elec *component.Zdj9_2_Electronic) {
func (zdj9 *ZDJ9TwoDragSys) exciteM1_TDFJ_2DQJ(elec *component.Zdj9TwoElectronic) {
tdfj1_1dqjf := component.BitStateType.Get(elec.TDFJ1_1DQJF)
dcj := component.BitStateType.Get(elec.TDC_DCJ)
fcj := component.BitStateType.Get(elec.TDC_FCJ)
@ -311,7 +368,7 @@ func (zdj9 *ZDJ9_2) exciteM1_TDFJ_2DQJ(elec *component.Zdj9_2_Electronic) {
}
// 转辙机二TDFJ_2DQJ励磁电路逻辑(暂时未考虑应急盘操作按钮电路)
func (zdj9 *ZDJ9_2) exciteM2_TDFJ_2DQJ(elec *component.Zdj9_2_Electronic) {
func (zdj9 *ZDJ9TwoDragSys) exciteM2_TDFJ_2DQJ(elec *component.Zdj9TwoElectronic) {
tdfj2_1dqjf := component.BitStateType.Get(elec.TDFJ2_1DQJF)
dcj := component.BitStateType.Get(elec.TDC_DCJ)
fcj := component.BitStateType.Get(elec.TDC_FCJ)

View File

@ -0,0 +1,32 @@
package common_sys
import (
"github.com/yohamta/donburi/filter"
"joylink.club/ecs"
"joylink.club/rtsssimulation/component"
)
type CounterDownSys struct {
query *ecs.Query
}
func NewCounterDownSys() *CounterDownSys {
return &CounterDownSys{
query: ecs.NewQuery(filter.Contains(component.CounterDownType)),
}
}
// 更新
func (c *CounterDownSys) Update(w ecs.World) {
c.query.Each(w, func(entry *ecs.Entry) {
cd := component.CounterDownType.Get(entry)
if cd.Val > 0 {
v := cd.Val - cd.Step
if v < 0 {
cd.Val = 0
} else {
cd.Val = v
}
}
})
}

View File

@ -1,4 +1,4 @@
package physics_sys
package common_sys
import (
"github.com/yohamta/donburi/filter"
@ -25,10 +25,8 @@ func (tp *TwoPositionMovementSys) Update(w ecs.World) {
pos := position.Pos + position.Speed
if pos < consts.TwoPosMin {
position.Pos = consts.TwoPosMin
position.Speed = 0
} else if pos > consts.TwoPosMax {
position.Pos = consts.TwoPosMax
position.Speed = 0
} else {
position.Pos = pos
}

View File

@ -8,17 +8,17 @@ import (
)
// 断相保护器
type DBQ struct {
type DBQSys struct {
query *ecs.Query
}
func NewDBQ() *DBQ {
return &DBQ{
func NewDBQSys() *DBQSys {
return &DBQSys{
query: ecs.NewQuery(filter.Contains(component.DBQTag, component.DBQType)),
}
}
func (q *DBQ) Update(w ecs.World) {
func (q *DBQSys) Update(w ecs.World) {
q.query.Each(w, func(entry *ecs.Entry) {
// 电路是否通电
dbq := component.DBQType.Get(entry)

View File

@ -37,7 +37,7 @@ func (rs *RelaySys) Update(w ecs.World) {
}
} else {
entry.AddComponent(component.CounterDownType, unsafe.Pointer(&component.CounterDown{
Val: consts.RelayHf,
Val: consts.RelayHfTime,
Step: w.Tick(),
}))
}
@ -54,15 +54,3 @@ func (rs *RelaySys) Update(w ecs.World) {
}
})
}
// 处理无极继电器励磁电路导通(励磁电路变化)
func HandleRelayLc(entry *ecs.Entry, lc bool) {
rd := component.RelayDriveType.Get(entry)
rd.Td = lc
}
// 处理有极继电器励磁电路导致的吸起/打落变化(励磁电路变化)
func HandleYjRelayXq(entry *ecs.Entry, xq bool) {
rd := component.RelayDriveType.Get(entry)
rd.Xq = xq
}

View File

@ -7,12 +7,12 @@ import (
"joylink.club/rtsssimulation/consts"
)
type Zzj struct {
type ZzjSys struct {
query *ecs.Query
}
func NewZzj() *Zzj {
return &Zzj{
func NewZzjSys() *ZzjSys {
return &ZzjSys{
query: ecs.NewQuery(filter.Contains(component.ZzjType, component.TwoPositionTransformType)),
}
}
@ -25,7 +25,7 @@ const (
KbqJsPercent = 0.05
)
func (z *Zzj) Update(w ecs.World) {
func (z *ZzjSys) Update(w ecs.World) {
z.query.Each(w, func(entry *ecs.Entry) {
zzj := component.ZzjType.Get(entry)
tp := component.TwoPositionTransformType.Get(entry)

24
sys/world_time.go Normal file
View File

@ -0,0 +1,24 @@
package sys
import (
"github.com/yohamta/donburi/filter"
"joylink.club/ecs"
"joylink.club/rtsssimulation/component"
)
// 世界世界更新系统
type WorldTimeSys struct {
query *ecs.Query
}
func NewWorldTimeSys() *WorldTimeSys {
return &WorldTimeSys{
query: ecs.NewQuery(filter.Contains(component.WorldDataType)),
}
}
func (s *WorldTimeSys) Update(w ecs.World) {
entry, _ := s.query.First(w)
data := component.WorldDataType.Get(entry)
data.Time += int64(w.Tick())
}

View File

@ -1,114 +0,0 @@
// ZDJ9单机转辙机电路系统
package circuit_sys
import (
"fmt"
"github.com/yohamta/donburi/filter"
"joylink.club/ecs"
"joylink.club/rtsssimulation/component"
"joylink.club/rtsssimulation/system/device_sys"
)
// ZDJ9单机转辙机电路系统
type ZDJ9_1 struct {
query *ecs.Query
}
func NewZdj9_1() *ZDJ9_1 {
return &ZDJ9_1{
query: ecs.NewQuery(filter.Contains(component.Zdj9_1_ElectronicType)),
}
}
func (zdj9 *ZDJ9_1) Update(w ecs.World) {
fmt.Println("ZDJ9单机牵引控制电路更新")
zdj9.query.Each(w, func(entry *ecs.Entry) {
elec := component.Zdj9_1_ElectronicType.Get(entry)
// TDFJ_1DQJ及1DQJF励磁状态变更
zdj9.exciteTDFJ_1DQJ(elec)
// TDFJ_2DQJ励磁状态变更
zdj9.exciteTDFJ_2DQJ(elec)
// 限时断相保护器限时13秒
zdj9.exciteTDFJ_DBQ(elec)
// TDFJ_BHJ励磁状态控制
zdj9.exciteTDFJ_BHJ(elec)
})
}
// 断相保护器控制
func (zdj9 *ZDJ9_1) exciteTDFJ_DBQ(elec *component.Zdj9_1_Electronic) {
tdfj_1dqj := component.BitStateType.Get(elec.TDFJ_1DQJ)
tdfj_1dqjf := component.BitStateType.Get(elec.TDFJ_1DQJF)
dbq := component.DBQType.Get(elec.TDFJ_DBQ)
if tdfj_1dqj.Val && tdfj_1dqjf.Val && !dbq.Td { // 默认电源没有问题,电路导通
dbq.Td = true
} else if (!tdfj_1dqj.Val || !tdfj_1dqjf.Val) && dbq.Td {
dbq.Td = false
}
}
// TDFJ_BHJ保护继电器励磁状态控制
func (zdj9 *ZDJ9_1) exciteTDFJ_BHJ(elec *component.Zdj9_1_Electronic) {
dbq := component.DBQType.Get(elec.TDFJ_DBQ)
bhj := component.BitStateType.Get(elec.TDFJ_BHJ)
if dbq.Dzkg && !bhj.Val { // BHJ吸起
device_sys.HandleRelayLc(elec.TDFJ_BHJ, true)
} else if !dbq.Dzkg && bhj.Val { // BHJ落下
device_sys.HandleRelayLc(elec.TDFJ_BHJ, false)
}
}
// TDFJ_1DQJ励磁电路逻辑
func (zdj9 *ZDJ9_1) exciteTDFJ_1DQJ(elec *component.Zdj9_1_Electronic) {
// 暂时先实现非应急按钮操作
tdfj_1dqj := component.BitStateType.Get(elec.TDFJ_1DQJ)
ycj := component.BitStateType.Get(elec.TDC_YCJ)
dcj := component.BitStateType.Get(elec.TDC_DCJ)
fcj := component.BitStateType.Get(elec.TDC_FCJ)
bhj := component.BitStateType.Get(elec.TDFJ_BHJ)
tdfj_1dqjf := component.BitStateType.Get(elec.TDFJ_1DQJF)
if tdfj_1dqj.Val { // 已经吸起
// 判定是否所有励磁电路断开(todo 暂不考虑应急按钮)
if !bhj.Val && !(ycj.Val && (fcj.Val || dcj.Val)) { // 电路断开1DQJ落下请求
device_sys.HandleRelayLc(elec.TDFJ_1DQJ, false)
}
// 1DQJF复示继电器
if !tdfj_1dqjf.Val { // 如果落下状态,1DQJF吸起请求
device_sys.HandleRelayLc(elec.TDFJ_1DQJF, true)
}
} else { // 在落下位置
if ycj.Val { // 允许操作继电器已经吸起
if fcj.Val || dcj.Val { // 电路导通1DQJ吸起请求
device_sys.HandleRelayLc(elec.TDFJ_1DQJ, true)
}
}
// 1DQJF复示继电器
if tdfj_1dqjf.Val { // 如果吸起状态,1DQJF落下请求
device_sys.HandleRelayLc(elec.TDFJ_1DQJF, false)
}
}
}
// TDFJ_2DQJ励磁电路逻辑(暂时未考虑应急盘操作按钮电路)
func (zdj9 *ZDJ9_1) exciteTDFJ_2DQJ(elec *component.Zdj9_1_Electronic) {
tdfj_1dqjf := component.BitStateType.Get(elec.TDFJ_1DQJF)
dcj := component.BitStateType.Get(elec.TDC_DCJ)
fcj := component.BitStateType.Get(elec.TDC_FCJ)
tdfj_2dqj := component.BitStateType.Get(elec.TDFJ_2DQJ)
if !(tdfj_1dqjf.Val && (dcj.Val || fcj.Val)) {
// 励磁电路断开
device_sys.HandleRelayLc(elec.TDFJ_2DQJ, false)
} else {
// 励磁电路导通
device_sys.HandleRelayLc(elec.TDFJ_2DQJ, true)
if tdfj_2dqj.Val && tdfj_1dqjf.Val && fcj.Val {
// 2DQJ定位但反操需打落
device_sys.HandleYjRelayXq(elec.TDFJ_2DQJ, false)
} else if !tdfj_2dqj.Val && tdfj_1dqjf.Val && dcj.Val {
// 2DQJ反位但定操需吸起
device_sys.HandleYjRelayXq(elec.TDFJ_2DQJ, true)
}
}
}

View File

@ -1,17 +0,0 @@
package common_sys
import (
"github.com/yohamta/donburi/filter"
"joylink.club/ecs"
"joylink.club/rtsssimulation/component"
)
type CounterDown struct {
query *ecs.Query
}
func NewCounterDown() *CounterDown {
return &CounterDown{
query: ecs.NewQuery(filter.Contains(component.CounterDownType)),
}
}