Ejemplo n.º 1
0
        public IHttpActionResult Calibrate()
        {
            WebApiApplication.calibration.State = MbrCalibration.Calibrating;
            string path = CalibrationPathNow("mbr_calibration", "csv");

            var V = Vector <double> .Build;

            var z = V.Dense(calibration_points + 1);
            var w = V.Dense(calibration_points + 1);

            Action <CancellationToken> asyncTask = (cancellationToken) =>
            {
                using (StreamWriter outfile = new StreamWriter(path))
                {
                    outfile.WriteLine("{0}, {1}", "Displacement (mm)", "Wavelength (nm)");
                    outfile.Flush();
                    double delta_z = (calibration_end - calibration_start) / calibration_points;
                    for (int i = 0; i < calibration_points + 1; i++)
                    {
                        double target = calibration_start + delta_z * i;
                        PositionController.TrySetPosition(target);

                        //Block while moving
                        while (MotionStateController.IsMoving())
                        {
                            Thread.Sleep(1000);
                        }
                        Thread.Sleep(100);

                        WebResponse  response   = WebRequest.Create("http://192.168.1.87:5000/wavelength_at_max").GetResponse();
                        StreamReader reader     = new StreamReader(response.GetResponseStream());
                        string       wavelength = reader.ReadToEnd();

                        outfile.WriteLine("{0}, {1}", target.ToString("F5"), wavelength);
                        outfile.Flush();
                        z[i] = target;

                        w[i] = Convert.ToDouble(wavelength);
                    }
                    CalibrateWavelengthForPosition(z, w);
                }
                WebApiApplication.calibration.CalibrationFile = path;
            };

            HostingEnvironment.QueueBackgroundWorkItem(asyncTask);

            return(Ok("Calibrating"));
        }
Ejemplo n.º 2
0
 public IHttpActionResult GotoWavelength(double targetWavelength_nm)
 {
     if (WebApiApplication.calibration.IsCalibrated())
     {
         double target_z = WebApiApplication.calibration.PositionForWavelength(targetWavelength_nm);
         if (PositionController.TrySetPosition(target_z))
         {
             return(Ok("Moving to wavelength"));
         }
         else
         {
             return(Ok("Motor not ready"));
         }
     }
     else
     {
         return(Ok("Not calibrated"));
     }
 }