public void StartBlindSearchTest()
        {
            using (Controller controller = new Controller(PORT_NAME, BAUDRATE))
            {
                controller.Open();

                controller.SetAccelerationSteps(TestUnit1, 1000);

                controller.Home(TestUnit1);

                controller.Move(TestUnit1, 5000, 20);

                controller.Home(TestUnit2);

                controller.Move(TestUnit2, 5000, 20);

                BlindSearchArgs horiArgs = new BlindSearchArgs(TestUnit1, 100, 1, 1, 50);
                BlindSearchArgs vertArgs = new BlindSearchArgs(TestUnit2, 1000, 10, 10, 100);

                controller.StartBlindSearch(horiArgs, vertArgs, ADCChannels.CH1, out List <Point3D> Results);

                controller.Close();


                TestContext.WriteLine($"{Results.Count} Points scanned.");
            }
        }
        public bool DoBlindSearch(BlindSearchArgsF HArgsF, BlindSearchArgsF VArgsF, ADCChannels AdcUsed, out List <Point3D> ScanResults)
        {
            ScanResults = new List <Point3D>();
            int XAxisNo = HArgsF.AxisNoBaseZero;
            int YAxisNo = VArgsF.AxisNoBaseZero;

            if (XAxisNo > MAX_AXIS - MIN_AXIS || XAxisNo < 0 || YAxisNo > MAX_AXIS - MIN_AXIS || YAxisNo < 0)
            {
                return(false);
            }

            var HArgs = new BlindSearchArgs()
            {
                Interval = (ushort)(HArgsF.Interval * AxisArgsList[XAxisNo].GainFactor),
                Speed    = HArgsF.Speed,
                Gap      = (ushort)(HArgsF.Gap * AxisArgsList[XAxisNo].GainFactor),
                Unit     = HArgsF.AxisNoBaseZero + UnitID.U1,
                Range    = (uint)(HArgsF.Range * AxisArgsList[XAxisNo].GainFactor),
            };

            var VArgs = new BlindSearchArgs()
            {
                Interval = (ushort)(VArgsF.Interval * AxisArgsList[YAxisNo].GainFactor),
                Speed    = VArgsF.Speed,
                Gap      = (ushort)(VArgsF.Gap * AxisArgsList[YAxisNo].GainFactor),
                Unit     = VArgsF.AxisNoBaseZero + UnitID.U1,
                Range    = (uint)(VArgsF.Range * AxisArgsList[YAxisNo].GainFactor),
            };

            _controller.StartBlindSearch(HArgs, VArgs, AdcUsed, out ScanResults);
            return(true);
        }
Esempio n. 3
0
        public void StartBlindSearchTest()
        {
            using (Controller controller = new Controller(PORT_NAME, BAUDRATE))
            {
                controller.Open();

                controller.Home(TestUnit1, 5, 50);
                controller.Move(TestUnit1, 10000, 100);

                controller.Home(TestUnit2, 5, 50);

                controller.Move(TestUnit2, 10000, 100);

                controller.SetOsr(ADC_OSR.AD7606_OSR_0);

                BlindSearchArgs horiArgs = new BlindSearchArgs(TestUnit1, 400, 100, 100, 20);
                BlindSearchArgs vertArgs = new BlindSearchArgs(TestUnit2, 400, 100, 100, 20);

                Exception      exCaptured = null;
                List <Point3D> Results    = null;

                for (int i = 0; i < 10; i++)
                {
                    exCaptured = null;

                    try
                    {
                        controller.StartBlindSearch(horiArgs, vertArgs, ADCChannels.CH1, out Results);
                    }
                    catch (Exception ex)
                    {
                        exCaptured = ex;
                    }
                    finally
                    {
                        TestContext.Write($"Cycle {i}, ");
                        if (exCaptured == null)
                        {
                            TestContext.WriteLine($"Points {Results.Count}, Succeed!");
                        }
                        else
                        {
                            TestContext.WriteLine($"Failed!");
                        }
                    }
                }



                controller.Close();


                //TestContext.WriteLine($"{Results.Count} Points scanned.");
            }
        }
Esempio n. 4
0
        /// <summary>
        /// Perform blind-search alignment.
        /// </summary>
        /// <param name="HAxis"></param>
        /// <param name="VAxis"></param>
        /// <param name="Range"></param>
        /// <param name="Gap"></param>
        /// <param name="Interval"></param>
        /// <param name="Speed"></param>
        /// <param name="AnalogCapture"></param>
        /// <param name="ScanResults"></param>
        public void StartBlindSearch(IAxis HAxis, IAxis VAxis, double Range, double Gap, double Interval, int Speed, ADCChannels AnalogCapture, out List <Point3D> ScanResults)
        {
            ScanResults = null;

            if (HAxis.GetType() != typeof(IrixiM12Axis) || VAxis.GetType() != typeof(IrixiM12Axis))
            {
                throw new Exception("The axis you specified does not support the Blind-Search function.");
            }

            var hUnit = ((IrixiM12Axis)HAxis).ID;
            var vUnit = ((IrixiM12Axis)VAxis).ID;

            // limit the speed to the maximum value defined in the config file.
            var horiSpeed = Speed * HAxis.MaxSpeed / 100;

            if (horiSpeed == 0)
            {
                horiSpeed = 1;
            }
            else if (horiSpeed > 100)
            {
                horiSpeed = 100;
            }

            // limit the speed to the maximum value defined in the config file.
            var vertSpeed = Speed * VAxis.MaxSpeed / 100;

            if (vertSpeed == 0)
            {
                vertSpeed = 1;
            }
            else if (vertSpeed > 100)
            {
                vertSpeed = 100;
            }

            BlindSearchArgs horiArgs = new BlindSearchArgs(
                hUnit,
                (uint)HAxis.UnitHelper.ConvertDistanceToSteps(Range),
                (uint)HAxis.UnitHelper.ConvertDistanceToSteps(Gap),
                (ushort)HAxis.UnitHelper.ConvertDistanceToSteps(Interval),
                (byte)horiSpeed);

            BlindSearchArgs veriArgs = new BlindSearchArgs(
                vUnit,
                (uint)VAxis.UnitHelper.ConvertDistanceToSteps(Range),
                (uint)VAxis.UnitHelper.ConvertDistanceToSteps(Gap),
                (ushort)VAxis.UnitHelper.ConvertDistanceToSteps(Interval),
                (byte)vertSpeed);


            _m12.StartBlindSearch(horiArgs, veriArgs, AnalogCapture, out ScanResults);
        }
Esempio n. 5
0
        /// <summary>
        /// Perform the blind-search.
        /// </summary>
        /// <param name="horizontalArgs">The arguments of the horizontal axis.</param>
        /// <param name="verticalArgs">The arguments of the vertical axis.</param>
        /// <param name="adcUsed">Note: only one ADC channel can be used to sample.</param>
        /// <param name="scanResults">Return the intensity-to-position points.</param>
        /// <param name="progressReportHandle"></param>
        public void StartBlindSearch(BlindSearchArgs horizontalArgs, BlindSearchArgs verticalArgs, ADCChannels adcUsed,
                                     out List <Point3D> scanResults, IProgress <BlindSearchProgressReport> progressReportHandle = null)
        {
            //! The memory is cleared automatically, you don't have to clear it manually.

            // arguments checking.
            if (GlobalDefinition.NumberOfSetBits((int)adcUsed) != 1)
            {
                throw new ArgumentException("only 1 analog capture channel can be activated.", nameof(adcUsed));
            }

            if (horizontalArgs.Gap < horizontalArgs.Interval)
            {
                throw new ArgumentException($"the capture interval of {horizontalArgs.Unit} should be less than the gap.");
            }

            if (verticalArgs.Gap < verticalArgs.Interval)
            {
                throw new ArgumentException($"the capture interval of {verticalArgs.Unit} should be less than the gap.");
            }

            scanResults = new List <Point3D>();

            ConfigAdcTrigger(adcUsed);

            // report progress.
            progressReportHandle?.Report(new BlindSearchProgressReport(BlindSearchProgressReport.ProgressStage.SCAN, 0));

            lock (_lockController)
            {
                Send(new CommandBlindSearch(horizontalArgs, verticalArgs));
            }

            var err = WaitBySystemState(200, 120000, new List <UnitID>()
            {
                horizontalArgs.Unit, verticalArgs.Unit
            });

            if (err.Error != Errors.ERR_NONE)
            {
                throw new SystemErrorException(err);
            }
            else
            {
                //var values = new List<double>(new double[100000]);
                // read the sampling points from the memory.
                var adcValues = ReadMemoryAll(new Progress <MemoryReadProgressReport>(e =>
                {
                    // report transmission progress.
                    progressReportHandle?.Report(new BlindSearchProgressReport(BlindSearchProgressReport.ProgressStage.TRANS, e.Complete));
                })).ToList();

                var    indexOfAdcValues = 0;
                var    cycle = 0;
                double x = 0, y = 0;

                // rebuild the relationship between the position and the intensity.
                while (true)
                {
                    var seq = cycle % 4;

                    BlindSearchArgs activeParam;
                    int             moveDirection;
                    switch (seq)
                    {
                    case 0:         // move horizontal axis (x) to positive direction (right)
                        activeParam   = horizontalArgs;
                        moveDirection = 1;
                        break;

                    case 1:
                        activeParam   = verticalArgs;
                        moveDirection = 1;
                        break;

                    case 2:
                        activeParam   = horizontalArgs;
                        moveDirection = -1;
                        break;

                    case 3:
                        activeParam   = verticalArgs;
                        moveDirection = -1;
                        break;

                    default:
                        throw new InvalidOperationException("unknown sequence in the blind search.");
                    }

                    var steps = moveDirection * (activeParam.Gap * (cycle / 2 + 1));

                    if (Math.Abs(steps) > activeParam.Range)
                    {
                        break;
                    }

                    // for the horizontal axis.
                    if (activeParam == horizontalArgs)
                    {
                        var originPos = x;

                        while (true)
                        {
                            scanResults.Add(indexOfAdcValues > (adcValues.Count - 1)
                                ? new Point3D(x, y, 0)
                                : new Point3D(x, y, adcValues[indexOfAdcValues++]));

                            x += moveDirection * activeParam.Interval;

                            if (!(Math.Abs(x - originPos) >= Math.Abs(steps)))
                            {
                                continue;
                            }

                            x = originPos + steps;
                            break;
                        }
                    }
                    else if (activeParam == verticalArgs)
                    {
                        var originPos = y;

                        while (true)
                        {
                            scanResults.Add(indexOfAdcValues > (adcValues.Count - 1)
                                ? new Point3D(x, y, 0)
                                : new Point3D(x, y, adcValues[indexOfAdcValues++]));

                            y += moveDirection * activeParam.Interval;

                            if (!(Math.Abs(y - originPos) >= Math.Abs(steps)))
                            {
                                continue;
                            }

                            y = originPos + steps;
                            break;
                        }
                    }

                    cycle++;
                }

                //// output debug data.
                //StringBuilder sb = new StringBuilder();
                //foreach(var point in ScanResults)
                //{
                //    sb.Append($"{point.X}\t{point.Y}\t{point.Z}\r\n");
                //}

                if (scanResults.Count != adcValues.Count)
                {
                    throw new ADCSamplingPointMissException(scanResults.Count, adcValues.Count);
                }
            }
        }
Esempio n. 6
0
        /// <summary>
        /// Perform the blind-search.
        /// </summary>
        /// <param name="HorizontalArgs">The arguments of the horizontal axis.</param>
        /// <param name="VerticalArgs">The arguments of the vertical axis.</param>
        /// <param name="AdcUsed">Note: only one ADC channel can be used to sample.</param>
        /// <param name="ScanResults">Return the intensity-to-position points.</param>
        public void StartBlindSearch(BlindSearchArgs HorizontalArgs, BlindSearchArgs VerticalArgs, ADCChannels AdcUsed, out List <Point3D> ScanResults)
        {
            //! The memory is cleared automatically, you don't have to clear it manually.

            // check argments.
            if (GlobalDefinition.NumberOfSetBits((int)AdcUsed) != 1)
            {
                throw new ArgumentException($"specify ONLY one channel of the ADC to capture the analog signal.");
            }

            if (HorizontalArgs.Gap < HorizontalArgs.Interval)
            {
                throw new ArgumentException($"the trigger interval of {HorizontalArgs.Unit} shoud be less than the value of the gap.");
            }

            if (VerticalArgs.Gap < VerticalArgs.Interval)
            {
                throw new ArgumentException($"the trigger interval of {VerticalArgs.Unit} shoud be less than the value of the gap.");
            }

            ScanResults = new List <Point3D>();

            ConfigADCTrigger(AdcUsed);

            lock (lockController)
            {
                Send(new CommandBlindSearch(HorizontalArgs, VerticalArgs));
            }

            var err = WaitBySystemState(200, 120000);

            if (err.Error != Errors.ERR_NONE)
            {
                throw new SystemErrorException(err);
            }
            else
            {
                //var values = new List<double>(new double[100000]);
                // read the sampling points from the memory.
                var adcValues = ReadMemoryAll();

                int             indexOfAdcValues = 0;
                int             cycle = 0;
                double          x = 0, y = 0;
                BlindSearchArgs activeParam   = null;
                int             moveDirection = 1;

                // rebuild the relationship between the position and the intensity.
                while (true)
                {
                    var seq = cycle % 4;

                    switch (seq)
                    {
                    case 0:         // move horizontal axis (x) to positive direction (right)
                        activeParam   = HorizontalArgs;
                        moveDirection = 1;
                        break;

                    case 1:
                        activeParam   = VerticalArgs;
                        moveDirection = 1;
                        break;

                    case 2:
                        activeParam   = HorizontalArgs;
                        moveDirection = -1;
                        break;

                    case 3:
                        activeParam   = VerticalArgs;
                        moveDirection = -1;
                        break;
                    }

                    var steps = moveDirection * (activeParam.Gap * (cycle / 2 + 1));

                    if (Math.Abs(steps) > activeParam.Range)
                    {
                        break;
                    }

                    // for the horizontal axis.
                    if (activeParam == HorizontalArgs)
                    {
                        var originPos = x;

                        while (true)
                        {
                            if (indexOfAdcValues > (adcValues.Count - 1))
                            {
                                ScanResults.Add(new Point3D(x, y, 0));
                            }
                            else
                            {
                                ScanResults.Add(new Point3D(x, y, adcValues[indexOfAdcValues++]));
                            }

                            x += moveDirection * activeParam.Interval;

                            if (Math.Abs(x - originPos) >= Math.Abs(steps))
                            {
                                x = originPos + steps;
                                break;
                            }
                        }
                    }
                    else if (activeParam == VerticalArgs)
                    {
                        var originPos = y;

                        while (true)
                        {
                            if (indexOfAdcValues > (adcValues.Count - 1))
                            {
                                ScanResults.Add(new Point3D(x, y, 0));
                            }
                            else
                            {
                                ScanResults.Add(new Point3D(x, y, adcValues[indexOfAdcValues++]));
                            }

                            y += moveDirection * activeParam.Interval;

                            if (Math.Abs(y - originPos) >= Math.Abs(steps))
                            {
                                y = originPos + steps;
                                break;
                            }
                        }
                    }

                    cycle++;
                }

                // output debug data.
                StringBuilder sb = new StringBuilder();
                foreach (var point in ScanResults)
                {
                    sb.Append($"{point.X}\t{point.Y}\t{point.Z}\r\n");
                }

                if (ScanResults.Count > adcValues.Count)
                {
                    throw new ADCSamplingPointMissException(ScanResults.Count, adcValues.Count);
                }
            }
        }