/// <summary> /// Handle the Orientation Data /// </summary> /// <param name="data"></param> private void HandleOrn(string[] data) { var aAndM = data[1].Split(new[] { ';' }); var aData = aAndM[0].Split(new[] { ',' }); var mData = aAndM[1].Split(new[] { ',' }); var altitudeprep = new Point3D(aData[0], aData[1], aData[2]); var azimuthPrep = new Point3D(mData[0], mData[1], mData[2]); var altitude = CalcuclateAltitude(altitudeprep); var azimuth = CalculateAzimuth(azimuthPrep); //Convert this into the Orientation neeed for google sky. var hcs = new HorizontalCs(azimuth, altitude); try { ArduinoMessageEvent(new ErrorEvent(string.Format("Alt {0} Azi {1}", altitude, azimuth))); var gcs = CoordinateConverter.HorizontalToGoogleSky(hcs); //Pass Data up to UI via event or something. ArduinoMessageEvent(new OrientationEvent(gcs)); } catch (Exception ex) { ArduinoMessageEvent(new ErrorEvent(string.Format("Error Occurred: {0}", ex.Message))); if (ex.Message.Contains("gps")) { GetGpsCoOrdinates(); } } }
/// <summary> /// Converts horizontal coordinates to coordinates the Google Sky object can process /// </summary> /// <param name="azimuth"></param> /// <param name="altitude"></param> /// <returns> Returns the latitude, longitude, and the zoom to the Google Sky object</returns> private double[] HorizontalToGoogleSkyDouble(int azimuth, int altitude) { var horizontal = new HorizontalCs(azimuth, altitude); try { GoogleSkyCoordinate = CoordinateConverter.HorizontalToGoogleSky(horizontal); return(new[] { GoogleSkyCoordinate.Latitude, GoogleSkyCoordinate.Longitude, 9000 }); } catch (Exception ex) { LogListBox("Exception occured: {0}", ex.Message); return(null); } }
private void btnMoveMap_Click(object sender, EventArgs e) { if (!isDECValid || !isRAValid) { MessageBox.Show("Invalid coordinates, please check your right ascencion and declination coordinates", "Invalid Inputs", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } var RA = Array.ConvertAll(txtBoxCoordinateRA.Text.Split(':'), double.Parse); var DEC = Array.ConvertAll(txtBoxCoordinateDEC.Text.Split(':'), double.Parse); GoogleSkyCoordinate = CoordinateConverter.EquatorialToGoogleSky(new EquatorialCs(RA, DEC)); 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 } }); }
/// <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(); }