Пример #1
0
        public static IEnumerable <InstructionCNC> GenerateInstructions(IEnumerable <ToolPathSegment> plan, double desiredSpeed)
        {
            var context = new PlanStreamerContext();

            foreach (var segment in plan)
            {
                context.AddSegment(segment);
            }

            var result = new List <InstructionCNC>();

            while (!context.IsComplete)
            {
                var instruction = context.GenerateNextInstruction(desiredSpeed);
                if (instruction != null)
                {
                    result.Add(instruction);
                }
            }
            return(result);
        }
Пример #2
0
        private void _stream(DriverCNC2 driver)
        {
            var context = new PlanStreamerContext();

            foreach (var part in PlanParts)
            {
                var s = part.StartPoint;
                var e = part.EndPoint;

                var segment = new ToolPathSegment(new Point3D(s.X, s.Y, s.Z), new Point3D(e.X, e.Y, e.Z), MotionMode.IsLinear);
                context.AddSegment(segment);
            }

            var zeroCompatibleSpeed        = Configuration.ReverseSafeSpeed.ToMetric();
            var instructionBuffer          = new Queue <InstructionCNC>();
            var maxPlannedInstructionCount = 5;

            while (!context.IsComplete)
            {
                while (_stop && context.CurrentSpeed <= zeroCompatibleSpeed)
                {
                    _isStreaming = false;
                    Thread.Sleep(10);
                }
                _isStreaming = true;

                if (driver.IncompleteInstructionCount >= maxPlannedInstructionCount)
                {
                    //wait some time so we are not spinning like crazy
                    Thread.Sleep(1);
                    continue;
                }

                do
                {
                    double speed;
                    lock (_L_speed)
                        speed = _stream_cuttingSpeed;

                    if (_stop)
                    {
                        speed = zeroCompatibleSpeed;
                    }

                    var instruction = context.GenerateNextInstruction(speed);
                    instructionBuffer.Enqueue(instruction);
                } while (driver.IncompleteInstructionCount == 0 && !context.IsComplete && instructionBuffer.Count < maxPlannedInstructionCount);

                while (instructionBuffer.Count > 0)
                {
                    var instruction = instructionBuffer.Dequeue();
                    driver.SEND(instruction);
                }
            }

            while (driver.IncompleteInstructionCount > 0)
            {
                //wait until all instructions are completed
                Thread.Sleep(10);
            }

            StreamingIsComplete?.Invoke();
        }