diff --git a/entity/iscs_bas.go b/entity/iscs_bas.go index 4d7cf48..2904130 100644 --- a/entity/iscs_bas.go +++ b/entity/iscs_bas.go @@ -147,6 +147,7 @@ func NewFanEntity(w ecs.World, id string, fanType proto.Fan_Type) *ecs.Entry { if !ok { e := w.Entry(w.Create(component.UidType, component.FanDeviceType, component.DeviceExceptionType)) component.UidType.SetValue(e, component.Uid{Id: id}) + component.FanDeviceType.Set(e, &component.FanDevice{Speed: 0, Forward: true, Fs: component.Off}) // switch fanType { case proto.Fan_CommonFan: diff --git a/sys/bind.go b/sys/bind.go index ef4de16..22eb1d7 100644 --- a/sys/bind.go +++ b/sys/bind.go @@ -62,6 +62,7 @@ func bindIscsSystem(w ecs.World) { iscs_sys.NewEarthingDeviceSystem(), // iscs_sys.NewNetworkSwitchSystem(), - iscs_sys.NewWireCabinetSystem()) + iscs_sys.NewWireCabinetSystem(), + iscs_sys.NewFanSystem()) } diff --git a/sys/iscs_sys/iscs_bas_fan.go b/sys/iscs_sys/iscs_bas_fan.go index c1442f1..500462b 100644 --- a/sys/iscs_sys/iscs_bas_fan.go +++ b/sys/iscs_sys/iscs_bas_fan.go @@ -11,6 +11,7 @@ type FanSystem struct { query *ecs.Query } +// NewFanSystem 风机系统 func NewFanSystem() *FanSystem { return &FanSystem{ query: ecs.NewQuery(filter.Contains(component.UidType, component.FanDeviceType, component.DeviceExceptionType)), @@ -23,48 +24,50 @@ func (s *FanSystem) Update(w ecs.World) { // speed := fan.Speed + s.calculateAc(fan, entry)*float32(w.Tick()) // - switch { - case entry.HasComponent(component.CommonFanTag): //一般风机(3000 r/min) - { - if speed > 3000 { - fan.Speed = 3000 - } - } - case entry.HasComponent(component.SoftStartFanTag): //软启风机(100 r/min) - { - if speed > 100 { - fan.Speed = 100 - } - } - case entry.HasComponent(component.HighLowSpeedFanTag): //双速风机(Low 2000 r/min ; High 7000 r/min) - { - highMode := component.FanHighLowSpeedModeType.Get(entry).HighMode - if highMode { //高速模式 - if speed > 7000 { - fan.Speed = 7000 - } - } else { //低速模式 - if speed > 2000 { - fan.Speed = 2000 - } - } - } - 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 { - fan.Speed = SPEED - } - } - } - // - if speed < 0 { + if speed <= 0 { fan.Speed = 0 + } else { + switch { + case entry.HasComponent(component.CommonFanTag): //一般风机(3000 r/min) + { + if speed > 3000 { + speed = 3000 + } + } + case entry.HasComponent(component.SoftStartFanTag): //软启风机(100 r/min) + { + if speed > 100 { + speed = 100 + } + } + 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 + } + } + } + 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 + } + } + } + // + fan.Speed = speed } }) } @@ -79,16 +82,14 @@ func (s *FanSystem) calculateAc(fan *component.FanDevice, fanEntry *ecs.Entry) f softStart = component.FanSoftStartUnitType.Get(fanEntry).SoftStart } // - if fan.Fs.Off() { //电源关闭 - ac = -4 //4 r/ms - } else { - if fan.Fs.On() { //电源---正转或反转启动 - if softStart { - ac = 0.02 // r/ms - } else { - ac = 1.5 // r/ms - } + if fan.Fs.On() { //电源---正转或反转启动 + if softStart { + ac = 0.02 // r/ms + } else { + ac = 1.5 // r/ms } + } else { //电源关闭 + ac = -3 // r/ms } return ac }