Пример #1
0
 /// <summary>
 /// Create a controlled z actuator
 /// </summary>
 /// <param name="controller">RCCM Trio controller object</param>
 /// <param name="axisNum">Number of port where axis is connected to Trio controller</param>
 /// <param name="rccm">The RCCM object</param>
 /// <param name="stage">Enum value of the set of fine actuators containing this actuator</param>
 public TrioStepperZMotor(TrioController controller, short axisNum, RCCMSystem rccm, RCCMStage stage)
 {
     this.controller = controller;
     this.axisNum    = axisNum;
     this.Jogging    = false;
     // Create height function reference from lens controller height property
     if (stage == RCCMStage.RCCM1)
     {
         this.height = delegate() { return(rccm.LensController.Height1); };
     }
     else
     {
         this.height = delegate() { return(rccm.LensController.Height2); };
     }
     // Create function reference that computes height of panel at current location
     this.minPosition = delegate()
     {
         PointF pos = rccm.GetNFOVLocation(stage, CoordinateSystem.Local);
         return(rccm.GetPanelDistance(pos.X, pos.Y));
     };
     this.commandHeight = this.height();
     // Start background thread
     this.bw                 = new BackgroundWorker();
     this.bw.DoWork         += new DoWorkEventHandler(this.heightAdjustLoop);
     this.adjustThreadExited = new AutoResetEvent(false);
     this.adjust             = true;
     this.adjustThreadPaused = false;
     this.bw.RunWorkerAsync();
 }
Пример #2
0
        /// <summary>
        /// Initialize panel view
        /// </summary>
        /// <param name="rccm">Reference to RCCM object</param>
        public PanelView(RCCMSystem rccm)
        {
            this.rccm = rccm;
            // Create rectangle for displaying panel
            this.panel      = new RectangleF();
            this.panelImage = Image.FromFile((string)Program.Settings.json["panel"]["image file"]);
            // Create rectangle for displaying coarse stages
            float wCoarse = (float)Program.Settings.json["coarse stage"]["x travel"];
            float hCoarse = (float)Program.Settings.json["coarse stage"]["y travel"];

            this.coarse = new RectangleF(0, 0, wCoarse, hCoarse);
            // Create rectangles for displaying fine stages
            float wFine1 = (float)Program.Settings.json["fine 1"]["x travel"];
            float hFine1 = (float)Program.Settings.json["fine 1"]["y travel"];
            float wFine2 = (float)Program.Settings.json["fine 2"]["x travel"];
            float hFine2 = (float)Program.Settings.json["fine 2"]["y travel"];

            this.fine1 = new RectangleF(0, 0, wFine1, hFine1);
            this.fine2 = new RectangleF(0, 0, wFine2, hFine2);
            // Create brushes/pens to draw with
            this.font        = new Font(FontFamily.GenericSansSerif, 4, FontStyle.Regular);
            this.fontBrush   = new SolidBrush(Color.Black);
            this.coarseBrush = new SolidBrush(Color.FromArgb(128, Color.Gray));
            this.fineBrush   = new SolidBrush(Color.FromArgb(128, Color.Green));
            this.pen         = new Pen(Color.Black, 0);
            // Initialize matrix for holding coordinate system transform
            this.transform = new Matrix();
            this.updatePositions();
        }
Пример #3
0
        /// <summary>
        /// Check if measurement conditions match calibration conditions
        /// </summary>
        /// <param name="rccm"></param>
        /// <returns>True if measurement conditions match calibration</returns>
        public bool CheckFOV(RCCMSystem rccm)
        {
            // Get z motor for this stage
            Motor z = this == rccm.NFOV1 ? rccm.motors["fine 1 Z"] : rccm.motors["fine 2 Z"];
            // Get curernt height
            double h = z.GetPos();

            // Check that calibration height and current height are within a tolerance
            return(Math.Abs(this.CalibrationHeight - h) < 3 * TrioStepperZMotor.ERROR);
        }
Пример #4
0
        /// <summary>
        /// Set image scale and save current height
        /// </summary>
        /// <param name="rccm"></param>
        /// <param name="scale">New calibration</param>
        public void SetScale(RCCMSystem rccm, double scale)
        {
            // Get z motor for this stage
            Motor z = this == rccm.NFOV1 ? rccm.motors["fine 1 Z"] : rccm.motors["fine 2 Z"];

            this.CalibrationHeight = z.GetPos();

            string camera = this == rccm.NFOV1 ? "nfov 1" : "nfov 2";

            Program.Settings.json[camera]["calibration height"] = this.CalibrationHeight;

            this.Scale = scale;
        }
Пример #5
0
 /// <summary>
 /// Write positions to file
 /// </summary>
 public static void SavePositions(RCCMSystem rccm)
 {
     using (StreamWriter positionsFile = new StreamWriter("log/positions.csv"))
     {
         positionsFile.Write(String.Format("coarse X,{0}\n", rccm.motors["coarse X"].GetActuatorPos()));
         positionsFile.Write(String.Format("coarse Y,{0}\n", rccm.motors["coarse Y"].GetActuatorPos()));
         positionsFile.Write(String.Format("fine 1 X,{0}\n", rccm.motors["fine 1 X"].GetActuatorPos()));
         positionsFile.Write(String.Format("fine 1 Y,{0}\n", rccm.motors["fine 1 Y"].GetActuatorPos()));
         positionsFile.Write(String.Format("fine 1 Z,{0}\n", rccm.motors["fine 1 Z"].GetActuatorPos()));
         positionsFile.Write(String.Format("fine 2 X,{0}\n", rccm.motors["fine 2 X"].GetActuatorPos()));
         positionsFile.Write(String.Format("fine 2 Y,{0}\n", rccm.motors["fine 2 Y"].GetActuatorPos()));
         positionsFile.Write(String.Format("fine 2 Z,{0}\n", rccm.motors["fine 2 Z"].GetActuatorPos()));
     }
 }
Пример #6
0
        /// <summary>
        /// Load positions from file
        /// </summary>
        public static void LoadPositions(RCCMSystem rccm)
        {
            try
            {
                string[] pairs = File.ReadAllText("log/positions.csv").Split('\n');

                foreach (string pair in pairs)
                {
                    string[] values = pair.Split(',');
                    if (values.Length == 2)
                    {
                        string motor    = values[0];
                        double position = Double.Parse(values[1]);
                        rccm.motors[motor].FixPosition(position);
                    }
                }
            }
            catch (Exception e)
            {
                MessageBox.Show("Failed to load positions file");
            }
        }
Пример #7
0
        public TestResults(RCCMSystem rccm, ObservableCollection <MeasurementSequence> cracks, Chart crackChart, Chart cycleChart, TextBox cycleIndicator, TextBox pressureIndicator, ListBox crackSelection)
        {
            // Initialize Paris law chart
            this.cracks = cracks;
            this.cracks.CollectionChanged += cracksChangedHandler;

            this.crackChart = crackChart;
            Title crackChartTitle = new Title("Crack Length vs Cycle Number");

            this.crackChart.Titles.Add(crackChartTitle);
            this.crackChart.ChartAreas[0].AxisX.Title = "Cycle";
            this.crackChart.ChartAreas[0].AxisY.Title = "Crack Length";
            // Initialize pressure vs time chart
            this.cycleChart = cycleChart;
            Title cycleChartTitle = new Title("Pressure Reading history");

            this.cycleChart.Titles.Add(cycleChartTitle);
            this.cycleChart.ChartAreas[0].AxisX.Title = "Time (s)";
            this.cycleChart.ChartAreas[0].AxisY.Title = "Pressure";
            this.cycleChart.Series[0].Name            = "Cycle";
            this.cycleChart.Series[0].ChartType       = SeriesChartType.Line;
            // Save cycle/pressure indicators for displaying test status & crack selection list
            this.cycleIndicator    = cycleIndicator;
            this.pressureIndicator = pressureIndicator;
            this.crackSelection    = crackSelection;
            // Save counter
            this.counter = rccm.Counter;
            // Create timer for updating test controls
            this.updateControlsTimer          = new Timer();
            this.updateControlsTimer.Enabled  = false;
            this.updateControlsTimer.Interval = (int)Program.Settings.json["repaint period"];
            this.updateControlsTimer.Tick    += new EventHandler(updateTestControls);
            this.updateControlsTimer.Start();
            // Create list for holding past pressure readings
            this.savedReadings = (int)Program.Settings.json["pressure readings saved"];
        }
Пример #8
0
        /// <summary>
        /// Create a measurement
        /// </summary>
        /// <param name="crack">Crack containing this measurement</param>
        /// <param name="rccm">Reference to RCCM object</param>
        /// <param name="pixelX">Pixel horizontal position within image to measurement</param>
        /// <param name="pixelY">Pixel vertical position within image to measurement</param>
        public Measurement(MeasurementSequence crack, RCCMSystem rccm, double pixelX, double pixelY)
        {
            // Get timestamp and save camera image
            ICamera   camera;
            string    stage;
            RCCMStage stageEnum;

            switch (crack.Camera)
            {
            case "nfov 1":
                stage     = "fine 1 ";
                stageEnum = RCCMStage.RCCM1;
                camera    = rccm.NFOV1;
                break;

            case "nfov 2":
                stage     = "fine 2 ";
                stageEnum = RCCMStage.RCCM2;
                camera    = rccm.NFOV2;
                break;

            case "wfov 1":
                stage     = "fine 1 ";
                stageEnum = RCCMStage.RCCM1;
                camera    = rccm.WFOV1;
                break;

            default:
                stage     = "fine 2 ";
                stageEnum = RCCMStage.RCCM2;
                camera    = rccm.WFOV2;
                break;
            }
            this.Timestamp = string.Format("{0:yyyy-MM-dd_hh-mm-ss-tt.fff}", DateTime.Now);
            this.Filename  = this.Timestamp + ".bmp";
            camera.Snap(crack.SaveDir + "\\" + this.Filename);

            // Info from cycle counter
            this.Cycle    = rccm.Counter.Cycle;
            this.Pressure = rccm.Counter.GetPressure();

            // Actuator positions
            this.CoarseX = rccm.motors["coarse X"].GetPos();
            this.CoarseY = rccm.motors["coarse Y"].GetPos();
            this.FineX   = rccm.motors[stage + "X"].GetPos();
            this.FineY   = rccm.motors[stage + "Y"].GetPos();
            this.FineZ   = rccm.motors[stage + "Z"].GetActuatorPos();
            this.Height  = stage == "fine 1 " ? rccm.LensController.Height1 : rccm.LensController.Height2;

            // Convert pixel position to coordinates in global and panel coordinate systems
            this.PixelX = pixelX;
            this.PixelY = pixelY;
            PointF globalPosition = rccm.GetNFOVLocation(stageEnum, CoordinateSystem.Global);

            this.X = globalPosition.X + this.PixelX;
            this.Y = globalPosition.Y + this.PixelY;
            PointF panelPosition = rccm.GlobalVectorToPanelVector(this.X, this.Y);

            this.PanelX = globalPosition.X + this.PixelX;
            this.PanelY = globalPosition.Y + this.PixelY;
        }