public async Task CanSetAzimuthAsync_SendValidRequest() { //Arrange string commandName = "cansetazimuth"; IRestRequest sentRequest = null; var commandSenderMock = new Mock <ICommandSender>(); commandSenderMock .Setup(x => x.ExecuteRequestAsync <BoolResponse>(It.IsAny <string>(), It.IsAny <RestRequest>())) .Callback((string baseUrl, IRestRequest request) => sentRequest = request) .Returns(Task.FromResult(new BoolResponse(false))); var dome = new Dome(_deviceConfiguration, commandSenderMock.Object); //Act await dome.CanSetAzimuthAsync(); //Assert Assert.Equal(Method.GET, sentRequest.Method); AssertCommonParameters(sentRequest.Parameters, _deviceConfiguration, commandName); }
public void GetAltitude_SendValidRequest() { //Arrange string commandName = "altitude"; IRestRequest sentRequest = null; var commandSenderMock = new Mock <ICommandSender>(); commandSenderMock .Setup(x => x.ExecuteRequest <DoubleResponse>(It.IsAny <string>(), It.IsAny <RestRequest>())) .Callback((string baseUrl, IRestRequest request) => sentRequest = request) .Returns(new DoubleResponse(1.0)); var dome = new Dome(_deviceConfiguration, commandSenderMock.Object); //Act dome.GetAltitude(); //Assert Assert.Equal(Method.GET, sentRequest.Method); AssertCommonParameters(sentRequest.Parameters, _deviceConfiguration, commandName); }
public override void GenerateNewFrame(float dt) { Reduce(.9f); //AnimationFrame output = new AnimationFrame(); m_currentSinParameter += m_sinWaveIncrement; // change this to change the parameterization of the function int thetaSteps = 360; // 36 double radiansPerStep = (double)(2.0f * Math.PI / thetaSteps); double a = (float)Dome.LEDS_PER_RIB; double thetaNaught = 0.0f; double currentSin = Math.Sin(m_currentSinParameter); currentSin += 1.0f; currentSin *= 0.5f; double k = currentSin * m_kMax; for (int i = 0; i < thetaSteps; i++) { double theta = (double)i * radiansPerStep; double radius = (a * Math.Cos((k * theta) + thetaNaught)) - 1; if (radius > 49.0) { radius = 49.0; } else if (radius < 0.0) { radius = 0.0; } int rib = Dome.GetNearestRibByRadians(theta); m_CurrentFrame.SetLedColor(rib, (int)radius, ColorManager.RandomColor()); } //m_CurrentFrame = output; }
public void SlewToAltitude_SendValidRequest() { //Arrange string commandName = "slewtoaltitude"; string altitudeParameterName = "Altitude"; double altitudeParameterValue = 2; IRestRequest sentRequest = null; var commandSenderMock = new Mock <ICommandSender>(); commandSenderMock .Setup(x => x.ExecuteRequest <CommandResponse>(It.IsAny <string>(), It.IsAny <RestRequest>())) .Callback((string baseUrl, IRestRequest request) => sentRequest = request) .Returns(new CommandResponse()); var dome = new Dome(_deviceConfiguration, commandSenderMock.Object); //Act dome.SlewToAltitude(altitudeParameterValue); //Assert Assert.Equal(Method.PUT, sentRequest.Method); AssertCommonParameters(sentRequest.Parameters, _deviceConfiguration, commandName); AssertParameter(sentRequest.Parameters, altitudeParameterName, altitudeParameterValue); }
public async Task SetSlavedAsync_SendValidRequest() { //Arrange string commandName = "slaved"; string slavedParameterName = "Slaved"; bool slavedParameterValue = true; IRestRequest sentRequest = null; var commandSenderMock = new Mock <ICommandSender>(); commandSenderMock .Setup(x => x.ExecuteRequestAsync <CommandResponse>(It.IsAny <string>(), It.IsAny <RestRequest>())) .Callback((string baseUrl, IRestRequest request) => sentRequest = request) .Returns(Task.FromResult(new CommandResponse())); var dome = new Dome(_deviceConfiguration, commandSenderMock.Object); //Act await dome.SetSlavedAsync(slavedParameterValue); //Assert Assert.Equal(Method.PUT, sentRequest.Method); AssertCommonParameters(sentRequest.Parameters, _deviceConfiguration, commandName); AssertParameter(sentRequest.Parameters, slavedParameterName, slavedParameterValue); }
public override void GenerateNewFrame(float dt) { //AnimationFrame output = new AnimationFrame(); Reduce(.75f); Random random = new Random(); m_currentSinParameter += m_sinWaveIncrement; double a = (float)Dome.LEDS_PER_RIB; double currentSin = Math.Sin(m_currentSinParameter); currentSin += 1.0f; currentSin *= 0.5f; double b = (a * currentSin); // change this to change the parameterization of the inner circle int thetaSteps = 360; // 36 double radiansPerStep = (double)(2.0f * Math.PI / thetaSteps); for (int i = 0; i < thetaSteps; i++) { double theta = (double)i * radiansPerStep; double x = ((a - b) * Math.Cos(theta)) + (b * Math.Cos((theta * (a - b)) / b)); double y = ((a - b) * Math.Sin(theta)) - (b * Math.Sin((theta * (a - b)) / b)); double r = Math.Sqrt(Math.Pow(x, 2.0f) + Math.Pow(y, 2.0f)) - 1; double drawTheta = Math.Atan2(y, x); // ATan2 returns values from of -π≤θ≤π drawTheta += Math.PI; int rib = Dome.GetNearestRibByRadians(drawTheta); Color newColor = ColorManager.RandomColor(); m_CurrentFrame.SetLedColor(rib, (int)r, newColor); } //m_CurrentFrame = output; }
public DomeSpecificMethodsApiTests() { instance = new Dome("http://localhost:5000/api/v1/"); }
private void ASCOMConnectButton_Click(object sender, RoutedEventArgs e) { try { // // Check if Dome is already connected // if (ASCOMConnectButton.Content.Equals(Dome_Control.Resources.Strings.Button_Connect)) { // Connect the AVR // // Initialize the AVR element // if (_dome == null) { _dome = new Dome(); } if (_dome._arduino == null || _dome._telescope == null) { // put the unused dome object to the garbage collector //_dome.Dispose(); _dome = null; return; } _dome.motor_accelleration_time = (uint)MotorSpeed.Value; _dome.dome_gear_ratio = (double)GearRatio.Value; _dome.dome_angular_speed = 2 * Math.PI * (int)MotorSpeed.Value / (double)GearRatio.Value / 60; _dome.encoder_resolution = (uint)EncoderRes.Value; _dome.Threshold = (uint)Threshold.Value; _dome.configureFirmware(); // // Gets connection information to the Arduino and the telescope // //_dome.SetupDialog(); // // Connect the Arduino // // _dome._arduino.Connect(); // // Read the Firmware Versions and show it on a MessageBox // string ver = _dome._arduino.GetVersion();//DriverVersion;// ((App)(System.Windows.Application.Current))._Dome_uC.GetVersion(); // Parse the received string to the the useful information only char[] delim = { ':', ' ', '\n' }; string[] tokens = ver.Split(delim); int i = 0; foreach (string tok in tokens) { if (tok.Equals("Firmware")) break; i++; } // Display the Firmware version ver = ""; for (int j = 0; j < 7; j++) { ver += tokens[i + j] + " "; } ver += "\n" + Dome_Control.Resources.Strings.DomeConnectionLabel + _dome._telescope.Name; // Show the AVR Firmware version into a message box System.Windows.MessageBox.Show(ver, "Info", MessageBoxButton.OK, MessageBoxImage.Information); // // Display the Control Tab into the GUI // // MainTab.SelectedIndex++; AVRCOMListBox.Items.Add(_dome.getArduinoPortName()); AVRCOMListBox.SelectedItem = _dome.getArduinoPortName(); AVRBaudrateListBox.SelectedIndex = 3; // // Start the Timers // mainTimer.Start(); // graphTimer.Start(); // Change the StatusBar Icon ConnectionImage.Source = new BitmapImage(new Uri(@"./images/ConnectedImg.png", UriKind.Relative)); // Change the StatusBar labels // ConnectionStatusLabel.Content = Properties.Resources.StatusBar_Connected; ConnectionStatusLabel.Content = Dome_Control.Resources.Strings.StatusBar_Connected; StatusBar_Version.Content = "FW Ver. : " + tokens[i + 1] + " " + tokens[i + 2]; // ASCOMConnectButton.Content = Properties.Resources.Button_Disconnect; ASCOMConnectButton.Content = Dome_Control.Resources.Strings.Button_Disconnect; } else { // // Disconnect the AVR Device // _dome.Connected = false; //((App)(System.Windows.Application.Current))._Dome_uC.Disconnect(); // Stops the timers mainTimer.Stop(); // graphTimer.Stop(); // Change the StatusBar Icon ConnectionImage.Source = new BitmapImage(new Uri(@"./images/DisconnectedImg.png", UriKind.Relative)); // Change the StatusBar labels // ConnectionStatusLabel.Content = Properties.Resources.StatusBar_Disconnected; ConnectionStatusLabel.Content = Dome_Control.Resources.Strings.StatusBar_Disconnected; StatusBar_Version.Content = "FW Ver. : "; // ASCOMConnectButton.Content = Properties.Resources.Button_Connect; ASCOMConnectButton.Content = Dome_Control.Resources.Strings.Button_Connect; // // If it is AVR Bootloader help to get into the AVR user code via avrdude // if (!isArduinoBootloader) { launchAVRDude(); System.Threading.Thread.Sleep(3000); } } //_telescope = new ASCOM_Telescope(); //ErrDlg("Telescope: " + Telescope.geetDeclination().ToString(), new Exception()); // ASCOMConnectButton.Content = Properties.Resources.Button_Disconnect; ASCOMConnectButton.Content = Dome_Control.Resources.Strings.Button_Connect; // Display a message box stating that the dome is disconnected // System.Windows.MessageBox.Show("Insert a string here", "Information", MessageBoxButton.OK, MessageBoxImage.Warning); } catch (Exception ex) { ErrDlg("Error Opening ASCOM or Arduino", ex); } }
protected override void ProcessRecord() { m_dome = new Dome(m_deviceId); WriteObject(m_dome); }
void Awake() { instance = this; }
private void Awake() { _dome = GetComponentInParent <Dome>(); _anim = GetComponent <Animator>(); _audio = GetComponent <AudioSource>(); }
private void timer1_Tick(object sender, EventArgs e) { lblVoltageBox.Text = (Dome.rotatorVoltage / 100.0).ToString("0,0.00"); if (Dome.rotatorVoltage <= Dome.rotatorCutoff) { lblLowWarn.Visible = true; } else { lblLowWarn.Visible = false; } lblPosition.Text = Dome.rotatorPosition.ToString(); lblAzimuth.Text = Dome.azimuth.ToString("0,0.00"); lblHomedState.Text = HomedText(Dome.rotatorHomedStatus); lblSeekMode.Text = SeekText(Dome.rotatorSeekState); if (Dome.rotatorHomedStatus == (int)HomeStatuses.ATHOME) { btnCalibrate.Enabled = true; } else { btnCalibrate.Enabled = false; } if (Dome.rotatorSeekState == (int)Seeks.HOMING_NONE || Dome.rotatorSeekState > (int)Seeks.HOMING_HOME) { isHoming = false; } Dome.LogMessage("Rotator Settings Get", "Slew Direction ({0})", Dome.rotatorSlewDirection); if (Dome.rotatorSlewDirection == -1) { lblMultiStatus.Text = "<<<"; } else if (Dome.rotatorSlewDirection == 1) { lblMultiStatus.Text = ">>>"; } else { lblMultiStatus.Text = "---"; } if (Dome.rotatorStepsPer != _stepsPer) { _stepsPer = Dome.rotatorStepsPer; Dome.tl.LogMessage("Rotator", "Calibration completed"); tbxStepsPerRotation.Text = Dome.rotatorStepsPer.ToString(); } if (myDome.AtPark == true) { lblAtPark.Visible = true; } else { lblAtPark.Visible = false; } if (Dome.isRaining == true) { lblRainState.Text = GlobalStrings.RainStateRainingText; lblRainState.ForeColor = Color.White; lblRainState.BackColor = Color.Red; } else { lblRainState.Text = GlobalStrings.RainStateNotRainingText; lblRainState.ForeColor = SystemColors.ControlText; lblRainState.BackColor = SystemColors.Control; } }
static void Main(string[] args) { string Filename = args[0]; int largestX = int.MinValue; int largestY = int.MinValue; List <Shape> shapes = new List <Shape>(); XmlReaderSettings settings = new XmlReaderSettings(); settings.ConformanceLevel = ConformanceLevel.Fragment; using (TextReader reader = new StreamReader(Filename)) { XmlReader xmlreader = XmlReader.Create(reader, settings); while (xmlreader.Read()) { if (xmlreader.Name == "AreaDefinition" && xmlreader.NodeType != XmlNodeType.EndElement) { string shape = xmlreader.GetAttribute("shape"); if (shape == "sphere") { Sphere sphere = new Sphere() { X = (int)float.Parse(xmlreader.GetAttribute("z1")), Y = -(int)float.Parse(xmlreader.GetAttribute("x1")), Radius = (int)float.Parse(xmlreader.GetAttribute("radius")), }; shapes.Add(sphere); if (largestX < sphere.X + sphere.Radius) { largestX = sphere.X + sphere.Radius; } if (largestY < Math.Abs(sphere.Y) + sphere.Radius) { largestY = Math.Abs(sphere.Y) + sphere.Radius; } } else if (shape == "box") { Box b = new Box() { X1 = (int)float.Parse(xmlreader.GetAttribute("z1")), Y1 = -(int)float.Parse(xmlreader.GetAttribute("x1")), X2 = (int)float.Parse(xmlreader.GetAttribute("z2")), Y2 = -(int)float.Parse(xmlreader.GetAttribute("x2")), }; shapes.Add(b); if (largestX < b.X2) { largestX = b.X2; } if (largestY < Math.Abs(b.Y2)) { largestY = Math.Abs(b.Y2); } } else if (shape == "dome") { Dome sphere = new Dome() { X = (int)float.Parse(xmlreader.GetAttribute("z1")), Y = -(int)float.Parse(xmlreader.GetAttribute("x1")), }; shapes.Add(sphere); if (largestX < sphere.X + 1) { largestX = sphere.X + 1; } if (largestY < Math.Abs(sphere.Y) + 1) { largestY = Math.Abs(sphere.Y) + 1; } } else { throw new Exception("No idea what " + shape + " Is"); } } } } largestX = Math.Abs(largestX); largestY = Math.Abs(largestY); Bitmap image = new Bitmap(largestX * 2, largestY * 2); Graphics g = Graphics.FromImage(image); SolidBrush brush = new SolidBrush(Color.Black); g.FillRectangle(brush, new Rectangle(0, 0, largestX * 2, largestY * 2)); foreach (Shape s in shapes) { s.Scale(largestX, largestY); s.DrawShapeOnCanvas(g); } string outputname = Filename.Replace(".xml", "") + "-Map.png"; image.Save(outputname, System.Drawing.Imaging.ImageFormat.Png); }
static void Main(string[] args) { string progID; Util U = new Util(); #region Focuser Console.WriteLine("\r\nFocuser:"******"ASCOM.Simulator.Focuser"); // Pre-select simulator (typ.) if (progID != "") { Focuser F = new Focuser(progID); F.Link = true; Console.WriteLine(" Connected to " + progID); Console.WriteLine(" Current position is " + F.Position); int nfp = (int)(0.7 * F.Position); Console.Write(" Moving to " + nfp); F.Move(nfp); while (F.IsMoving) { Console.Write("."); U.WaitForMilliseconds(333); } Console.WriteLine("\r\n Move complete. New position is " + F.Position.ToString()); F.Link = false; F.Dispose(); // Release this now, not at exit (typ.) } #endregion #region Telescope Console.WriteLine("\r\nTelescope:"); progID = Telescope.Choose("ASCOM.Simulator.Telescope"); if (progID != "") { Telescope T = new Telescope(progID); T.Connected = true; Console.WriteLine(" Connected to " + progID); Console.WriteLine(" Current LST = " + U.HoursToHMS(T.SiderealTime)); Console.WriteLine(" Current RA = " + U.HoursToHMS(T.RightAscension)); Console.WriteLine(" Current DEC = " + U.DegreesToDMS(T.Declination)); Console.WriteLine(" CanSetTracking = " + T.CanSetTracking); if (T.CanSetTracking) { Console.WriteLine(" Turning Tracking off..."); T.Tracking = false; Console.WriteLine(" Tracking is now " + (T.Tracking ? "on" : "off") + "."); Console.WriteLine(" Wait 5 seconds..."); U.WaitForMilliseconds(5000); Console.WriteLine(" Turning Tracking back on..."); T.Tracking = true; } Console.WriteLine(" Latitude = " + U.DegreesToDMS(T.SiteLatitude)); Console.WriteLine(" Longitude = " + U.DegreesToDMS(T.SiteLongitude)); Console.Write(" Slewing to point 1"); T.SlewToCoordinatesAsync(T.SiderealTime - 2, (T.SiteLatitude > 0 ? +55 : -55)); while (T.Slewing) { Console.Write("."); U.WaitForMilliseconds(300); } Console.WriteLine("\r\n Slew complete."); Console.Write(" Slewing to point 2"); T.SlewToCoordinatesAsync(T.SiderealTime + 2, (T.SiteLatitude > 0 ? +35 : -35)); while (T.Slewing) { Console.Write("."); U.WaitForMilliseconds(300); } Console.WriteLine("\r\n Slew complete."); IAxisRates AxR = T.AxisRates(TelescopeAxes.axisPrimary); Console.WriteLine(" " + AxR.Count + " rates"); if (AxR.Count == 0) { Console.WriteLine(" Empty AxisRates"); } else { foreach (IRate r in AxR) { Console.WriteLine(" Max=" + r.Maximum + " Min=" + r.Minimum); } } ITrackingRates TrR = T.TrackingRates; if (TrR.Count == 0) { Console.WriteLine(" Empty TrackingRates!"); } else { foreach (DriveRates dr in TrR) { Console.WriteLine(" DriveRate=" + dr); } } T.Connected = false; T.Dispose(); } #endregion #region Camera Console.WriteLine("\r\nCamera:"); progID = Camera.Choose("ASCOM.Simulator.Camera"); if (progID != "") { Camera C = new Camera(progID); C.Connected = true; Console.WriteLine(" Connected to " + progID); Console.WriteLine(" Description = " + C.Description); Console.WriteLine(" Pixel size = " + C.PixelSizeX + " * " + C.PixelSizeY); Console.WriteLine(" Camera size = " + C.CameraXSize + " * " + C.CameraYSize); Console.WriteLine(" Max Bin = " + C.MaxBinX + " * " + C.MaxBinY); Console.WriteLine(" Bin = " + C.BinX + " * " + C.BinY); Console.WriteLine(" MaxADU = " + C.MaxADU); Console.WriteLine(" CameraState = " + C.CameraState.ToString()); Console.WriteLine(" CanAbortExposure = " + C.CanAbortExposure); Console.WriteLine(" CanAsymmetricBin = " + C.CanAsymmetricBin); Console.WriteLine(" CanGetCoolerPower = " + C.CanGetCoolerPower); Console.WriteLine(" CanPulseGuide = " + C.CanPulseGuide); Console.WriteLine(" CanSetCCDTemperature = " + C.CanSetCCDTemperature); Console.WriteLine(" CanStopExposure = " + C.CanStopExposure); Console.WriteLine(" CCDTemperature = " + C.CCDTemperature); if (C.CanGetCoolerPower) { Console.WriteLine(" CoolerPower = " + C.CoolerPower); } Console.WriteLine(" ElectronsPerADU = " + C.ElectronsPerADU); Console.WriteLine(" FullWellCapacity = " + C.FullWellCapacity); Console.WriteLine(" HasShutter = " + C.HasShutter); Console.WriteLine(" HeatSinkTemperature = " + C.HeatSinkTemperature); if (C.CanPulseGuide) { Console.WriteLine(" IsPulseGuiding = " + C.IsPulseGuiding); } Console.Write(" Take 15 second image"); C.StartExposure(15.0, true); while (!C.ImageReady) { Console.Write("."); U.WaitForMilliseconds(300); } Console.WriteLine("\r\n Exposure complete, ready for download."); Console.WriteLine(" CameraState = " + C.CameraState.ToString()); Console.WriteLine(" LastExposureDuration = " + C.LastExposureDuration); Console.WriteLine(" LastExposureStartTime = " + C.LastExposureStartTime); int[,] imgArray = (int[, ])C.ImageArray; Console.WriteLine(" Array is " + (imgArray.GetUpperBound(0) + 1) + " by " + (imgArray.GetUpperBound(1) + 1)); C.Connected = false; C.Dispose(); } #endregion #region FilterWheel Console.WriteLine("\r\nFilterWheel:"); progID = FilterWheel.Choose("ASCOM.Simulator.FilterWheel"); if (progID != "") { FilterWheel fw = new FilterWheel(progID); fw.Connected = true; Console.WriteLine(" Position = " + fw.Position); string[] names = fw.Names; Console.WriteLine(" There are " + names.Length + " filters:\r\n "); for (int i = 0; i < names.Length; i++) { Console.Write(names[i] + " "); } Console.WriteLine(""); fw.Connected = false; fw.Dispose(); } #endregion #region Rotator Console.WriteLine("\r\nRotator:"); progID = Rotator.Choose("ASCOM.Simulator.Rotator"); if (progID != "") { Rotator R = new Rotator(progID); R.Connected = true; Console.WriteLine(" Position = " + R.Position); float np = R.Position + 60; if (np >= 360) { np -= 360; } Console.Write(" Rotating to " + np.ToString("0")); R.MoveAbsolute(np); while (R.IsMoving) { Console.Write("."); U.WaitForMilliseconds(300); } Console.WriteLine("\r\n Rotation complete."); R.Connected = false; R.Dispose(); } #endregion #region Dome Console.WriteLine("\r\nDome:"); progID = Dome.Choose("ASCOM.Simulator.Dome"); if (progID != "") { Dome D = new Dome(progID); D.Connected = true; Console.WriteLine(" Description = " + D.Description); Console.WriteLine(" Name = " + D.Name); if (D.CanSetAzimuth) { Console.WriteLine(" This is a rotatable dome"); Console.WriteLine(" Current slit azimuth = " + D.Azimuth.ToString("0.0")); double z = D.Azimuth + 60; if (z >= 360) { z -= 360; } D.SlewToAzimuth(z); Console.Write(" Rotating to azimuth " + z.ToString("0")); while (D.Slewing) { Console.Write("."); U.WaitForMilliseconds(300); } Console.WriteLine("\r\n Rotation complete."); } if (D.CanSetShutter) { if (D.CanSetAzimuth) { Console.WriteLine(" This dome has a controllable shutter"); } else { Console.WriteLine(" This is a roll-off roof"); } Console.WriteLine(" It is currently " + D.ShutterStatus.ToString()); switch (D.ShutterStatus) { case ShutterState.shutterClosed: Console.Write(" Opening"); D.OpenShutter(); while (D.ShutterStatus != ShutterState.shutterOpen && D.ShutterStatus != ShutterState.shutterError) { Console.Write("."); U.WaitForMilliseconds(300); } Console.WriteLine("\r\n It is now " + D.ShutterStatus.ToString()); break; case ShutterState.shutterOpen: Console.Write(" Closing"); D.CloseShutter(); while (D.ShutterStatus != ShutterState.shutterClosed && D.ShutterStatus != ShutterState.shutterError) { Console.Write("."); U.WaitForMilliseconds(300); } Console.WriteLine("\r\n It is now " + D.ShutterStatus.ToString()); break; case ShutterState.shutterError: Console.WriteLine(" ** cannot do anything right now **"); break; default: Console.WriteLine(" ** it's moving so can't do anythjing else now **"); break; } } D.Connected = false; D.Dispose(); } #endregion Console.Write("\r\nPress enter to quit..."); Console.ReadLine(); }