Пример #1
0
        public object Clone( )
        {
            Ke2510Settings v = ( Ke2510Settings )this.MemberwiseClone( );

            return(v);
        }
Пример #2
0
        public double StabilizeTemperatureSelfTuningFalse( ) // was StabilizeTemperature
        {
            if (doOverrideSettings)
            {
                settings_ = overridingSettings_;
            }

            gpib_.Write(SET_SOURCE_TEMPERATURE);
            System.Threading.Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo("en-US");
            var target = this.getTargetTemperature( );

            LogMessage("Starting to stabilize");
            bool     hitTimeout = false;
            TimeSpan timeout    = new TimeSpan(0, 0, 0, 0, ( int )(settings_.StabilizationTimeout * 1000));
            DateTime start      = DateTime.UtcNow;

            Queue <double> tempQ  = new Queue <double>( );
            double         avg    = 0;
            double         stddev = 1000; // a large number
            double         temp;
            double         dif;
            TimeSpan       delay = new TimeSpan(0, 0, 0, 0, ( int )(settings_.StabilizationDelay * 1000));

            ;

            Stopwatch t = new Stopwatch( );

            t.Start( );
            PIDSet PID = new PIDSet( ), stablePIDset_;

            double sum           = 0;
            double sum2          = 0;
            bool   exitForbidden = true;
            int    iteration     = 0;

            do
            {
                try {
                    iteration++;
                    hitTimeout = (DateTime.UtcNow - start) > timeout;
                    Thread.Sleep(( int )delay.TotalMilliseconds);
                    stablePIDset_ = calcStablePidSet(target);

                    temp = measureTemperature( );
                    tempQ.Enqueue(temp);
                    sum  += temp;
                    sum2 += Math.Pow(temp, 2);
                    if (tempQ.Count > settings_.StabilizationSamples)
                    {
                        double tdequed = tempQ.Dequeue( );
                        sum          -= tdequed;
                        sum2         -= Math.Pow(tdequed, 2);
                        exitForbidden = false;
                    }

                    avg = sum / tempQ.Count;

                    stddev = Math.Sqrt(sum2 / ( double )tempQ.Count - Math.Pow(avg, 2));

                    bool stdDevOK = (stddev < settings_.MaxTStdDev);
                    bool offsetOK = (Math.Abs(avg - target) < settings_.MaxTError);

                    if (debugMode_)
                    {
                        LogMessage(("Iteration = " + iteration + " Samples used in calculation = " + settings_.StabilizationSamples));
                        LogMessage(("T = " + temp));
                        LogMessage(("stddev = " + stddev + " Limit = " + settings_.MaxTStdDev + " OK =" + stdDevOK.ToString( )));
                        LogMessage(("Mean offset = " + (avg - target) + " Limit = " + settings_.MaxTError + " OK =" + offsetOK.ToString( )));
                        LogMessage("----");
                    }

                    isStable_ = stdDevOK && offsetOK;

                    if (isStable_)
                    {
                        if (!PID.EqualTo(stablePIDset_))
                        {
                            LogMessage("Switching to stable PID parameters"); // ...if necessary
                            setTempSourcePidParams(stablePIDset_);
                            PID       = stablePIDset_;
                            isStable_ = false; // isStable must be recalculated at least once if PID's were changed..
                        }
                    }
                    else if (!PID.EqualTo(settings_.Fast))
                    {
                        LogMessage("Switching to fast PID parameters");
                        setTempSourcePidParams(settings_.Fast);
                        PID = settings_.Fast;
                    }

                    dif = temp - target;
                    if (writeLogMessages_)
                    {
                        if (t.ElapsedMilliseconds > 10000)
                        {
                            LogMessage("Currently at: " + measureTemperature( ) + ". Dif is: " + dif);
                            t.Reset( );
                            t.Start( );
                        }
                    }
                }
                catch (Exception ex) {
                    LogMessage("Got an exception in stabilization loop: " + ex.Message + "(this has no effect on temperature)");
                    continue;
                }
            } while((!hitTimeout && !isStable_) || exitForbidden || stabilizeForever_);

            DateTime stop = DateTime.UtcNow;

            if (hitTimeout)
            {
                LogMessage("Hit timelimit while stabilizing temperature");
                throw new Exception("Hit timelimit while stabilizing temperature");
            }
            else
            {
                LogMessage("Done stabilizing after " + (stop - start).TotalSeconds.ToString("####.0") + " Seconds.");
                return((stop - start).TotalMinutes);
            }
        }