Ejemplo n.º 1
0
        void MainFormLoad(object sender, System.EventArgs e)
        {
            FindAvailableSerialPorts();
            MakeThrusterGraphs();

            #region Servo init
            servo1         = new AdvancedServo();
            servo1.Attach += new AttachEventHandler(servo1_Attach);
            try{
                servo1.open();
            }
            catch (PhidgetException pe)
            {
                MessageBox.Show(pe.ToString());
            }
            #endregion

            //InitDirectInput();

            cameraAngle1.MaxAngle  = camMaxAngle;
            cameraAngle1.MinAngle  = camMinAngle;
            cameraAngle1.FlipGraph = true;

            errorCheck.Enabled             = true;
            joystickDetectionTimer.Enabled = true;
            timer1.Enabled = true;
            if (serialPort1.IsOpen)
            {
                serialPort1.Close();
            }

            LoadSettings();
        }
Ejemplo n.º 2
0
        //PhidgetServo detach event handling code
        void advServo_Detach(object sender, DetachEventArgs e)
        {
            AdvancedServo detached = (AdvancedServo)sender;

            attachedTxt.Text = detached.Attached.ToString();
            nameTxt.Clear();
            serialTxt.Clear();
            versiontxt.Clear();
            numServosTxt.Clear();

            velocityTrk.Enabled          = false;
            velocityTrk.Value            = velocityTrk.Minimum;
            positionTrk.Enabled          = false;
            positionTrk.Value            = positionTrk.Minimum;
            accelTrk.Enabled             = false;
            accelTrk.Value               = accelTrk.Minimum;
            engagedCheckBox.Enabled      = false;
            speedRampingCheckBox.Enabled = false;
            maxPosnTrackBar.Enabled      = false;
            minPosnTrackBar.Enabled      = false;
            servoTypeCmb.Enabled         = false;
            servoCmb.Items.Clear();

            target_positionTxt.Clear();
            target_velocityTxt.Clear();

            minPosnTextBox.Clear();
            maxPosnTextBox.Clear();

            accelTxt.Clear();

            servoCmb.Enabled = false;
            servoTypeCmb.Items.Clear();
        }
Ejemplo n.º 3
0
        public override void OnLoad()
        {
            servo         = PhidgetManager.Get <AdvancedServo>(false);
            servo.Attach += servo_Attach;
            servo.Detach += servo_Detach;

            foreach (string servoType in Enum.GetNames(typeof(ServoServo.ServoType)))
            {
                //stop here

                if (servoType.Equals(ServoServo.ServoType.USER_DEFINED.ToString()))
                {
                    break;
                }

                TypeComboBox.Items.Add(servoType);

                // Select the type we are given originally.
                if (servoType == ServoType.ToString())
                {
                    TypeComboBox.SelectedItem = servoType;
                }
            }

            PositionSlider.Value = Position;

            // Set the text (this doesn't get called if position was 0)
            PositionSlider_ValueChanged(null, null);

            SetAttached();
        }
Ejemplo n.º 4
0
        private void ServoBoard_Attach(object sender, AttachEventArgs e)
        {
            for (int i = 0; i < _servoBoard.servos.Count; i++)
            {
                if (_servoCount == 0)
                {
                    SetServoProperties(i, _servos[i].ServoType, _servos[i].ServoMinPulseWidth, _servos[i].ServoMaxPulseWidth, _servos[i].ServoMaxVelocity, _servos[i].ServoDegrees);

                    _servos[i].MinAcceleration = _servoBoard.servos[i].AccelerationMin;
                    _servos[i].MaxAcceleration = _servoBoard.servos[i].AccelerationMax;
                    _servos[i].Acceleration    = _servos[i].MaxAcceleration;

                    _servos[i].MinVelocity   = _servoBoard.servos[i].VelocityMin;
                    _servos[i].MaxVelocity   = _servoBoard.servos[i].VelocityMax;
                    _servos[i].VelocityLimit = _servos[i].MaxVelocity;

                    RegisterBindings(i);
                }
                _servoBoard.servos[i].VelocityLimit = _servos[i].VelocityLimit;
                _servoBoard.servos[i].Acceleration  = _servos[i].Acceleration < _servoBoard.servos[i].AccelerationMax ? _servos[i].Acceleration : _servoBoard.servos[i].AccelerationMax;;

                _servos[i].Calibration.OutputLimitMax = _servoBoard.servos[i].PositionMax;
                _servos[i].Calibration.OutputLimitMin = _servoBoard.servos[i].PositionMin;
            }

            if (_servoCount == 0)
            {
                _servoCount = _servoBoard.servos.Count;
                ConfigManager.LogManager.LogDebug("Detaching phidget servo board after config. (SerialNumber=\"" + _serialNumber + "\")");
                _servoBoard.close();
                _servoBoard = null;
            }
        }
Ejemplo n.º 5
0
        public void Detach()
        {
            ConfigManager.LogManager.LogDebug("Detaching phidget servo board. (SerialNumber=\"" + _serialNumber + "\")");
            try
            {
                if (_servoBoard != null && _servoBoard.Attached)
                {
                    /*
                     * for (int i = 0; i < _servoBoard.servos.Count; i++)
                     * {
                     *  while (!_servoBoard.servos[i].Stopped)
                     *  {
                     *      // Wait for all steppers to reset to their zero position.
                     *      System.Threading.Thread.Sleep(50);
                     *  }
                     * }
                     */


                    for (int i = 0; i < _servoBoard.servos.Count; i++)
                    {
                        _servoBoard.servos[i].Engaged = false;
                    }

                    _servoBoard.close();
                    _servoBoard = null;
                }
            }
            catch (PhidgetException e)
            {
                ConfigManager.LogManager.LogError("Error closing servo board", e);
            }
        }
Ejemplo n.º 6
0
 public void Attach()
 {
     if (_serialNumber > 0 && _servoBoard == null)
     {
         _servoBoard         = new AdvancedServo();
         _servoBoard.Attach += new AttachEventHandler(ServoBoard_Attach);
         _servoBoard.open(_serialNumber);
     }
 }
Ejemplo n.º 7
0
        //Attach event handler. Display serial number of the attached servo device
        static void advServo_Attach(object sender, AttachEventArgs e)
        {
            Console.WriteLine("AdvancedServo {0} attached!",
                              e.Device.SerialNumber.ToString());
            AdvancedServo attached = (AdvancedServo)sender;

            for (int i = 0; i < attached.servos.Count; i++)
            {
                attached.servos[i].Position      = 30.00;   //range is -23 to 232
                attached.servos[i].VelocityLimit = 1000.00; //max 1500, min 0
                attached.servos[i].Acceleration  = 1000.00; //max 4590, min 0
            }
        }
Ejemplo n.º 8
0
        //When the application is terminating, close the Phidget.
        private void Form1_FormClosed(object sender, FormClosedEventArgs e)
        {
            advServo.Attach -= new AttachEventHandler(advServo_Attach);
            advServo.Detach -= new DetachEventHandler(advServo_Detach);
            advServo.Error  -= new ErrorEventHandler(advServo_Error);

            advServo.CurrentChange  -= new CurrentChangeEventHandler(advServo_CurrentChange);
            advServo.PositionChange -= new PositionChangeEventHandler(advServo_PositionChange);
            advServo.VelocityChange -= new VelocityChangeEventHandler(advServo_VelocityChange);

            //run any events in the message queue - otherwise close will hang if there are any outstanding events
            Application.DoEvents();

            advServo.close();
            advServo = null;
        }
Ejemplo n.º 9
0
        //Initialization code
        private void Form1_Load(object sender, EventArgs e)
        {
            advServo = new AdvancedServo();

            advServo.Attach += new AttachEventHandler(advServo_Attach);
            advServo.Detach += new DetachEventHandler(advServo_Detach);
            advServo.Error  += new ErrorEventHandler(advServo_Error);

            advServo.CurrentChange  += new CurrentChangeEventHandler(advServo_CurrentChange);
            advServo.PositionChange += new PositionChangeEventHandler(advServo_PositionChange);
            advServo.VelocityChange += new VelocityChangeEventHandler(advServo_VelocityChange);

            //This assumes that if there is a command line argument, it is a serial number
            //and we try to open that specific device. Otherwise, open any device.
            openCmdLine(advServo);
        }
Ejemplo n.º 10
0
        /// <summary>
        /// Initialises a configuration form
        /// TODO - refactor
        /// </summary>
        public ConfigurationForm(ref List<Phidget> devicesToBeConfigured, String windowName)
        {
            Helper.Logger("HaptiQ_API.ConfigurationForm.ConfigurationForm::Configuration Form started");
            InitializeComponent();
            this.TopMost = true;

            this._devicesToBeConfigured = devicesToBeConfigured;
            this._windowName = windowName;

            _actuatorsValues = new Tuple<int, int>[MAX_NUMBER_ACTUATORS];

            // Initialise combo boxes - XXX move to separate method
            var servoBoards = new List<int>();
            var intfKits = new List<int>();
            intfKits.Add(0); // no intfKit board
            foreach (Phidget phidget in devicesToBeConfigured)
            {
                if (phidget.GetType() == typeof(AdvancedServo))
                {
                    servoBoards.Add(phidget.SerialNumber);
                }
                else if (phidget.GetType() == typeof(InterfaceKit))
                {
                    intfKits.Add(phidget.SerialNumber);
                }
            }
            ServoBoardsComboBox.DataSource = servoBoards;
            InterfaceKitsComboBox.DataSource = intfKits; 
            ServoBoardsComboBox.DropDownStyle = ComboBoxStyle.DropDownList;
            InterfaceKitsComboBox.DropDownStyle = ComboBoxStyle.DropDownList;
            ServoBoardsComboBox.SelectedValueChanged += new EventHandler(ServoBoardsComboBox_SelectedValueChanged);
            _currentAdvancedServoBoard = new AdvancedServo();
            _currentAdvancedServoBoard.open((int)ServoBoardsComboBox.SelectedItem);
            _currentAdvancedServoBoard.waitForAttachment();

            InterfaceKitsComboBox.SelectedValueChanged += new EventHandler(InterfaceKitsComboBox_SelectedValueChanged);

            var inputIdentifiers = new List<String>();
            inputIdentifiers.Add("Tag");
            inputIdentifiers.Add("Glyph");
            InputIdentifiersComboBox.DataSource = inputIdentifiers;
            InputIdentifiersComboBox.DropDownStyle = ComboBoxStyle.DropDownList;

            this.TopMost = false;
        }
Ejemplo n.º 11
0
        //PhidgetServo attach event handling code
        void advServo_Attach(object sender, AttachEventArgs e)
        {
            AdvancedServo attached = (AdvancedServo)sender;

            attachedTxt.Text  = attached.Attached.ToString();
            nameTxt.Text      = attached.Name;
            serialTxt.Text    = attached.SerialNumber.ToString();
            versiontxt.Text   = attached.Version.ToString();
            numServosTxt.Text = attached.servos.Count.ToString();

            velocityTrk.Enabled          = true;
            positionTrk.Enabled          = true;
            accelTrk.Enabled             = true;
            engagedCheckBox.Enabled      = true;
            speedRampingCheckBox.Enabled = true;
            maxPosnTrackBar.Enabled      = true;
            minPosnTrackBar.Enabled      = true;

            //Set the default servo type to the one Phidgets sells
            foreach (AdvancedServoServo motor in attached.servos)
            {
                motor.Type = ServoServo.ServoType.HITEC_HS322HD;
            }

            foreach (String servoType in System.Enum.GetNames(typeof(ServoServo.ServoType)))
            {
                //stop here
                if (servoType.Equals(ServoServo.ServoType.USER_DEFINED.ToString()))
                {
                    break;
                }
                servoTypeCmb.Items.Add(servoType);
            }

            servoTypeCmb.Enabled = true;

            for (int i = 0; i < attached.servos.Count; i++)
            {
                servoCmb.Items.Add(i);
            }
            //this will initialize all values
            servoCmb.SelectedIndex = 0;
            servoCmb.Enabled       = true;
        }
Ejemplo n.º 12
0
        public void Detach()
        {
            ConfigManager.LogManager.LogDebug("Detaching phidget servo board. (SerialNumber=\"" + _serialNumber + "\")");
            if (_servoBoard != null && _servoBoard.Attached)
            {
                try
                {
                    for (int i = 0; i < _servoBoard.servos.Count; i++)
                    {
                        _servoBoard.servos[i].Engaged = false;
                    }

                    _servoBoard.close();
                    _servoBoard = null;
                }
                catch (PhidgetException e)
                {
                    ConfigManager.LogManager.LogError("Error closing servo board", e);
                }
            }
        }
Ejemplo n.º 13
0
 protected override void OnEnabling(EnablingEventArgs e)
 {
     if (!e.WasConfiguring)
     {
         try
         {
             advServo = PhidgetManager.Get <AdvancedServo>();
             foreach (AdvancedServoServo servo in advServo.servos)
             {
                 servo.Engaged      = true;
                 servo.SpeedRamping = false;
             }
         }
         catch (InvalidOperationException)
         {
             ErrorLog.AddError(ErrorType.Failure, "The Phidget servo controller is not attached");
             e.Cancel = true;
             return;
         }
     }
 }
Ejemplo n.º 14
0
        private void initialiseServoBoard()
        {
            //Declare an Advanced Servo object
            _advServo = new AdvancedServo();
            //Hook the basic event handlers
            _advServo.Attach += new AttachEventHandler(advServo_Attach);
            _advServo.Detach += new DetachEventHandler(advServo_Detach);
            _advServo.Error += new ErrorEventHandler(advServo_Error);
            _advServo.PositionChange += new PositionChangeEventHandler(advServo_PositionChange);

            _advServo.open(configuration.idServoBoard);
            Helper.Logger("HaptiQ_API.HaptiQ.HaptiQ::Waiting for HaptiQ (" + _id + ") ServoBoard(" + configuration.idServoBoard + ") to be attached.");
            _advServo.waitForAttachment();
            Helper.Logger("HaptiQ_API.HaptiQ.HaptiQ::HaptiQ (" + _id + ") ServoBoard(" + configuration.idServoBoard + ") Connected");
            setAllActuatorsToMinPosition();
        }
Ejemplo n.º 15
0
		void MainFormLoad(object sender, System.EventArgs e)
		{
            FindAvailableSerialPorts();
            MakeThrusterGraphs();

			#region Servo init
			servo1 = new AdvancedServo();
			servo1.Attach += new AttachEventHandler(servo1_Attach);
			try{
			servo1.open();
			}
			catch (PhidgetException pe)
            {
                MessageBox.Show(pe.ToString());
            }
			#endregion
			
			//InitDirectInput();

            cameraAngle1.MaxAngle = camMaxAngle;
            cameraAngle1.MinAngle = camMinAngle;
            cameraAngle1.FlipGraph = true;

            errorCheck.Enabled = true;
            joystickDetectionTimer.Enabled = true;
			timer1.Enabled = true;
			if(serialPort1.IsOpen){serialPort1.Close();}

            LoadSettings();

		}
Ejemplo n.º 16
0
        //When the application is terminating, close the Phidget.
        private void Form1_FormClosed(object sender, FormClosedEventArgs e)
        {
            advServo.Attach -= new AttachEventHandler(advServo_Attach);
            advServo.Detach -= new DetachEventHandler(advServo_Detach);
            advServo.Error -= new ErrorEventHandler(advServo_Error);

            advServo.CurrentChange -= new CurrentChangeEventHandler(advServo_CurrentChange);
            advServo.PositionChange -= new PositionChangeEventHandler(advServo_PositionChange);
            advServo.VelocityChange -= new VelocityChangeEventHandler(advServo_VelocityChange);

            //run any events in the message queue - otherwise close will hang if there are any outstanding events
            Application.DoEvents();

            advServo.close();
            advServo = null;
        }
Ejemplo n.º 17
0
        static void Main(string[] args)
        {
            //Declare an Advanced Servo object
            AdvancedServo advServo = new AdvancedServo();

            //Hook the basic event handlers
            advServo.Attach += new AttachEventHandler(advServo_Attach);
            advServo.Detach += new DetachEventHandler(advServo_Detach);
            advServo.Error  += new ErrorEventHandler(advServo_Error);

            //hook the phidget specific event handlers
            //I decided to leave out the current change event handler for readability.
            advServo.PositionChange += new PositionChangeEventHandler
                                           (advServo_PositionChange);
            advServo.VelocityChange += new VelocityChangeEventHandler
                                           (advServo_VelocityChange);

            //open the Servo object for device connections
            advServo.open();

            //Get the program to wait for an Advanced Servo to be attached
            Console.WriteLine("Waiting for Advanced Servo to be attached...");
            advServo.waitForAttachment();

            //Set the initial position for the servo motor.  I set it to 15 here just
            //since I am going to cycle through the positive values to show a basic
            //full movement
            if (advServo.Attached)
            {
                advServo.servos[0].Acceleration  = 1000.00; //max 4590, min 0
                advServo.servos[0].VelocityLimit = 1000.00; //max 1500, min 0
                advServo.servos[0].Position      = 30.00;   //range is -23 to 232
            }

            //Wait for the motor to finish getting to position and let user continue
            Console.WriteLine("Press any key to continue...");
            Console.Read();

            //Move the motor from position value 30 to 200, we sleep for 500
            //milliseconds to give the motor enough time to move to the set position
            if (advServo.Attached)
            {
                advServo.servos[0].Position = 200; //range is -23 to 232
                Thread.Sleep(500);
            }

            //Wait for the events to fire and display, user input will continue the
            //program
            Console.WriteLine("Press any key to end...");
            Console.Read();


            //user input was read so we can terminate the program now, close the
            //AdvancedServo object. Left out the current change event handler for
            //readability.
            advServo.PositionChange -= new PositionChangeEventHandler
                                           (advServo_PositionChange);
            advServo.VelocityChange -= new VelocityChangeEventHandler
                                           (advServo_VelocityChange);

            //user input was read so we can terminate the program now, close the
            //AdvancedServo object
            advServo.close();

            //set the object to null to get it out of memory
            advServo = null;

            Console.WriteLine("ok");
        }
Ejemplo n.º 18
0
        //Initialization code
        private void Form1_Load(object sender, EventArgs e)
        {
            advServo = new AdvancedServo();

            advServo.Attach += new AttachEventHandler(advServo_Attach);
            advServo.Detach += new DetachEventHandler(advServo_Detach);
            advServo.Error += new ErrorEventHandler(advServo_Error);

            advServo.CurrentChange += new CurrentChangeEventHandler(advServo_CurrentChange);
            advServo.PositionChange += new PositionChangeEventHandler(advServo_PositionChange);
            advServo.VelocityChange += new VelocityChangeEventHandler(advServo_VelocityChange);

            //This assumes that if there is a command line argument, it is a serial number
            //and we try to open that specific device. Otherwise, open any device.
            openCmdLine(advServo);
        }
Ejemplo n.º 19
0
 private void closeServoBoard()
 {
     _advServo.Attach -= new AttachEventHandler(advServo_Attach);
     _advServo.Detach -= new DetachEventHandler(advServo_Detach);
     _advServo.Error -= new ErrorEventHandler(advServo_Error);
     _advServo.PositionChange -= new PositionChangeEventHandler(advServo_PositionChange);
     _advServo.close();
     _advServo = null; //set the object to null to get it out of memory
     Helper.Logger("HaptiQ_API.HaptiQ.close::HaptiQ (" + _id + ") ServoBoard (" + configuration.idServoBoard + ") disconnected");
 }