public void TestCwLimit() { Random random = new Random(); double revsPerSecond = 2; StepperController sc = new StepperController(IP); sc.StartListening(); sc.SetFormatDecimal(); sc.SetVelocity(5); sc.ResetEncoderPosition(0); double numberTurns = random.NextDouble() * 2.5; double cwLimitCounts = Math.Floor(sc.MaxStepsPerRev * numberTurns); sc.SetCwLimit(cwLimitCounts); sc.SetVelocity(revsPerSecond); sc.ResetEncoderPosition(0); sc.EnableMotor(); sc.SetNumberStepsPerRevolution(sc.MaxStepsPerRev); // move to number of turns + ten percent double calculatedPosition = Math.Floor((cwLimitCounts * 1.1)); sc.MoveToAbsolutePosition((long)calculatedPosition); Thread.Sleep(2500); sc.GetEncoderPosition(); Thread.Sleep(500); Debug.Print($"Limit ={cwLimitCounts}"); Debug.Print($"Calculated ={calculatedPosition}"); Debug.Print($"Encoder Position = {sc.Sm.EncoderPosition}"); // over position is limited by software limit Assert.AreNotEqual(calculatedPosition, sc.Sm.EncoderPosition); // software limit and encoder position match Assert.AreEqual(cwLimitCounts, sc.Sm.EncoderPosition); // remove software limit sc.ClearCwLimit(); sc.MoveToAbsolutePosition((long)calculatedPosition); // over position is not limited by software limit and matches the encoder position Assert.AreEqual(calculatedPosition, sc.Sm.EncoderPosition); sc.Dispose(); }