Ejemplo n.º 1
0
        private void ResetToFactoryCalibration(Device dev = null)
        {
            using (var ctx = new Context())
            {
                dev = dev ?? ctx.QueryDevices()[0];

                if (!IsTheDeviceD400Series(dev))
                {
                    return;
                }

                Console.WriteLine($"{Environment.NewLine}Reset to factory settings device an {dev.Info[CameraInfo.Name]}" +
                                  $"{Environment.NewLine}\tSerial number: {dev.Info[CameraInfo.SerialNumber]}" +
                                  $"{Environment.NewLine}\tFirmware version: {dev.Info[CameraInfo.FirmwareVersion]}");
                var aCalibratedDevice = AutoCalibratedDevice.FromDevice(dev);

                aCalibratedDevice.reset_to_factory_calibration();

                Console.WriteLine($"Device calibration has been reset to factory defaults");
            }
        }
Ejemplo n.º 2
0
        public void TestCalibrationModes(Device dev = null)
        {
            try
            {
                if (dev == null)
                {
                    Console.WriteLine($"{Environment.NewLine}Getting context...");
                    dev = new Context().QueryDevices().First();
                }

                if (!IsTheDeviceD400Series(dev))
                {
                    return;
                }

                Console.WriteLine($"{Environment.NewLine}Test calibration modes using device {dev.Info[CameraInfo.Name]}" +
                                  $"{Environment.NewLine}\tSerial number: {dev.Info[CameraInfo.SerialNumber]}" +
                                  $"{Environment.NewLine}\tFirmware version: {dev.Info[CameraInfo.FirmwareVersion]}");
                var depthProfiles = dev.QuerySensors()
                                    .SelectMany(s => s.StreamProfiles)
                                    .Where(sp => sp.Stream == Stream.Depth)
                                    .Select(sp => sp.As <VideoStreamProfile>())
                                    .OrderByDescending(p => p.Height)
                                    .OrderByDescending(p => p.Width)
                                    .OrderByDescending(p => p.Framerate)
                                    .OrderByDescending(p => p.Format)
                                    .ToList();

                var fileName = Path.Combine(Directory.GetCurrentDirectory(), "ReportTestCalibrationModes.csv");
                Console.WriteLine($"Report about testing calibration modes will be written to file:\n\t{fileName}");

                var calibrationSetCount = 0;
                if (IsLinux)
                {
                    calibrationSetCount = CountEnumEntries <CalibrationSpeed>() * CountEnumEntries <CalibrationScanParameter>();
                }
                else
                {
                    calibrationSetCount = CountEnumEntries <CalibrationSpeed>() * CountEnumEntries <CalibrationScanParameter>() * CountEnumEntries <CalibrationDataSampling>();
                }

                var depthProfileSet      = 0;
                var depthProfileSetCount = depthProfiles.Count;
                using (var file = new StreamWriter(fileName))
                {
                    var headers = GetHeader4FileReport();
                    file.WriteLine(headers);
                    file.Flush();

                    foreach (var depthProfile in depthProfiles)
                    {
                        Console.WriteLine($"{Environment.NewLine}Starting pipeline for calibration mode, depth profile set {++depthProfileSet} of {depthProfiles.Count}");
                        Console.WriteLine($"\t Format:\t {depthProfile.Format}");
                        Console.WriteLine($"\t Framerate:\t {depthProfile.Framerate}");
                        Console.WriteLine($"\t Width:\t\t {depthProfile.Width}");
                        Console.WriteLine($"\t Height:\t {depthProfile.Height}");
                        using (var pipeline = StartPipeline(depthProfile, dev))
                        {
                            var aCalibratedDevice = AutoCalibratedDevice.FromDevice(dev);

                            //calibratoin config set
                            var calibrationSet = 0;
                            foreach (var calibrationSpeed in GetEnumEntries <CalibrationSpeed>())
                            {
                                foreach (var calibrationScanParameter in GetEnumEntries <CalibrationScanParameter>())
                                {
                                    foreach (var calibrationDataSampling in GetEnumEntries <CalibrationDataSampling>())
                                    {
                                        if (calibrationDataSampling == CalibrationDataSampling.Windows && IsLinux)
                                        {
                                            continue;
                                        }
                                        Console.WriteLine("");
#if (CalibrationTestAndBurns2FW)
                                        // 1. Calibration table before running on-chip calibration.
                                        Console.WriteLine($"{Environment.NewLine}1. Calibration table before running on-chip calibration.");
                                        var calTableBefore = aCalibratedDevice.CalibrationTable;
                                        Console.WriteLine("\t Step 1 :  done");
#endif
                                        // 2. Runs the on-chip self-calibration routine that returns pointer to new calibration table.
                                        Console.WriteLine($"2. Runs the on-chip self-calibration routine for depth profile {depthProfileSet} of {depthProfileSetCount} calibration, set {++calibrationSet} of {calibrationSetCount} ");
                                        Console.WriteLine($"\t Format                    : {depthProfile.Format}");
                                        Console.WriteLine($"\t Framerate                 : {depthProfile.Framerate}");
                                        Console.WriteLine($"\t Width                     : {depthProfile.Width}");
                                        Console.WriteLine($"\t Height                    : {depthProfile.Height}");
                                        Console.WriteLine($"\t Calibration Speed         : {calibrationSpeed}");
                                        Console.WriteLine($"\t Calibration Scan Parameter: {calibrationScanParameter}");
                                        Console.WriteLine($"\t Calibration Data Sampling : {calibrationDataSampling}");

                                        string calibrationConfig = GetCalibrationConfig(calibrationSpeed, calibrationScanParameter, calibrationDataSampling);

                                        //var timeout = _timeoutForCalibrationSpeed[calibrationSpeed];
                                        var    timeout       = Convert.ToInt32(TimeSpan.FromMinutes(2).TotalMilliseconds);
                                        float  health        = 888;
                                        var    deviceHealth  = DeviceHealth.Failed;
                                        byte[] calTableAfter = null;
                                        var    sw            = new Stopwatch();
                                        try
                                        {
                                            sw.Start();
                                            calTableAfter = aCalibratedDevice.RunOnChipCalibration(calibrationConfig, out health, timeout);
                                            sw.Stop();
                                            deviceHealth = GetDeviceHealth(health);
                                        }
                                        catch (Exception ex)
                                        {
                                            sw.Stop();
                                            //write to report file
                                            file.WriteLine(GetRow4FileReport(depthProfileSet, depthProfile, calibrationSet, calibrationSpeed, calibrationScanParameter, calibrationDataSampling, timeout, sw.Elapsed, "", _deviceHealthDescription[DeviceHealth.Failed], ex.Message.Replace("\n", "\t")));
                                            file.Flush();

                                            Console.WriteLine($"\t Time spend: {sw.Elapsed.ToString(@"mm\:ss\.fff")}");
                                            Console.WriteLine($"\t Calibration failed: {ex.Message.Replace("\n", "\t")}");
                                            Console.WriteLine("\t Step 2: failed");
                                            continue;
                                        }
                                        file.WriteLine(GetRow4FileReport(depthProfileSet, depthProfile, calibrationSet, calibrationSpeed, calibrationScanParameter, calibrationDataSampling, timeout, sw.Elapsed, health.ToString(), _deviceHealthDescription[GetDeviceHealth(health)]));
                                        file.Flush();

                                        Console.WriteLine($"\t Time spend: {sw.Elapsed.ToString(@"mm\:ss\.fff")}");
                                        Console.WriteLine($"\t Device health: {health} ({_deviceHealthDescription[GetDeviceHealth(health)]})");
                                        Console.WriteLine("\t Step 2: done");

#if (CalibrationTestAndBurns2FW)
                                        // 3. Toggle between calibration tables to assess which is better. This is optional.
                                        Console.WriteLine("3. Toggle between calibration tables to assess which is better.");
                                        if (deviceHealth <= DeviceHealth.CouldBePerformed)
                                        {
                                            aCalibratedDevice.CalibrationTable = calTableAfter;
                                            Console.WriteLine("\t Step 3: done");
                                        }
                                        else
                                        {
                                            Console.WriteLine("\t Step 3: skipped");
                                        }

                                        // 4. burns the new calibration to FW persistently.
                                        Console.WriteLine("4. Burns the new calibration to FW persistently.");
                                        if (deviceHealth <= DeviceHealth.CouldBePerformed)
                                        {
                                            aCalibratedDevice.WriteCalibration();
                                            Console.WriteLine("\t Step 4: done");
                                        }
                                        else
                                        {
                                            Console.WriteLine("\t Step 4: skipped");
                                        }
#endif
                                    }
                                }
                            }

                            Console.WriteLine($"{Environment.NewLine}Stopping calibration pipeline for depth profile set {depthProfileSet} of {depthProfiles.Count}...");
                            pipeline.Stop();
                        }
                    }
                }
                Console.WriteLine($"Report about testing calibration modes has been written to file:\n\t{fileName}");
                Console.WriteLine("Testing calibration modes complete");
            }
            catch (Exception ex)
            {
                Console.WriteLine($"{Environment.NewLine} Error during calibration:{Environment.NewLine} {ex.Message}");
            }
        }
Ejemplo n.º 3
0
        public void Calibrate(Device dev = null)
        {
            try
            {
                if (dev == null)
                {
                    Console.WriteLine($"{Environment.NewLine}Getting context...");
                    dev = new Context().QueryDevices().First();
                }

                if (!IsTheDeviceD400Series(dev))
                {
                    return;
                }

                Console.WriteLine($"{Environment.NewLine}Calibration device {dev.Info[CameraInfo.Name]}" +
                                  $"{Environment.NewLine}\tSerial number: {dev.Info[CameraInfo.SerialNumber]}" +
                                  $"{Environment.NewLine}\tFirmware version: {dev.Info[CameraInfo.FirmwareVersion]}");

                VideoStreamProfile depthProfile = dev.QuerySensors()
                                                  .SelectMany(s => s.StreamProfiles)
                                                  .Where(sp => sp.Stream == Stream.Depth)
                                                  .Select(sp => sp.As <VideoStreamProfile>())
                                                  .Where(p =>
                                                         p.Width == 256 &&
                                                         p.Height == 144 &&
                                                         p.Framerate == 90 &&
                                                         p.Format == Format.Z16
                                                         ).Last();

                Console.WriteLine($"{Environment.NewLine}Starting pipeline for calibration mode");
                using (var pipeline = StartPipeline(depthProfile, dev))
                {
                    var aCalibratedDevice = AutoCalibratedDevice.FromDevice(dev);


                    // 1. Calibration table before running on-chip calibration.
                    Console.WriteLine($"{Environment.NewLine}1. Calibration table before running on-chip calibration.");
                    var calTableBefore = aCalibratedDevice.CalibrationTable;
                    Console.WriteLine("Step 1 :  done");

                    // 2. Runs the on-chip self-calibration routine that returns pointer to new calibration table.

                    //calibratoin config
                    var    calibrationSpeed         = CalibrationSpeed.Slow;
                    var    calibrationScanParameter = CalibrationScanParameter.Intrinsic;
                    var    calibrationDataSampling  = CalibrationDataSampling.WindowsAndLinux;
                    string calibrationConfig        = GetCalibrationConfig(calibrationSpeed, calibrationScanParameter, calibrationDataSampling);

                    var    timeout = _timeoutForCalibrationSpeed[calibrationSpeed];
                    float  health  = 100;
                    var    succeedOnChipCalibration = false;
                    var    abortRequested           = false;
                    byte[] calTableAfter            = null;
                    while (!succeedOnChipCalibration && !abortRequested)
                    {
                        Console.WriteLine($"{Environment.NewLine}2. Runs the on-chip self-calibration routine that returns pointer to new calibration table.");
                        Console.WriteLine($"\t Format                    : {depthProfile.Format}");
                        Console.WriteLine($"\t Framerate                 : {depthProfile.Framerate}");
                        Console.WriteLine($"\t Width                     : {depthProfile.Width}");
                        Console.WriteLine($"\t Height                    : {depthProfile.Height}");
                        Console.WriteLine($"\t Calibration Speed         : {calibrationSpeed}");
                        Console.WriteLine($"\t Calibration Scan Parameter: {calibrationScanParameter}");
                        Console.WriteLine($"\t Calibration Data Sampling : {calibrationDataSampling}");
                        Console.WriteLine($"\t Calibration Timeout       : {TimeSpan.FromMilliseconds(timeout).ToString(@"mm\:ss\.fff")} (min:sec.millisec)");

                        var sw = new Stopwatch();
                        var thisCalibrationfault = false;
                        try
                        {
                            sw.Start();
                            ProgressCallback pc = (x) => { Console.WriteLine("Progress: {0} percents", x); };
                            // The following line performs the same calibration flow but does not report progress"
                            //calTableAfter = aCalibratedDevice.RunOnChipCalibration(calibrationConfig, out health, timeout);
                            calTableAfter = aCalibratedDevice.RunOnChipCalibration(calibrationConfig, out health, pc, timeout);
                            sw.Stop();
                        }
                        catch (Exception ex)
                        {
                            sw.Stop();
                            thisCalibrationfault = true;
                            Console.WriteLine($"\n\t Error during calibration: {ex.Message.Replace("\n", "\t")}");
                            Console.WriteLine($"\t Please try to change distance to target or light conditions{Environment.NewLine}");
                            if (ConsoleKey.N == ConsoleGetKey(new[] { ConsoleKey.Y, ConsoleKey.N },
                                                              @"Let's try calibrate one more time? (Y\N)"
                                                              ))
                            {
                                Console.WriteLine("");
                                Console.WriteLine($"Calibration failed");
                                Console.WriteLine($"Stopping calibration pipeline...");
                                pipeline.Stop();
                                return;
                            }
                        }

                        if (!thisCalibrationfault)
                        {
                            Console.WriteLine($"\n\t Time spend: {sw.Elapsed.ToString(@"mm\:ss\.fff")}  (min:sec.millisec)");
                            Console.WriteLine($"\t Device health: {health} ({_deviceHealthDescription[GetDeviceHealth(health)]})");

                            var res = ConsoleGetKey(new[] { ConsoleKey.Y, ConsoleKey.N, ConsoleKey.A }, @"Accept calibration ? Yes/No/Abort");
                            Console.WriteLine("User's selection = {0}", res);
                            if (res == ConsoleKey.A)
                            {
                                abortRequested = true;
                            }
                            else
                            {
                                succeedOnChipCalibration = (res == ConsoleKey.Y);
                            }
                        }
                    }

                    Console.WriteLine("Step 2 :  done");

                    // 3. Toggle between calibration tables to assess which is better. This is optional.
                    Console.WriteLine($"{Environment.NewLine}3. Toggle between calibration tables to assess which is better.");
                    aCalibratedDevice.CalibrationTable = calTableAfter;
                    Console.WriteLine("Step 3 :  done");

                    // 4. burns the new calibration to FW persistently.
                    Console.WriteLine("");
                    if (ConsoleKey.Y == ConsoleGetKey(new[] { ConsoleKey.Y, ConsoleKey.N },
                                                      @"4. Burns the new calibration to FW persistently. (Y\N)"))
                    {
                        aCalibratedDevice.WriteCalibration();
                        Console.WriteLine("Step 4 :  done");
                    }
                    else
                    {
                        Console.WriteLine("Step 4 :  skipped");
                    }

                    Console.WriteLine("Calibration complete");
                    Console.WriteLine($"{Environment.NewLine}Stopping calibration pipeline...");

                    pipeline.Stop();
                }

                //}
            }
            catch (Exception ex)
            {
                Console.WriteLine($"{Environment.NewLine} Error during calibration:{Environment.NewLine} {ex.Message}");
            }
        }