Exemplo n.º 1
0
        public enuScannerErrors NextPosition()
        {
            if (!mStatus.HasFlag(enuScannerErrors.Initialized))
            {
                //todo log error
                return(mStatus);
            }

            //premovement hook: usually move away from surface to avoid damage of the tip
            if (mPositioner.SetRelativePosition(mPreMove) != enuPositionerStatus.Ready)
            {
                return(enuScannerErrors.Error); //todo either validate the position, or use automatic parameters validation by positioner
            }
            Position oldpos = new Position();   //this will be the current absolute position

            if (mPositioner.GetAbsolutePosition(ref oldpos) != enuPositionerStatus.Ready)
            {
                return(enuScannerErrors.Error);                    // todo: log the error?
            }
            Position Dest = CalculateNextAbsolutePosition(oldpos); // here we get a new absolute position to go as next

            if (Dest == null)
            {//no next position, scan finished
                mStatus |= enuScannerErrors.Finished;
                return(mStatus);
            }

            if (mTilt != null)
            {//consider the tilt corrected Z-height if tilt is set
                Dest.Z = mTilt.CalculateZ(Dest);
            }
            //and move to the next position

            //set speeds first, otherwise motors fail-safes will be used
            if (mPositioner.SetSpeeds(mSpeeds) != enuPositionerStatus.Ready)
            {
                return(enuScannerErrors.Error);                                                             // todo: log the error?
            }
            // move to dest position
            if (mPositioner.SetAbsolutePosition(Dest) != enuPositionerStatus.Ready)
            {
                return(enuScannerErrors.Error);                                                                    // todo: log the error?
            }
            log.AddStatusUpdate(0, Dest);

            //postmovement hook: usually move down to surface to reduce travel distance for FBC.
            //The hook is less, then the premovement. Not really meaningful while using tilt correction
            if (mPositioner.SetRelativePosition(mPostMove) != enuPositionerStatus.Ready)
            {
                return(enuScannerErrors.Error);
            }
            return(mStatus);
        }