/// <summary> /// Constructor. You can have multiple simultaneous steppers, all moving /// at different speeds and accelerations, provided you call their run() /// functions at frequent enough intervals. Current Position is set to 0, target /// position is set to 0. MaxSpeed and Acceleration default to 1.0. /// The motor pins will be initialised to OUTPUT mode during the /// constructor by a call to enableOutputs(). /// \param[in] interface Number of pins to interface to. Integer values are /// supported, but it is preferred to use the \ref MotorInterfaceType symbolic names. /// AccelStepper::DRIVER (1) means a stepper driver (with Step and Direction pins). /// If an enable line is also needed, call setEnablePin() after construction. /// You may also invert the pins using setPinsInverted(). /// AccelStepper::FULL2WIRE (2) means a 2 wire stepper (2 pins required). /// AccelStepper::FULL3WIRE (3) means a 3 wire stepper, such as HDD spindle (3 pins required). /// AccelStepper::FULL4WIRE (4) means a 4 wire stepper (4 pins required). /// AccelStepper::HALF3WIRE (6) means a 3 wire half stepper, such as HDD spindle (3 pins required) /// AccelStepper::HALF4WIRE (8) means a 4 wire half stepper (4 pins required) /// Defaults to AccelStepper::FULL4WIRE (4) pins. /// </summary> /// <param name="motorInterface">Defines the motor type</param> /// <param name="pin1"></param> /// <param name="pin2"></param> /// <param name="pin3"></param> /// <param name="pin4"></param> /// <param name="enable">Defines whether the outputs are powered or unpowered after instantiation</param> /// <param name="getMicroSeconds">Custom time method. To be used when hardware allows time measurement with less latency then DateTime.UtcNow.Ticks</param> public AccelStepper(MotorInterfaceType motorInterface, byte pin1, byte pin2, byte pin3, byte pin4, bool enable, GetMicroSecondsHandler getMicroSeconds = null) { _interface = motorInterface; _currentPos = 0; _targetPos = 0; _speed = 0.0f; _maxSpeed = 1.0f; _acceleration = 0.0f; _stepInterval = 0; _minPulseWidth = 1; _enablePin = new Pin { Num = 0xff }; _lastStepTime = 0; _pin[0] = new Pin { Num = pin1 }; _pin[1] = new Pin { Num = pin2 }; _pin[2] = new Pin { Num = pin3 }; _pin[3] = new Pin { Num = pin4 }; _enableInverted = 0; _getMicroSecondsHandler = getMicroSeconds ?? defaultGetMicroSeconds; // NEW _n = 0; _c0 = 0.0f; _cn = 0.0f; _cmin = 1.0f; _direction = Direction.DIRECTION_CCW; int i; for (i = 0; i < 4; i++) { _pinInverted[i] = 0x00; } if (enable) { EnableOutputs(); } // Some reasonable default SetAcceleration(1); }
/// <summary> /// Alternate Constructor which will call your own functions for forward and backward steps. /// You can have multiple simultaneous steppers, all moving /// at different speeds and accelerations, provided you call their run() /// functions at frequent enough intervals. Current Position is set to 0, target /// position is set to 0. MaxSpeed and Acceleration default to 1.0. /// Any motor initialization should happen before hand, no pins are used or initialized. /// </summary> /// <param name="forward">forward void-returning procedure that will make a forward step</param> /// <param name="backward">backward void-returning procedure that will make a backward step</param> /// <param name="getMicrosecondsHandler">Custom time method. To be used when hardware allows time measurement with less latency then DateTime.UtcNow.Ticks</param> public AccelStepper(ForwardHandler forward, BackwardHandler backward, GetMicroSecondsHandler getMicrosecondsHandler) { _interface = 0; _currentPos = 0; _targetPos = 0; _speed = 0.0f; _maxSpeed = 1.0f; _acceleration = 0.0f; _stepInterval = 0; _minPulseWidth = 1; _enablePin = new Pin { Num = 0xff }; _lastStepTime = 0; _pin[0] = new Pin(); _pin[1] = new Pin(); _pin[2] = new Pin(); _pin[3] = new Pin(); _forward = forward; _backward = backward; _getMicroSecondsHandler = getMicrosecondsHandler; // NEW _n = 0; _c0 = 0.0f; _cn = 0.0f; _cmin = 1.0f; _direction = Direction.DIRECTION_CCW; int i; for (i = 0; i < 4; i++) { _pinInverted[i] = 0; } // Some reasonable default SetAcceleration(1); }