iscs bas 大系统-阀门

This commit is contained in:
xzb 2023-12-27 13:35:33 +08:00
parent ead7947345
commit a922cf8133
2 changed files with 19 additions and 6 deletions

View File

@ -21,14 +21,19 @@ func main() {
protoRepo.Fans = append(protoRepo.Fans, &proto.Fan{Id: "fan3", FanType: proto.Fan_SoftStartFan})
protoRepo.Fans = append(protoRepo.Fans, &proto.Fan{Id: "fan4", FanType: proto.Fan_HighLowSpeedFan})
//
protoRepo.Valves = append(protoRepo.Valves, &proto.Valve{Id: "valve1", ValveType: proto.Valve_ElectricControlValve})
protoRepo.Valves = append(protoRepo.Valves, &proto.Valve{Id: "valve2", ValveType: proto.Valve_ElectricAirValve})
protoRepo.Valves = append(protoRepo.Valves, &proto.Valve{Id: "valve3", ValveType: proto.Valve_CombinationAirValve})
protoRepo.Valves = append(protoRepo.Valves, &proto.Valve{Id: "valve4", ValveType: proto.Valve_ElectricButterflyValve})
//
repo, _ := repository.BuildRepository(protoRepo)
sim, _ := newIscsSimulation(repo)
sim.StartUp()
time.Sleep(2 * time.Second)
fi.MotorOperate(sim, "fan2", fi.FiMsOnForward, 60)
time.Sleep(8 * time.Second)
fi.MotorOperate(sim, "fan2", fi.FiMsOnReverse, 60)
time.Sleep(8 * time.Second)
fi.ValveOperate(sim, "valve1", 100)
time.Sleep(5 * time.Second)
fi.ValveOperate(sim, "valve1", 1)
time.Sleep(4 * time.Second)
sim.Close()
time.Sleep(2 * time.Second)
}

View File

@ -1,12 +1,12 @@
package iscs_sys
import (
"fmt"
"joylink.club/ecs"
"joylink.club/ecs/filter"
"joylink.club/rtsssimulation/component"
"joylink.club/rtsssimulation/consts"
"joylink.club/rtsssimulation/entity"
"math"
)
// ValveSystem 阀门
@ -31,18 +31,26 @@ func (s *ValveSystem) Update(w ecs.World) {
valve.Closed = valve.OpenRate <= 0
valve.Opened = valve.OpenRate >= 100
valve.Moving = valve.OpenRate != valveController.TargetOpenRate
fmt.Printf("==>>阀门[%s],OpenRate = %d%% , 全开 = %t , 全关 = %t", valveId, valve.OpenRate, valve.Opened, valve.Closed)
//fmt.Printf("==>>阀门[%s],OpenRate = %d%% , 全开 = %t , 全关 = %t , Moving = %t ,Pos = %d\n", valveId, valve.OpenRate, valve.Opened, valve.Closed, valve.Moving, position.Pos)
//
valveModel, ok := wd.Repo.FindById(valveId).(valveModeler)
if !ok {
valveModel = vm
}
//计算速度
speed := int32((float64(consts.TwoPosMax-consts.TwoPosMin) / float64(valveModel.MaxMoveTime())) * float64(w.Tick()))
targetPos := int32((float64(valveController.TargetOpenRate) / float64(100)) * float64(consts.TwoPosMax-consts.TwoPosMin))
targetLen := int32(math.Abs(float64(targetPos - position.Pos)))
//修正尾速
if speed > targetLen {
speed = targetLen
}
if valveController.TargetOpenRate < valve.OpenRate {
speed = -speed
} else if valveController.TargetOpenRate == valve.OpenRate {
speed = 0
}
position.Speed = speed
})
}