public Telescope(string telescopeId) : base(telescopeId)
 {
     if (DriverLoader.AscomInterfaces(Impl.GetType()).Contains(typeof(ITelescopeV3)))
     {
         isPlatform6Telescope = true;
     }
     TL.LogMessage("Telescope", "Platform 5 Telescope: " + isPlatform5Telescope.ToString() + " Platform 6 Telescope: " + isPlatform6Telescope.ToString());
 }
Exemple #2
0
        protected virtual void Dispose(bool disposing)
        {
            if (disposing)
            {
                try { TL.LogMessage("Dispose", "Dispose called: " + disposing.ToString()); } catch { }
                //try { Handbox.Close(); } catch { }
                //try { Handbox.Dispose(); } catch { }
                try { _moveTimer.Stop(); } catch { }
                try { _moveTimer.Close(); } catch { }
                try { _moveTimer.Dispose(); } catch { }

                //Don't dispose shared TraceLogger
                //try { TL.Enabled = false; } catch { }
                //try { TL.Dispose(); } catch { }
            }
        }
Exemple #3
0
        /// <summary>
        /// Initializes a new instance of the <see cref=driverType/> class.
        /// Must be public for COM registration.
        /// </summary>
        public FilterWheel()
        {
            try
            {
                TL.Enabled = RegistryCommonCode.GetBool(GlobalConstants.SIMULATOR_TRACE, GlobalConstants.SIMULATOR_TRACE_DEFAULT);
                TL.LogMessage("New", "Started");

                //check to see if the profile is ok
                if (ValidateProfile())
                {
                    TL.LogMessage("New", "Validated OK");
                    KeepMoving      = false;
                    LastOffset      = 0;
                    RateOfChange    = 1;
                    MouseDownTime   = DateTime.MaxValue; //Initialise to "don't accelerate" value
                    RandomGenerator = new Random();      //Temperature fluctuation random generator
                    LoadDriverKeyValues();
                    TL.LogMessage("New", "Loaded Key Values");
                    //Handbox = new FilterWheelHandboxForm(this);
                    //Handbox.Hide();
                    //TL.LogMessage("FocusSettingsForm", "Created Handbox");

                    // start a timer that monitors and moves the FilterWheel
                    _moveTimer          = new System.Timers.Timer();
                    _moveTimer.Elapsed += new System.Timers.ElapsedEventHandler(MoveTimer_Tick);
                    _moveTimer.Interval = 100;
                    _moveTimer.Enabled  = true;
                    _lastTemp           = Temperature;
                    Target = _position;

                    TL.LogMessage("New", "Started Simulation");
                }
                else
                {
                    TL.LogMessage("New", "Registering Profile");
                    RegisterWithProfile();
                    TL.LogMessage("New", "Registered OK");
                }

                TL.LogMessage("New", "Completed");
            }
            catch (Exception ex)
            {
                TL.LogMessageCrLf("New Exception", ex.ToString());
                Console.WriteLine($"FilterWheel: {ex}");
            }
        }
Exemple #4
0
        /// <summary>
        /// Ticks 10 times a second, updating the FilterWheel position and IsMoving properties
        /// </summary>
        private void MoveTimer_Tick(object source, System.Timers.ElapsedEventArgs e)
        {
            // Change at introduction of IFilterWheelV3 - only allow random temperature induced changes when the motor is in the idle state
            // This is because IFilterWheel V3 allows moves when temperature compensation is active
            if (motorState == MotorState.idle)
            {
                //Create random temperature change
                if (DateTime.Now.Subtract(lastTempUpdate).TotalSeconds > TempPeriod)
                {
                    lastTempUpdate = DateTime.Now;
                    // apply a random change to the temperature
                    double tempOffset = (RandomGenerator.NextDouble() - 0.5);// / 10.0;
                    Temperature = Math.Round(Temperature + tempOffset, 2);

                    // move the FilterWheel target to track the temperature if required
                    if (tempComp)
                    {
                        var dt = (int)((Temperature - _lastTemp) * TempSteps);
                        if (dt != 0)// return;
                        {
                            Target   += dt;
                            _lastTemp = Temperature;
                        }
                    }
                }
            }

            if (Target > MaxPosition)
            {
                Target = MaxPosition;                       // Condition target within the acceptable range
            }
            if (Target < 0)
            {
                Target = 0;
            }

            if (_position != Target) //Actually move the focuse if necessary
            {
                TL.LogMessage("Moving", "LastOffset, Position, Target RateOfChange " + LastOffset + " " + _position + " " + Target + " " + RateOfChange);

                if (Math.Abs(_position - Target) <= RateOfChange)
                {
                    _position = Target;
                    TL.LogMessage("Moving", "  Set position = target");
                }
                else
                {
                    _position += (_position > Target) ? -RateOfChange : RateOfChange;
                    TL.LogMessage("Moving", "  Updated position = " + _position);
                }
                TL.LogMessage("Moving", "  New position = " + _position);
            }
            if (KeepMoving & (DateTime.Now.Subtract(MouseDownTime).TotalSeconds > 0.5))
            {
                Target        = (Math.Sign(LastOffset) > 0) ? MaxPosition : 0;
                MouseDownTime = DateTime.Now;
                if (RateOfChange < 100)
                {
                    RateOfChange = (int)Math.Ceiling((double)RateOfChange * 1.2);
                }
                TL.LogMessage("KeepMoving", "LastOffset, Position, Target, RateOfChange MouseDownTime " + LastOffset + " " + _position + " " + Target + " " + RateOfChange + " " + MouseDownTime.ToLongTimeString());
            }

            // handle MotorState
            switch (motorState)
            {
            case MotorState.moving:
                if (_position == Target)
                {
                    motorState       = MotorState.settling;
                    settleFinishTime = DateTime.Now + TimeSpan.FromMilliseconds(settleTime);
                    TL.LogMessage("MoveTimer", "Settle start, time " + settleTime.ToString());
                }
                return;

            case MotorState.settling:
                if (settleFinishTime < DateTime.Now)
                {
                    motorState = MotorState.idle;
                    TL.LogMessage("MoveTimer", "settle finished");
                }
                return;
            }
        }
Exemple #5
0
 public void Dispose()
 {
     try { TL.LogMessage("Dispose", "Dispose called."); } catch { }
     Dispose(true);
     GC.SuppressFinalize(this);
 }