コード例 #1
0
 /// <summary>
 /// Set the acceleration of the stage
 /// </summary>
 /// <param name="a">The acceleration in mm/s2, We need a smaller than 10mm/s2</param>
 public void SetAcceleration(decimal a)
 {
     if (a < 10)
     {
         VelocityParameters velPars = channel.GetVelocityParams();
         velPars.Acceleration = a;
         channel.SetVelocityParams(velPars);
     }
     else
     {
         #region Log
         DateTime date1 = DateTime.Now;
         string   str1  = string.Format("{0}-{1}-{2}, {3:00}:{4:00}:{5:00}: ERROR: Acceleration of {6:00} is too high for the linear stage, a set to 10mm/s2 ",
                                        date1.Year,
                                        date1.Month,
                                        date1.Day,
                                        date1.Hour,
                                        date1.Minute,
                                        date1.Second,
                                        a);
         using StreamWriter writer = new StreamWriter("log.txt", true);
         writer.WriteLine(str1);
         #endregion
         VelocityParameters velPars = channel.GetVelocityParams();
         velPars.Acceleration = 10m;
         channel.SetVelocityParams(velPars);
     }
 }
コード例 #2
0
 /// <summary>
 /// Set the max velocity of the stage
 /// </summary>
 /// <param name="velocity">The velocity in mm/s, We need v smaller than 12mm/s</param>
 public void SetVelocity(decimal velocity)
 {
     if (velocity < 12)
     {
         VelocityParameters velPars = channel.GetVelocityParams();
         velPars.MaxVelocity = velocity;
         channel.SetVelocityParams(velPars);
     }
     else
     {
         #region Log
         DateTime date1 = DateTime.Now;
         string   str1  = string.Format("{0}-{1}-{2}, {3:00}:{4:00}:{5:00}: ERROR: Velocity of {6:00} is too high for the linear stage, v set to 12mm/s ",
                                        date1.Year,
                                        date1.Month,
                                        date1.Day,
                                        date1.Hour,
                                        date1.Minute,
                                        date1.Second,
                                        velocity);
         using StreamWriter writer = new StreamWriter("log.txt", true);
         writer.WriteLine(str1);
         #endregion
         VelocityParameters velPars = channel.GetVelocityParams();
         velPars.MaxVelocity = 12m;
         channel.SetVelocityParams(velPars);
     }
 }
コード例 #3
0
ファイル: K10RC1.cs プロジェクト: zhangxd6/DataMonster
        public void MoveTo(decimal position, decimal vel, decimal acceleration, decimal motorstep)
        {
            VelocityParameters velPars = device.GetVelocityParams();

            velPars.MaxVelocity  = vel;
            velPars.Acceleration = acceleration;

            device.SetVelocityParams(velPars);


            device.SetJogStepSize(motorstep);
            device.MoveTo(position, 60000);
        }
コード例 #4
0
ファイル: Program.cs プロジェクト: diracdeltafunct/astrophoto
        /// <summary> Tests velocity parameters. </summary>
        /// <param name="device"> The device. </param>
        public static void TestVelocityParameters(IGenericAdvancedMotor device)
        {
            try
            {
                VelocityParameters_DeviceUnit originalVelocityParameters = device.GetVelocityParams_DeviceUnit();
                VelocityParameters            realVP = device.GetVelocityParams();
                realVP.Acceleration += 0.5m;
                realVP.MaxVelocity  += 0.5m;
                device.SetVelocityParams(realVP);
                Thread.Sleep(250);

                realVP = device.GetVelocityParams();

                device.SetVelocityParams_DeviceUnit(originalVelocityParameters);
            }
            catch (DeviceException ex)
            {
                Console.WriteLine("Failed to update settings {0} - {1}", ex.DeviceID, ex.Message);
            }
        }
コード例 #5
0
        private void CreateConfigs()
        {
            // start the device polling.
            // Polling requests a status update every specified number of milliseconds.
            this.currentMotor.StartPolling(250);

            // needs a delay so that the current enabled state can be obtained
            // ????
            Thread.Sleep(500);

            // enable the channel otherwise any move is ignored
            this.currentMotor.EnableDevice();

            // needs a delay to give time for the device to be enabled
            Thread.Sleep(500);

            // call GetMotorConfiguration on the device to initialize the DeviceUnitConverter object required for real world unit parameters
            // Sets up proper unit conversion for the correct device.  Only call this function ONCE
            MotorConfiguration motorSettings = this.currentMotor.LoadMotorConfiguration(this.serialNo);

            // Simply retrieves the "motor device settings"
            KCubeDCMotorSettings currentDeviceSettings = this.currentMotor.MotorDeviceSettings as KCubeDCMotorSettings;

            // display info about device

            // Retrieves a device info block
            DeviceInfo deviceInfo = this.currentMotor.GetDeviceInfo();

            Console.WriteLine("Device {0} = {1}", deviceInfo.SerialNumber, deviceInfo.Name);

            // After the device is opened we want to save the velocity
            // Retrieves the "velocity parameters" in real world units
            VelocityParameters velPars = this.currentMotor.GetVelocityParams();

            // Restricts the velocity allowed to be the user-defined velocity
            decimal dVelocity = this.velocity;

            velPars.MaxVelocity = dVelocity;
            this.currentMotor.SetVelocityParams(velPars);
        }
コード例 #6
0
        public bool MoveTo(decimal _requestedX, decimal _requestedY, decimal _requestedVelocity = 1m)
        {
            if (_requestedVelocity == 1m)
            {
                VelocityParameters xParam = this.MicroscopeXAxis.GetVelocityParams();
                xParam.MaxVelocity = 200.0m;
                this.MicroscopeXAxis.SetVelocityParams(xParam);
                VelocityParameters yParam = this.MicroscopeYAxis.GetVelocityParams();
                xParam.MaxVelocity = 200.0m;
                this.MicroscopeYAxis.SetVelocityParams(yParam);
                _requestedVelocity = this.DefaultVelocity;
            }

            if (this.XEnabled)
            {
                this.MicroscopeXAxis.MoveTo(_requestedX, this.MovementTimeoutInMillis);
            }
            if (this.YEnabled)
            {
                this.MicroscopeYAxis.MoveTo(_requestedY, this.MovementTimeoutInMillis);
            }
            return(true);
        }
コード例 #7
0
        static void Main(string[] args)
        {
            // Get parameters from command line
            int argc = args.Count();

            if (argc < 1)
            {
                Console.WriteLine("Usage: BSC_Console_net_managed serial_number [position: (0 - 50)] [velocity: (0 - 5)]");
                Console.ReadKey();
                return;
            }

            // Get the test motor position
            decimal position = 0m;

            if (argc > 1)
            {
                position = decimal.Parse(args[1]);
            }

            // Get the test velocity
            decimal velocity = 0m;

            if (argc > 2)
            {
                velocity = decimal.Parse(args[2]);
            }

            // get the test BSC203 serial number
            string serialNo = args[0];

            try
            {
                // Tell the device manager to get the list of all devices connected to the computer
                DeviceManagerCLI.BuildDeviceList();
            }
            catch (Exception ex)
            {
                // An error occurred - see ex for details
                Console.WriteLine("Exception raised by BuildDeviceList {0}", ex);
                Console.ReadKey();
                return;
            }

            // Get available Benchtop Stepper Motor and check our serial number is correct - by using the device prefix
            // i.e for serial number 70000123, device prefix is 70)
            List <string> serialNumbers = DeviceManagerCLI.GetDeviceList(BenchtopStepperMotor.DevicePrefix70);

            if (!serialNumbers.Contains(serialNo))
            {
                // The requested serial number is not a BSC203 or is not connected
                Console.WriteLine("{0} is not a valid serial number", serialNo);
                Console.ReadKey();
                return;
            }

            // Create the BenchtopStepperMotor device
            BenchtopStepperMotor device = BenchtopStepperMotor.CreateBenchtopStepperMotor(serialNo);

            if (device == null)
            {
                // An error occured
                Console.WriteLine("{0} is not a BenchtopStepperMotor", serialNo);
                Console.ReadKey();
                return;
            }

            // Open a connection to the device.
            try
            {
                Console.WriteLine("Opening device {0}", serialNo);
                device.Connect(serialNo);
            }
            catch (Exception)
            {
                // Connection failed
                Console.WriteLine("Failed to open device {0}", serialNo);
                Console.ReadKey();
                return;
            }

            // Get the correct channel - channel 1
            StepperMotorChannel channel = device.GetChannel(1);

            if (channel == null)
            {
                // Connection failed
                Console.WriteLine("Channel unavailable {0}", serialNo);
                Console.ReadKey();
                return;
            }

            // Wait for the device settings to initialize - timeout 5000ms
            if (!channel.IsSettingsInitialized())
            {
                try
                {
                    channel.WaitForSettingsInitialized(5000);
                }
                catch (Exception)
                {
                    Console.WriteLine("Settings failed to initialize");
                }
            }

            // Start the device polling
            // The polling loop requests regular status requests to the motor to ensure the program keeps track of the device.
            channel.StartPolling(250);
            // Needs a delay so that the current enabled state can be obtained
            Thread.Sleep(500);
            // Enable the channel otherwise any move is ignored
            channel.EnableDevice();
            // Needs a delay to give time for the device to be enabled
            Thread.Sleep(500);

            // Call LoadMotorConfiguration on the device to initialize the DeviceUnitConverter object required for real world unit parameters
            //  - loads configuration information into channel
            // Use the channel.DeviceID "70xxxxxx-1" to get the channel 1 settings. This is different to the serial number
            MotorConfiguration motorConfiguration = channel.LoadMotorConfiguration(channel.DeviceID);

            // Not used directly in example but illustrates how to obtain device settings
            ThorlabsBenchtopStepperMotorSettings currentDeviceSettings = channel.MotorDeviceSettings as ThorlabsBenchtopStepperMotorSettings;

            // Display info about device
            DeviceInfo deviceInfo = channel.GetDeviceInfo();

            Console.WriteLine("Device {0} = {1}", deviceInfo.SerialNumber, deviceInfo.Name);

            Home_Method1(channel);
            // or
            //Home_Method2(channel);
            bool homed = channel.Status.IsHomed;

            // If a position is requested
            if (position != 0)
            {
                // Update velocity if required using real world methods
                if (velocity != 0)
                {
                    VelocityParameters velPars = channel.GetVelocityParams();
                    velPars.MaxVelocity = velocity;
                    channel.SetVelocityParams(velPars);
                }

                Move_Method1(channel, position);
                // or
                // Move_Method2(channel, position);

                Decimal newPos = channel.Position;
                Console.WriteLine("Device Moved to {0}", newPos);
            }

            channel.StopPolling();
            device.Disconnect(true);

            Console.ReadKey();
        }
コード例 #8
0
ファイル: Program.cs プロジェクト: diracdeltafunct/astrophoto
        static void Main(string[] args)
        {
            TCubeDCServo.RegisterDevice();
            KCubeDCServo.RegisterDevice();

            // get parameters from command line
            int argc = args.Count();

            if (argc < 1)
            {
                Console.WriteLine("Usage = DC_Console_net_managed [serial_no] [position: optional (0 - 50)] [velocity: optional (0 - 5)]");
                Console.ReadKey();
                return;
            }

            decimal position = 0m;

            if (argc > 1)
            {
                position = decimal.Parse(args[1]);
            }

            decimal velocity = 0m;

            if (argc > 2)
            {
                velocity = decimal.Parse(args[2]);
            }

            string serialNo = args[0];

            try
            {
                // build device list
                DeviceManagerCLI.BuildDeviceList();
            }
            catch (Exception ex)
            {
                Console.WriteLine("Exception raised by BuildDeviceList {0}", ex);
                Console.ReadKey();
                return;
            }

            // get available KCube DC Servos and check our serial number is correct
            List <string> serialNumbers = DeviceManagerCLI.GetDeviceList(new List <int> {
                KCubeDCServo.DevicePrefix, TCubeDCServo.DevicePrefix
            });

            if (!serialNumbers.Contains(serialNo))
            {
                if (serialNumbers.Count > 0)
                {
                    serialNo = serialNumbers[0];
                    Console.WriteLine("using serial number {0}", serialNo);
                }
                else
                {
                    Console.WriteLine("{0} is not a valid serial number", serialNo);
                    Console.ReadKey();
                    return;
                }
            }

            // create the device
            IGenericCoreDeviceCLI device = DeviceFactory.CreateDevice(serialNo);
            IGenericAdvancedMotor motor  = device as IGenericAdvancedMotor;

            if (motor == null)
            {
                Console.WriteLine("{0} is not a DCServo", serialNo);
                Console.ReadKey();
                return;
            }

            // connect device
            try
            {
                Console.WriteLine("Opening device {0}", serialNo);
                device.Connect(serialNo);

                if (!motor.IsSettingsInitialized())
                {
                    motor.WaitForSettingsInitialized(5000);
                }

                // display info about device
                DeviceInfo di = device.GetDeviceInfo();
                Console.WriteLine("Device {0} = {1}", di.SerialNumber, di.Name);

                // start the device polling
                motor.StartPolling(250);
            }
            catch (DeviceException ex)
            {
                Console.WriteLine("Failed to open device {0} - {1}", ex.DeviceID, ex.Message);
                Console.ReadKey();
                return;
            }

            DeviceUnitConverter deviceUnitConverter;

            try
            {
                // call GetMotorConfiguration on the device to initialize the DeviceUnitConverter object required for real unit parameters
                MotorConfiguration motorSettings = motor.GetMotorConfiguration(serialNo);
                motorSettings.DeviceSettingsName = "PRM1-Z8";
                motorSettings.UpdateCurrentConfiguration();

                MotorDeviceSettings motorDeviceSettings = motor.MotorDeviceSettings;
                motor.SetSettings(motorDeviceSettings, true, false);

                // test code to test get / sert of parameters using real world units
                TestVelocityParameters(motor);
                TestJogParameters(motor);
                TestHomingParameters(motor);
                TestLimitParameters(motor);
                if (device is TCubeDCServo)
                {
                    TestPotentiometerParameters(device as TCubeDCServo);                     // TDC Only
                }

                motorSettings.UpdateCurrentConfiguration();
                deviceUnitConverter = motor.UnitConverter;
            }
            catch (DeviceException ex)
            {
                Console.WriteLine("Failed prepare settings {0} - {1}", ex.DeviceID, ex.Message);
                Console.ReadKey();
                return;
            }

            try
            {
                if (!Home_1(motor))
                {
                    Console.WriteLine("Failed to home device");
                    Console.ReadKey();
                    return;
                }
            }
            catch (DeviceException ex)
            {
                Console.WriteLine("Failed to Home device settings {0} - {1}", ex.DeviceID, ex.Message);
                Console.ReadKey();
                return;
            }

            try
            {
                // if position is set
                if (position != 0)
                {
                    // update velocity if required using real world methods
                    if (velocity != 0)
                    {
                        VelocityParameters velPars = motor.GetVelocityParams();
                        velPars.MaxVelocity = velocity;
                        motor.SetVelocityParams(velPars);
                    }

                    if (!MoveTo_1(motor, position, deviceUnitConverter))
                    {
                        Console.WriteLine("Failed to set position");
                        Console.ReadKey();
                    }
                }
                else
                {
                    char c = '\0';
                    do
                    {
                        do
                        {
                            Console.WriteLine("Press a key");
                            Console.WriteLine("0 to exit");
                            Console.WriteLine("1 to test StopImmediate()");
                            Console.WriteLine("2 to test Stop(5000)");
                            Console.WriteLine("3 to test Stop(WaitEvent)");
                            c = Console.ReadKey().KeyChar;
                        } while (c < '0' || c > '3');

                        if (c != '0')
                        {
                            motor.MoveContinuous(MotorDirection.Forward);
                            Console.WriteLine("Press any key to stop");
                            Console.ReadKey();
                            StatusBase status;
                            if (c == '1')
                            {
                                motor.Stop(5000);
                            }
                            if (c == '2')
                            {
                                motor.StopImmediate();
                            }
                            if (c == '3')
                            {
                                ManualResetEvent waitEvent = new ManualResetEvent(false);
                                waitEvent.Reset();
                                motor.Stop(p =>
                                {
                                    Console.WriteLine("Message Id {0}", p);
                                    waitEvent.Set();
                                });
                                if (!waitEvent.WaitOne(5000))
                                {
                                    Console.WriteLine("Failed to Stop");
                                }
                            }
                            do
                            {
                                status = motor.Status;
                                Console.WriteLine("Status says {0} ({1:X})", status.IsInMotion ? "Moving" : "Stopped", status.Status);
                                Thread.Sleep(50);
                            } while (status.IsInMotion);
                        }
                    } while (c != '0');
                }
            }
            catch (DeviceException ex)
            {
                Console.WriteLine("Failed to Move device settings {0} - {1}", ex.DeviceID, ex.Message);
                Console.ReadKey();
                return;
            }

            try
            {
                device.Disconnect(true);
            }
            catch (DeviceException ex)
            {
                Console.WriteLine("Failed to Disconnect {0} - {1}", ex.DeviceID, ex.Message);
            }

            Console.ReadKey();
        }
コード例 #9
0
ファイル: Program.cs プロジェクト: diracdeltafunct/astrophoto
        static void Main(string[] args)
        {
            // get parameters from command line
            int argc = args.Count();

            if (argc < 1)
            {
                Console.WriteLine("Usage = BBD_Console_net_managed [serial_no] [channel] [position: optional (0 - 50)] [velocity: optional (0 - 5)]");
                Console.ReadKey();
                return;
            }

            short channel = 1;

            if (argc > 2)
            {
                channel = short.Parse(args[1]);
            }

            decimal position = 0m;

            if (argc > 2)
            {
                position = decimal.Parse(args[2]);
            }

            decimal velocity = 0m;

            if (argc > 3)
            {
                velocity = decimal.Parse(args[3]);
            }

            string serialNo = args[0];

            try
            {
                // build device list
                DeviceManagerCLI.BuildDeviceList();
            }
            catch (Exception ex)
            {
                Console.WriteLine("Exception raised by BuildDeviceList {0}", ex);
                Console.ReadKey();
                return;
            }

            // get available TCube DC Servos and check our serial number is correct
            List <string> serialNumbers = DeviceManagerCLI.GetDeviceList(BenchtopBrushlessMotor.DevicePrefix);

            if (!serialNumbers.Contains(serialNo))
            {
                Console.WriteLine("{0} is not a valid serial number", serialNo);
                Console.ReadKey();
                return;
            }

            // create the device
            BenchtopBrushlessMotor device = BenchtopBrushlessMotor.CreateDevice(serialNo) as BenchtopBrushlessMotor;

            if (device == null)
            {
                Console.WriteLine("{0} is not a BenchtopBrushlessMotor", serialNo);
                Console.ReadKey();
                return;
            }

            //BrushlessMotorChannel benchtopChannel = device.GetChannel(channel);
            BrushlessMotorChannel benchtopChannel = device[channel] as BrushlessMotorChannel;

            if (benchtopChannel == null)
            {
                Console.WriteLine("{0} is not a valid channel number", channel);
                Console.ReadKey();
                return;
            }

            // connect device
            try
            {
                Console.WriteLine("Opening device {0}", serialNo);
                device.Connect(serialNo);

                if (!benchtopChannel.IsSettingsInitialized())
                {
                    benchtopChannel.WaitForSettingsInitialized(5000);
                }

                // display info about device
                DeviceInfo di = device.GetDeviceInfo();
                Console.WriteLine("Device {0} = {1}", di.SerialNumber, di.Name);

                // start the device polling
                benchtopChannel.StartPolling(250);
            }
            catch (DeviceException ex)
            {
                Console.WriteLine("Failed to open device {0} - {1}", ex.DeviceID, ex.Message);
                Console.ReadKey();
                return;
            }

            DeviceUnitConverter deviceUnitConverter;

            try
            {
                // call GetMotorConfiguration on the device to initialize the DeviceUnitConverter object required for real unit parameters
                MotorConfiguration motorSettings = benchtopChannel.GetMotorConfiguration(serialNo);

                // test code to test get / sert of parameters using real world units
                TestVelocityParameters(benchtopChannel);
                TestJogParameters(benchtopChannel);
                TestHomingParameters(benchtopChannel);
                TestLimitParameters(benchtopChannel);

                motorSettings.UpdateCurrentConfiguration();
                deviceUnitConverter = benchtopChannel.UnitConverter;
            }
            catch (DeviceException ex)
            {
                Console.WriteLine("Failed prepare settings {0} - {1}", ex.DeviceID, ex.Message);
                Console.ReadKey();
                return;
            }

            try
            {
                if (!Home_1(benchtopChannel))
                {
                    Console.WriteLine("Failed to home device");
                    Console.ReadKey();
                    return;
                }
            }
            catch (DeviceException ex)
            {
                Console.WriteLine("Failed to Home device settings {0} - {1}", ex.DeviceID, ex.Message);
                Console.ReadKey();
                return;
            }

            try
            {
                // if position is set
                if (position != 0)
                {
                    // update velocity if required using real world methods
                    if (velocity != 0)
                    {
                        VelocityParameters velPars = benchtopChannel.GetVelocityParams();
                        velPars.MaxVelocity = velocity;
                        benchtopChannel.SetVelocityParams(velPars);
                    }

                    if (!MoveTo_1(benchtopChannel, position, deviceUnitConverter))
                    {
                        Console.WriteLine("Failed to set position");
                        Console.ReadKey();
                    }
                }
            }
            catch (DeviceException ex)
            {
                Console.WriteLine("Failed to Move device settings {0} - {1}", ex.DeviceID, ex.Message);
                Console.ReadKey();
                return;
            }

            try
            {
                device.Disconnect(true);
            }
            catch (DeviceException ex)
            {
                Console.WriteLine("Failed to Disconnect {0} - {1}", ex.DeviceID, ex.Message);
            }

            Console.ReadKey();
        }