Ejemplo n.º 1
0
        internal InstructionCNC GenerateNextInstruction(double desiredSpeed, bool stopRemainingTimeLockstep = false)
        {
            if (_currentState == null)
            {
                _currentState = new PlanStreamerState(_workSegments.ToArray());
                if (_estimationSteps != null)
                {
                    _timeEstimationState = _currentState.CreateBranch();
                    var th = new Thread(_runRemainingTicksEstimation);
                    th.Priority     = ThreadPriority.Lowest;
                    th.IsBackground = true;
                    th.Start();
                }

                _workSegments = null; // prevent modifications after generation started
            }

            var instruction = _currentState.GenerateNextInstruction(desiredSpeed);

            if (_timeEstimationState != null && !stopRemainingTimeLockstep)
            {
                if (!_wasEstimationLockstepDisabled && desiredSpeed == _previewEstimationDesiredSpeed)
                {
                    _estimationSteps.Add(() =>
                    {
                        moveEstimationByNextInstruction(desiredSpeed);
                    });
                }
                else
                {
                    _previewEstimationDesiredSpeed = desiredSpeed;
                    var newState = _currentState.CreateBranch();
                    _previewTimeEstimationState = newState;
                    _estimationSteps.Add(() =>
                    {
                        _lastEstimationDesiredSpeed = desiredSpeed;
                        setNewTimeEstimationState(newState);
                    });
                }
            }

            _wasEstimationLockstepDisabled = stopRemainingTimeLockstep;

            return(instruction);
        }
Ejemplo n.º 2
0
        private void recalculateRemainingTime()
        {
            // we need to recalculate the state from current point
            var stateCopy      = _timeEstimationState.CreateBranch();
            var remainingTicks = 0UL;

            while (!stateCopy.IsComplete)
            {
                if (_previewTimeEstimationState != _timeEstimationState)
                {
                    // early stopping - the recalculation will run soon again
                    return;
                }

                var instruction = stateCopy.GenerateNextInstruction(_lastEstimationDesiredSpeed);
                remainingTicks += instruction.CalculateTotalTime();
            }
            _remainingTicksEstimation = remainingTicks;
        }