Example #1
0
        public WiseVirtualMotor(
            string name,
            WisePin motorPin,
            WisePin guideMotorPin,
            WisePin slewPin,
            TelescopeAxes axis,
            Const.AxisDirection direction,
            List <object> encoders = null)
        {
            this.WiseName = name;

            this.motorPin      = motorPin;
            this.guideMotorPin = guideMotorPin;
            this.slewPin       = slewPin;
            this.allPins       = new List <WisePin> {
                motorPin, slewPin, guideMotorPin
            };

            this.encoders   = encoders;
            this._axis      = axis;
            this._otherAxis = (_axis == TelescopeAxes.axisPrimary) ?
                              TelescopeAxes.axisSecondary : TelescopeAxes.axisPrimary;
            this._direction = direction;

            if (Simulated && (encoders == null || encoders.Count() == 0))
            {
                throw new WiseException(WiseName + ": A simulated WiseVirtualMotor must have at least one encoder reference");
            }

            if (Simulated)
            {
                simulationTimerFrequency = 30; // 15;
                TimerCallback TimerCallback = new TimerCallback(bumpEncoders);
                simulationTimer = new System.Threading.Timer(TimerCallback, null, Timeout.Infinite, Timeout.Infinite);
            }
        }
Example #2
0
        /// <summary>
        /// For movement-study ONLY.  Implements a timed-movement (as opposed to a measured-movement in the driver)
        /// </summary>
        /// <returns></returns>
        List <TimedMovementResult> MakeStepsInTheBackground(BackgroundWorker bgw, TimedMovementArg arg)
        {
            List <TimedMovementResult> bgResults = new List <TimedMovementResult>();

            Const.AxisDirection direction = arg.rate < 0 ? Const.AxisDirection.Decreasing : Const.AxisDirection.Increasing;

            for (int stepNo = 0; stepNo < arg.nsteps; stepNo++)
            {
                int selector;
                TimedMovementResult res = new TimedMovementResult(arg.axis);
                res.cancelled = false;

                res.threadId = Thread.CurrentThread.ManagedThreadId;

                selector           = (int)TimedMovementResult.ResultSelector.AtStart;
                res.time[selector] = DateTime.Now; res.encoder_angle[selector] = arg.axis == TelescopeAxes.axisPrimary ?
                                                                                 Angle.FromHours(wisetele.RightAscension) :
                                                                                 Angle.FromDegrees(wisetele.Declination);

                if (bgw.CancellationPending)
                {
                    res.cancelled = true;
                    bgResults.Add(res);
                    break;
                }

                wisetele.MoveAxis(arg.axis, arg.rate);
                for (long endTicks = DateTime.Now.Ticks + 10000 * arg.millis; DateTime.Now.Ticks < endTicks; Thread.Sleep(1))
                {
                    if (bgw.CancellationPending)
                    {
                        wisetele.Stop();
                        res.cancelled = true;
                        bgResults.Add(res);
                        goto Out;
                    }
                }

                selector           = (int)TimedMovementResult.ResultSelector.AtStop;
                res.time[selector] = DateTime.Now; res.encoder_angle[selector] = arg.axis == TelescopeAxes.axisPrimary ?
                                                                                 Angle.FromHours(wisetele.RightAscension) :
                                                                                 Angle.FromDegrees(wisetele.Declination);

                if (wisetele.Simulated)    // move some more, to simulate telescope inertia
                {
                    wisetele.MoveAxis(arg.axis, arg.rate);
                    long deltaTicks = 10000 * (long)(WiseTele.Instance.movementParameters[arg.axis][arg.rate].stopMovement.Degrees * WiseTele.Instance.movementParameters[arg.axis][arg.rate].millisecondsPerDegree);
                    for (long endTicks = DateTime.Now.Ticks + deltaTicks; DateTime.Now.Ticks < endTicks; Thread.Sleep(10))
                    {
                        if (bgw.CancellationPending)
                        {
                            wisetele.Stop();
                            res.cancelled = true;
                            bgResults.Add(res);
                            goto Out;
                        }
                    }
                }

                wisetele.Stop();

                if (bgw.CancellationPending)
                {
                    res.cancelled = true;
                    bgResults.Add(res);
                    goto Out;
                }

                while (wisetele.AxisIsMoving(arg.axis))
                {
                    if (bgw.CancellationPending)
                    {
                        res.cancelled = true;
                        bgResults.Add(res);
                        goto Out;
                    }
                    Thread.Sleep(500);
                }

                selector           = (int)TimedMovementResult.ResultSelector.AtIdle;
                res.time[selector] = DateTime.Now; res.encoder_angle[selector] = arg.axis == TelescopeAxes.axisPrimary ?
                                                                                 Angle.FromHours(wisetele.RightAscension) :
                                                                                 Angle.FromDegrees(wisetele.Declination);

                bgResults.Add(res);
            }

Out:
            return(bgResults);
        }
 public ShortestDistanceResult()
 {
     angle     = Angle.invalid;
     direction = Const.AxisDirection.None;
 }
 public ShortestDistanceResult(Angle a, Const.AxisDirection d)
 {
     angle     = a;
     direction = d;
 }