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

43 lines
1.0 KiB
Go

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{
query: ecs.NewQuery(filter.Contains(component.AsdMotorStateType, component.TwoPositionTransformType)),
}
}
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)
twoPosition := component.TwoPositionTransformType.Get(entry)
if psdMotorState.TD {
if psdMotorState.KM {
twoPosition.Speed = speed
if twoPosition.Pos == consts.TwoPosMax { //开门到位后断电
psdMotorState.TD = false
}
} else {
twoPosition.Speed = -speed
if twoPosition.Pos == consts.TwoPosMin { //关门到位后断电
psdMotorState.TD = false
}
}
}
//门关继电器状态
psdMotorState.MG = twoPosition.Pos == consts.TwoPosMin
})
}