示例#1
0
        public CoordController(DriverCNC2 cnc)
        {
            _cnc = cnc;

            _movementWorker = new Thread(worker);
            _movementWorker.Start();
            _movementWorker.IsBackground = true;
        }
示例#2
0
        public void StreamInstructions(DriverCNC2 driver)
        {
            var streamThread = new Thread(() =>
            {
                _stream(driver);
            });

            streamThread.IsBackground = true;
            streamThread.Start();
        }
示例#3
0
 internal SpeedController(DriverCNC2 cnc)
 {
     _cnc                      = cnc;
     _desiredDeltaT            = Configuration.StartDeltaT;
     _currentDeltaT            = _desiredDeltaT;
     _speedWorker              = new Thread(worker);
     _speedWorker.IsBackground = true;
     _stop                     = true;
     SetRPM(400);
     _speedWorker.Start();
 }
示例#4
0
        public CutterPanel()
        {
            System.Globalization.CultureInfo customCulture = (System.Globalization.CultureInfo)Thread.CurrentThread.CurrentCulture.Clone();
            customCulture.NumberFormat.NumberDecimalSeparator = ".";
            Thread.CurrentThread.CurrentCulture = customCulture;
            SystemUtilities.PreventSleepMode();

            InitializeComponent();
            MessageBox.Visibility = Visibility.Hidden;

            _motionCommands.Add(Calibration);
            _motionCommands.Add(GoToZeros);
            _motionCommands.Add(AlignHeads);
            _motionCommands.Add(StartPlan);
            _motionCommands.Add(CuttingDeltaT);

            Cnc = new DriverCNC2();
            Cnc.OnConnectionStatusChange += () => Dispatcher.Invoke(refreshConnectionStatus);
            Cnc.OnHomeCalibrated         += () => Dispatcher.Invoke(enableMotionCommands);

            Cnc.Initialize();

            CoordController = new Coord2DController(Cnc);

            _messageTimer.Interval  = TimeSpan.FromMilliseconds(_messageShowDelay);
            _messageTimer.IsEnabled = false;
            _messageTimer.Tick     += _messageTimer_Tick;
            _statusTimer.Interval   = TimeSpan.FromMilliseconds(20);
            _statusTimer.Tick      += _statusTimer_Tick;
            _statusTimer.IsEnabled  = true;
            _autosaveTime.IsEnabled = false;
            _autosaveTime.Interval  = TimeSpan.FromMilliseconds(1000);
            _autosaveTime.Tick     += _autosaveTime_Tick;

            KeyUp      += keyUp;
            KeyDown    += keyDown;
            ContextMenu = createWorkspaceMenu();

            resetWorkspace(true);

            initializeTransitionHandlers();

            _factory = new ShapeFactory(this);

            /*/
             * OpenEditor_Click(null, null);
             * this.Hide();
             * /**/
        }
示例#5
0
        public RouterPanel()
        {
            Configuration.EnableRouterMode();
            System.Windows.Forms.Integration.ElementHost.EnableModelessKeyboardInterop(this);
            System.Globalization.CultureInfo customCulture = (System.Globalization.CultureInfo)Thread.CurrentThread.CurrentCulture.Clone();
            customCulture.NumberFormat.NumberDecimalSeparator = ".";
            Thread.CurrentThread.CurrentCulture = customCulture;
            SystemUtilities.PreventSleepMode();


            InitializeComponent();
            MessageBox.Visibility = Visibility.Hidden;

            _motionCommands.Add(Calibration);
            _motionCommands.Add(GoToZerosXY);
            _motionCommands.Add(StartPlan);
            _motionCommands.Add(SetZLevel);

            Cnc = new DriverCNC2();
            Cnc.OnConnectionStatusChange += () => Dispatcher.Invoke(refreshConnectionStatus);
            Cnc.OnHomeCalibrated         += () => Dispatcher.Invoke(enableMotionCommands);

            Cnc.Initialize();

            CoordController = new CoordController(Cnc);

            _messageTimer.Interval  = TimeSpan.FromMilliseconds(_messageShowDelay);
            _messageTimer.IsEnabled = false;
            _messageTimer.Tick     += _messageTimer_Tick;
            _statusTimer.Interval   = TimeSpan.FromMilliseconds(20);
            _statusTimer.Tick      += _statusTimer_Tick;
            _statusTimer.IsEnabled  = true;
            _autosaveTime.IsEnabled = false;
            _autosaveTime.Interval  = TimeSpan.FromMilliseconds(1000);
            _autosaveTime.Tick     += _autosaveTime_Tick;

            PreviewKeyUp   += previewKeyUp;
            PreviewKeyDown += previewKeyDown;
            ContextMenu     = createWorkspaceMenu();

            resetWorkspace(true);

            initializeTransitionHandlers();

            _factory = new MillingShapeFactory(this);
        }
示例#6
0
        public TestPanel()
        {
            InitializeComponent();

            Output.ScrollToEnd();

            _cnc = new DriverCNC2();
            _cnc.OnDataReceived += _driver_OnDataReceived;
            _cnc.Initialize();

            _positionController = new PositionController(_cnc);
            _speedController    = new SpeedController(_cnc);
            _coord2DController  = new Coord2DController(_cnc);

            _positionTimer.Interval  = new TimeSpan(1 * 10 * 1000);
            _positionTimer.Tick     += _positionTimer_Tick;
            _positionTimer.IsEnabled = false;

            _statusTimer.Interval  = new TimeSpan(100 * 10 * 1000);
            _statusTimer.Tick     += _statusTimer_Tick;
            _statusTimer.IsEnabled = true;
        }
示例#7
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();
        }
示例#8
0
 public PositionController(DriverCNC2 driver)
 {
     _cnc = driver;
 }
示例#9
0
        private void _stream(DriverCNC2 driver)
        {
            PlanStreamerContext intermContext = null;

            _context = new PlanStreamerContext(true);
            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;

            var currentContext = _context;

            while (!currentContext.IsComplete || intermContext != null)
            {
                if (intermContext != null && intermContext.IsComplete)
                {
                    intermContext  = null;
                    currentContext = _context;
                    continue;
                }

                while (_stop && _context.CurrentSpeed <= zeroCompatibleSpeed)
                {
                    _isStreaming = false;
                    Thread.Sleep(10);
                }

                _isStreaming = true;

                if (IsChangingPosition)
                {
                    // create intermediate context which will transfer machine to the new position
                    var np           = CurrentStreamPosition.As3Dmm();
                    var cp           = driver.CurrentState.As3Dstep().As3Dmm();
                    var cpTransition = new Point3Dmm(cp.X, cp.Y, _transitionLevel);
                    var npTransition = new Point3Dmm(np.X, np.Y, _transitionLevel);

                    intermContext = new PlanStreamerContext(false);
                    intermContext.AddSegment(new ToolPathSegment(cp.As3D(), cpTransition.As3D(), MotionMode.IsLinear));
                    intermContext.AddSegment(new ToolPathSegment(cpTransition.As3D(), npTransition.As3D(), MotionMode.IsLinear));
                    intermContext.AddSegment(new ToolPathSegment(npTransition.As3D(), np.As3D(), MotionMode.IsLinear));

                    currentContext     = intermContext;
                    IsChangingPosition = false;
                }

                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 = currentContext.GenerateNextInstruction(speed, stopRemainingTimeLockstep: _stop);
                    instructionBuffer.Enqueue(instruction);
                } while (driver.IncompleteInstructionCount == 0 && !currentContext.IsComplete && instructionBuffer.Count < maxPlannedInstructionCount);

                while (instructionBuffer.Count > 0)
                {
                    var instruction = instructionBuffer.Dequeue();
                    if (!driver.SEND(instruction))
                    {
                        throw new InvalidOperationException("Instruction was not accepted. (Probably over bounds?). Progress: " + Progress * 100);
                    }
                }
            }

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

            StreamingIsComplete?.Invoke();
        }
示例#10
0
        private void _stream(DriverCNC2 driver)
        {
            var planStream  = new PlanStream3D(_plan.ToArray());
            var preloadTime = 0.05;

            var startTime                   = DateTime.Now;
            var lastTimeMeasure             = startTime;
            var lastTotalSecondsRefreshTime = startTime;
            var lastCuttingSpeed            = Speed.Zero;
            var currentlyQueuedTime         = 0.0;
            var timeQueue                   = new Queue <double>();

            while (!planStream.IsComplete)
            {
                var currentCuttingSpeed = _stream_cuttingSpeed;
                var currentTime         = DateTime.Now;

                if ((currentTime - lastTotalSecondsRefreshTime).TotalSeconds > 5.0)
                {
                    //force recalculation every few seconds
                    lastCuttingSpeed = null;
                }

                if (lastCuttingSpeed != currentCuttingSpeed)
                {
                    //recalculate totalSeconds
                    lastCuttingSpeed = currentCuttingSpeed;
                    var cuttingDistance  = planStream.GetRemainingConstantDistance();
                    var rampTime         = planStream.GetRemainingRampTime();
                    var totalElapsedTime = (currentTime - startTime).TotalSeconds;
                    _totalSeconds = totalElapsedTime + rampTime + cuttingDistance / currentCuttingSpeed.ToMetric() + currentlyQueuedTime;
                    lastTotalSecondsRefreshTime = currentTime;
                }


                var timeElapsed = (currentTime - lastTimeMeasure).TotalSeconds;
                lastTimeMeasure = currentTime;

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

                if (timeQueue.Count > 0)
                {
                    currentlyQueuedTime -= timeQueue.Dequeue();
                }

                IEnumerable <InstructionCNC> nextInstructions;
                if (planStream.IsSpeedLimitedBy(Configuration.MaxCuttingSpeed))
                {
                    var lengthLimit = preloadTime * currentCuttingSpeed.ToMetric();
                    nextInstructions = planStream.ShiftByConstantSpeed(lengthLimit, currentCuttingSpeed);
                }
                else
                {
                    nextInstructions = planStream.NextRampInstructions();
                }

                driver.SEND(nextInstructions);

                var duration    = nextInstructions.Select(i => i.CalculateTotalTime());
                var timeToQueue = duration.Sum(d => (float)d) / Configuration.TimerFrequency;
                currentlyQueuedTime += timeToQueue;
                timeQueue.Enqueue(currentlyQueuedTime);
            }
            while (driver.IncompleteInstructionCount > 0)
            {
                Thread.Sleep(10);
            }

            StreamingIsComplete?.Invoke();
        }