rts-sim-module/sys/device_sys/asd.go

69 lines
1.7 KiB
Go
Raw Normal View History

package device_sys
import (
"joylink.club/ecs"
"joylink.club/ecs/filter"
"joylink.club/rtsssimulation/component"
"joylink.club/rtsssimulation/consts"
)
type AsdSys struct {
query *ecs.Query
}
func NewAsdSys() *AsdSys {
return &AsdSys{
2023-12-29 17:48:57 +08:00
query: ecs.NewQuery(filter.Contains(component.AsdMotorStateType, component.FixedPositionTransformType)),
}
}
func (s *AsdSys) Update(world ecs.World) {
var speed int32 = consts.TwoPosMax / 4
s.query.Each(world, func(entry *ecs.Entry) {
//设置两位置转换速度
psdMotorState := component.AsdMotorStateType.Get(entry)
2023-12-29 17:48:57 +08:00
twoPosition := component.FixedPositionTransformType.Get(entry)
asdState := component.AsdStateType.Get(entry)
pos := twoPosition.Pos
2023-11-06 10:52:57 +08:00
if entry.HasComponent(component.AsdCannotOpenTag) {
pos = consts.TwoPosMin
speed = 0
2023-11-06 13:53:59 +08:00
psdMotorState.TD = false
2023-11-06 10:52:57 +08:00
} else if entry.HasComponent(component.AsdCannotCloseTag) {
pos = consts.TwoPosMax
speed = 0
2023-11-06 13:53:59 +08:00
psdMotorState.TD = false
2023-11-06 10:52:57 +08:00
} else if psdMotorState.TD {
if psdMotorState.KM {
2023-11-06 10:52:57 +08:00
if pos == consts.TwoPosMax {
psdMotorState.TD = false
2023-11-06 10:52:57 +08:00
twoPosition.Speed = 0
} else {
twoPosition.Speed = speed
}
} else {
if pos == consts.TwoPosMin { //关门到位后断电
psdMotorState.TD = false
2023-11-06 10:52:57 +08:00
twoPosition.Speed = 0
} else {
twoPosition.Speed = -speed
}
}
}
//门关继电器状态
psdMotorState.MG = pos == consts.TwoPosMin
asdState.Mgj = psdMotorState.MG
//滑动门状态
if pos == consts.TwoPosMax {
asdState.Kmdw = true
asdState.Gmdw = false
} else if pos == consts.TwoPosMin {
asdState.Kmdw = false
asdState.Gmdw = true
} else {
asdState.Kmdw = false
asdState.Gmdw = false
}
})
}