添加创建仿真

完善仿真实体加载
This commit is contained in:
walker 2023-09-28 14:34:00 +08:00
parent d36ba6fc7d
commit d3a187e00f
17 changed files with 387 additions and 68 deletions

View File

@ -1 +1,11 @@
# 轨道交通仿真模块
基于 ECSEntity-Component-System架构实现的轨道交通仿真系统
# 目录说明
- component - 组件文件夹,包含所有业务使用到的组件
- consts - 常量文件夹
- entity - 实体文件夹,用于实体对象的加载、初始化
- fi - function interface功能接口提供外部与仿真的功能交互接口
- sys - 系统文件夹,所有功能逻辑实现(系统逻辑依赖组件,系统不能有数据)

View File

@ -6,9 +6,9 @@ import "joylink.club/ecs"
var DBQTag = ecs.NewTag()
// 断相保护器控制请求组件
type DBQ struct {
type DBQState struct {
Td bool // 是否通电true通电
Dzkg bool // 电子开关状态true: 开
}
var DBQType = ecs.NewComponentType[DBQ]()
var DBQStateType = ecs.NewComponentType[DBQState]()

View File

@ -8,10 +8,10 @@ var (
RelayTag = ecs.NewTag()
// 无极继电器
WjRelayTag = ecs.NewTag()
// 缓放继电器
HfRelayTag = ecs.NewTag()
// 有极
YjRelayTag = ecs.NewTag()
// 缓放继电器
HfRelayTag = ecs.NewTag()
)
// 无极继电器和偏极继电器稳态为落下,也就是后接点(8组采集接点中的1,3接点1为中接点)吸气为前接点1,2接点

View File

@ -1,6 +1,8 @@
package component
import "joylink.club/ecs"
import (
"joylink.club/ecs"
)
// 道岔标签
var TurnoutTag = ecs.NewTag()
@ -60,17 +62,91 @@ type Zdj9TwoElectronic struct {
TDFJ2_DBQ *ecs.Entry // 断相保护器
TDFJ2_DBJ *ecs.Entry // 定位表示继电器
TDFJ2_FBJ *ecs.Entry // 反位表示继电器
}
Zzj1 *ecs.Entry //转辙机一
Zzj2 *ecs.Entry //转辙机二
// 检查空引用,返回空引用字段名称
func (te *Zdj9TwoElectronic) CheckNilReference() []string {
var nils []string = make([]string, 0)
if te.TDC_DCJ == nil {
nils = append(nils, "TDC_DCJ")
}
if te.TDC_FCJ == nil {
nils = append(nils, "TDC_FCJ")
}
if te.TDC_YCJ == nil {
nils = append(nils, "TDC_YCJ")
}
if te.TDC_ZDBJ == nil {
nils = append(nils, "TDC_ZDBJ")
}
if te.TDC_ZFBJ == nil {
nils = append(nils, "TDC_ZFBJ")
}
// 一机
if te.TDFJ1_1DQJ == nil {
nils = append(nils, "TDFJ1_1DQJ")
}
if te.TDFJ1_BHJ == nil {
nils = append(nils, "TDFJ1_BHJ")
}
if te.TDFJ1_2DQJ == nil {
nils = append(nils, "TDFJ1_2DQJ")
}
if te.TDFJ1_1DQJF == nil {
nils = append(nils, "TDFJ1_1DQJF")
}
if te.TDFJ1_DBQ == nil {
nils = append(nils, "TDFJ1_DBQ")
}
if te.TDFJ1_DBJ == nil {
nils = append(nils, "TDFJ1_DBJ")
}
if te.TDFJ1_FBJ == nil {
nils = append(nils, "TDFJ1_FBJ")
}
if te.TDFJ1_QDJ == nil {
nils = append(nils, "TDFJ1_QDJ")
}
if te.TDFJ1_ZBHJ == nil {
nils = append(nils, "TDFJ1_ZBHJ")
}
// 二机
if te.TDFJ2_1DQJ == nil {
nils = append(nils, "TDFJ2_1DQJ")
}
if te.TDFJ2_BHJ == nil {
nils = append(nils, "TDFJ2_BHJ")
}
if te.TDFJ2_2DQJ == nil {
nils = append(nils, "TDFJ2_2DQJ")
}
if te.TDFJ2_1DQJF == nil {
nils = append(nils, "TDFJ2_1DQJF")
}
if te.TDFJ2_DBQ == nil {
nils = append(nils, "TDFJ2_DBQ")
}
if te.TDFJ2_DBJ == nil {
nils = append(nils, "TDFJ2_DBJ")
}
if te.TDFJ2_FBJ == nil {
nils = append(nils, "TDFJ2_FBJ")
}
return nils
}
// 是否有空引用
func (te *Zdj9TwoElectronic) HasNilReference() bool {
nils := te.CheckNilReference()
return len(nils) > 0
}
// ZDJ9双机电路元器件组件类型
var Zdj9TwoElectronicType = ecs.NewComponentType[Zdj9TwoElectronic]()
// 转辙机状态
type Zzj struct {
type ZzjState struct {
// 自动开闭器接点位置默认定位接通1/3排反位接通2/4排
// 由定位转反位1DQJ和1DQJF励磁吸起2DQJ在反位——即落下三相电路导通电机开始反转转辙机将第3排接点接通第4排到位锁闭后转辙机的自动开闭器拉簧将第1排接点拉到第2排接点到2排后三相电路断路
// 由反位转定位1DQJ和1DQJF励磁吸起2DQJ在定位——即吸起三相电路导通电机开始正转转辙机将第2排接点接通第1排到位锁闭后转辙机的自动开闭器拉簧将第4排接点拉到第3排接点到3排后三相电路断路
@ -82,4 +158,61 @@ type Zzj struct {
}
// 转辙机状态
var ZzjType = ecs.NewComponentType[Zzj]()
var ZzjStateType = ecs.NewComponentType[ZzjState]()
// 道岔的转辙机引用
type TurnoutZzj struct {
ZzjList []*ecs.Entry
}
func (tz *TurnoutZzj) GetZzj1() *ecs.Entry {
len := len(tz.ZzjList)
if len > 0 {
return tz.ZzjList[0]
}
panic("道岔没有转辙机一")
}
func (tz *TurnoutZzj) GetZzj2() *ecs.Entry {
len := len(tz.ZzjList)
if len > 1 {
return tz.ZzjList[1]
}
panic("道岔没有转辙机二")
}
var TurnoutZzjType = ecs.NewComponentType[TurnoutZzj]()
func GetTurnoutZzj1(entry *ecs.Entry) *ecs.Entry {
if entry.HasComponent(TurnoutZzjType) {
zzjs := TurnoutZzjType.Get(entry)
return zzjs.GetZzj1()
}
panic("道岔没有转辙机引用组件")
}
func GetTurnoutZzj1State(entry *ecs.Entry) *ZzjState {
if entry.HasComponent(TurnoutZzjType) {
zzjs := TurnoutZzjType.Get(entry)
zzj := zzjs.GetZzj1()
return ZzjStateType.Get(zzj)
}
panic("道岔没有转辙机引用组件")
}
func GetTurnoutZzj2(entry *ecs.Entry) *ecs.Entry {
if entry.HasComponent(TurnoutZzjType) {
zzjs := TurnoutZzjType.Get(entry)
return zzjs.GetZzj2()
}
panic("道岔没有转辙机引用组件")
}
func GetTurnoutZzj2State(entry *ecs.Entry) *ZzjState {
if entry.HasComponent(TurnoutZzjType) {
zzjs := TurnoutZzjType.Get(entry)
zzj := zzjs.GetZzj2()
return ZzjStateType.Get(zzj)
}
panic("道岔没有转辙机引用组件")
}

16
entity/dbq.go Normal file
View File

@ -0,0 +1,16 @@
package entity
import (
"joylink.club/ecs"
"joylink.club/rtsssimulation/component"
)
// 创建断相保护器实体
func NewDBQEntity(w ecs.World, uid string, entityMap map[string]*ecs.Entry) *ecs.Entry {
entry, ok := entityMap[uid]
if !ok {
entry = w.Create(component.DBQTag, component.DBQStateType)
entityMap[uid] = entry
}
return entry
}

19
entity/init.go Normal file
View File

@ -0,0 +1,19 @@
package entity
import (
"joylink.club/ecs"
"joylink.club/rtsssimulation/repository"
)
// 仿真实体加载
func Load(w ecs.World, repo *repository.Repository) error {
// 初始化世界数据单例组件
LoadWorldData(w, repo)
// 加载道岔相关实体
err := LoadTurnouts(w)
if err != nil {
return err
}
return err
}

View File

@ -1,25 +1,29 @@
package entity
import (
"github.com/yohamta/donburi"
"strings"
"joylink.club/ecs"
"joylink.club/rtsssimulation/component"
"joylink.club/rtsssimulation/repository"
"joylink.club/rtsssimulation/repository/model/proto"
)
// 创建继电器实体(无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 {
func NewRelayEntity(w ecs.World, relay *repository.Relay, entityMap map[string]*ecs.Entry) *ecs.Entry {
uid := relay.Id()
model := proto.Relay_Model_name[int32(relay.Model())]
entry, ok := entityMap[uid]
if !ok {
entry = w.Create(component.RelayTag, component.UidType, component.RelayDriveType)
entry = w.Create(component.RelayTag, component.UidType, component.RelayDriveType, component.BitStateType)
if strings.Contains(model, "Y") {
entry.AddComponent(component.YjRelayTag)
} else if strings.Contains(model, "W") {
entry.AddComponent(component.WjRelayTag)
}
if strings.Contains(model, "H") {
entry.AddComponent(component.HfRelayTag)
}
entityMap[uid] = entry
}
return entry

View File

@ -9,7 +9,7 @@ import (
)
// 初始化世界数据
func InitWorldData(w ecs.World, repo *repository.Repository) {
func LoadWorldData(w ecs.World, repo *repository.Repository) {
entry := w.Create(component.WorldDataType)
component.WorldDataType.Set(entry, &component.WorldData{
Repo: repo,

View File

@ -2,6 +2,8 @@ package entity
import (
"fmt"
"strings"
"unsafe"
"joylink.club/ecs"
"joylink.club/rtsssimulation/component"
@ -20,7 +22,7 @@ func LoadTurnouts(w ecs.World) error {
case proto.Turnout_ZDJ9_Single:
err = LoadTurnoutZdj9One(w, turnout, entry)
case proto.Turnout_ZDJ9_Double:
err = LoadTurnoutZdj9Two(w, turnout, entry)
err = LoadTurnoutZdj9Two(w, turnout, entry, data.EntityMap)
default:
fmt.Println("id=", turnout.Id(), "的道岔没有转辙机类型")
}
@ -37,8 +39,97 @@ func LoadTurnoutZdj9One(w ecs.World, turnout *repository.Turnout, entry *ecs.Ent
}
// 加载道岔ZDJ9双机转辙机
func LoadTurnoutZdj9Two(w ecs.World, turnout *repository.Turnout, entry *ecs.Entry) error {
panic("unimplemented")
func LoadTurnoutZdj9Two(w ecs.World, turnout *repository.Turnout, entry *ecs.Entry, entityMap map[string]*ecs.Entry) error {
// 加载转辙机
entrys := w.CreateMany(2, component.ZzjStateType, component.TwoPositionTransformType)
// 给道岔添加转辙机引用组件
entry.AddComponent(component.TurnoutZzjType, unsafe.Pointer(&component.TurnoutZzj{
ZzjList: entrys,
}))
// 继电器组合电路
groups := turnout.RelayGroups()
size := len(groups)
if size == 3 { // 有继电器组合,加载继电器实体和电路相关组件
zdj9TwoElectronic := &component.Zdj9TwoElectronic{}
for _, group := range groups {
elecs := group.Components()
if group.Code() == "TDC" {
for _, elec := range elecs {
relay := elec.(*repository.Relay)
if relay.Code() == "DCJ" {
zdj9TwoElectronic.TDC_DCJ = NewRelayEntity(w, relay, entityMap)
} else if relay.Code() == "FCJ" {
zdj9TwoElectronic.TDC_FCJ = NewRelayEntity(w, relay, entityMap)
} else if relay.Code() == "YCJ" {
zdj9TwoElectronic.TDC_YCJ = NewRelayEntity(w, relay, entityMap)
} else if relay.Code() == "ZDBJ" {
zdj9TwoElectronic.TDC_ZDBJ = NewRelayEntity(w, relay, entityMap)
} else if relay.Code() == "ZFBJ" {
zdj9TwoElectronic.TDC_ZFBJ = NewRelayEntity(w, relay, entityMap)
} else {
return fmt.Errorf("未知的道岔[%s]的组合[%s]继电器: %s", turnout.Id(), group.Code(), relay.Code())
}
}
} else if group.Code() == "TDFJ1" {
for _, elec := range elecs {
if elec.Code() == "1DQJ" {
zdj9TwoElectronic.TDFJ1_1DQJ = NewRelayEntity(w, elec.(*repository.Relay), entityMap)
} else if elec.Code() == "BHJ" {
zdj9TwoElectronic.TDFJ1_BHJ = NewRelayEntity(w, elec.(*repository.Relay), entityMap)
} else if elec.Code() == "2DQJ" {
zdj9TwoElectronic.TDFJ1_2DQJ = NewRelayEntity(w, elec.(*repository.Relay), entityMap)
} else if elec.Code() == "1DQJF" {
zdj9TwoElectronic.TDFJ1_1DQJF = NewRelayEntity(w, elec.(*repository.Relay), entityMap)
} else if elec.Code() == "DBQ" { // 断相保护器
zdj9TwoElectronic.TDFJ1_DBQ = NewDBQEntity(w, elec.Id(), entityMap)
} else if elec.Code() == "DBJ" {
zdj9TwoElectronic.TDFJ1_DBJ = NewRelayEntity(w, elec.(*repository.Relay), entityMap)
} else if elec.Code() == "FBJ" {
zdj9TwoElectronic.TDFJ1_FBJ = NewRelayEntity(w, elec.(*repository.Relay), entityMap)
} else if elec.Code() == "QDJ" {
zdj9TwoElectronic.TDFJ1_QDJ = NewRelayEntity(w, elec.(*repository.Relay), entityMap)
} else if elec.Code() == "ZBHJ" {
zdj9TwoElectronic.TDFJ1_ZBHJ = NewRelayEntity(w, elec.(*repository.Relay), entityMap)
} else {
return fmt.Errorf("未知的道岔[%s]的组合[%s]继电器: %s", turnout.Id(), group.Code(), elec.Code())
}
}
} else if group.Code() == "TDFJ2" {
for _, elec := range elecs {
if elec.Code() == "1DQJ" {
zdj9TwoElectronic.TDFJ2_1DQJ = NewRelayEntity(w, elec.(*repository.Relay), entityMap)
} else if elec.Code() == "BHJ" {
zdj9TwoElectronic.TDFJ2_BHJ = NewRelayEntity(w, elec.(*repository.Relay), entityMap)
} else if elec.Code() == "2DQJ" {
zdj9TwoElectronic.TDFJ2_2DQJ = NewRelayEntity(w, elec.(*repository.Relay), entityMap)
} else if elec.Code() == "1DQJF" {
zdj9TwoElectronic.TDFJ2_1DQJF = NewRelayEntity(w, elec.(*repository.Relay), entityMap)
} else if elec.Code() == "DBQ" { // 断相保护器
zdj9TwoElectronic.TDFJ2_DBQ = NewDBQEntity(w, elec.Id(), entityMap)
} else if elec.Code() == "DBJ" {
zdj9TwoElectronic.TDFJ2_DBJ = NewRelayEntity(w, elec.(*repository.Relay), entityMap)
} else if elec.Code() == "FBJ" {
zdj9TwoElectronic.TDFJ2_FBJ = NewRelayEntity(w, elec.(*repository.Relay), entityMap)
} else {
return fmt.Errorf("未知的道岔[%s]的组合[%s]继电器: %s", turnout.Id(), group.Code(), elec.Code())
}
}
} else {
return fmt.Errorf("未知的道岔[%s]组合类型:%s", turnout.Id(), group.Code())
}
}
nils := zdj9TwoElectronic.CheckNilReference()
if len(nils) > 0 {
return fmt.Errorf("未知的道岔[%s]ZDJ9双机继电器组合数据异常,缺失:[%s]", turnout.Id(), strings.Join(nils, ","))
} else {
// 给道岔添加电路组件
entry.AddComponent(component.Zdj9TwoElectronicType, unsafe.Pointer(zdj9TwoElectronic))
}
} else if size > 0 && size < 3 {
fmt.Println("id=", turnout.Id(), "的道岔是ZDJ9双机牵引,但继电器组合类型少于3个(应为TDC、TDFJ1、TDFJ2三个组合)")
}
return nil
}
// 新建道岔实体

View File

@ -1,7 +1,11 @@
package main
import "joylink.club/rtsssimulation/examples/test1/sjzdj9"
import (
"fmt"
"joylink.club/rtsssimulation/repository/model/proto"
)
func main() {
sjzdj9.Test()
fmt.Println(proto.Relay_Model_name[int32(proto.Relay_JPXC_1700)])
}

View File

@ -10,18 +10,33 @@ import (
// 道岔功能接口
// 驱动道岔定操相关继电器
func DriveTurnoutDCRelay(w ecs.World, id string, on bool) {
func driveTurnoutZzj(w ecs.World, id string, dc bool, on bool) {
w.Execute(func() {
wd := entity.GetWorldData(w)
entry, ok := wd.EntityMap[id]
if ok {
if entry.HasComponent(component.Zdj9TwoElectronicType) {
if entry.HasComponent(component.Zdj9TwoElectronicType) { // 有电路,驱动继电器
zdj9 := component.Zdj9TwoElectronicType.Get(entry)
ycj := component.RelayDriveType.Get(zdj9.TDC_YCJ)
dcj := component.RelayDriveType.Get(zdj9.TDC_DCJ)
fcj := component.RelayDriveType.Get(zdj9.TDC_FCJ)
ycj.Td = on
if dc {
dcj.Td = on
} else {
fcj.Td = on
}
} else { // 无电路,直接驱动转辙机
tz := component.TurnoutZzjType.Get(entry)
for _, zzj := range tz.ZzjList {
state := component.ZzjStateType.Get(zzj)
state.Td = on
if dc {
state.Dw = true
} else {
state.Dw = false
}
}
}
} else {
fmt.Println("未找到id=", id, "的道岔")
@ -29,21 +44,22 @@ func DriveTurnoutDCRelay(w ecs.World, id string, on bool) {
})
}
// 驱动道岔反操相关继电器
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
// 驱动道岔转辙机定操启动
func DriveTurnoutDCOn(w ecs.World, id string) {
driveTurnoutZzj(w, id, true, true)
}
} else {
fmt.Println("未找到id=", id, "的道岔")
// 驱动道岔转辙机定操停止
func DriveTurnoutDCOff(w ecs.World, id string) {
driveTurnoutZzj(w, id, true, false)
}
})
// 驱动道岔转辙机反操启动
func DriveTurnoutFCOn(w ecs.World, id string) {
driveTurnoutZzj(w, id, false, true)
}
// 驱动道岔转辙机反操停止
func DriveTurnoutFCOff(w ecs.World, id string) {
driveTurnoutZzj(w, id, false, false)
}

16
init.go
View File

@ -1,3 +1,19 @@
package rtss_simulation
import (
"joylink.club/ecs"
"joylink.club/rtsssimulation/entity"
"joylink.club/rtsssimulation/repository"
)
const (
// 仿真循环间隔单位ms
RtssSimulationTick = 20
)
// 初始化仿真
func NewSimulation(repo *repository.Repository) ecs.World {
w := ecs.NewWorld(RtssSimulationTick)
entity.Load(w, repo)
return w
}

View File

@ -2,6 +2,12 @@ package repository
import "joylink.club/rtsssimulation/repository/model/proto"
// 组合的电子元件
type IGroupedElectronicComponent interface {
Identity
Code() string
}
// Relay 继电器
type Relay struct {
Identity
@ -31,14 +37,14 @@ func (r *Relay) Model() proto.Relay_Model {
// ElectronicComponentGroup 电子元件组合
type ElectronicComponentGroup struct {
code string
components []Identity
components []IGroupedElectronicComponent
}
func (r *ElectronicComponentGroup) Code() string {
return r.code
}
func (r *ElectronicComponentGroup) Components() []Identity {
func (r *ElectronicComponentGroup) Components() []IGroupedElectronicComponent {
return r.components
}
@ -48,6 +54,10 @@ type PhaseFailureProtector struct {
code string
}
func (dbq *PhaseFailureProtector) Code() string {
return dbq.code
}
func newPhaseFailureProtector(id string, code string) *PhaseFailureProtector {
return &PhaseFailureProtector{
Identity: identity{

View File

@ -262,7 +262,7 @@ func buildTurnoutRelationShip(source *proto.Repository, repo *Repository) error
}
//关联继电器组
for _, group := range protoData.ElectronicComponentGroups {
var components []Identity
var components []IGroupedElectronicComponent
for _, id := range group.GetComponentIds() {
if relay := repo.relayMap[id]; relay != nil {
components = append(components, relay)

View File

@ -16,7 +16,7 @@ type ZDJ9TwoDragSys struct {
func NewZdj9TwoDragSys() *ZDJ9TwoDragSys {
return &ZDJ9TwoDragSys{
query: ecs.NewQuery(filter.Contains(component.Zdj9TwoElectronicType, component.TwoPositionTransformType)),
query: ecs.NewQuery(filter.Contains(component.Zdj9TwoElectronicType, component.TurnoutZzjType)),
}
}
@ -41,7 +41,7 @@ func (zdj9 *ZDJ9TwoDragSys) Update(w ecs.World) {
// 切断继电器
zdj9.exciteM1_TDFJ_QDJ(w, entry, elec)
// 定表/反表继电器
zdj9.exciteM1_TDFJ1_DFBJ(elec)
zdj9.exciteM1_TDFJ1_DFBJ(entry, elec)
// 转辙机二机电路相关动作
// 1DQJ励磁状态控制
@ -55,7 +55,7 @@ func (zdj9 *ZDJ9TwoDragSys) Update(w ecs.World) {
// TDFJ1_BHJ励磁状态控制
zdj9.exciteM2_TDFJ_BHJ(elec)
// 定表/反表继电器
zdj9.exciteM2_TDFJ1_DFBJ(elec)
zdj9.exciteM2_TDFJ1_DFBJ(entry, elec)
// 总定表/反表继电器
zdj9.exciteZDFBJ(elec)
@ -94,10 +94,10 @@ func (zdj9 *ZDJ9TwoDragSys) exciteZDFBJ(elec *component.Zdj9TwoElectronic) {
// 二极管整流电路为继电器励磁电路提供半波整流电源
// 转辙机一定表/反表继电器控制
func (zdj9 *ZDJ9TwoDragSys) exciteM1_TDFJ1_DFBJ(elec *component.Zdj9TwoElectronic) {
func (zdj9 *ZDJ9TwoDragSys) exciteM1_TDFJ1_DFBJ(entry *ecs.Entry, elec *component.Zdj9TwoElectronic) {
_1dqj := component.BitStateType.Get(elec.TDFJ1_1DQJ)
_2dqj := component.BitStateType.Get(elec.TDFJ1_2DQJ)
zzj := component.ZzjType.Get(elec.Zzj1)
zzj := component.GetTurnoutZzj1State(entry)
dbj_drive := component.RelayDriveType.Get(elec.TDFJ1_DBJ)
fbj_drive := component.RelayDriveType.Get(elec.TDFJ1_FBJ)
// 默认BB道岔表示变压器正常
@ -122,10 +122,10 @@ func (zdj9 *ZDJ9TwoDragSys) exciteM1_TDFJ1_DFBJ(elec *component.Zdj9TwoElectroni
}
// 转辙机二定表/反表继电器控制
func (zdj9 *ZDJ9TwoDragSys) exciteM2_TDFJ1_DFBJ(elec *component.Zdj9TwoElectronic) {
func (zdj9 *ZDJ9TwoDragSys) exciteM2_TDFJ1_DFBJ(entry *ecs.Entry, elec *component.Zdj9TwoElectronic) {
_1dqj := component.BitStateType.Get(elec.TDFJ2_1DQJ)
_2dqj := component.BitStateType.Get(elec.TDFJ2_2DQJ)
zzj := component.ZzjType.Get(elec.Zzj2)
zzj := component.GetTurnoutZzj2State(entry)
dbj_drive := component.RelayDriveType.Get(elec.TDFJ2_DBJ)
fbj_drive := component.RelayDriveType.Get(elec.TDFJ2_FBJ)
// 默认BB道岔表示变压器正常
@ -206,8 +206,8 @@ func (zdj9 *ZDJ9TwoDragSys) exciteM1_TDFJ_DBQ(w ecs.World, entry *ecs.Entry, ele
_1dqj := component.BitStateType.Get(elec.TDFJ1_1DQJ)
_1dqjf := component.BitStateType.Get(elec.TDFJ1_1DQJF)
_2dqj := component.BitStateType.Get(elec.TDFJ1_2DQJ)
zzj := component.ZzjType.Get(elec.Zzj1)
dbq := component.DBQType.Get(elec.TDFJ1_DBQ)
zzj := component.GetTurnoutZzj1State(entry)
dbq := component.DBQStateType.Get(elec.TDFJ1_DBQ)
if dbq.Td { // 通电
if !(_1dqj.Val && _1dqjf.Val && !zzj.JD12 && !_2dqj.Val) &&
!(_1dqj.Val && _1dqjf.Val && zzj.JD34 && _2dqj.Val) { // 断开
@ -228,8 +228,8 @@ func (zdj9 *ZDJ9TwoDragSys) exciteM2_TDFJ_DBQ(w ecs.World, entry *ecs.Entry, ele
_1dqj := component.BitStateType.Get(elec.TDFJ2_1DQJ)
_1dqjf := component.BitStateType.Get(elec.TDFJ2_1DQJF)
_2dqj := component.BitStateType.Get(elec.TDFJ2_2DQJ)
zzj := component.ZzjType.Get(elec.Zzj2)
dbq := component.DBQType.Get(elec.TDFJ2_DBQ)
zzj := component.GetTurnoutZzj2State(entry)
dbq := component.DBQStateType.Get(elec.TDFJ2_DBQ)
if dbq.Td { // 通电
if !(_1dqj.Val && _1dqjf.Val && !zzj.JD12 && !_2dqj.Val) &&
!(_1dqj.Val && _1dqjf.Val && zzj.JD34 && _2dqj.Val) { // 断开
@ -247,7 +247,7 @@ func (zdj9 *ZDJ9TwoDragSys) exciteM2_TDFJ_DBQ(w ecs.World, entry *ecs.Entry, ele
// 转辙机一TDFJ_BHJ保护继电器励磁状态控制
func (zdj9 *ZDJ9TwoDragSys) exciteM1_TDFJ_BHJ(elec *component.Zdj9TwoElectronic) {
dbq := component.DBQType.Get(elec.TDFJ1_DBQ)
dbq := component.DBQStateType.Get(elec.TDFJ1_DBQ)
bhj := component.RelayDriveType.Get(elec.TDFJ1_BHJ)
if !bhj.Td && dbq.Dzkg { // BHJ励磁电路导通
bhj.Td = true
@ -258,7 +258,7 @@ func (zdj9 *ZDJ9TwoDragSys) exciteM1_TDFJ_BHJ(elec *component.Zdj9TwoElectronic)
// 转辙机二TDFJ_BHJ保护继电器励磁状态控制
func (zdj9 *ZDJ9TwoDragSys) exciteM2_TDFJ_BHJ(elec *component.Zdj9TwoElectronic) {
dbq := component.DBQType.Get(elec.TDFJ2_DBQ)
dbq := component.DBQStateType.Get(elec.TDFJ2_DBQ)
bhj := component.RelayDriveType.Get(elec.TDFJ2_BHJ)
if !bhj.Td && dbq.Dzkg { // BHJ励磁电路导通
bhj.Td = true

View File

@ -14,14 +14,14 @@ type DBQSys struct {
func NewDBQSys() *DBQSys {
return &DBQSys{
query: ecs.NewQuery(filter.Contains(component.DBQTag, component.DBQType)),
query: ecs.NewQuery(filter.Contains(component.DBQTag, component.DBQStateType)),
}
}
func (q *DBQSys) Update(w ecs.World) {
q.query.Each(w, func(entry *ecs.Entry) {
// 电路是否通电
dbq := component.DBQType.Get(entry)
dbq := component.DBQStateType.Get(entry)
if dbq.Td && !dbq.Dzkg { // 通电但开关未开,启动
dbq.Dzkg = true
if entry.HasComponent(component.CounterType) {

View File

@ -13,7 +13,7 @@ type ZzjSys struct {
func NewZzjSys() *ZzjSys {
return &ZzjSys{
query: ecs.NewQuery(filter.Contains(component.ZzjType, component.TwoPositionTransformType)),
query: ecs.NewQuery(filter.Contains(component.ZzjStateType, component.TwoPositionTransformType)),
}
}
@ -27,7 +27,7 @@ const (
func (z *ZzjSys) Update(w ecs.World) {
z.query.Each(w, func(entry *ecs.Entry) {
zzj := component.ZzjType.Get(entry)
zzj := component.ZzjStateType.Get(entry)
tp := component.TwoPositionTransformType.Get(entry)
if zzj.Td { // 通电
if tp.Speed == 0 && tp.Pos > consts.TwoPosMin && zzj.Dw { // 转到定位