计轴区段ecs

This commit is contained in:
xzb 2023-10-23 16:08:05 +08:00
parent 365f5a50d9
commit 68e270779c
2 changed files with 59 additions and 26 deletions

View File

@ -26,26 +26,22 @@ type AxleSectionDevice struct {
Rjt bool
//计轴区段内车轴数
Count int16
//true-计轴系统正在执行直接复位操作
Drst bool
//true-计轴系统正在执行直接预复位操作
Pdrst bool
//true-计轴区段内车轴数由大于零到零产生的count下降沿脉冲用于与检测压道车完全通过该计轴区段
CountTo0Pulse bool
}
// AxleSectionDeviceDrive 计轴区段设备驱动
type AxleSectionDeviceDrive struct {
//true-计轴直接复位
//计轴的轮对计数清零,区段转换为空闲状态
DrstTd bool
Drst bool
//true-计轴预复位
//将计轴的轮对计数清零,但是区段不会立即变成空闲区段,而是处于一种“占用”状态,在压道车通过之后确认区段空闲且计轴正常后,区段转换为空闲状态
PdrstTd bool
Pdrst bool
//true-计轴系统正在执行直接预复位操作
DoingPdrst bool
//true-计轴区段内列车正常通过车轴数由大于零到零产生的count下降沿脉冲用于与检测压道车完全通过该计轴区段
CountTrainOutPulse bool
CountTrainInPulse bool
//Count变化前的数据
CountLast int16
}
var (
AxleSectionStateType = ecs.NewComponentType[AxleSectionState]()
AxleSectionDeviceType = ecs.NewComponentType[AxleSectionDevice]()
AxleSectionDeviceDriveType = ecs.NewComponentType[AxleSectionDeviceDrive]()
AxleSectionStateType = ecs.NewComponentType[AxleSectionState]()
AxleSectionDeviceType = ecs.NewComponentType[AxleSectionDevice]()
)

View File

@ -14,21 +14,23 @@ type AxleSectionSystem struct {
func NewAxleSectionSystem() *AxleSectionSystem {
return &AxleSectionSystem{
query: ecs.NewQuery(filter.Contains(component.AxleSectionStateType, component.AxleSectionDeviceType, component.AxleSectionDeviceDriveType)),
query: ecs.NewQuery(filter.Contains(component.AxleSectionStateType, component.AxleSectionDeviceType)),
}
}
func (s *AxleSectionSystem) Update(w ecs.World) {
s.query.Each(w, func(entry *donburi.Entry) {
s.calculateAxleCount(entry)
s.calculateDRST(entry)
s.calculatePDRST(entry)
s.calculateDrst(entry)
s.calculatePdrst(entry)
s.calculateSectionState(entry)
s.calculateAxleCount(entry)
})
}
// 计算计轴区段内车轴数
// 目前通过查看有哪些车在该计轴区段内实现,定性
func (s *AxleSectionSystem) calculateAxleCount(entry *donburi.Entry) {
//收集该计轴区段上的车轴数
//device.Count = 该计轴区段上当前车轴数
}
@ -36,17 +38,52 @@ func (s *AxleSectionSystem) calculateAxleCount(entry *donburi.Entry) {
func (s *AxleSectionSystem) calculateSectionState(entry *donburi.Entry) {
state := component.AxleSectionStateType.Get(entry)
device := component.AxleSectionDeviceType.Get(entry)
isIdle := device.Count <= 0 && device.Pdrst //区段空闲:区段内车轴数为零且没有预复位
isIdle := device.Count <= 0 && !device.DoingPdrst //区段空闲:区段内车轴数为零且没有预复位
state.Clr = isIdle
state.Occ = !isIdle
}
// 直接复位
func (s *AxleSectionSystem) calculateDRST(entry *donburi.Entry) {
// 计轴直接复位
func (s *AxleSectionSystem) calculateDrst(entry *donburi.Entry) {
device := component.AxleSectionDeviceType.Get(entry)
if device.Drst && !device.Rjo && !device.Rjt { //直接复位且没有拒绝原因
device.Count = 0
device.CountLast = 0
device.DoingPdrst = false
device.CountTrainOutPulse = false
device.CountTrainInPulse = false
}
}
// 预复位
func (s *AxleSectionSystem) calculatePDRST(entry *donburi.Entry) {
// 计轴预复位
func (s *AxleSectionSystem) calculatePdrst(entry *donburi.Entry) {
device := component.AxleSectionDeviceType.Get(entry)
if device.Pdrst && !device.Rjo && !device.Rjt && !device.DoingPdrst { //预复位且没有拒绝原因
device.Count = 0
device.CountLast = 0
device.DoingPdrst = true
device.CountTrainOutPulse = false
device.CountTrainInPulse = false
}
//压道车计算
if !device.CountTrainInPulse { //计算压道车进入该计轴区段
device.CountTrainInPulse = device.CountLast <= 0 && device.Count > 0
}
if !device.CountTrainOutPulse { //计算压道车离开该计轴区段
device.CountTrainOutPulse = device.CountLast > 0 && device.Count <= 0
}
device.CountLast = device.Count
//压道车通过该计轴区段,完成计轴预复位
if device.CountTrainInPulse && device.CountTrainOutPulse {
device.DoingPdrst = false
}
}
// 复位回复运算
func (s *AxleSectionSystem) calculateHf(entry *donburi.Entry) {
device := component.AxleSectionDeviceType.Get(entry)
state := component.AxleSectionStateType.Get(entry)
device.Rac = device.Drst || device.Pdrst
device.Rjo = state.Clr && !state.Occ //空闲拒绝复位
device.Rjt = false // 技术原因拒绝复位
}