Beispiel #1
0
        private void OnArduinoMessageEvent(CustomEventArgs customEventArgs)
        {
            var args = customEventArgs as OrientationEvent;

            if (args == null)
            {
                return;
            }
            or = args;
            semi.Release();
        }
Beispiel #2
0
 private void HandleOrientationEvent(OrientationEvent orientationEvent)
 {
     if (orientationEvent == null)
     {
         return;
     }
     if (GoogleSkyWebBrowser.InvokeRequired)
     {
         GoogleSkyWebBrowser.Invoke(new Action(() => HandleOrientationEvent(orientationEvent)));
         return;
     }
     GoogleSkyCoordinate = orientationEvent.Orientation;
     LogListBox("Update Google Sky coordinates \n Latitiude:{0} \n Longitude:{1}", GoogleSkyCoordinate.Latitude, GoogleSkyCoordinate.Longitude);
     GoogleSkyWebBrowser.Document.InvokeScript("updateGoogleSkyCoordinates",
                                               new object[] { new object[] { GoogleSkyCoordinate.Latitude, GoogleSkyCoordinate.Longitude, DefaultRange } });
 }
Beispiel #3
0
        /// <summary>
        ///     Request the AutoSky Telescope to point to a new direction.
        /// </summary>
        /// <param name="coordinate"> the GoogleSky coordinate you wish to use</param>
        /// <param name="telescopeUp"></param>
        /// <param name="telescopeDown"></param>
        public void RequestNewPosition(GoogleSkyCs coordinate)
        {
            //ArduinoMessageEvent += RetrieveOrientationEvent();
            stop = false;
            if (!CheckConnection())
            {
                return;
            }
            var destinationHcs = CoordinateConverter.GoogleSkyToHorizonatal(coordinate);
            var altitude       = destinationHcs.Altitude;
            var azimuth        = destinationHcs.Azimuth;
            //First, set the altitude using the 3axis data
            //Y arrow points towards front of telescope. Z arrow points straight up. (X axis not used.)
            const int maxIterations = 500;

            for (var i = 0; i < maxIterations; i++)
            {
                if (stop)
                {
                    break;
                }
                ArduinoMessageEvent += OnArduinoMessageEvent;
                GetOrientation();
                semi.WaitOne(800);
                ArduinoMessageEvent -= OnArduinoMessageEvent;
                if (or == null)
                {
                    ArduinoMessageEvent(new ErrorEvent("Didn't get orientation Data!"));
                    StopMotors();
                    continue;
                }
                var gcs = new GoogleSkyCs(or.Orientation.Latitude, or.Orientation.Longitude);

                or = null;
                var currentHcs     = CoordinateConverter.GoogleSkyToHorizonatal(gcs);
                var currentAlt     = currentHcs.Altitude;
                var currentHeading = currentHcs.Azimuth;
                ArduinoMessageEvent(new ErrorEvent(String.Format("Alt: {0},Azi: {1}", currentAlt, currentHeading)));
                //Too close to adjust
                var altComplete = false;
                if (Math.Abs(altitude - currentAlt) < 5)
                {
                    if (Math.Abs(altitude - currentAlt) < 3)
                    {
                        UpDownStop();
                        altComplete = true;
                    }
                    else
                    {
                        altComplete = false;
                        if (altitude > currentAlt)
                        {
                            telescopeUp();
                        }
                        else
                        {
                            telescopeDown();
                        }
                    }
                }
                else
                {
                    altComplete = false;
                    if (altitude > currentAlt)
                    {
                        telescopeUp();
                    }
                    else
                    {
                        telescopeDown();
                    }
                }
                //Too close to adjust
                var aziComplete = false;
                if (Math.Abs(azimuth - currentHeading) < 40)
                {
                    if (Math.Abs(azimuth - currentHeading) < 10)
                    {
                        LeftRightStop();
                        aziComplete = true;
                    }
                    else
                    {
                        aziComplete = false;
                        var a = azimuth - currentHeading;
                        var b = currentHeading - azimuth;
                        if (a < 0)
                        {
                            a = a + 360;
                        }
                        if (b < 0)
                        {
                            b = b + 360;
                        }
                        if (a < b)
                        {
                            telescopeRightSlow();
                        }
                        else
                        {
                            telescopeLeftSlow();
                        }
                    }
                }
                else
                {
                    aziComplete = false;
                    var a = azimuth - currentHeading;
                    var b = currentHeading - azimuth;

                    if (a < b)
                    {
                        telescopeRight();
                    }
                    else
                    {
                        telescopeLeft();
                    }
                }
                if (!aziComplete || !altComplete)
                {
                    continue;
                }
                ArduinoMessageEvent(new ErrorEvent("Success! Pointing where we want to!"));
                StopMotors();
                break;
            }
            StopMotors();
        }