public void generateDataFiles() { string directory = string.Format("c:/temp/MotionStudy/{0}/{1}/{2}.dat", motorStopPoint.millis.ToString("yyyy-MMM-dd_HH-mm"), axis.ToString().Substring(4), WiseTele.RateName(Math.Abs(rate))); System.IO.Directory.CreateDirectory(System.IO.Path.GetDirectoryName(directory)); string rateName = WiseTele.RateName(Math.Abs(rate)); string datFile = System.IO.Path.Combine(directory, rateName + ".dat"); System.IO.StreamWriter sw = new System.IO.StreamWriter(datFile); //sw.WriteLine(string.Format(";")); //sw.WriteLine(string.Format("; Start to motor stop: {0} millis", motorStop.Subtract(start).TotalMilliseconds)); //sw.WriteLine(string.Format("; Start to motor stop: {0} delta", Math.Abs(motorStopValue - startValue))); //sw.WriteLine(string.Format("; Motor stop to axis stop: {0} millis", axisStop.Subtract(motorStop).TotalMilliseconds)); //sw.WriteLine(string.Format("; Motor stop to axis stop: {0} millis", Math.Abs(axisStopValue - motorStopValue))); //sw.WriteLine(string.Format(";")); foreach (DataPoint point in dataPoints) { sw.WriteLine(point.ToString()); } sw.Close(); string gnuplotFile = System.IO.Path.Combine(directory, rateName + ".pl"); sw = new System.IO.StreamWriter(gnuplotFile); sw.WriteLine(""); sw.WriteLine(string.Format("plot '{0}' with lines title \"{1}\"", datFile, axis.ToString().Substring(4) + " " + rateName)); sw.Close(); }
public void SetOn(double rate) { rate = Math.Abs(rate); string activeBefore = ActiveMortorPins(); if (motorPin != null && motorPin.isOn) { motorPin.SetOff(); } if (guideMotorPin != null && guideMotorPin.isOn) { guideMotorPin.SetOff(); } if (slewPin != null && slewPin.isOn) { bool inUseByOtherAxis = false; foreach (WiseVirtualMotor m in wisetele.axisMotors[_otherAxis]) { if (m.currentRate == Const.rateSlew) { inUseByOtherAxis = true; break; } } if (!inUseByOtherAxis) { slewPin.SetOff(); } } currentRate = rate; if (rate == Const.rateSlew) { slewPin.SetOn(); motorPin.SetOn(); } else if (rate == Const.rateSet) { motorPin.SetOn(); } else if (rate == Const.rateGuide) { guideMotorPin.SetOn(); } else if (rate == Const.rateTrack) { motorPin.SetOn(); } debugger.WriteLine(Debugger.DebugLevel.DebugAxes, "{0}.SetOn at {1}: pins before: {2}, pins after: {3}", WiseName, WiseTele.RateName(rate), activeBefore, ActiveMortorPins()); if (Simulated) { timer_counts = 0; prevTick = DateTime.Now; simulationTimer.Change(0, 1000 / simulationTimerFrequency); } }
public void AxisBecomesReadyToMoveAtRate(TelescopeAxes axis, double rate) { long newValue = -1; lock (_lock) { switch (axis) { case TelescopeAxes.axisPrimary: if (rate == Const.rateSlew) { newValue = Interlocked.Increment(ref primaryReadyForSlew); } else if (rate == Const.rateSet) { newValue = Interlocked.Increment(ref primaryReadyForSet); } else if (rate == Const.rateGuide) { newValue = Interlocked.Increment(ref primaryReadyForGuide); } break; case TelescopeAxes.axisSecondary: if (rate == Const.rateSlew) { newValue = Interlocked.Increment(ref secondaryReadyForSlew); } else if (rate == Const.rateSet) { newValue = Interlocked.Increment(ref secondaryReadyForSet); } else if (rate == Const.rateGuide) { newValue = Interlocked.Increment(ref secondaryReadyForGuide); } break; } } #region debug debugger.WriteLine(Debugger.DebugLevel.DebugAxes, "AxisBecomesReadyToMoveAtRate: {0} at {1} (newValue: {2})", axis.ToString(), WiseTele.RateName(rate), newValue); #endregion }
public string ActiveMotors(TelescopeAxes axis) { string ret = string.Empty; List <WiseVirtualMotor> motors = new List <WiseVirtualMotor>(wisetele.axisMotors[axis]); if (axis == TelescopeAxes.axisPrimary) { motors.Add(wisetele.TrackingMotor); } foreach (var m in motors) { if (m.isOn) { ret += m.WiseName + " (" + WiseTele.RateName(m.currentRate) + ") "; } } return(ret); }
public void generateDataFiles() { string rateName = WiseTele.RateName(Math.Abs(rate)); string directory = string.Format(Const.topWise40Directory + "Telescope/MotionStudy/{0}/{1}/{2}", motorStop.ToString("yyyy-MMM-dd_HH-mm"), axis.ToString().Substring(4), rateName); System.IO.Directory.CreateDirectory(directory); string radiansFile = System.IO.Path.Combine(directory, "radians.dat"); string velocitiesFile = System.IO.Path.Combine(directory, "velocities.dat"); System.IO.StreamWriter radians = new System.IO.StreamWriter(radiansFile); System.IO.StreamWriter velocities = new System.IO.StreamWriter(velocitiesFile); //sw.WriteLine(string.Format(";")); //sw.WriteLine(string.Format("; Start to motor stop: {0} millis", motorStop.Subtract(start).TotalMilliseconds)); //sw.WriteLine(string.Format("; Start to motor stop: {0} delta", Math.Abs(motorStopValue - startValue))); //sw.WriteLine(string.Format("; Motor stop to axis stop: {0} millis", axisStop.Subtract(motorStop).TotalMilliseconds)); //sw.WriteLine(string.Format("; Motor stop to axis stop: {0} millis", Math.Abs(axisStopValue - motorStopValue))); //sw.WriteLine(string.Format(";")); for (int i = 0; i < dataPoints.Count; i++) { DataPoint dp = dataPoints[i]; radians.WriteLine(dp.ToString()); if (i > 0) { DataPoint dpPrev = dataPoints[i - 1]; double v = Math.Abs(dp.value - dpPrev.value) / (dp.millis - dpPrev.millis); velocities.WriteLine(string.Format("{0} {1}", dp.millis, v.ToString("F10"))); } } radians.Close(); velocities.Close(); string gnuplotFile = System.IO.Path.Combine(directory, rateName + ".pl"); System.IO.StreamWriter gnuPlot = new System.IO.StreamWriter(gnuplotFile); gnuPlot.WriteLine(""); gnuPlot.WriteLine(string.Format("plot '{0}' with lines title \"radians\"", radiansFile)); gnuPlot.WriteLine(string.Format("plot '{0}' with lines title \"velocity\"", velocitiesFile)); gnuPlot.Close(); }
public void RefreshDisplay() { //if (!panelControls.Visible) // return; DateTime now = DateTime.Now; DateTime utc = now.ToUniversalTime(); ASCOM.Utilities.Util u = new Utilities.Util(); labelDate.Text = utc.ToLongDateString(); labelLTValue.Text = now.TimeOfDay.ToString(@"hh\hmm\mss\.f\s"); labelUTValue.Text = utc.TimeOfDay.ToString(@"hh\hmm\mss\.f\s"); labelSiderealValue.Text = wisesite.LocalSiderealTime.ToString(); labelRightAscensionValue.Text = Angle.FromHours(wisetele.RightAscension).ToNiceString(); labelDeclinationValue.Text = Angle.FromDegrees(wisetele.Declination).ToNiceString(); labelHourAngleValue.Text = Angle.FromHours(wisetele.HourAngle, Angle.Type.HA).ToNiceString(); labelNewRA.Text = ""; labelNewRARadians.Text = Angle.FromHours(wisetele.RightAscension).Radians.ToString(); labelNewDec.Text = ""; labelNewDecRadians.Text = Angle.FromDegrees(wisetele.Declination).Radians.ToString(); labelAltitudeValue.Text = Angle.FromDegrees(wisetele.Altitude).ToNiceString(); labelAzimuthValue.Text = Angle.FromDegrees(wisetele.Azimuth).ToNiceString(); labelHAEncValue.Text = wisetele.HAEncoder.Value.ToString(); labelDecEncValue.Text = wisetele.DecEncoder.Value.ToString(); axisValue.Text = wisetele.HAEncoder.AxisValue.ToString(); wormValue.Text = wisetele.HAEncoder.WormValue.ToString(); string why; if (wisesite.computerControl == null) { labelTelescopeComputerControl.ForeColor = Color.Yellow; why = "Cannot read the computer control switch!"; } else if (wisesite.computerControl.IsSafe) { labelTelescopeComputerControl.ForeColor = Color.Green; why = "Computer control is enabled."; } else { labelTelescopeComputerControl.ForeColor = Color.Red; why = why = "Computer control switch is OFF!"; } toolTip.SetToolTip(labelTelescopeComputerControl, why); if (wisesite.safeToOpen == null) { labelTelescopeSafeToOpen.ForeColor = Color.Yellow; why = "Cannot connect to the safeToOpen driver!"; } else if (wisesite.safeToOpen.IsSafe) { labelTelescopeSafeToOpen.ForeColor = Color.Green; why = "Conditions are safe to open the dome."; } else { labelTelescopeSafeToOpen.ForeColor = Color.Red; why = wisesite.safeToOpen.CommandString("unsafeReasons", false); } toolTip.SetToolTip(labelTelescopeSafeToOpen, why); if (wisesite.safeToImage == null) { labelTelescopeSafeToImage.ForeColor = Color.Yellow; why = "Cannot connect to the safeToImage driver!"; } else if (wisesite.safeToImage.IsSafe) { labelTelescopeSafeToImage.ForeColor = Color.Green; why = "Conditions are safe to image."; } else { labelTelescopeSafeToImage.ForeColor = Color.Red; why = wisesite.safeToImage.CommandString("unsafeReasons", false); } toolTip.SetToolTip(labelTelescopeSafeToImage, why); checkBoxPrimaryIsActive.Checked = wisetele.AxisIsMoving(TelescopeAxes.axisPrimary); checkBoxSecondaryIsActive.Checked = wisetele.AxisIsMoving(TelescopeAxes.axisSecondary); string activeSlewers = wisetele.slewers.ToString(); checkBoxSlewingIsActive.Text = (activeSlewers == string.Empty) ? "Slewing" : "Slewing (" + activeSlewers + ")"; checkBoxSlewingIsActive.Checked = wisetele.Slewing; checkBoxTrackingIsActive.Checked = wisetele.Tracking; WiseVirtualMotor m; m = null; if (wisetele.WestMotor.isOn) { m = wisetele.WestMotor; } else if (wisetele.EastMotor.isOn) { m = wisetele.EastMotor; } checkBoxPrimaryIsActive.Text = "Primary"; if (m != null) { checkBoxPrimaryIsActive.Text += ": " + m.Name.Remove(m.Name.IndexOf('M')) + "@" + WiseTele.RateName(m.currentRate).Replace("rate", ""); } m = null; if (wisetele.NorthMotor.isOn) { m = wisetele.NorthMotor; } else if (wisetele.SouthMotor.isOn) { m = wisetele.SouthMotor; } checkBoxSecondaryIsActive.Text = "Secondary"; if (m != null) { checkBoxSecondaryIsActive.Text += ": " + m.Name.Remove(m.Name.IndexOf('M')) + "@" + WiseTele.RateName(m.currentRate).Replace("rate", ""); } checkBoxTrack.Checked = wisetele.Tracking; if (scopeBackgroundMover != null && scopeBackgroundMover.IsBusy) { TextBoxLog.Text = "Working ..."; } if (resultsAvailable) { TextBoxLog.Clear(); if (results.Count == 0) { TextBoxLog.Text = "Cancelled by user!"; } else { TelescopeAxes axis = results[0].axis; for (int i = 0; i < results.Count; i++) { TextBoxLog.Text += string.Format("[{0}]: ({2})\r\n{1}", i, results[i].ToString(), results[i].cancelled ? "cancelled" : "completed"); } } resultsAvailable = false; } if (panelDome.Visible) { labelDomeAzimuthValue.Text = domeSlaveDriver.Azimuth; labelDomeStatusValue.Text = domeSlaveDriver.Status; labelDomeShutterStatusValue.Text = domeSlaveDriver.ShutterStatus; checkBoxVent.Checked = WiseDome.Instance.Vent; } if (groupBoxWeather.Visible) { if (!wisesite.observingConditions.Connected) { string nc = "???"; labelAgeValue.Text = nc; labelCloudCoverValue.Text = nc; labelCloudCoverValue.Text = nc; labelDewPointValue.Text = nc; labelSkyTempValue.Text = nc; labelTempValue.Text = nc; labelHumidityValue.Text = nc; labelPressureValue.Text = nc; labelRainRateValue.Text = nc; labelWindSpeedValue.Text = nc; labelWindDirValue.Text = nc; } else { try { ObservingConditions oc = wisesite.observingConditions; labelAgeValue.Text = ((int)Math.Round(oc.TimeSinceLastUpdate(""), 2)).ToString() + "sec"; double d = oc.CloudCover; if (d == 0.0) { labelCloudCoverValue.Text = "Clear"; } else if (d == 50.0) { labelCloudCoverValue.Text = "Cloudy"; } else if (d == 90.0) { labelCloudCoverValue.Text = "VeryCloudy"; } else { labelCloudCoverValue.Text = "Unknown"; } labelDewPointValue.Text = oc.DewPoint.ToString() + "°C"; labelSkyTempValue.Text = oc.SkyTemperature.ToString() + "°C"; labelTempValue.Text = oc.Temperature.ToString() + "°C"; labelHumidityValue.Text = oc.Humidity.ToString() + "%"; labelPressureValue.Text = oc.Pressure.ToString() + "mB"; labelRainRateValue.Text = (oc.RainRate > 0.0) ? "Wet" : "Dry"; labelWindSpeedValue.Text = oc.WindSpeed.ToString() + "m/s"; labelWindDirValue.Text = oc.WindDirection.ToString() + "°"; } catch (PropertyNotImplementedException e) { debugger.WriteLine(Debugger.DebugLevel.DebugLogic, "OC: exception: {0}", e.Message); } } } if (panelFocuser.Visible) { labelFocusCurrentValue.Text = wisefocuser.position.ToString();; } }
/// <summary> /// This is used only by simulated motors. /// It is called at a timer interval (simulationTimerFrequency) and increases/decreases /// the attached encoder(s) according to the motor's currentRate. /// /// The TrackMotor is a special case. /// </summary> /// <param name="StateObject"></param> private void bumpEncoders(object StateObject) { if (!Simulated) { return; } bool primary = (_axis == TelescopeAxes.axisPrimary) ? true : false; Angle delta = Angle.zero; // // Calculate the delta to be added/subtracted from the attached encoder(s) // if (WiseName == "TrackMotor") { // // To better simulate the tracking-motor, we use the actual LocalSiderealTime // that passed since the last time we read it. This neutralizes // inaccuracies of the timer intervals. // // The wisetele._lastTrackingLST variable gets initialized each time // Tracking is enabled. // double lstHoursNow = wisesite.LocalSiderealTime.Hours; delta = Angle.FromHours(lstHoursNow - wisetele._lastTrackingLST); wisetele._lastTrackingLST = lstHoursNow; } else { double degrees = currentRate / simulationTimerFrequency; double hours = Angle.Deg2Hours(currentRate) / simulationTimerFrequency; delta = primary ? Angle.FromHours(hours, Angle.Type.HA) : Angle.FromDegrees(degrees, Angle.Type.Dec); } foreach (IEncoder encoder in encoders) { Angle before, after; string op; lock (primary ? wisetele._primaryEncoderLock : wisetele._secondaryEncoderLock) { before = primary ? Angle.FromHours(wisetele.HourAngle, Angle.Type.HA) : Angle.FromDegrees(wisetele.Declination, Angle.Type.Dec); if (_direction == Const.AxisDirection.Increasing) { if (primary) { op = "-"; encoder.Angle -= delta; } else { op = "+"; encoder.Angle += delta; } } else { if (primary) { op = "+"; encoder.Angle += delta; } else { op = "-"; encoder.Angle -= delta; } } after = primary ? Angle.FromHours(wisetele.HourAngle, Angle.Type.HA) : Angle.FromDegrees(wisetele.Declination, Angle.Type.Dec); } debugger.WriteLine(Debugger.DebugLevel.DebugMotors, "bumpEncoders: {0}: {1}: {13} {2}: {3} {4} {5} = {6} ({7} {8} {9} = {10}) (#{11}, {12} ms)", WiseName, // 0 encoder.WiseName, // 1 primary ? "ha" : "dec", // 2 before, // 3 op, // 4 delta, // 5 after, // 6 before.Degrees, // 7 op, // 8 delta.Degrees, // 9 after.Degrees, // 10 timer_counts++, // 11 DateTime.Now.Subtract(prevTick).Milliseconds, // 12 WiseTele.RateName(currentRate)); // 13 prevTick = DateTime.Now; } }