Exemplo n.º 1
0
        private void Tet_Click(object sender, RoutedEventArgs e)
        {
            var stepI       = new ConstantInstruction((short)4, 25000, 0);
            var waitI       = new ConstantInstruction((short)0, 1000000, 0);
            var instruction = Axes.UVXY(waitI, stepI, waitI, waitI);

            Cnc.SEND(instruction);
        }
Exemplo n.º 2
0
        private void sendNextPlan()
        {
            var accelerationX = CreateAcceleration(_deltaTX, _desiredSpeed * _desiredDirectionX);
            var accelerationY = CreateAcceleration(_deltaTY, _desiredSpeed * _desiredDirectionY);

            if (accelerationX.Concat(accelerationY).Count() > 2 && accelerationX.Length != accelerationY.Length)
            {
                throw new NotImplementedException("We have to handle reverting one axis and starting the other");
            }

            if (accelerationX.Any() && accelerationY.Any())
            {
                for (var i = 0; i < accelerationX.Length; ++i)
                {
                    sendInstruction(accelerationX[i], accelerationY[i]);
                }

                velocityReached();
                return;
            }

            //here we have single acceleration per axes
            if (accelerationX.Any() || accelerationY.Any())
            {
                foreach (var acceleration in accelerationX)
                {
                    sendInstruction(acceleration, null);
                }

                foreach (var acceleration in accelerationY)
                {
                    sendInstruction(null, acceleration);
                }

                velocityReached();
                return;
            }

            velocityReached();
            if (_deltaTX == 0 && _deltaTY == 0)
            {
                _stop = true;
                return;
            }

            var instructionTime = 100 * 350;
            var timedStepCountX = _deltaTX == 0 ? 0 : instructionTime / Math.Abs(_deltaTX);
            var timedStepCountY = _deltaTY == 0 ? 0 : instructionTime / Math.Abs(_deltaTY);

            var stepCountX = (Int16)(timedStepCountX * Math.Sign(_deltaTX));
            var stepCountY = (Int16)(timedStepCountY * Math.Sign(_deltaTY));

            var xInstruction = new ConstantInstruction(stepCountX, (UInt16)Math.Abs(_deltaTX), 0);
            var yInstruction = new ConstantInstruction(stepCountY, (UInt16)Math.Abs(_deltaTY), 0);

            sendInstruction(xInstruction, yInstruction);
        }
Exemplo n.º 3
0
        private void sendNewPlan()
        {
            if (_currentDeltaT != _desiredDeltaT)
            {
                _currentDeltaT = _desiredDeltaT;
            }

            var stepCount     = (Int16)(Math.Max(2, 20000 / _currentDeltaT));
            var sendStepCount = Direction ? (Int16)(-stepCount) : stepCount;
            var remainder     = (UInt16)(_desiredDeltaRemainder * stepCount);
            var instruction   = new ConstantInstruction(sendStepCount, _currentDeltaT, remainder);

            _cnc.SEND(Axes.UVXY(instruction, instruction, instruction, instruction));

            var plannedTime = stepCount * _currentDeltaT;

            _plannedTimeTotal += plannedTime;
            _plannedTimes.Enqueue(plannedTime);
        }
Exemplo n.º 4
0
 private void addConstantPlan(int tickCount, double distance, List <StepInstrution> pathPlans)
 {
     checked
     {
         //fraction is clipped because period can be used for remainder
         var stepCount = (Int16)distance;
         if (stepCount == 0)
         {
             pathPlans.Add(new ConstantInstruction(0, 0, 0));
             return;
         }
         checked
         {
             var baseDeltaExact = Math.Abs(tickCount / stepCount);
             var baseDelta      = Math.Abs((int)(baseDeltaExact));
             var tickRemainder  = (UInt16)(tickCount - Math.Abs(stepCount) * baseDelta);
             var constantPlan   = new ConstantInstruction(stepCount, baseDelta, tickRemainder);
             pathPlans.Add(constantPlan);
         }
     }
 }
Exemplo n.º 5
0
        private StepInstrution createInstruction(double offsetTime, double stepDuration, int stepCount)
        {
            //Debug.WriteLine($"Cp({offsetTime:0.00},{stepDuration:0.00},{stepCount})");

            _lastStepCount = stepCount;
            if (stepCount == 0)
            {
                _lastInstructionDuration = 0;
                return(new ConstantInstruction(0, 0, 0));
            }

            checked
            {
                var offset     = (int)Math.Round(offsetTime);
                var baseDeltaT = (int)Math.Truncate(stepDuration);
                var remainder  = (int)Math.Truncate(stepDuration * stepCount - baseDeltaT * stepCount);

                var instruction = new ConstantInstruction((short)(Math.Sign(_ratio) * stepCount), baseDeltaT, (ushort)remainder, offset);
                _lastInstructionDuration = instruction.GetInstructionDuration();
                return(instruction);
            }
        }
Exemplo n.º 6
0
        private StepInstrution getConstantInstruction(double speed)
        {
            checked
            {
                var trajectory      = speed * _instructionDurationLimit;
                var trajectorySteps = (Int16)Math.Round(trajectory / Configuration.MilimetersPerStep);
                var tickCount       = _instructionDurationLimit * Configuration.TimerFrequency;

                StepInstrution instruction;
                if (trajectorySteps == 0)
                {
                    instruction = new ConstantInstruction(0, (int)Math.Round(tickCount), 0);
                }
                else
                {
                    var baseDeltaExact = Math.Abs(tickCount / trajectorySteps);
                    var baseDelta      = Math.Abs((int)(baseDeltaExact));
                    var tickRemainder  = (UInt16)(tickCount - Math.Abs(trajectorySteps) * baseDelta);

                    instruction = new ConstantInstruction(trajectorySteps, baseDelta, tickRemainder);
                }
                return(instruction);
            }
        }
Exemplo n.º 7
0
 public virtual void VisitConstant(ConstantInstruction x)
 {
     VisitInstruction(x);
 }
Exemplo n.º 8
0
 public override void VisitConstant(ConstantInstruction x)
 {
     emit(Expression.Constant(x.Constant));
 }