private void EnableTuning() { UseTuning = !UseTuning; if (UseTuning) { autoTune = new AutoTunePID(op.Params); if (UseTuning) { UseTuning = false; SetupAutoTune(); UseTuning = true; } } }
//const string pidFileName = "pidParameters.json"; //private string pidStorePath; //public PIDState PIDStatus //{ // get { return _pidStatus; } // private set { _pidStatus = value; } //} public PIDControlModule(IHubContext <PIDHub> hub, IConfiguration configuration, TemperatureModule temperatureControlModule, HardwareIOModule hardwareIOModule, DisplayManager displayManager) { UseTuning = false; //_pidStatus = PIDState.Stopped; Hub = hub; _temperatureControlModule = temperatureControlModule; _hardwareIOModule = hardwareIOModule; _displayManager = displayManager; prevElState = false; //pidStorePath = Path.Combine(env.ContentRootPath, pidFileName); // StoreProvider = new JsonStoreProvider(configuration); //StoreProvider.SetStoreName("pidModule"); PIDParameter parameters; List <PIDParameter> p = new List <PIDParameter>(); // = StoreProvider.LoadStore<PIDParameter>(); if (p.Count > 0) { parameters = p[0]; } else { //set default parameters... parameters = new PIDParameter() { Name = "PID", Kd = 0.01, Ki = 10, Kp = 4000, WindowSize = 10000, Target = 40, LastOutput = 0, LastValue = 0 }; p.Add(parameters); //StoreProvider.SaveStore<PIDParameter>(p); } activeSensorID = _temperatureControlModule.GetSavedProbes().Find(sensor => sensor.DefaultSelected).SensorId; op = new PIDOperationalParameters(); op.State = PIDState.Stopped; op.Params = parameters; pidController = new PIDController(op.Params.Kp, op.Params.Ki, op.Params.Kd, 1); pidController.SetOutputLimits(0, parameters.WindowSize); pidController.Setup(PIDMode.AUTOMATIC, op.Params.Target); autoTune = new AutoTunePID(parameters); if (UseTuning) { UseTuning = false; SetupAutoTune(); UseTuning = true; } _windowStart = DateTime.Now; _timer = new Timer(TimerTick, null, _tickInterval, _tickInterval); // temperatureControlModule.TemperatureChanged += TemperatureControlModule_TemperatureChanged; }