コード例 #1
0
ファイル: MAlignmentCalculator.cs プロジェクト: AdilGM/2DCAD
        public static Matrix4x4 GetAlignmentTransform(MAlignmentType alignmentType, List <MarkGeometryPoint> estimatedPoints, List <MarkGeometryPoint> measuredPoints)
        {
            if (alignmentType == MAlignmentType.Type1 && measuredPoints?.Count > 0)
            {
                return(GeometricArithmeticModule.GetTranslationTransformationMatrix(
                           measuredPoints[0].X, measuredPoints[0].Y
                           ));
            }

            return(GeometricArithmeticModule.EstimateTransformationMatrixFromPoints(
                       estimatedPoints, measuredPoints
                       ));
        }
コード例 #2
0
        public async Task <Matrix4x4> GetAbsoluteTransformFromStageOrigin(
            IProcessConfigurationTasksHandler taskHandler,
            ICamToBeam cam2Beam,
            MRecipe recipe,
            MRecipeBaseNode recipeNode,
            CancellationToken ctIn
            )
        {
            // firstly, find closest parent with fiducials
            var parent = recipeNode;

            while (
                parent != null &&
                parent.Fiducials.Count <= 0
                )
            {
                parent = parent.Parent as MRecipeBaseNode;
            }

            if (parent != null)
            {
                // recursion - get it's parent's transform
                var baseTransform = await GetAbsoluteTransformFromStageOrigin(
                    taskHandler, cam2Beam, recipe, parent.Parent as MRecipeBaseNode, ctIn
                    );

                var fiducialPoints = new List <MarkGeometryPoint>();
                var measuredPoints = new List <MarkGeometryPoint>();

                for (int i = 0; i < parent.Fiducials.Count; i++)
                {
                    var fiducial = parent.Fiducials[i];

                    if (!_cachedFiducials.ContainsKey(fiducial))
                    {
                        // estimate stage position
                        var stageLocation = new MarkGeometryPoint(
                            fiducial.X, fiducial.Y, fiducial.Z
                            );
                        stageLocation.Transform(baseTransform);

                        // goto estimated position
                        if (!await taskHandler.GotoXY(
                                stageLocation.X, stageLocation.Y, ctIn
                                ))
                        {
                            throw new Exception($"Failed to goto the estimated position; origin: {await taskHandler.GetStageOrigin(ctIn)}, fiducial: {(fiducial.X, fiducial.Y)} est: {stageLocation}");
                        }

                        // find and centre
                        {
                            if (!await cam2Beam.MoveBeamToCamOffset(ctIn))
                            {
                                throw new Exception($"Failed to move beam to cam offset");
                            }

                            if (!await taskHandler.MovetoCameraFocus(ctIn))
                            {
                                throw new Exception($"Failed to move camera to focus");
                            }

                            await taskHandler.SwitchCameraLedOn(ctIn);

                            // attempt to centre on fiducial
                            if (!await taskHandler.CentreOnVisibleObject(ctIn))
                            {
                                _logger.Info($"Failed to centre on fiducial");

                                // ask user to locate fiducials
                                Application.Current.Dispatcher.Invoke(
                                    () =>
                                {
                                    var fidVm              = taskHandler.GetNewFidFindViewModel();
                                    var inspectionDialog   = new InspectionWindow(fidVm, Application.Current.MainWindow);
                                    inspectionDialog.Owner = Application.Current.MainWindow;

                                    if (inspectionDialog.ShowDialog() != true)
                                    {
                                        throw new Exception("Failed to find fiducial");
                                    }

                                    // TODO : think about updating the machine's origin
                                }
                                    );
                            }

                            if (!await cam2Beam.MoveCamToBeamOffset(ctIn))
                            {
                                throw new Exception($"Failed to move camera to beam offset");
                            }
                        }

                        // read fiducial position
                        var(stgX, stgY, success) = await taskHandler.GetStageXY(ctIn);

                        if (!success)
                        {
                            throw new Exception("Failed to read the current stage position");
                        }

                        // update cache
                        _cachedFiducials[fiducial] = new MarkGeometryPoint(stgX, stgY);
                    }

                    // update measured points
                    fiducialPoints.Add(new MarkGeometryPoint(fiducial.X, fiducial.Y));
                    measuredPoints.Add(_cachedFiducials[fiducial]);
                }

                // calculate transform from measured fiducials
                var parentTransform = GeometricArithmeticModule.EstimateTransformationMatrixFromPoints(
                    fiducialPoints, measuredPoints
                    );

                return(GeometricArithmeticModule.CombineTransformations(
                           parentTransform,
                           await InvertTransform(
                               taskHandler,
                               parentTransform,
                               MRecipe.GetRelativeTransformFromParent(
                                   parent, recipeNode
                                   ),
                               ctIn
                               )
                           ));
            }

            var origin = await taskHandler.GetStageOrigin(ctIn);

            var stageOrigin = GeometricArithmeticModule.GetTranslationTransformationMatrix(
                origin.X, origin.Y
                );

            return(GeometricArithmeticModule.CombineTransformations(
                       stageOrigin,
                       await InvertTransform(
                           taskHandler,
                           stageOrigin,
                           MRecipe.GetRelativeTransform(
                               recipe, recipeNode
                               ),
                           ctIn
                           )
                       ));
        }