Пример #1
0
        internal static AccelerationInstruction[] CreateAcceleration(int speed, int desiredSpeed)
        {
            var canSkipAcceleration = speed == desiredSpeed;

            canSkipAcceleration |= Math.Abs(speed) >= Configuration.StartDeltaT && Math.Abs(desiredSpeed) >= Configuration.StartDeltaT;
            if (canSkipAcceleration)
            {
                //no acceleration is required
                return(new AccelerationInstruction[0]);
            }

            if (Math.Abs(Math.Sign(speed) - Math.Sign(desiredSpeed)) > 1)
            {
                throw new NotImplementedException("Stop and run in other direction");
            }

            var stepCount = desiredSpeed > 0 ? (Int16)5000 : (Int16)(-5000);

            if (desiredSpeed == 0)
            {
                stepCount = speed > 0 ? (Int16)5000 : (Int16)(-5000);
            }

            speed        = Math.Abs(speed);
            desiredSpeed = Math.Abs(desiredSpeed);
            if (speed == 0)
            {
                speed = Configuration.StartDeltaT;
            }

            if (desiredSpeed == 0)
            {
                desiredSpeed = Configuration.StartDeltaT;
            }

            var acceleration = PlanBuilder.CalculateBoundedAcceleration((UInt16)speed, (UInt16)desiredSpeed, stepCount);

            return(new AccelerationInstruction[] { acceleration });
        }