public void GetEncoderCounts() { StepperController sc = new StepperController(IP); sc.EnableMotor(); //sc.ResetEncoderPosition(0); sc.SetFormatDecimal(); sc.StartListening(); sc.GetEncoderCounts(); sc.GetEncoderPosition(); Thread.Sleep(100); Debug.Print($"Encoder position= {sc.Sm.EncoderPosition}"); Debug.Print($"Encoder counts= {sc.Sm.EncoderCounts}"); sc.StartJog(5, 5, 5); Thread.Sleep(1000); sc.StopJog(); sc.GetEncoderPosition(); sc.GetEncoderCounts(); Thread.Sleep(2000); double newCounts = sc.Sm.EncoderCounts; double newPosition = sc.Sm.EncoderPosition; Debug.Print($"Encoder position= {sc.Sm.EncoderPosition}"); Debug.Print($"Encoder counts= {sc.Sm.EncoderCounts}"); Thread.Sleep(1000); Assert.AreEqual(sc.Sm.EncoderPosition, newPosition); Assert.AreEqual(sc.Sm.EncoderCounts, newCounts); Thread.Sleep(1000); sc.StopListening(); sc.Dispose(); }
public void SetStepsToAcceptableValue() { StepperController sc = new StepperController(IP); sc.StartListening(); int expectedStepsPerRev = 20000; sc.SetNumberStepsPerRevolution(expectedStepsPerRev); Assert.AreEqual(expectedStepsPerRev, sc.Sm.StepsPerRev); expectedStepsPerRev = 10000; sc.SetNumberStepsPerRevolution(expectedStepsPerRev); Assert.AreEqual(expectedStepsPerRev, sc.Sm.StepsPerRev); expectedStepsPerRev = 200; sc.SetNumberStepsPerRevolution(expectedStepsPerRev); Assert.AreEqual(expectedStepsPerRev, sc.Sm.StepsPerRev); expectedStepsPerRev = 51101; sc.SetNumberStepsPerRevolution(expectedStepsPerRev); Assert.AreEqual(expectedStepsPerRev, sc.Sm.StepsPerRev); expectedStepsPerRev = 51099; sc.SetNumberStepsPerRevolution(expectedStepsPerRev); Assert.AreEqual(expectedStepsPerRev, sc.Sm.StepsPerRev); expectedStepsPerRev = 205; sc.SetNumberStepsPerRevolution(expectedStepsPerRev); Assert.AreEqual(expectedStepsPerRev, sc.Sm.StepsPerRev); sc.Dispose(); }
public void MinStepsPerRevCoerced() { StepperController sc = new StepperController(IP); sc.StartListening(); sc.SetNumberStepsPerRevolution(1); Assert.AreEqual(sc.MinStepsPerRev, sc.Sm.StepsPerRev); sc.Dispose(); }
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(); }
public void RotateTenRevolutions() { double revsPerSecond = 5; StepperController sc = new StepperController(IP); sc.StartListening(); sc.SetFormatDecimal(); sc.SetVelocity(revsPerSecond); sc.ResetEncoderPosition(0); sc.EnableMotor(); sc.SetNumberStepsPerRevolution(sc.MaxStepsPerRev); double calculatedPosition = sc.MaxStepsPerRev * 10; sc.MoveToAbsolutePosition((long)calculatedPosition); Thread.Sleep(2500); sc.GetEncoderPosition(); Thread.Sleep(500); Debug.Print($"Calculated ={calculatedPosition}"); Debug.Print($"Encoder Position = {sc.Sm.EncoderPosition}"); Assert.AreEqual(calculatedPosition, sc.Sm.EncoderPosition); sc.StopListening(); sc.Dispose(); }
public void GetAlarmCodes() { StepperController sc = new StepperController(IP); sc.StartListening(); BitArray bA = new BitArray(BitConverter.GetBytes(0)); AlarmCode blankAlarmCode = new AlarmCode(bA); sc.GetAlarmCode(); Thread.Sleep(500); Assert.IsNotNull(sc.Sm.AlarmCode); sc.Sm.AlarmCode.CwLimit = true; Assert.AreNotEqual(blankAlarmCode.CwLimit, sc.Sm.AlarmCode.CwLimit); sc.ClearAlarms(); sc.GetAlarmCode(); Thread.Sleep(500); Assert.AreEqual(blankAlarmCode.CwLimit, sc.Sm.AlarmCode.CwLimit); sc.Dispose(); }
private static void Main() { // Configure Log4Net XmlConfigurator.Configure(new FileInfo("log4net.config")); // Configure PostSharp Logging to use Log4Net StepperController sc = new StepperController("10.10.10.10"); try { // stop the drive from moving sc.Stop(); sc.EnableMotor(); sc.ClearAlarms(); sc.GetModel(); sc.GetStatus(); sc.StartListening(); sc.SetFormatDecimal(); Thread.Sleep(500); Thread.Sleep(2000); Console.WriteLine("Resetting position to 0"); sc.ResetEncoderPosition(0); //Console.WriteLine("Moving..."); //System.Threading.Thread.Sleep(2000); //sc.StartJog(-0.5, 25, 25); //System.Threading.Thread.Sleep(2500); //sc.ChangeJogSpeed(2.5); //System.Threading.Thread.Sleep(2500); //sc.ChangeJogSpeed(.5); //System.Threading.Thread.Sleep(2500); //sc.StopJog(); //Console.WriteLine("Move complete."); //Console.WriteLine("Status: " + sc.GetStatus()); Thread.Sleep(1000); //Console.WriteLine("Current Position: " + sc.GetEncoderPosition()); // stop the drive from moving sc.Stop(); sc.ClearAlarms(); // set the number of steps per rev sc.SetNumberStepsPerRevolution(51200); // set revolutions per second sc.SetVelocity(25); sc.GetModel(); Console.WriteLine($"Model: {sc.Sm.Model}"); sc.GetStatus(); sc.GetEncoderPosition(); Console.WriteLine("Resetting position to 0"); sc.ResetEncoderPosition(0); sc.EnableMotor(); // read 15 positions Console.ForegroundColor = ConsoleColor.Green; Console.WriteLine("read 15 positions. 1 revolution = 51200 steps " + "\nmin number: -2147483648" + "\nmax number: 2147483647"); int maxPositions = 15; for (int i = 0; i < maxPositions; i++) { try { Console.WriteLine($"Enter a position #{i} of {maxPositions}"); long position = (long)Convert.ToDouble(Console.ReadLine()); sc.MoveToAbsolutePosition(position); sc.GetEncoderPosition(); Console.WriteLine($"Current Position: {sc.Sm.EncoderPosition}"); } catch (Exception e) { StepperController.Log.Error(e.Message); Console.WriteLine(e); } } } catch (Exception e) { StepperController.Log.Error(e.Message); Console.WriteLine(e); } finally { sc.Stop(); sc.DisableMotor(); sc.StopListening(); } }