Exemplo n.º 1
0
 public void position_Update2(TCubeInertialMotor device, InertialMotorStatus.MotorChannels channel)
 {
     if (channel == ch1)
     {
         motorX         = device.GetPosition(channel);
         motorXlbl.Text = "X: " + motorX.ToString();
     }
     else
     {
         motorY         = device.GetPosition(channel);
         motorYlbl.Text = "Y: " + motorY.ToString();
     }
 }
Exemplo n.º 2
0
        public void Move_Method2(TCubeInertialMotor device, InertialMotorStatus.MotorChannels channel, int position)
        {
            //TIM

            ready         = false;
            _taskComplete = false;

            richTextBox1.ScrollToCaret();

            _taskID = device.MoveTo(channel, position, CommandCompleteFunction);
            int i = 0;

            while (!_taskComplete)
            {
                Thread.Sleep(250);
                if (channel == ch1)
                {
                    motorX         = device.GetPosition(channel);
                    motorXlbl.Text = "X: " + motorX.ToString() + " - moving";
                }
                else
                {
                    motorY         = device.GetPosition(channel);
                    motorYlbl.Text = "Y: " + motorY.ToString() + " - moving";
                }

                if (i > 10)
                {
                    device.Stop(channel);
                    break;
                }

                i++;
                Application.DoEvents();
                // will need some timeout functionality;
            }



            Application.DoEvents();
            ready = true;

            position_Update2(device, channel);
        }
Exemplo n.º 3
0
        public Main()
        {
            InitializeComponent();

            if (Properties.Settings.Default.UpgradeRequired)
            {
                Properties.Settings.Default.Upgrade();
                Properties.Settings.Default.UpgradeRequired = false;
                Properties.Settings.Default.Save();
            }

            derrX[0] = 0; derrX[1] = 0; derrX[2] = 0; derrY[0] = 0; derrY[1] = 0; derrY[2] = 0;



            stopWatch.Start();

            //Get the list of IM devices
            DeviceManagerCLI.BuildDeviceList();

            List <string> serialNumbersTIM = DeviceManagerCLI.GetDeviceList(TCubeInertialMotor.DevicePrefix);

            serialNumbersTDC = DeviceManagerCLI.GetDeviceList(TCubeDCServo.DevicePrefix);

            richTextBox1.AppendText("TIM devices: " + serialNumbersTIM.Count() + " | TDC devices: " + serialNumbersTDC.Count() + Environment.NewLine);

            //Put the devices into an array


            for (int i = 0; i < serialNumbersTDC.Count(); i++)
            {
                devicesTDC[i] = TCubeDCServo.CreateTCubeDCServo(serialNumbersTDC[i]);
                TIM           = false;
            }

            for (int i = 0; i < serialNumbersTIM.Count(); i++)
            {
                //TIM takes preference
                devicesTIM[i] = TCubeInertialMotor.CreateTCubeInertialMotor(serialNumbersTIM[i]);
                TIM           = true;
            }



            if (TIM)
            {
                KpxUD.Value      = (decimal)Properties.Settings.Default.Kpx;
                KixUD.Value      = (decimal)Properties.Settings.Default.Kix;
                KdxUD.Value      = (decimal)Properties.Settings.Default.Kdx;
                KpyUD.Value      = (decimal)Properties.Settings.Default.Kpy;
                KiyUD.Value      = (decimal)Properties.Settings.Default.Kiy;
                KdyUD.Value      = (decimal)Properties.Settings.Default.Kdy;
                minMoveXUD.Value = (decimal)Properties.Settings.Default.minMoveX;
                minMoveYUD.Value = (decimal)Properties.Settings.Default.minMoveY;

                imaxxUD.Value = (decimal)Properties.Settings.Default.imaxX;
                imaxyUD.Value = (decimal)Properties.Settings.Default.imaxY;

                reverseX.Checked = Properties.Settings.Default.revx;
                reverseY.Checked = Properties.Settings.Default.revy;

                deviceTIM = devicesTIM[0];

                //Connect and initialise

                deviceTIM.Connect(serialNumbersTIM[0]);

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

                deviceTIM.StartPolling(100);

                // call GetMotorConfiguration on the device to initialize the DeviceUnitConverter object required for real world unit parameters
                //MotorConfiguration motorSettings = device[i].GetMotorConfiguration(serialNumbers[i]);

                InertialMotorConfiguration    motorSettings         = deviceTIM.GetInertialMotorConfiguration(serialNumbersTIM[0]);
                ThorlabsInertialMotorSettings currentDeviceSettings = deviceTIM.InertialMotorDeviceSettings as ThorlabsInertialMotorSettings;

                // display info about device
                DeviceInfo deviceInfo = deviceTIM.GetDeviceInfo();
                richTextBox1.AppendText("Selected device " + deviceInfo.Name + " serial: " + deviceInfo.SerialNumber + Environment.NewLine);// device[i].GetPosition(ch1).ToString("F4")

                ch1 = InertialMotorStatus.MotorChannels.Channel1;
                ch2 = InertialMotorStatus.MotorChannels.Channel2;

                //Set step rate and acceleration

                currentDeviceSettings.Drive.Channel(ch1).StepRate         = 1000;
                currentDeviceSettings.Drive.Channel(ch1).StepAcceleration = 100000;
                currentDeviceSettings.Drive.Channel(ch2).StepRate         = 1000;
                currentDeviceSettings.Drive.Channel(ch2).StepAcceleration = 100000;


                //apply setting

                deviceTIM.SetSettings(currentDeviceSettings, true, true);

                //get motor positions and print

                motorX = deviceTIM.GetPosition(ch1);//GetPosition(ch1);
                motorY = deviceTIM.GetPosition(ch2);
            }
            else
            {
                //TDC



                KpxUD.Value      = (decimal)Properties.Settings.Default.Kpx2;
                KixUD.Value      = (decimal)Properties.Settings.Default.Kix2;
                KdxUD.Value      = (decimal)Properties.Settings.Default.Kdx2;
                KpyUD.Value      = (decimal)Properties.Settings.Default.Kpy2;
                KiyUD.Value      = (decimal)Properties.Settings.Default.Kiy2;
                KdyUD.Value      = (decimal)Properties.Settings.Default.Kdy2;
                minMoveXUD.Value = (decimal)Properties.Settings.Default.minMoveX2;
                minMoveYUD.Value = (decimal)Properties.Settings.Default.minMoveY2;

                imaxxUD.Value = (decimal)Properties.Settings.Default.imaxX2;
                imaxyUD.Value = (decimal)Properties.Settings.Default.imaxY2;

                reverseX.Checked = Properties.Settings.Default.revx2;
                reverseY.Checked = Properties.Settings.Default.revy2;

                stepUpDown.DecimalPlaces = 2;
                stepUpDown.Increment     = (decimal)0.05;

                for (int i = 0; i < serialNumbersTDC.Count(); i++)
                {
                    devicesTDC[i] = TCubeDCServo.CreateTCubeDCServo(serialNumbersTDC[i]);

                    richTextBox1.AppendText(i + " Serial: " + serialNumbersTDC[i]);

                    try {
                        devicesTDC[i].Connect(serialNumbersTDC[i]);

                        if (!devicesTDC[i].IsSettingsInitialized())
                        {
                            devicesTDC[i].WaitForSettingsInitialized(5000);
                        }

                        devicesTDC[i].StartPolling(100);

                        MotorConfiguration motorSettings = devicesTDC[i].GetMotorConfiguration(serialNumbersTDC[i], DeviceConfiguration.DeviceSettingsUseOptionType.UseDeviceSettings); //serialNumbersTDC[i]

                        DCMotorSettings currentDeviceSettings = devicesTDC[i].MotorDeviceSettings as DCMotorSettings;

                        // display info about device
                        DeviceInfo deviceInfo = devicesTDC[i].GetDeviceInfo();
                        richTextBox1.AppendText(i + " Device  " + deviceInfo.Name + " " + deviceInfo.SerialNumber + " " + devicesTDC[i].GetMoveAbsolutePosition().ToString("F4") + Environment.NewLine);
                    } catch (Exception ex) {
                        richTextBox1.AppendText(" " + ex.Message + Environment.NewLine);
                    }
                }
            }



            motorXlbl.Text = "X: " + motorX.ToString();
            motorYlbl.Text = "Y: " + motorY.ToString();



            if (TIM)
            {
                //get status of ch1

                //InertialMotorStatus status = deviceTIM.ChannelStatus(ch1);
                // richTextBox1.AppendText(status.Status + " " + status.Position + " " + status.IsError + " " + status.IsMoving + Environment.NewLine);// device[i].GetPosition(ch1).ToString("F4")
            }
            else
            {
            }


            //Create MaxIm DL object

            ccd = new MaxIm.CCDCamera();

            // ccd.Notify += notify();

            //Connect CCD

            ccd.LinkEnabled = true;

            /*
             * ccd.MultiStarGuiding = true;
             *
             * ccd.GuiderExpose(1.0);
             *
             * while (ccd.GuiderRunning) {
             *  Thread.Sleep(100);
             * }
             *
             * ccd.GuiderTrack(1.0);
             */

            //Thread.Sleep(2000);

            //Notify on new guider image(?)

            ccd.EventMask = 256;

            ccd.Notify += new MaxIm._CameraEvents_NotifyEventHandler(notify);

            //Sets minimum correction interval

            timer1.Interval = Convert.ToInt16(correctionUpDown.Value * 1000);
            timer1.Enabled  = true;

            ready = true;
        }