2023-12-11 17:16:51 +08:00
|
|
|
|
package iscs_sys
|
2023-12-26 10:59:07 +08:00
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"joylink.club/ecs"
|
|
|
|
|
"joylink.club/ecs/filter"
|
|
|
|
|
"joylink.club/rtsssimulation/component"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
// FanSystem 风机
|
|
|
|
|
type FanSystem struct {
|
|
|
|
|
query *ecs.Query
|
|
|
|
|
}
|
|
|
|
|
|
2023-12-26 13:36:15 +08:00
|
|
|
|
// NewFanSystem 风机系统
|
2023-12-26 10:59:07 +08:00
|
|
|
|
func NewFanSystem() *FanSystem {
|
|
|
|
|
return &FanSystem{
|
|
|
|
|
query: ecs.NewQuery(filter.Contains(component.UidType, component.FanDeviceType, component.DeviceExceptionType)),
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
func (s *FanSystem) Update(w ecs.World) {
|
|
|
|
|
s.query.Each(w, func(entry *ecs.Entry) {
|
|
|
|
|
fan := component.FanDeviceType.Get(entry)
|
|
|
|
|
fan.Forward = fan.Fs.OnForward()
|
|
|
|
|
//
|
2023-12-26 13:13:30 +08:00
|
|
|
|
speed := fan.Speed + s.calculateAc(fan, entry)*float32(w.Tick())
|
|
|
|
|
//
|
2023-12-26 13:36:15 +08:00
|
|
|
|
if speed <= 0 {
|
|
|
|
|
fan.Speed = 0
|
|
|
|
|
} else {
|
|
|
|
|
switch {
|
|
|
|
|
case entry.HasComponent(component.CommonFanTag): //一般风机(3000 r/min)
|
|
|
|
|
{
|
|
|
|
|
if speed > 3000 {
|
|
|
|
|
speed = 3000
|
|
|
|
|
}
|
2023-12-26 13:13:30 +08:00
|
|
|
|
}
|
2023-12-26 13:36:15 +08:00
|
|
|
|
case entry.HasComponent(component.SoftStartFanTag): //软启风机(100 r/min)
|
|
|
|
|
{
|
|
|
|
|
if speed > 100 {
|
|
|
|
|
speed = 100
|
2023-12-26 13:13:30 +08:00
|
|
|
|
}
|
2023-12-26 13:36:15 +08:00
|
|
|
|
}
|
|
|
|
|
case entry.HasComponent(component.HighLowSpeedFanTag): //双速风机(Low 2000 r/min ; High 7000 r/min)
|
|
|
|
|
{
|
|
|
|
|
highMode := component.FanHighLowSpeedModeType.Get(entry).HighMode
|
|
|
|
|
if highMode { //高速模式
|
|
|
|
|
if speed > 7000 {
|
|
|
|
|
speed = 7000
|
|
|
|
|
}
|
|
|
|
|
} else { //低速模式
|
|
|
|
|
if speed > 2000 {
|
|
|
|
|
speed = 2000
|
|
|
|
|
}
|
2023-12-26 13:13:30 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
2023-12-26 13:36:15 +08:00
|
|
|
|
case entry.HasComponent(component.FcBypassFanTag):
|
|
|
|
|
//变频旁路风机
|
|
|
|
|
//电机转速与变频器频率关系 计算公式:n=60f/p(其中n是同步转速,f是频率,P是磁极对数)
|
|
|
|
|
//变频器的额定输出频率一般为0-100HZ
|
|
|
|
|
//假设风机磁极对数为1,则n=60f
|
|
|
|
|
{
|
|
|
|
|
fcUnit := component.FanFcUnitType.Get(entry)
|
|
|
|
|
SPEED := 60 * float32(fcUnit.F) //当前频率目标转速
|
|
|
|
|
if speed > SPEED {
|
|
|
|
|
speed = SPEED
|
|
|
|
|
}
|
2023-12-26 13:13:30 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
2023-12-26 13:36:15 +08:00
|
|
|
|
//
|
|
|
|
|
fan.Speed = speed
|
2023-12-26 13:13:30 +08:00
|
|
|
|
}
|
2023-12-26 10:59:07 +08:00
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 计算风机加速度
|
|
|
|
|
func (s *FanSystem) calculateAc(fan *component.FanDevice, fanEntry *ecs.Entry) float32 {
|
2023-12-26 11:06:34 +08:00
|
|
|
|
//大于0加速,小于0减速
|
2023-12-26 10:59:07 +08:00
|
|
|
|
ac := float32(0)
|
2023-12-26 13:13:30 +08:00
|
|
|
|
//
|
|
|
|
|
softStart := false
|
|
|
|
|
if fanEntry.HasComponent(component.FanSoftStartUnitType) {
|
|
|
|
|
softStart = component.FanSoftStartUnitType.Get(fanEntry).SoftStart
|
|
|
|
|
}
|
|
|
|
|
//
|
2023-12-26 13:36:15 +08:00
|
|
|
|
if fan.Fs.On() { //电源---正转或反转启动
|
|
|
|
|
if softStart {
|
|
|
|
|
ac = 0.02 // r/ms
|
|
|
|
|
} else {
|
|
|
|
|
ac = 1.5 // r/ms
|
2023-12-26 10:59:07 +08:00
|
|
|
|
}
|
2023-12-26 13:36:15 +08:00
|
|
|
|
} else { //电源关闭
|
|
|
|
|
ac = -3 // r/ms
|
2023-12-26 10:59:07 +08:00
|
|
|
|
}
|
|
|
|
|
return ac
|
|
|
|
|
}
|