diff --git a/component/iscs_bas_fan.go b/component/iscs_bas_fan.go index 280c51a..692163f 100644 --- a/component/iscs_bas_fan.go +++ b/component/iscs_bas_fan.go @@ -5,13 +5,39 @@ import "joylink.club/ecs" // FanDevice 风机设备 // 正转即顺时针转-排风;反转即逆时针转-进风 type FanDevice struct { - Speed uint16 //风机转速,r/min - Forward bool //true-正转;false-反转 + Speed float32 //风机转速,r/min + Forward bool //true-正转;false-反转 + Fs FanSwitch //风机开关 +} + +// FanSwitch 风机电源开关定义 +type FanSwitch uint8 + +const ( + Off FanSwitch = iota + OnForward //正转 + OnReverse //反转 +) + +func (f *FanSwitch) Off() bool { + return *f == Off +} +func (f *FanSwitch) OnForward() bool { + return *f == OnForward +} +func (f *FanSwitch) OnReverse() bool { + return *f == OnReverse +} +func (f *FanSwitch) On() bool { + return *f == OnReverse || *f == OnForward } // FanFcUnit 风机变频器 +// 电机转速与变频器频率关系 计算公式:n=60f/p(其中n是同步转速,f是频率,P是磁极对数) +// 变频器的额定输出频率一般为0-100HZ type FanFcUnit struct { - Fc bool //true-变频器已开启 + Fc bool //true-变频器已开启 + F uint16 //变频器频率(0-100HZ) } // FanBypassUnit 风机旁路装置 diff --git a/sys/iscs_sys/iscs_bas_fan.go b/sys/iscs_sys/iscs_bas_fan.go index 2c15227..0190ca3 100644 --- a/sys/iscs_sys/iscs_bas_fan.go +++ b/sys/iscs_sys/iscs_bas_fan.go @@ -1 +1,87 @@ package iscs_sys + +import ( + "joylink.club/ecs" + "joylink.club/ecs/filter" + "joylink.club/rtsssimulation/component" +) + +// FanSystem 风机 +type FanSystem struct { + query *ecs.Query +} + +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() + // + }) +} + +// 计算风机加速度 +func (s *FanSystem) calculateAc(fan *component.FanDevice, fanEntry *ecs.Entry) float32 { + ac := float32(0) + if fan.Fs.Off() { //电源关闭 + ac = -4 //4 r/ms + } else { + softStart := false + if fanEntry.HasComponent(component.FanSoftStartUnitType) { + softStart = component.FanSoftStartUnitType.Get(fanEntry).SoftStart + } + if fan.Fs.On() { //电源---正转或反转启动 + if softStart { + ac = 0.02 // r/ms + } else { + ac = 1.5 // r/ms + } + } + } + //一般风机(3000 r/min) + if fanEntry.HasComponent(component.CommonFanTag) { + if fan.Speed > 3000 && ac > 0 { + ac = -1 + } + return ac + } + //软启风机(100 r/min) + if fanEntry.HasComponent(component.SoftStartFanTag) { + if fan.Speed > 100 && ac > 0 { + ac = -1 + } + return ac + } + //双速风机(Low 2000 r/min ; High 7000 r/min) + if fanEntry.HasComponent(component.HighLowSpeedFanTag) { + highMode := component.FanHighLowSpeedModeType.Get(fanEntry).HighMode + if highMode { //高速模式 + if fan.Speed > 7000 && ac > 0 { + ac = -1 + } + } else { //低速模式 + if fan.Speed > 2000 && ac > 0 { + ac = -1 + } + } + return ac + } + //变频旁路风机 + //电机转速与变频器频率关系 计算公式:n=60f/p(其中n是同步转速,f是频率,P是磁极对数) + //变频器的额定输出频率一般为0-100HZ + //假设风机磁极对数为1,则n=60f + if fanEntry.HasComponent(component.FcBypassFanTag) { + fcUnit := component.FanFcUnitType.Get(fanEntry) + if fcUnit.Fc { + //SPEED := 60 * fcUnit.F + + } else { + + } + } + return ac +}