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();
        }
Ejemplo n.º 3
0
        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();
            }
        }
Ejemplo n.º 4
0
        private static void Main(string[] args)
        {
            StepperController sc = new StepperController("10.10.10.10");

            try
            {
                // stop the drive from moving
                sc.Stop();
                //for (int i = 0; i < 10; i++)
                //{
                //    SendScript(sc);
                //    System.Threading.Thread.Sleep(2000);
                //}

                //System.Threading.ThreadPool.QueueUserWorkItem((obj) =>
                //{
                //    while (true)
                //    {
                //        Console.WriteLine("Status: " + sc.GetStatus());
                //        Console.WriteLine("Alarm: " + sc.GetAlarmCode());
                //        System.Threading.Thread.Sleep(1000);
                //    }
                //});

                Console.WriteLine("Model: " + sc.GetModel());
                Console.WriteLine("Status: " + sc.GetStatus());
                sc.DisableMotor();
                //System.Threading.Thread.Sleep(2000);
                //Console.WriteLine("Current Position: " + sc.GetEncoderPosition());
                //Console.WriteLine("Resetting position to 0");
                //sc.ResetEncoderPosition(0);
                //Console.WriteLine("Current Position: " + sc.GetEncoderPosition());
                //sc.EnableMotor();
                //Console.WriteLine("Moving...");
                //sc.MoveToAbsolutePosition(20000);
                //Console.WriteLine("Move complete.");
                //System.Threading.Thread.Sleep(2000);
                //sc.StartJog(10, 25, 25);
                //System.Threading.Thread.Sleep(2500);
                //sc.ChangeJogSpeed(25);
                //System.Threading.Thread.Sleep(2500);
                //sc.ChangeJogSpeed(3);
                //System.Threading.Thread.Sleep(2500);
                //sc.StopJog();

                //Console.WriteLine("Status: " + sc.GetStatus());
                //System.Threading.Thread.Sleep(1000);
                //Console.WriteLine("Current Position: " + sc.GetEncoderPosition());

                // stop the drive from moving
                sc.Stop();

                // set the number of steps per rev
                sc.SetNumberStepsPerRevolution(51200);

                // set revolutions per second
                sc.SetVelocity(25);

                Console.WriteLine($"Model: {sc.GetModel()}");
                Console.WriteLine($"Status: {sc.GetStatus()} Position: {sc.GetEncoderPosition()} ");

                Console.WriteLine("Resetting position to 0");
                sc.ResetEncoderPosition(0);
                sc.EnableMotor();

                string stopText = string.Empty;
                // 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}");
                        sc.EnableMotor();
                        var position = (long)Convert.ToDouble(Console.ReadLine());
                        sc.MoveToAbsolutePosition(position);
                        Console.WriteLine($"Current Position: {sc.GetEncoderPosition()}");
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine(e);
                    }
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }
            finally
            {
                sc.Stop();
                sc.DisableMotor();
            }
        }