Exemple #1
0
        //actual watchdog pulse generator
        private void timer_Tick()
        {
            WatchdoLoopcount++;
            if (WatchdoLoopcount > 19)
            {
                WatchdoLoopcount = 0;
            }
            int bitState = (WatchdoLoopcount) % 5 > 0 ? 1 : 0; //1:5 duty cycle

            lock (this.dev)
            {
                this.dev.OutputBit(4, 0, bitState);
            }

            if (WatchdoLoopcount == 0)
            {
                if (dev.Connected && state == DishState.Stopped)
                {
                    if (azCommand == -1.0)
                    {
                        //initialize old value in lowpass filter so
                        //it doesn't take too long to settle on startup
                        azPos = azEncoder.countsToDegrees(0);
                        elPos = elEncoder.countsToDegrees(0);
                    }
                    azPos = azReadPosition();
                    elPos = elReadPosition();
                    if (azCommand == -1.0)
                    {
                        azCommand = azPos;
                        elCommand = elPos;
                        GeoAngle mAzAngle = GeoAngle.FromDouble(azCommand, true);
                        GeoAngle mElAngle = GeoAngle.FromDouble(elCommand);
                        this.commandAz.Text = string.Format("{0} : {1}", mAzAngle.Degrees, mAzAngle.Minutes);
                        this.commandEl.Text = string.Format("{2}{0} : {1}", mElAngle.Degrees, mElAngle.Minutes, mElAngle.IsNegative ? "-" : "");
                    }
                }
            }

            if (state != DishState.Stopped && state != DishState.Unknown)
            {
                if (azPid.Complete && elPid.Complete)
                {
                    this.Stop();
                }
            }
        }
Exemple #2
0
        public static GeoAngle FromDouble(double angleInDegrees, bool range360 = false)
        {
            //ensure the value will fall within the primary range [-180.0..+180.0]
            if (!range360)
            {
                while (angleInDegrees < -180.0)
                {
                    angleInDegrees += 360.0;
                }

                while (angleInDegrees > 180.0)
                {
                    angleInDegrees -= 360.0;
                }
            }
            else
            {
                while (angleInDegrees < 0.0)
                {
                    angleInDegrees += 360.0;
                }

                while (angleInDegrees > 360.0)
                {
                    angleInDegrees -= 360.0;
                }
            }
            var result = new GeoAngle();

            //switch the value to positive
            result.IsNegative = angleInDegrees < 0;
            angleInDegrees    = Math.Abs(angleInDegrees);

            //gets the degree
            result.Degrees = (int)Math.Floor(angleInDegrees);
            var delta = angleInDegrees - result.Degrees;

            //gets minutes and seconds
            result.Minutes = (int)Math.Floor(delta * 60.0);
            double seconds = 3600.0 * delta;

            result.Seconds = seconds % 60.0;

            return(result);
        }
Exemple #3
0
        public static GeoAngle FromString(string point)
        {
            var multiplier = (point.Contains("S") || point.Contains("W")) ? -1 : 1; //handle south and west

            point = Regex.Replace(point, "[^0-9. :]", "");                          //remove the characters

            var pointArray = point.Split(new char [] { ':' });                      //split the string.

            for (int i = 0, j = pointArray.Length; i < j; i++)
            {
                pointArray[i] = Regex.Replace(pointArray[i], "[^0-9. ]", ""); //remove the characters
            }
            //Decimal degrees =
            //   whole number of degrees,
            //   plus minutes divided by 60,
            //   plus seconds divided by 3600
            var result = new GeoAngle();
            int d      = 0;

            Int32.TryParse(pointArray[0], out d);
            result.Degrees = d;
            d = 0;
            if (pointArray.Length > 1)
            {
                Int32.TryParse(pointArray[1], out d);
            }
            result.Minutes = d;
            double dd = 0;

            if (pointArray.Length > 2)
            {
                double.TryParse(pointArray[2], out dd);
            }
            result.Seconds = dd;
            if (multiplier < 0)
            {
                result.IsNegative = true;
            }
            else
            {
                result.IsNegative = false;
            }
            return(result);
        }
Exemple #4
0
        private void presetSelector_SelectedIndexChanged(object sender, EventArgs e)
        {
            int item = presetSelector.SelectedIndex;

            if (item != 0)
            {
                this.azCommand = this.Presets[item].Az;
                this.elCommand = this.Presets[item].El;
                GeoAngle mAzAngle = GeoAngle.FromDouble(azCommand, true);
                GeoAngle mElAngle = GeoAngle.FromDouble(elCommand);
                this.commandAz.Text = string.Format("{0} : {1}", mAzAngle.Degrees, mAzAngle.Minutes);
                this.commandEl.Text = string.Format("{0} : {1}", mElAngle.Degrees, mElAngle.Minutes);

                RaDec    astro = celestialConversion.CalcualteRaDec(mElAngle.ToDouble(), mAzAngle.ToDouble(), settings.latitude, settings.longitude);
                GeoAngle Dec   = GeoAngle.FromDouble(astro.Dec);
                GeoAngle RA    = GeoAngle.FromDouble(astro.RA, true);

                this.commandRA.Text  = string.Format("{0:D3} : {1:D2}", RA.Degrees, RA.Minutes);
                this.commandDec.Text = string.Format("{0:D2} : {1:D2}", Dec.Degrees, Dec.Minutes);
            }
        }
Exemple #5
0
        private void SouthPark_Click(object sender, EventArgs e)
        {
            azCommand = settings.azSouthPark;
            elCommand = settings.elSouthPark;
            GeoAngle mAzAngle = GeoAngle.FromDouble(azCommand, true);
            GeoAngle mElAngle = GeoAngle.FromDouble(elCommand);

            this.commandAz.Text = string.Format("{0} : {1}", mAzAngle.Degrees, mAzAngle.Minutes);
            this.commandEl.Text = string.Format("{0} : {1}", mElAngle.Degrees, mElAngle.Minutes);

            RaDec    astro = celestialConversion.CalcualteRaDec(mElAngle.ToDouble(), mAzAngle.ToDouble(), settings.latitude, settings.longitude);
            GeoAngle Dec   = GeoAngle.FromDouble(astro.Dec);
            GeoAngle RA    = GeoAngle.FromDouble(astro.RA, true);

            this.commandRA.Text  = string.Format("{0:D3} : {1:D2}", RA.Degrees, RA.Minutes);
            this.commandDec.Text = string.Format("{0:D2} : {1:D2}", Dec.Degrees, Dec.Minutes);

            this.state = DishState.Parking;;

            azPid.Enable();
            elPid.Enable();
        }
Exemple #6
0
 private void commandAz_TextChanged(object sender, EventArgs e)
 {
     azCommand = GeoAngle.FromString(commandAz.Text).ToDouble();
 }
Exemple #7
0
        //update position display
        private void updatePosition()
        {
            if ((DateTime.Now - messageTime).TotalSeconds > 30)
            {
                Message.Text = "";
            }

            //read actual form encoders
            //if (dev.Connected && state == DishState.Stopped)
            //{
            //    azPos = azReadPosition();
            //    elPos = elReadPosition();
            //}
            //set up display variables in deg, min, sec format
            GeoAngle AzAngle = GeoAngle.FromDouble(azPos, true);
            GeoAngle ElAngle = GeoAngle.FromDouble(elPos);

            //convert to RA/DEC
            RaDec astro = celestialConversion.CalcualteRaDec(elPos, azPos, settings.latitude, settings.longitude);
            //set up RA DEC as deg,min,sec
            GeoAngle Dec = GeoAngle.FromDouble(astro.Dec);
            GeoAngle RA  = GeoAngle.FromDouble(astro.RA, true);

            //log position every tenth time through
            string posLog = string.Format("RA {0:D3} : {1:D2}\t DEC {2:D3} : {3:D2}", RA.Degrees, RA.Minutes, Dec.Degrees, Dec.Minutes);

            currentIncrement++;
            if (currentIncrement % 9 == 0)
            {
                RollingLogger.LogMessage(posLog);
                currentIncrement = 0;
            }

            //show AZ, EL on main form
            this.Azimuth.Text   = string.Format("{0:D3} : {1:D2}", AzAngle.Degrees, AzAngle.Minutes);
            this.Elevation.Text = string.Format("{0:D2} : {1:D2}", ElAngle.Degrees, ElAngle.Minutes);

            //show RA,DEC on main form
            this.RA.Text  = string.Format("{0:D3} : {1:D2}", RA.Degrees, RA.Minutes);
            this.DEC.Text = string.Format("{0:D2} : {1:D2}", Dec.Degrees, Dec.Minutes);

            //if celestial track is set, check to make sure command position is above horizon if so then enable motion
            //probably have to have a completely seperate velocity track loop here - PID loop may not be satisfactor
            //-----NEEDS TESTING
            if (trackCelestial)
            {
                AltAz aa = celestialConversion.CalculateAltAz(RAcommand, decCommand, settings.latitude, settings.longitude);
                if (aa.Alt < 0)
                {
                    Message.Text   = "Requested position is below horizon!";
                    trackMoon      = false;
                    messageTime    = DateTime.Now;
                    trackCelestial = false;
                }
                GeoAngle cAzAngle = GeoAngle.FromDouble(aa.Az, true);
                GeoAngle cElAngle = GeoAngle.FromDouble(aa.Alt);
                azCommand           = aa.Az;
                elCommand           = aa.Alt;
                this.commandAz.Text = string.Format("{0:D3} : {1:D2}", cAzAngle.Degrees, cAzAngle.Minutes);
                this.commandEl.Text = string.Format("{0:D2} : {1:D2}", cElAngle.Degrees, cElAngle.Minutes);

                if (state != DishState.Moving && state != DishState.Tracking && aa.Alt > 1.0)
                {
                    this.Go();
                }
            }


            //if Lunar track is set, check to make sure Moon position is above horizon if so then enable motion
            //probably have to have a completely seperate velocity track loop here - PID loop may not be satisfactor
            //-----NEEDS TESTING
            if (trackMoon)
            {
                SunCalc sc    = new SunCalc();
                long    eDate = sc.epochDate(DateTime.UtcNow);
                double  jdate = sc.toJulian(eDate);
                AltAz   aa    = sc.getMoonPosition(eDate, settings.latitude, settings.longitude);
                if (aa.Alt < 0)
                {
                    Message.Text = "Moon is below horizon!";
                    trackMoon    = false;
                    messageTime  = DateTime.Now;
                }
                moonRiseSet mrs = sc.getMoonTimes(eDate, settings.latitude, settings.longitude, true);
                azCommand = aa.Az;
                elCommand = aa.Alt;
                GeoAngle mAzAngle = GeoAngle.FromDouble(aa.Az, true);
                GeoAngle mElAngle = GeoAngle.FromDouble(aa.Alt);
                this.commandAz.Text = string.Format("{0} : {1}", mAzAngle.Degrees, mAzAngle.Minutes);
                this.commandEl.Text = string.Format("{2}{0} : {1}", mElAngle.Degrees, mElAngle.Minutes, mElAngle.IsNegative ? "-" : "");

                double Alt = elCommand;
                if (Alt > 90.0)
                {
                    Alt = Alt - 90.0;
                }
                RaDec    mastro = celestialConversion.CalcualteRaDec(Alt, azCommand, settings.latitude, settings.longitude);
                GeoAngle mDec   = GeoAngle.FromDouble(mastro.Dec);
                GeoAngle mRA    = GeoAngle.FromDouble(mastro.RA, true);

                this.commandRA.Text  = string.Format("{0:D3} : {1:D2}", mRA.Degrees, mRA.Minutes);
                this.commandDec.Text = string.Format("{0:D2} : {1:D2}", mDec.Degrees, mDec.Minutes);
                if (state != DishState.Moving && state != DishState.Tracking && aa.Alt > 1.0)
                {
                    this.Go();
                }
            }//trackMoon

            //send stop command if we have to here
            if (state != DishState.Stopped && state != DishState.Unknown)
            {
                if (azPid.Complete && elPid.Complete)
                {
                    this.Stop();
                }
            }
        }
Exemple #8
0
 private void longitude_TextChanged(object sender, EventArgs e)
 {
     settings.longitude = GeoAngle.FromString(this.longitude.Text).ToDouble();
 }
Exemple #9
0
        public Config(Eth32 dev, configModel settings)
        {
            InitializeComponent();
            this.dev      = dev;
            this.settings = settings;
            if (settings.AzimuthEncoderBits != 0)
            {
                this.latitude.Text               = GeoAngle.FromDouble(settings.latitude).ToString("NS");
                this.longitude.Text              = GeoAngle.FromDouble(settings.longitude).ToString("WE");
                this.altitude.Text               = settings.altitude.ToString();
                this.alpha.Text                  = settings.alpha.ToString();
                this.AzRevsPerRot.Text           = settings.AzimuthRevsPerRot.ToString();
                this.encBitsAz.Text              = settings.AzimuthEncoderBits.ToString();
                this.AzStartBit.Text             = settings.AzimuthStartBit.ToString();
                this.AzOffset.Text               = settings.AzimuthOffsetDeg.ToString();
                this.ElRevsPerRot.Text           = settings.ElevationRevsPerRot.ToString();
                this.encBitsEl.Text              = settings.ElevationEncoderBits.ToString();
                this.ElStartBit.Text             = settings.ElevationStartBit.ToString();
                this.ElOffset.Text               = settings.ElevationOffsetDeg.ToString();
                this.encoder_coding.SelectedItem = settings.coding.ToString();
                this.cmbETH32.Items.Add(settings.eth32Address);
                this.cmbETH32.SelectedItem   = settings.eth32Address;
                this.outputPort.SelectedItem = settings.outputPort;
                this.jogIncrement.Text       = settings.jogIncrement.ToString();
                this.driveEnableBit.Text     = settings.driveEnablebit.ToString();
                this.azCBactiveHi.Checked    = settings.azActiveHi;
                this.azCW_CCW.Checked        = settings.azDriveType == driveType.CCW;
                this.azEnbDir.Checked        = settings.azDriveType == driveType.DirEnable;
                this.azBoth.Checked          = settings.azDriveType == driveType.Both;
                if (settings.azDriveType == driveType.CCW)
                {
                    azCB1.Text      = "CW";
                    azCB2.Text      = "CCW";
                    azCB3.Text      = "";
                    azEnBit.Enabled = false;
                }
                else if (settings.azDriveType == driveType.DirEnable)
                {
                    azCB1.Text      = "Dir";
                    azCB2.Text      = "Enable";
                    azCB3.Text      = "";
                    azEnBit.Enabled = false;
                }
                else
                {
                    azCB1.Text      = "CW";
                    azCB2.Text      = "CCW";
                    azCB3.Text      = "Enable";
                    azEnBit.Enabled = true;
                }
                this.azCWbit.Text        = settings.azCWbit.ToString();
                this.azCCWbit.Text       = settings.azCCWbit.ToString();
                this.azEnBit.Text        = settings.azEnable.ToString();
                this.azPWMch.Text        = settings.azPWMchan.ToString();
                this.azKd.Text           = settings.azKd.ToString();
                this.azKi.Text           = settings.azKi.ToString();
                this.azKp.Text           = settings.azKp.ToString();
                this.Gain.Text           = settings.azG.ToString();
                this.azMax.Text          = settings.azMax.ToString();
                this.azMin.Text          = settings.azMin.ToString();
                this.azOutMax.Text       = settings.azOutMax.ToString();
                this.azOutMin.Text       = settings.azOutMin.ToString();
                this.azPark.Text         = settings.azPark.ToString();
                this.SouthParkPosAz.Text = settings.azSouthPark.ToString();

                this.elCBactiveHi.Checked = settings.elActiveHi;
                this.elCW_CCW.Checked     = settings.elDriveType == driveType.CCW;
                this.elEnbDir.Checked     = settings.elDriveType == driveType.DirEnable;
                this.elBoth.Checked       = settings.elDriveType == driveType.Both;
                if (settings.azDriveType == driveType.CCW)
                {
                    elCB1.Text      = "CW";
                    elCB2.Text      = "CCW";
                    elCB3.Text      = "";
                    elEnBit.Enabled = false;
                }
                else if (settings.azDriveType == driveType.DirEnable)
                {
                    elCB1.Text      = "Dir";
                    elCB2.Text      = "Enable";
                    elCB3.Text      = "";
                    elEnBit.Enabled = false;
                }
                else
                {
                    elCB1.Text      = "CW";
                    elCB2.Text      = "CCW";
                    elCB3.Text      = "Enable";
                    elEnBit.Enabled = true;
                }
                this.elCWbit.Text        = settings.elCWbit.ToString();
                this.elCCWbit.Text       = settings.elCCWbit.ToString();
                this.elEnBit.Text        = settings.elEnable.ToString();
                this.elPWMch.Text        = settings.elPWMchan.ToString();
                this.elKd.Text           = settings.elKd.ToString();
                this.elKi.Text           = settings.elKi.ToString();
                this.elKp.Text           = settings.elKp.ToString();
                this.elMax.Text          = settings.elMax.ToString();
                this.elMin.Text          = settings.elMin.ToString();
                this.elOutMax.Text       = settings.elOutMax.ToString();
                this.elOutMin.Text       = settings.elOutMin.ToString();
                this.elPark.Text         = settings.elPark.ToString();
                this.SouthParkPosEl.Text = settings.elSouthPark.ToString();

                this.PosLogFile.Text    = settings.positionFileLog;
                this.maxPosLogSize.Text = settings.maxPosLogSizeBytes.ToString();
                this.MaxFiles.Text      = settings.maxPosLogFiles.ToString();

                this.PS1Name.Text = settings.Preset1Name;
                this.PS1Az.Text   = settings.Preset1Az.ToString();
                this.PS1El.Text   = settings.Preset1El.ToString();

                this.PS2Name.Text = settings.Preset2Name;
                this.PS2Az.Text   = settings.Preset2Az.ToString();
                this.PS2El.Text   = settings.Preset2El.ToString();

                this.PS3Name.Text = settings.Preset3Name;
                this.PS3Az.Text   = settings.Preset3Az.ToString();
                this.PS3El.Text   = settings.Preset3El.ToString();

                this.PS4Name.Text = settings.Preset4Name;
                this.PS4Az.Text   = settings.Preset4Az.ToString();
                this.PS4El.Text   = settings.Preset4El.ToString();

                this.PS5Name.Text = settings.Preset5Name;
                this.PS5Az.Text   = settings.Preset5Az.ToString();
                this.PS5El.Text   = settings.Preset5El.ToString();
            }
        }