public void load() { try { // Read File corresponding to Motor ID load_trajectory(); //Hook the basic event handlers stepper.Attach += new AttachEventHandler(stepper_Attach); stepper.Detach += new DetachEventHandler(stepper_Detach); stepper.Error += new ErrorEventHandler(stepper_Error); stepper.open(); Console.WriteLine("Waiting for a Stepper to be attached...."); stepper.waitForAttachment(); Console.ReadLine(); //Acceleration at Max stepper.steppers[0].Acceleration = stepper.steppers[0].AccelerationMax; //ensure the value is between the AccelerationMin and AccelerationMax Console.WriteLine("Stepper motor acceleration set to: {0}", stepper.steppers[0].Acceleration.ToString()); stepper.steppers[0].Engaged = true; stepper.steppers[0].VelocityLimit = 0; stepper.steppers[0].CurrentLimit = 1.7; //stepper.steppers[0].TargetPosition = 0; Goal_Position = stepper.steppers[0].TargetPosition; } catch (PhidgetException ex) { Console.WriteLine(ex.Description); } catch (Exception ex) { Console.WriteLine(ex.Message); } }
public void Attach() { if (_serialNumber > 0 && _stepperBoard == null) { _stepperBoard = new Stepper(); _stepperBoard.Attach += new AttachEventHandler(StepperBoard_Attach); _stepperBoard.open(_serialNumber); } if (Profile != null) { Profile.ProfileTick += Profile_ProfileTick; } }
private void InitPhidget() { try { //Initialize the InterfaceKit object ifKit = new Stepper(); //Hook the basica event handlers ifKit.Error += new ErrorEventHandler(ifKit_Error); //Open the object for device connections ifKit.open(); //Wait for an InterfaceKit phidget to be attached ifKit.waitForAttachment(3000); //Hook the phidget spcific event handlers ifKit.InputChange += new InputChangeEventHandler(ifKit_InputChange); } catch (PhidgetException ex) { Console.WriteLine(ex.Description); } }
static void Main(string[] args) { try { //Declare a Stepper object Stepper stepper = new Stepper(); //Hook the basic event handlers stepper.Attach += new AttachEventHandler(stepper_Attach); stepper.Detach += new DetachEventHandler(stepper_Detach); stepper.Error += new ErrorEventHandler(stepper_Error); //Hook the Stepper specific event handlers stepper.CurrentChange += new CurrentChangeEventHandler (stepper_CurrentChange); stepper.InputChange += new InputChangeEventHandler (stepper_InputChange); stepper.PositionChange += new StepperPositionChangeEventHandler (stepper_PositionChange); stepper.VelocityChange += new VelocityChangeEventHandler (stepper_VelocityChange); //Open the Stepper object for device connections stepper.open(); //get the program to wait for a Stepper device to be attached Console.WriteLine("Waiting for a Stepper to be attached...."); stepper.waitForAttachment(); Console.WriteLine("Now the velocity will be set"); Console.WriteLine("The motor will run until it reaches the set goal position"); Console.WriteLine("Press any key to continue..."); Console.ReadLine(); //Set the max velocity to start the stepper motor moving until it hits //the goal position stepper.steppers[0].VelocityLimit = 100.00; //Max velocity Console.WriteLine("Stepper motor velocity set to: {0}", stepper.steppers[0].VelocityLimit.ToString()); stepper.steppers[0].Acceleration = stepper.steppers[0].AccelerationMin; //ensure the value is between the AccelerationMin and AccelerationMax Console.WriteLine("Stepper motor acceleration set to: {0}", stepper.steppers[0].Acceleration.ToString()); stepper.steppers[0].TargetPosition = 0; stepper.steppers[0].Engaged = true; Console.WriteLine("Press any key to continue..."); Console.ReadLine(); Console.WriteLine("Will now move to position 2000."); Console.WriteLine("Please wait until the motor stops."); Console.WriteLine("Press any key to continue..."); Console.ReadLine(); //Set the goal position to 2000 stepper.steppers[0].TargetPosition = 2000; Console.WriteLine("Press any key to end...."); Console.ReadLine(); stepper.steppers[0].Engaged = false; //close the Stepper object stepper.close(); //set the object to null to get it out of memory stepper = null; //if no exceptions were thrown at this point it is safe to terminate Console.WriteLine("ok"); } catch (PhidgetException ex) { Console.WriteLine(ex.Description); } catch (Exception ex) { Console.WriteLine(ex.Message); } }