示例#1
0
        private async Task PrepareForSlewingAsync(MountAxis axis, double speed, double absoluteSpeed)
        {
            await this._mountControl.QueryStatus(axis).ConfigureAwait(false);

            await this.StopAxisIfRequiredAsync(axis, speed, absoluteSpeed).ConfigureAwait(false);

            MotionModeHiBitFlags directionOnClock = MotionModeHiBitFlags.None;

            if (speed < 0.0)
            {
                directionOnClock = MotionModeHiBitFlags.DirectionOnClock;
            }
            else
            {
                //
            }

            if (absoluteSpeed > MountControlConstants.LOW_SPEED_MARGIN)
            {
                // Set HIGH speed slewing mode.
                await this._mountControl.SetMotionMode(axis, MotionModeLoBitFlags.TrackingModeFast, directionOnClock).ConfigureAwait(false);
            }
            else
            {
                // Set LOW speed slewing mode.
                await this._mountControl.SetMotionMode(axis, MotionModeLoBitFlags.TrackingModeSlow, directionOnClock).ConfigureAwait(false);
            }
        }
        public byte[] BuildSetBreakStepsCommand(MountAxis axis, string parameters)
        {
            string command = base.Build(axis, ClientCommandSet.COMMAND_SET_BREAK_STEPS, parameters);

            byte[] rawCommand = Encoding.ASCII.GetBytes(command);

            return(rawCommand);
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="axis"></param>
        public byte[] BuildGetAxisPositionCommand(MountAxis axis)
        {
            string command = base.Build(axis, ClientCommandSet.COMMAND_GET_AXIS_POSITION);

            byte[] rawCommand = Encoding.ASCII.GetBytes(command);

            return(rawCommand);
        }
        public byte[] BuildSetGotoTargetIncrementCommand(MountAxis axis, string parameters)
        {
            string command = base.Build(axis, ClientCommandSet.COMMAND_SET_GOTO_TARGET_INCREMENT, parameters);

            byte[] rawCommand = Encoding.ASCII.GetBytes(command);

            return(rawCommand);
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="axis"></param>
        public byte[] BuildGetStatusExCommand(MountAxis axis, string parameters)
        {
            string command = base.Build(axis, ClientCommandSet.COMMAND_GET_STATUS_EX);

            byte[] rawCommand = Encoding.ASCII.GetBytes(command);

            return(rawCommand);
        }
示例#6
0
        public Task SetStepPeriod(MountAxis axis, double stepsCount)
        {
            string szCmd = stepsCount.ToBinaryCodedDecimal();

            byte[] command = this._commandBuilder.BuildSetStepPeriodCommand(axis, szCmd);

            return(this.SendCommand(this._mountInfo.WifiMount, command));
        }
        public byte[] BuildSetBreakPointIncrementCommand(MountAxis axis, string parameters)
        {
            string command = base.Build(axis, ClientCommandSet.COMMAND_SET_BREAK_POINT_INCREMENT, parameters);

            byte[] rawCommand = Encoding.ASCII.GetBytes(command);

            return(rawCommand);
        }
示例#8
0
        public async Task SetAxisInstantStop(MountAxis axis)
        {
            byte[] command = this._commandBuilder.BuildSetAxisInstantStopCommand(axis);

            await this.SendCommand(this._mountInfo.WifiMount, command).ConfigureAwait(false);

            this._mountInfo.MountState.AxesStatus[(int)axis].FullStop = true;
        }
        public byte[] BuildGetTimerInterruptFreqCommand(MountAxis axis)
        {
            string command = base.Build(axis, ClientCommandSet.COMMAND_GET_TIMER_INTERRUPT_FREQ);

            byte[] rawCommand = Encoding.ASCII.GetBytes(command);

            return(rawCommand);
        }
        public byte[] BuildSetStepPeriodCommand(MountAxis axis, string parameters)
        {
            string command = base.Build(axis, ClientCommandSet.COMMAND_SET_STEP_PERIOD, parameters);

            byte[] rawCommand = Encoding.ASCII.GetBytes(command);

            return(rawCommand);
        }
示例#11
0
        public Task SetBreakSteps(MountAxis axis, double breakSteps)
        {
            string szCmd = breakSteps.ToBinaryCodedDecimal();

            byte[] command = this._commandBuilder.BuildSetBreakStepsCommand(axis, szCmd);

            return(this.SendCommand(this._mountInfo.WifiMount, command));
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="axis"></param>
        public byte[] BuildFinaliseInitialisationCommand(MountAxis axis)
        {
            string command = base.Build(axis, ClientCommandSet.COMMAND_FINALISE_INITIALISATION);

            byte[] rawCommand = Encoding.ASCII.GetBytes(command);

            return(rawCommand);
        }
        public byte[] BuildSetAxisInstantStopCommand(MountAxis axis)
        {
            string command = base.Build(axis, ClientCommandSet.COMMAND_SET_AXIS_INSTANT_STOP);

            byte[] rawCommand = Encoding.ASCII.GetBytes(command);

            return(rawCommand);
        }
        public byte[] BuildSetMotionModeCommand(MountAxis axis, string parameters)
        {
            string command = base.Build(axis, ClientCommandSet.COMMAND_SET_MOTION_MODE, parameters);

            byte[] rawCommand = Encoding.ASCII.GetBytes(command);

            return(rawCommand);
        }
        /// <summary>
        /// Inquire high speed ratio ":g(*2)", where *2: '1'= CH1, '2' = CH2.
        /// </summary>
        /// <param name="axis"></param>
        public byte[] BuildGetHighSpeedRatioCommand(MountAxis axis)
        {
            string command = base.Build(axis, ClientCommandSet.COMMAND_GET_HIGH_SPEED_RATIO);

            byte[] rawCommand = Encoding.ASCII.GetBytes(command);

            return(rawCommand);
        }
示例#16
0
        public Task SetMotionMode(MountAxis axis, MotionModeLoBitFlags func, MotionModeHiBitFlags direction)
        {
            string szCmd = "" + (int)func + (int)direction;

            byte[] command = this._commandBuilder.BuildSetMotionModeCommand(axis, szCmd);

            return(this.SendCommand(this._mountInfo.WifiMount, command));
        }
        public byte[] BuildGetCountsPerRevolutionCommand(MountAxis axis)
        {
            string command = base.Build(axis, ClientCommandSet.COMMAND_GET_GRID_PER_REVOLUTION);

            byte[] rawCommand = Encoding.ASCII.GetBytes(command);

            return(rawCommand);
        }
        public byte[] BuildGetMotorBoardVersionCommand(MountAxis axis)
        {
            string command = base.Build(axis, ClientCommandSet.COMMAND_GET_MOTOR_BOARD_VERSION);

            byte[] rawCommand = Encoding.ASCII.GetBytes(command);

            return(rawCommand);
        }
        public byte[] BuildSetStartMotionCommand(MountAxis axis)
        {
            string command = base.Build(axis, ClientCommandSet.COMMAND_SET_START_MOTION);

            byte[] rawCommand = Encoding.ASCII.GetBytes(command);

            return(rawCommand);
        }
示例#20
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="axis"></param>
        /// <param name="speed"></param>
        /// <returns>If stopping was required</returns>
        private async Task <bool> StopAxisIfRequiredAsync(MountAxis axis, double speed, double absoluteSpeed)
        {
            AxisStatus mountInfoAxisStatus = this._mountInfo.MountState.AxesStatus[(int)axis];

            if (!mountInfoAxisStatus.FullStop)
            {
                if (!mountInfoAxisStatus.Tracking)
                {
                    await this._mountControl.SetAxisStop(axis).ConfigureAwait(false);
                }
                else if (mountInfoAxisStatus.HighSpeed)
                {
                    await this._mountControl.SetAxisStop(axis).ConfigureAwait(false);
                }
                // Moving to ludicrous speed
                else if (absoluteSpeed >= MountControlConstants.LOW_SPEED_MARGIN)
                {
                    await this._mountControl.SetAxisStop(axis).ConfigureAwait(false);
                }
                // Changing direction
                else if (mountInfoAxisStatus.SlewingClockWise && speed < 0)
                {
                    await this._mountControl.SetAxisStop(axis).ConfigureAwait(false);
                }
                // Changing direction
                else if (mountInfoAxisStatus.SlewingClockWise && speed > 0)
                {
                    await this._mountControl.SetAxisStop(axis).ConfigureAwait(false);
                }
                else
                {
                    // All checks passed, safe to set motion mode
                    return(false);
                }

                // Wait until the axis stops
                while (true)
                {
                    await this._mountControl.QueryStatus(axis).ConfigureAwait(false);

                    // Return if the axis has stopped.
                    if (mountInfoAxisStatus.FullStop)
                    {
                        break;
                    }

                    Thread.Sleep(100);
                }
            }

            return(true);
        }
示例#21
0
        public async Task SlewAxisToAsync(MountAxis axis, double targetPosition)
        {
            // Update our stored axes
            await this._mountControl.QueryStatus(axis).ConfigureAwait(false);

            var deltaAngle = targetPosition - this._mountInfo.MountState.AxisPositions[(int)axis];

            var stepsToMove = Conversion.AngleToStep(this._mountInfo.MountState.StepCoefficients[(int)axis].FactorRadToStep, deltaAngle);

            // Nothing to do
            if (stepsToMove == 0)
            {
                return;
            }

            MotionModeHiBitFlags directionOnClock;

            if (stepsToMove > 0)
            {
                directionOnClock = MotionModeHiBitFlags.None;
                this._mountInfo.MountState.AxesStatus[(int)axis].SlewingClockWise = true;
            }
            else
            {
                directionOnClock = MotionModeHiBitFlags.DirectionOnClock;
                this._mountInfo.MountState.AxesStatus[(int)axis].SlewingClockWise = false;
            }

            stepsToMove = Math.Abs(stepsToMove);

            // Check if it's far enough that we should go at ludicrous speed
            if (stepsToMove > this._mountInfo.MountState.StepCoefficients[(int)axis].LowSpeedGotoMargin)
            {
                await this._mountControl.SetMotionMode(axis, MotionModeLoBitFlags.GotoModeFast, directionOnClock).ConfigureAwait(false);

                this._mountInfo.MountState.AxesStatus[(int)axis].HighSpeed = true;
            }
            else
            {
                await this._mountControl.SetMotionMode(axis, MotionModeLoBitFlags.GotoModeSlow, directionOnClock).ConfigureAwait(false);

                this._mountInfo.MountState.AxesStatus[(int)axis].HighSpeed = false;
            }

            await this._mountControl.SetGotoTargetIncrement(axis, stepsToMove).ConfigureAwait(false);

            await this._mountControl.SetBreakPointIncrement(axis, this._mountInfo.MountState.BreakSteps[(int)axis]).ConfigureAwait(false);

            await this._mountControl.StartMotion(axis).ConfigureAwait(false);
        }
示例#22
0
        private async Task QueryExtendedStatus(IMountInfo mountInfo, MountAxis axis)
        {
            byte[] command = this._commonCommandBuilder.BuildGetStatusExCommand(axis, "010000");

            byte[] response = await this.SendRecieveCommand(mountInfo.WifiMount, command).ConfigureAwait(false);

            if (!base.ValidateResponse(response))
            {
                return;
            }

            AxisStatusEx statusEx = this._commonCommandParser.ParseExtendedStatusResponse(response);

            mountInfo.MountState.AxesStatusExtended[(int)axis] = statusEx;
        }
示例#23
0
        private async Task QueryHighSpeedRatio(IMountInfo mountInfo, MountAxis axis)
        {
            byte[] command = this._commandBuilder.BuildGetHighSpeedRatioCommand(axis);

            byte[] response = await this.SendRecieveCommand(mountInfo.WifiMount, command).ConfigureAwait(false);

            if (!base.ValidateResponse(response))
            {
                return;
            }

            double ratio = this._commandParser.ParseHighSpeedRatioResponse(response);

            mountInfo.MountState.HighSpeedRatio[(int)axis] = ratio;
        }
示例#24
0
        private async Task QueryCountsPerRevolution(IMountInfo mountInfo, MountAxis axis)
        {
            byte[] command = this._commandBuilder.BuildGetCountsPerRevolutionCommand(axis);

            byte[] response = await this.SendRecieveCommand(mountInfo.WifiMount, command).ConfigureAwait(false);

            if (!base.ValidateResponse(response))
            {
                return;
            }

            double gearRatio = this._commandParser.ParseCountsPerRevolutionRepsonse(response, mountInfo.MountState.MountControllerVersion);

            mountInfo.MountState.StepCoefficients[(int)axis] = new StepCoefficients(gearRatio);
        }
示例#25
0
        private async Task QueryTimerInteruptFrequency(IMountInfo mountInfo, MountAxis axis)
        {
            byte[] command = this._commandBuilder.BuildGetTimerInterruptFreqCommand(axis);

            byte[] response = await this.SendRecieveCommand(mountInfo.WifiMount, command).ConfigureAwait(false);

            if (!base.ValidateResponse(response))
            {
                return;
            }

            double timerFreq = this._commandParser.ParseTimerInterruptFreqResponse(response);

            mountInfo.MountState.TimerInterruptFrequencies[(int)axis] = timerFreq;

            mountInfo.MountState.MotorInterval[(int)axis] = Conversion.CalculateMotorInterval(mountInfo.MountState.StepCoefficients[(int)axis].FactorRadToStep, timerFreq);
        }
示例#26
0
        private async Task QueryAxisPosition(IMountInfo mountInfo, MountAxis axis)
        {
            byte[] command = this._commonCommandBuilder.BuildGetAxisPositionCommand(axis);

            byte[] response = await this.SendRecieveCommand(mountInfo.WifiMount, command).ConfigureAwait(false);

            if (!base.ValidateResponse(response))
            {
                return;
            }

            double steps = this._commonCommandParser.ParseAxisPositionResponse(response);

            mountInfo.MountState.AxisPositions[(int)axis] = Conversion.StepToAngle(mountInfo.MountState.StepCoefficients[(int)axis].FactorStepToRad, steps);

            mountInfo.MountState.AxisSexagesimalAngles[(int)axis] = SexagesimalAngle.FromDouble(Maths.RadToDeg(mountInfo.MountState.AxisPositions[(int)axis]));
        }
示例#27
0
        private async Task QueryStatus(IMountInfo mountInfo, MountAxis axis)
        {
            byte[] command = this._commonCommandBuilder.BuildGetStatusCommand(axis);

            byte[] response = await this.SendRecieveCommand(mountInfo.WifiMount, command).ConfigureAwait(false);

            if (!base.ValidateResponse(response))
            {
                return;
            }

            if (response.Length != 5)
            {
                Debug.WriteLine($"Got malformed response to status query {response.Length} bytes");
                return;
            }

            AxisStatus status = this._commonCommandParser.ParseStatusResponse(response);

            mountInfo.MountState.AxesStatus[(int)axis] = status;
        }
示例#28
0
        public Task StartMotion(MountAxis axis)
        {
            byte[] command = this._commandBuilder.BuildSetStartMotionCommand(axis);

            return(this.SendCommand(this._mountInfo.WifiMount, command));
        }
示例#29
0
 public Task Stop(MountAxis axis)
 {
     return(this._mountControl.SetAxisStop(MountAxis.UpDown));
 }
示例#30
0
        public async Task SlewAxisAsync(MountAxis axis, double speed)
        {
            // Limit maximum speed
            if (speed > MountControlConstants.MAX_SPEED)             // 3.4 degrees/sec, 800X sidereal rate, is the highest speed.
            {
                speed = MountControlConstants.MAX_SPEED;
            }
            else if (speed < -MountControlConstants.MAX_SPEED)
            {
                speed = -MountControlConstants.MAX_SPEED;
            }

            double absoluteSpeed = Math.Abs(speed);

            if (absoluteSpeed <= MountControlConstants.INTERNAL_SIDEREAL_RATE)
            {
                await this._mountControl.SetAxisStop(axis).ConfigureAwait(false);

                return;
            }

            // The motor has to be stopped to set the motion mode
            await this.PrepareForSlewingAsync(axis, speed, absoluteSpeed).ConfigureAwait(false);

            if (speed > 0.0)
            {
                this._mountInfo.MountState.AxesStatus[(int)axis].SlewingClockWise = true;
            }
            else
            {
                this._mountInfo.MountState.AxesStatus[(int)axis].SlewingClockWise = false;
            }

            double internalSpeed = absoluteSpeed;

            if (internalSpeed > MountControlConstants.LOW_SPEED_MARGIN)
            {
                // High speed adjustment
                internalSpeed = internalSpeed / this._mountInfo.MountState.HighSpeedRatio[(int)axis];

                this._mountInfo.MountState.AxesStatus[(int)axis].HighSpeed = true;
            }

            double speedInSecondsPerRadian = 1 / internalSpeed;

            double motorInterval = Conversion.CalculateMotorInterval(this._mountInfo.MountState.StepCoefficients[(int)axis].FactorRadToStep, speedInSecondsPerRadian);

            // For special MC version.
            if ((this._mountInfo.MountState.MountControllerVersion == 0x010600) ||
                (this._mountInfo.MountState.MountControllerVersion == 0x010601))
            {
                motorInterval -= 3;
            }

            motorInterval = Math.Max(motorInterval, 1);

            await this._mountControl.SetStepPeriod(axis, motorInterval).ConfigureAwait(false);

            // Let's goooo
            await this._mountControl.StartMotion(axis).ConfigureAwait(false);
        }