Update Stepper.md
This commit is contained in:
parent
740a56b9f8
commit
df02332afe
|
|
@ -26,47 +26,47 @@ The **StepperControl** class provides the following methods to operate and contr
|
||||||
* enables current flow to the stepper motor coils, actively holding the motor in its position
|
* enables current flow to the stepper motor coils, actively holding the motor in its position
|
||||||
|
|
||||||
* `void disable()`
|
* `void disable()`
|
||||||
* disables current flow to the stepper motor coils and leaves in a state of high impedence, allowing the motor to turn freely
|
* disables current flow to the stepper motor coils and leaves them in a state of high impedence, allowing the motor to turn freely
|
||||||
|
|
||||||
* `void brake()`
|
* `void brake()`
|
||||||
* disables current flow to the stepper motor coils and leaves in a state of low impedence, creating "friction" that prevents the motor from freely turning
|
* disables current flow to the stepper motor coils but leaves them in a state of low impedence, preventing the motor from freely turning
|
||||||
* applicable only for driver chips that support a "short brake" mode, otherwise has no effect
|
* applicable only for driver chips that support a "short brake" mode, otherwise has no effect
|
||||||
|
|
||||||
* `void move(int nSteps, uint32_t msDelay, endAction_t endAction=NONE)`
|
* `void move(int nSteps, uint32_t msDelay, endAction_t endAction=NONE)`
|
||||||
* enables the stepper motor and moves it *nSteps* steps. Note this is a **non-blocking** function and returns immediately after being called while the stepper turns for *nSteps* steps in the background
|
* enables the stepper motor and turns it *nSteps* steps. Note this is a **non-blocking** function and returns immediately after being called while the motor turns for *nSteps* steps in the background
|
||||||
|
|
||||||
* *nSteps* - the number of steps to move. A positive number moves the motor in one direction; a negative number moved the motor in the opposite direction; a value of zero causes the motor to *stop* if it is already moving
|
* *nSteps* - the number of steps to turn. A positive number turns the motor in one direction; a negative number turns the motor in the opposite direction; a value of zero causes the motor to *stop* if it is already turning
|
||||||
* *msDelay* - the delay, in milliseconds, to pause between steps. Must be greater than zero. The lower the number, the faster the motor moves, subject to limitations of the motor itself
|
* *msDelay* - the delay, in milliseconds, to pause between steps. Must be greater than zero. The lower the number, the faster the motor turns, subject to limitations of the motor itself
|
||||||
* *endAction* - an optional action to be performed *after* the motor has finished moving *nSteps* steps. Choices include:
|
* *endAction* - an optional action to be performed *after* the motor has finished moving *nSteps* steps. Choices include:
|
||||||
* **StepperControl::NONE** - no action is taken; the stepper motor is left in the enabled state (this is the default)
|
* **StepperControl::NONE** - no action is taken; the stepper motor is left in the enabled state (this is the default)
|
||||||
* **StepperControl::DISABLE** - current to the stepper motor is disabled
|
* **StepperControl::DISABLE** - current to the stepper motor is disabled
|
||||||
* **StepperControl::BRAKE** - the stepper motor is placed in a brake state
|
* **StepperControl::BRAKE** - the stepper motor is placed in a brake state
|
||||||
* if this method is called while the stepper motor is moving, the number of steps to turn will be reset to the new *nSteps* value. It is okay to change the sign of *nSteps* to reverse the motor while it is moving, though this may not be desireable depending on what your motor is connected to in the real world
|
* if this method is called while the stepper motor is already turning, the number of steps to turn will be reset to the new *nSteps* value. It is okay to change the sign of *nSteps* to reverse the direction of motor while it is turning, though this may not be desireable depending on what your motor is connected to in the real world
|
||||||
* calling this method with a value of *nSteps=0* causes the motor to stop, if it is moving. If the motor is not moving, calling this method with *nSteps=0* simply enables the motor and the immediately performs the *endAction* (if specified).
|
* calling this method with a value of *nSteps=0* causes the motor to stop, if it is already turning. If the motor is not turning, calling this method with *nSteps=0* simply enables the motor and the immediately performs the *endAction* (if specified).
|
||||||
* example: `myMotor.move(200,5,StepperControl::BRAKE);` starts the motor turning for 200 steps with a delay of 5ms between steps. When the motor has completed all 200 steps, it is placed in the brake state where inductive "friction" holds it in place
|
* example: `myMotor.move(200,5,StepperControl::BRAKE);` starts the motor turning for 200 steps with a delay of 5ms between steps. When the motor has completed all 200 steps, it is placed in the brake state.
|
||||||
|
|
||||||
* `int stepsRemaining()`
|
* `int stepsRemaining()`
|
||||||
* returns the number of steps remaining to turn
|
* returns the number of steps remaining to turn
|
||||||
* may be positive or negative depending on the direction the motor is turning
|
* may be positive or negative depending on the direction the motor is turning
|
||||||
* returns zero when the motor is not turning
|
* returns zero if the motor is not turning
|
||||||
* example: `myMotor.move(200,5); while(myMotor.stepsRemaining()!=0); myMotor.move(-300,5);` starts the motor turning, waits until it completes all 200 steps, and then turns the motor in the opposite direction for 300 steps
|
* example: `myMotor.move(200,5); while(myMotor.stepsRemaining()!=0); myMotor.move(-300,5);` starts the motor turning, waits until it completes all 200 steps, and then turns the motor in the opposite direction for 300 steps
|
||||||
|
|
||||||
* `int position()`
|
* `int position()`
|
||||||
* returns the absolute position of the stepper motor, which is defined as the cumulative sum of the all positive and negative steps turned since initial start-up
|
* returns the absolute position of the stepper motor, which is defined as the cumulative sum of the all positive and negative steps turned since initial start-up
|
||||||
* can be called when the stepper motor is moving or when it is stopped
|
* can be called when the stepper motor is turning or when it is stopped
|
||||||
* example: `myMotor.move(-800,5); while(myMotor.stepsRemaining()); myMotor.move(200,5); while(myMotor.stepsRemaining()); Serial.print(myMotor.position())` would print a value of -600 after the motor finishes turning (first one direction for 800 steps, and then the other for 200 steps)
|
* example: `myMotor.move(-800,5); while(myMotor.stepsRemaining()); myMotor.move(200,5); while(myMotor.stepsRemaining()); Serial.print(myMotor.position())` would print a value of -600 after the motor finishes turning (first one direction for 800 steps, and then the other for 200 steps)
|
||||||
|
|
||||||
* `void setPosition(int pos)`
|
* `void setPosition(int pos)`
|
||||||
* resets the current position counter to *pos*
|
* resets the current position counter to *pos*
|
||||||
* this method does *not* move the motor; it only resets the internal position counter as returned by `position()`
|
* this method does *not* turn the motor; it only resets the internal position counter as returned by `position()`
|
||||||
* this method can only be called when the motor is **not** moving (if called when the motor is turning it is ignored and the internal position counter is **not** changed)
|
* this method is only effective when the motor is **not** turning (if called when the motor is turning the internal position counter remainms unchanged)
|
||||||
* example: `myMotor.move(300,5); while(myMotor.stepsRemaining()); myMotor.setPosition(-200); myMotor.move(600,5); while(myMotor.stepsRemaining()); Serial.print(myMotor.position())` would print a value of +400 after the motor finishes turning
|
* example: `myMotor.move(300,5); while(myMotor.stepsRemaining()); myMotor.setPosition(-200); myMotor.move(600,5); while(myMotor.stepsRemaining()); Serial.print(myMotor.position())` would print a value of +400 after the motor finishes turning
|
||||||
|
|
||||||
* `void moveTo(int nPosition, uint32_t msDelay, endAction_t endAction=NONE)`
|
* `void moveTo(int nPosition, uint32_t msDelay, endAction_t endAction=NONE)`
|
||||||
* enables the stepper motor and moves it to the position *nPosition*. Note this is a **non-blocking** function and returns immediately after being called while the stepper motor turns until it reaches *nPosition*
|
* enables the stepper motor and turns it to the position *nPosition*. Note this is a **non-blocking** function and returns immediately after being called while the stepper motor turns until it reaches *nPosition*
|
||||||
|
|
||||||
* *nPosition* - the position to which the stepper move should move, where position is defined as the cumulative number of positive and negative steps the motor has turned since initial start-up, as returned by `position()`
|
* *nPosition* - the position to which the stepper move should turn, where position is defined as the cumulative number of positive and negative steps the motor has turned since initial start-up, as returned by `position()`
|
||||||
* *msDelay* - the delay, in milliseconds, to pause between steps. Must be greater than zero. The lower the number, the faster the motor moves, subject to limitations of the motor itself
|
* *msDelay* - the delay, in milliseconds, to pause between steps. Must be greater than zero. The lower the number, the faster the motor turns, subject to limitations of the motor itself
|
||||||
* *endAction* - an optional action to be performed *after* the motor has reached *nPosition*. Choices include:
|
* *endAction* - an optional action to be performed *after* the motor has reached *nPosition*. Choices include:
|
||||||
* **StepperControl::NONE** - no action is taken; the stepper motor is left in the enabled state (this is the default)
|
* **StepperControl::NONE** - no action is taken; the stepper motor is left in the enabled state (this is the default)
|
||||||
* **StepperControl::DISABLE** - current to the stepper motor is disabled
|
* **StepperControl::DISABLE** - current to the stepper motor is disabled
|
||||||
|
|
@ -75,8 +75,12 @@ The **StepperControl** class provides the following methods to operate and contr
|
||||||
* calls to `stepsRemaining()` after calling `moveTo()` work as expected - the value returned will be the number of steps remaining until the motor reaches the *nPosition* specified
|
* calls to `stepsRemaining()` after calling `moveTo()` work as expected - the value returned will be the number of steps remaining until the motor reaches the *nPosition* specified
|
||||||
* note that `moveTo(nPosition)` is mathematically the same as `move(nPosition-position())`, but the `moveTo()` method is more accurate since it computes the position of the motor directly inside the task that is actually controlling the motor
|
* note that `moveTo(nPosition)` is mathematically the same as `move(nPosition-position())`, but the `moveTo()` method is more accurate since it computes the position of the motor directly inside the task that is actually controlling the motor
|
||||||
|
|
||||||
* `void setAccel(float accelSize, float accelSteps)`
|
* `void setAccel(float accelSize, float accelSteps)`
|
||||||
|
* adds an additional set of delays between steps so that the motor gradually accelerates when it starts and decelerates when it stops
|
||||||
|
* *accelSize* - the maximum size of the additional delay, expressed as a factor to be multiplied by the *msDelay* parameter used in `move()` and `moveTo()`. Must be a value greater or equal to 0.0. The larger the value, the greater the magnitude of the acceleration and deceleration. A value of zero yields no acceleration/deceleration
|
||||||
|
* *accelSteps* - the number of steps over which the *accelSize* factor exponentially decays so that the motor begins turning at the full speed specified by the *msDelay* parameter. Must be a value greater or equal to 1.0. The larger the value, the longer the acceleration and deceleration period
|
||||||
|
* example: `myMotor.setAccel(10,20); myMotor.move(200,5);` adds an additional 50ms delay (=10*5ms) after the first step, an additional 47ms after the second step, an additional 45ms after the third step, and so forth, until at step 82 the additional has fully decayed and the delay between steps remains fixed at the 5ms *msDelay* parameter specified. Then, starting at step 118 an additional delay of 1ms is added, at step 134 this increases to 2ms, and so forth, until the additional delay reaches 50ms once again at step 199 just before the motor stops turning at step 200
|
||||||
|
|
||||||
* `void setStepType(int mode)`
|
* `void setStepType(int mode)`
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue