From 1255ab56820746137aba3d5d788f5d0b9baf6d4a Mon Sep 17 00:00:00 2001 From: Patrick Date: Wed, 23 Nov 2022 20:19:36 -0500 Subject: [PATCH] update to 1.64 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 1.62 2022-05-22 Added link to AccelStepper - The Missing Manual. - Fixed a problem when setting the maxSpeed to 1.0 due to incomplete initialisation. Reported by Olivier Pécheux. - 1.63 2022-06-30 Added virtual destructor at the request of Jan. - 1.64 2022-10-31 Patch courtesy acwest: Changes to make AccelStepper more subclassable. These changes are largely oriented to implementing new step-scheduling algorithms. --- LICENSE | 4 +- extras/doc/annotated.html | 13 +- extras/doc/classAccelStepper-members.html | 20 +- extras/doc/classAccelStepper.html | 232 +++++++++--- extras/doc/doxygen.css | 441 ++++++++++++++++------ extras/doc/files.html | 13 +- extras/doc/functions.html | 36 +- extras/doc/functions_func.html | 33 +- extras/doc/index.html | 79 ++-- keywords.txt | 1 + library.properties | 2 +- src/AccelStepper.cpp | 37 +- src/AccelStepper.h | 56 ++- 13 files changed, 697 insertions(+), 270 deletions(-) diff --git a/LICENSE b/LICENSE index 814fc7b..52998af 100644 --- a/LICENSE +++ b/LICENSE @@ -1,4 +1,4 @@ -This software is Copyright (C) 2008 Mike McCauley. Use is subject to license +This software is Copyright (C) Mike McCauley. Use is subject to license conditions. The main licensing options available are GPL V3 or Commercial: Open Source Licensing GPL V3 @@ -14,4 +14,4 @@ Commercial Licensing This is the appropriate option if you are creating proprietary applications and you are not prepared to distribute and share the source code of your -application. Contact info@open.com.au for details. +application. Contact info@airspayce for details. diff --git a/extras/doc/annotated.html b/extras/doc/annotated.html index 7f48b6f..e60691d 100644 --- a/extras/doc/annotated.html +++ b/extras/doc/annotated.html @@ -1,9 +1,9 @@ - + - + AccelStepper: Class List @@ -26,14 +26,15 @@ - + +/* @license-end */
@@ -50,9 +51,7 @@
diff --git a/extras/doc/classAccelStepper-members.html b/extras/doc/classAccelStepper-members.html index 44b31e5..49f5140 100644 --- a/extras/doc/classAccelStepper-members.html +++ b/extras/doc/classAccelStepper-members.html @@ -1,9 +1,9 @@ - + - + AccelStepper: Member List @@ -26,14 +26,15 @@ - + +/* @license-end */
@@ -45,9 +46,11 @@

This is the complete list of members for AccelStepper, including all inherited members.

+ + - + @@ -90,14 +93,15 @@ + + +
_directionAccelStepperprotected
_stepIntervalAccelStepperprotected
acceleration()AccelStepper
AccelStepper(uint8_t interface=AccelStepper::FULL4WIRE, uint8_t pin1=2, uint8_t pin2=3, uint8_t pin3=4, uint8_t pin4=5, bool enable=true)AccelStepper
AccelStepper(void(*forward)(), void(*backward)())AccelStepper
computeNewSpeed()AccelStepperprotected
computeNewSpeed()AccelStepperprotectedvirtual
currentPosition()AccelStepper
Direction enum nameAccelStepperprotected
DIRECTION_CCW enum valueAccelStepperprotected
step4(long step)AccelStepperprotectedvirtual
step6(long step)AccelStepperprotectedvirtual
step8(long step)AccelStepperprotectedvirtual
stepBackward()AccelStepperprotected
stepForward()AccelStepperprotected
stop()AccelStepper
targetPosition()AccelStepper
~AccelStepper()AccelStepperinlinevirtual
diff --git a/extras/doc/classAccelStepper.html b/extras/doc/classAccelStepper.html index a45161a..fec3900 100644 --- a/extras/doc/classAccelStepper.html +++ b/extras/doc/classAccelStepper.html @@ -1,9 +1,9 @@ - + - + AccelStepper: AccelStepper Class Reference @@ -26,14 +26,15 @@ - + +/* @license-end */
@@ -57,17 +58,17 @@

Public Types

enum  MotorInterfaceType {
-  FUNCTION = 0, -DRIVER = 1, -FULL2WIRE = 2, -FULL3WIRE = 3, +  FUNCTION = 0 +, DRIVER = 1 +, FULL2WIRE = 2 +, FULL3WIRE = 3 +,
+  FULL4WIRE = 4 +, HALF3WIRE = 6 +, HALF4WIRE = 8
-  FULL4WIRE = 4, -HALF3WIRE = 6, -HALF4WIRE = 8 -
- } Symbolic names for number of pins. Use this in the pins argument the AccelStepper constructor to provide a symbolic name for the number of pins to use. More...
- + } + Symbolic names for number of pins. Use this in the pins argument the AccelStepper constructor to provide a symbolic name for the number of pins to use. More...
  - + + + @@ -124,23 +127,31 @@ + + +

@@ -88,8 +89,10 @@

 
float maxSpeed ()
 
void setAcceleration (float acceleration)
void setAcceleration (float acceleration)
 
float acceleration ()
 
void setSpeed (float speed)
 
float speed ()
 
bool isRunning ()
 
+virtual ~AccelStepper ()
 Virtual destructor to prevent warnings during delete.
 
- - + +

Protected Types

enum  Direction { DIRECTION_CCW = 0, -DIRECTION_CW = 1 - }
 Direction indicator Symbolic names for the direction the motor is turning. More...
enum  Direction { DIRECTION_CCW = 0 +, DIRECTION_CW = 1 + }
 Direction indicator Symbolic names for the direction the motor is turning. More...
 
- - + + + + + + @@ -160,13 +171,15 @@ Protected Attributes + +

Protected Member Functions

void computeNewSpeed ()
 
virtual unsigned long computeNewSpeed ()
 
virtual void setOutputPins (uint8_t mask)
 
virtual void step (long step)
 
long stepForward ()
 
long stepBackward ()
 
virtual void step0 (long step)
 
virtual void step1 (long step)
boolean _direction
 
unsigned long _stepInterval
 

Detailed Description

Support for stepper motors with acceleration etc.

This defines a single 2 or 4 pin stepper motor, or stepper moter with fdriver chip, with optional acceleration, deceleration, absolute positioning commands etc. Multiple simultaneous steppers are supported, all moving at different speeds and accelerations.

Operation
This module operates by computing a step time in microseconds. The step time is recomputed after each step and after speed and acceleration parameters are changed by the caller. The time of each step is recorded in microseconds. The run() function steps the motor once if a new step is due. The run() function must be called frequently until the motor is in the desired position, after which time run() will do nothing.
Positioning
Positions are specified by a signed long integer. At construction time, the current position of the motor is consider to be 0. Positive positions are clockwise from the initial position; negative positions are anticlockwise. The current position can be altered for instance after initialization positioning.
-
Caveats
This is an open loop controller: If the motor stalls or is oversped, AccelStepper will not have a correct idea of where the motor really is (since there is no feedback of the motor's real position. We only know where we think it is, relative to the initial starting point).
+
Caveats
This is an open loop controller: If the motor stalls or is oversped, AccelStepper will not have a correct idea of where the motor really is (since there is no feedback of the motor's real position. We only know where we think it is, relative to the initial starting point).
Performance
The fastest motor speed that can be reliably supported is about 4000 steps per second at a clock frequency of 16 MHz on Arduino such as Uno etc. Faster processors can support faster stepping speeds. However, any speed less than that down to very slow speeds (much less than one per second) are also supported, provided the run() function is called frequently enough to step the motor whenever required for the speed set. Calling setAcceleration() is expensive, since it requires a square root to be calculated.

Gregor Christandl reports that with an Arduino Due and a simple test program, he measured 43163 steps per second using runSpeed(), and 16214 steps per second using run();

Member Enumeration Documentation

@@ -212,7 +225,7 @@

-

Symbolic names for number of pins. Use this in the pins argument the AccelStepper constructor to provide a symbolic name for the number of pins to use.

+

Symbolic names for number of pins. Use this in the pins argument the AccelStepper constructor to provide a symbolic name for the number of pins to use.

@@ -284,9 +297,9 @@

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().

Parameters

Enumerator
FUNCTION 

Use the functional interface, implementing your own driver functions (internal use only)

- - - + + + @@ -294,7 +307,7 @@

References _direction, DIRECTION_CCW, enableOutputs(), and setAcceleration().

+

References _direction, _stepInterval, DIRECTION_CCW, enableOutputs(), setAcceleration(), and setMaxSpeed().

@@ -331,13 +344,33 @@

References _direction, DIRECTION_CCW, and setAcceleration().

+

References _direction, _stepInterval, DIRECTION_CCW, setAcceleration(), and setMaxSpeed().

Member Function Documentation

- -

◆ computeNewSpeed()

+ +

◆ acceleration()

+ +
+
+

[in]interfaceNumber of pins to interface to. Integer values are supported, but it is preferred to use the 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(). Caution: DRIVER implements a blocking delay of minPulseWidth microseconds (default 1us) for each step. You can change this with setMinPulseWidth(). 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.
[in]pin1Arduino digital pin number for motor pin 1. Defaults to pin 2. For a AccelStepper::DRIVER (interface==1), this is the Step input to the driver. Low to high transition means to step)
[in]pin2Arduino digital pin number for motor pin 2. Defaults to pin 3. For a AccelStepper::DRIVER (interface==1), this is the Direction input the driver. High means forward.
[in]interfaceNumber of pins to interface to. Integer values are supported, but it is preferred to use the 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(). Caution: DRIVER implements a blocking delay of minPulseWidth microseconds (default 1us) for each step. You can change this with setMinPulseWidth(). 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.
[in]pin1Arduino digital pin number for motor pin 1. Defaults to pin 2. For a AccelStepper::DRIVER (interface==1), this is the Step input to the driver. Low to high transition means to step)
[in]pin2Arduino digital pin number for motor pin 2. Defaults to pin 3. For a AccelStepper::DRIVER (interface==1), this is the Direction input the driver. High means forward.
[in]pin3Arduino digital pin number for motor pin 3. Defaults to pin 4.
[in]pin4Arduino digital pin number for motor pin 4. Defaults to pin 5.
[in]enableIf this is true (the default), enableOutputs() will be called to enable the output pins at construction time.
+ + + + + + +
float AccelStepper::acceleration ()
+

+

Returns the acceleration/deceleration rate configured for this stepper that was previously set by setAcceleration();

Returns
The currently configured acceleration/deceleration
+ +

Referenced by setAcceleration().

+ +
+ + +

◆ computeNewSpeed()

@@ -362,10 +395,11 @@

setMaxSpeed()
  • after change to acceleration through setAcceleration()
  • -
  • after change to target position (relative or absolute) through move() or moveTo()
  • +
  • after change to target position (relative or absolute) through move() or moveTo()
    Returns
    the new step interval
    +
  • -

    References _direction, DIRECTION_CCW, DIRECTION_CW, and distanceToGo().

    +

    References _direction, _stepInterval, DIRECTION_CCW, DIRECTION_CW, and distanceToGo().

    Referenced by moveTo(), run(), setAcceleration(), and setMaxSpeed().

    @@ -435,7 +469,7 @@

    The distance from the current position to the target position.

    Returns
    the distance from the current position to the target position in steps. Positive is clockwise from the current position.
    -

    Referenced by computeNewSpeed(), and run().

    +

    Referenced by computeNewSpeed(), and run().

    @@ -557,7 +591,7 @@

    References computeNewSpeed().

    +

    References computeNewSpeed().

    Referenced by move(), MultiStepper::moveTo(), and runToNewPosition().

    @@ -579,7 +613,7 @@

    Poll the motor and step it if a step is due, implementing accelerations and decelerations to achieve the target position. You must call this as frequently as possible, but at least once per minimum step time interval, preferably in your main loop. Note that each call to run() will make at most one step, and then only when a step is due, based on the current speed and the time since the last step.

    Returns
    true if the motor is still running to the target position.
    -

    References computeNewSpeed(), distanceToGo(), and runSpeed().

    +

    References computeNewSpeed(), distanceToGo(), and runSpeed().

    Referenced by runToPosition().

    @@ -601,9 +635,9 @@

    Poll the motor and step it if a step is due, implementing a constant speed as set by the most recent call to setSpeed(). You must call this as frequently as possible, but at least once per step interval,

    Returns
    true if the motor was stepped.
    -

    References _direction, DIRECTION_CW, and step().

    +

    References _direction, _stepInterval, DIRECTION_CW, and step().

    -

    Referenced by MultiStepper::run(), run(), and runSpeedToPosition().

    +

    Referenced by run(), MultiStepper::run(), and runSpeedToPosition().

    @@ -621,7 +655,7 @@

    -

    Runs at the currently selected speed until the target position is reached. Does not implement accelerations.

    Returns
    true if it stepped
    +

    Executes runSpeed() unless the targetPosition is reached. This function needs to be called often just like runSpeed() or run(). Will step the motor if a step is required at the currently selected speed unless the target position has been reached. Does not implement accelerations.

    Returns
    true if it stepped

    References _direction, DIRECTION_CCW, DIRECTION_CW, and runSpeed().

    @@ -697,7 +731,7 @@

    References computeNewSpeed().

    +

    References acceleration(), and computeNewSpeed().

    Referenced by AccelStepper().

    @@ -725,6 +759,8 @@

    References _stepInterval.

    +

    Referenced by MultiStepper::run().

    @@ -776,7 +812,9 @@

    References computeNewSpeed(), and speed().

    +

    References computeNewSpeed(), and speed().

    + +

    Referenced by AccelStepper().

    @@ -797,7 +835,8 @@

    Sets the minimum pulse width allowed by the stepper driver. The minimum practical pulse width is approximately 20 microseconds. Times less than 20 microseconds will usually result in 20 microseconds or so.

    Parameters
    - +
    [in]minWidthThe minimum pulse width in microseconds.
    [in]minWidthThe minimum pulse width in microseconds.
    +
    @@ -955,7 +994,7 @@

    References _direction, DIRECTION_CCW, DIRECTION_CW, and speed().

    +

    References _direction, _stepInterval, DIRECTION_CCW, DIRECTION_CW, and speed().

    Referenced by MultiStepper::moveTo().

    @@ -1013,7 +1052,7 @@

    References DRIVER, FULL2WIRE, FULL3WIRE, FULL4WIRE, FUNCTION, HALF3WIRE, HALF4WIRE, step0(), step1(), step2(), step3(), step4(), step6(), and step8().

    -

    Referenced by runSpeed().

    +

    Referenced by runSpeed(), step0(), step1(), step2(), step3(), step4(), step6(), step8(), stepBackward(), and stepForward().

    @@ -1047,6 +1086,8 @@

    References step().

    +

    Referenced by step().

    @@ -1081,7 +1122,7 @@

    References _direction, and setOutputPins().

    +

    References _direction, setOutputPins(), and step().

    Referenced by step().

    @@ -1117,7 +1158,7 @@

    References setOutputPins().

    +

    References setOutputPins(), and step().

    Referenced by step().

    @@ -1153,7 +1194,7 @@

    References setOutputPins().

    +

    References setOutputPins(), and step().

    Referenced by step().

    @@ -1189,7 +1230,7 @@

    References setOutputPins().

    +

    References setOutputPins(), and step().

    Referenced by step().

    @@ -1225,7 +1266,7 @@

    References setOutputPins().

    +

    References setOutputPins(), and step().

    Referenced by step().

    @@ -1254,17 +1295,73 @@

    -

    Called to execute a step on a 4 pin half-steper motor. Only called when a new step is required. Subclasses may override to implement new stepping interfaces. The default sets or clears the outputs of pin1, pin2, pin3, pin4.

    Parameters
    +

    Called to execute a step on a 4 pin half-stepper motor. Only called when a new step is required. Subclasses may override to implement new stepping interfaces. The default sets or clears the outputs of pin1, pin2, pin3, pin4.

    Parameters
    [in]stepThe current step phase number (0 to 7)
    -

    References setOutputPins().

    +

    References setOutputPins(), and step().

    Referenced by step().

    + + + +

    ◆ stepBackward()

    + +
    +
    + + + + + +
    + + + + + + + +
    long AccelStepper::stepBackward ()
    +
    +protected
    +
    +

    Called to execute a counter-clockwise(-) step. Only called when a new step is required. This decrements the _currentPos and calls step()

    Returns
    the updated current position
    + +

    References step().

    + +
    +
    + +

    ◆ stepForward()

    + +
    +
    + + + + + +
    + + + + + + + +
    long AccelStepper::stepForward ()
    +
    +protected
    +
    +

    Called to execute a clockwise(+) step. Only called when a new step is required. This increments the _currentPos and calls step()

    Returns
    the updated current position
    + +

    References step().

    +
    @@ -1327,7 +1424,32 @@

    Current direction motor is spinning in Protected because some peoples subclasses need it to be so

    -

    Referenced by AccelStepper(), computeNewSpeed(), runSpeed(), runSpeedToPosition(), setSpeed(), and step1().

    +

    Referenced by AccelStepper(), computeNewSpeed(), runSpeed(), runSpeedToPosition(), setSpeed(), and step1().

    + + + + +

    ◆ _stepInterval

    + +
    +
    + + + + + +
    + + + + +
    unsigned long AccelStepper::_stepInterval
    +
    +protected
    +
    +

    The current interval between steps in microseconds. 0 means the motor is currently stopped with _speed == 0

    + +

    Referenced by AccelStepper(), computeNewSpeed(), runSpeed(), setCurrentPosition(), and setSpeed().

    @@ -1338,9 +1460,7 @@

    diff --git a/extras/doc/doxygen.css b/extras/doc/doxygen.css index 4f1ab91..ffbff02 100644 --- a/extras/doc/doxygen.css +++ b/extras/doc/doxygen.css @@ -1,4 +1,4 @@ -/* The standard CSS for doxygen 1.8.13 */ +/* The standard CSS for doxygen 1.9.1 */ body, table, div, p, dl { font: 400 14px/22px Roboto,sans-serif; @@ -53,17 +53,24 @@ dt { font-weight: bold; } -div.multicol { +ul.multicol { -moz-column-gap: 1em; -webkit-column-gap: 1em; + column-gap: 1em; -moz-column-count: 3; -webkit-column-count: 3; + column-count: 3; } p.startli, p.startdd { margin-top: 2px; } +th p.starttd, th p.intertd, th p.endtd { + font-size: 100%; + font-weight: 700; +} + p.starttd { margin-top: 0px; } @@ -80,6 +87,15 @@ p.endtd { margin-bottom: 2px; } +p.interli { +} + +p.interdd { +} + +p.intertd { +} + /* @end */ caption { @@ -87,30 +103,96 @@ caption { } span.legend { - font-size: 70%; - text-align: center; + font-size: 70%; + text-align: center; } h3.version { - font-size: 90%; - text-align: center; + font-size: 90%; + text-align: center; } -div.qindex, div.navtab{ - background-color: #EBEFF6; - border: 1px solid #A3B4D7; - text-align: center; +div.navtab { + border-right: 1px solid #A3B4D7; + padding-right: 15px; + text-align: right; + line-height: 110%; } -div.qindex, div.navpath { +div.navtab table { + border-spacing: 0; +} + +td.navtab { + padding-right: 6px; + padding-left: 6px; +} +td.navtabHL { + background-image: url('tab_a.png'); + background-repeat:repeat-x; + padding-right: 6px; + padding-left: 6px; +} + +td.navtabHL a, td.navtabHL a:visited { + color: #fff; + text-shadow: 0px 1px 1px rgba(0, 0, 0, 1.0); +} + +a.navtab { + font-weight: bold; +} + +div.qindex{ + text-align: center; width: 100%; line-height: 140%; + font-size: 130%; + color: #A0A0A0; } -div.navtab { - margin-right: 15px; +dt.alphachar{ + font-size: 180%; + font-weight: bold; } +.alphachar a{ + color: black; +} + +.alphachar a:hover, .alphachar a:visited{ + text-decoration: none; +} + +.classindex dl { + padding: 25px; + column-count:1 +} + +.classindex dd { + display:inline-block; + margin-left: 50px; + width: 90%; + line-height: 1.15em; +} + +.classindex dl.odd { + background-color: #F8F9FC; +} + +@media(min-width: 1120px) { + .classindex dl { + column-count:2 + } +} + +@media(min-width: 1320px) { + .classindex dl { + column-count:3 + } +} + + /* @group Link Styling */ a { @@ -127,19 +209,8 @@ a:hover { text-decoration: underline; } -a.qindex { - font-weight: bold; -} - -a.qindexHL { - font-weight: bold; - background-color: #9CAFD4; - color: #ffffff; - border: 1px double #869DCA; -} - .contents a.qindexHL:visited { - color: #ffffff; + color: #FFFFFF; } a.el { @@ -163,6 +234,25 @@ dl.el { margin-left: -1cm; } +ul { + overflow: hidden; /*Fixed: list item bullets overlap floating elements*/ +} + +#side-nav ul { + overflow: visible; /* reset ul rule for scroll bar in GENERATE_TREEVIEW window */ +} + +#main-nav ul { + overflow: visible; /* reset ul rule for the navigation bar drop down lists */ +} + +.fragment { + text-align: left; + direction: ltr; + overflow-x: auto; /*Fixed: fragment lines overlap floating elements*/ + overflow-y: hidden; +} + pre.fragment { border: 1px solid #C4CFE5; background-color: #FBFCFD; @@ -177,8 +267,8 @@ pre.fragment { } div.fragment { - padding: 0px; - margin: 4px 8px 4px 2px; + padding: 0 0 1px 0; /*Fixed: last line underline overlap border*/ + margin: 4px 8px 4px 2px; background-color: #FBFCFD; border: 1px solid #C4CFE5; } @@ -248,7 +338,7 @@ span.lineno a:hover { div.ah, span.ah { background-color: black; font-weight: bold; - color: #ffffff; + color: #FFFFFF; margin-bottom: 3px; margin-top: 3px; padding: 0.2em; @@ -324,7 +414,7 @@ img.formulaDsp { } -img.formulaInl { +img.formulaInl, img.inline { vertical-align: middle; } @@ -402,6 +492,13 @@ blockquote { padding: 0 12px 0 16px; } +blockquote.DocNodeRTL { + border-left: 0; + border-right: 2px solid #9CAFD4; + margin: 0 4px 0 24px; + padding: 0 16px 0 12px; +} + /* @end */ /* @@ -498,7 +595,7 @@ table.memberdecls { white-space: nowrap; } -.memItemRight { +.memItemRight, .memTemplItemRight { width: 100%; } @@ -666,17 +763,17 @@ dl.reflist dd { padding-left: 0px; } -.params .paramname, .retval .paramname { +.params .paramname, .retval .paramname, .tparams .paramname, .exception .paramname { font-weight: bold; vertical-align: top; } -.params .paramtype { +.params .paramtype, .tparams .paramtype { font-style: italic; vertical-align: top; } -.params .paramdir { +.params .paramdir, .tparams .paramdir { font-family: "courier new",courier,monospace; vertical-align: top; } @@ -1081,72 +1178,143 @@ div.headertitle padding: 5px 5px 5px 10px; } -dl -{ - padding: 0 0 0 10px; +.PageDocRTL-title div.headertitle { + text-align: right; + direction: rtl; } -/* dl.note, dl.warning, dl.attention, dl.pre, dl.post, dl.invariant, dl.deprecated, dl.todo, dl.test, dl.bug */ -dl.section -{ +dl { + padding: 0 0 0 0; +} + +/* dl.note, dl.warning, dl.attention, dl.pre, dl.post, dl.invariant, dl.deprecated, dl.todo, dl.test, dl.bug, dl.examples */ +dl.section { margin-left: 0px; padding-left: 0px; } -dl.note -{ - margin-left:-7px; - padding-left: 3px; - border-left:4px solid; - border-color: #D0C000; +dl.section.DocNodeRTL { + margin-right: 0px; + padding-right: 0px; } -dl.warning, dl.attention -{ - margin-left:-7px; - padding-left: 3px; - border-left:4px solid; - border-color: #FF0000; +dl.note { + margin-left: -7px; + padding-left: 3px; + border-left: 4px solid; + border-color: #D0C000; } -dl.pre, dl.post, dl.invariant -{ - margin-left:-7px; - padding-left: 3px; - border-left:4px solid; - border-color: #00D000; +dl.note.DocNodeRTL { + margin-left: 0; + padding-left: 0; + border-left: 0; + margin-right: -7px; + padding-right: 3px; + border-right: 4px solid; + border-color: #D0C000; +} + +dl.warning, dl.attention { + margin-left: -7px; + padding-left: 3px; + border-left: 4px solid; + border-color: #FF0000; } -dl.deprecated -{ - margin-left:-7px; - padding-left: 3px; - border-left:4px solid; - border-color: #505050; +dl.warning.DocNodeRTL, dl.attention.DocNodeRTL { + margin-left: 0; + padding-left: 0; + border-left: 0; + margin-right: -7px; + padding-right: 3px; + border-right: 4px solid; + border-color: #FF0000; } -dl.todo -{ - margin-left:-7px; - padding-left: 3px; - border-left:4px solid; - border-color: #00C0E0; +dl.pre, dl.post, dl.invariant { + margin-left: -7px; + padding-left: 3px; + border-left: 4px solid; + border-color: #00D000; } -dl.test -{ - margin-left:-7px; - padding-left: 3px; - border-left:4px solid; - border-color: #3030E0; +dl.pre.DocNodeRTL, dl.post.DocNodeRTL, dl.invariant.DocNodeRTL { + margin-left: 0; + padding-left: 0; + border-left: 0; + margin-right: -7px; + padding-right: 3px; + border-right: 4px solid; + border-color: #00D000; } -dl.bug -{ - margin-left:-7px; - padding-left: 3px; - border-left:4px solid; - border-color: #C08050; +dl.deprecated { + margin-left: -7px; + padding-left: 3px; + border-left: 4px solid; + border-color: #505050; +} + +dl.deprecated.DocNodeRTL { + margin-left: 0; + padding-left: 0; + border-left: 0; + margin-right: -7px; + padding-right: 3px; + border-right: 4px solid; + border-color: #505050; +} + +dl.todo { + margin-left: -7px; + padding-left: 3px; + border-left: 4px solid; + border-color: #00C0E0; +} + +dl.todo.DocNodeRTL { + margin-left: 0; + padding-left: 0; + border-left: 0; + margin-right: -7px; + padding-right: 3px; + border-right: 4px solid; + border-color: #00C0E0; +} + +dl.test { + margin-left: -7px; + padding-left: 3px; + border-left: 4px solid; + border-color: #3030E0; +} + +dl.test.DocNodeRTL { + margin-left: 0; + padding-left: 0; + border-left: 0; + margin-right: -7px; + padding-right: 3px; + border-right: 4px solid; + border-color: #3030E0; +} + +dl.bug { + margin-left: -7px; + padding-left: 3px; + border-left: 4px solid; + border-color: #C08050; +} + +dl.bug.DocNodeRTL { + margin-left: 0; + padding-left: 0; + border-left: 0; + margin-right: -7px; + padding-right: 3px; + border-right: 4px solid; + border-color: #C08050; } dl.section dd { @@ -1245,10 +1413,12 @@ dl.citelist dt { font-weight:bold; margin-right:10px; padding:5px; + text-align:right; + width:52px; } dl.citelist dd { - margin:2px 0; + margin:2px 0 2px 72px; padding:5px 0; } @@ -1263,6 +1433,11 @@ div.toc { width: 200px; } +.PageDocRTL-title div.toc { + float: left !important; + text-align: right; +} + div.toc li { background: url("bdwn.png") no-repeat scroll 0 5px transparent; font: 10px/1.2 Verdana,DejaVu Sans,Geneva,sans-serif; @@ -1271,6 +1446,12 @@ div.toc li { padding-top: 2px; } +.PageDocRTL-title div.toc li { + background-position-x: right !important; + padding-left: 0 !important; + padding-right: 10px; +} + div.toc h3 { font: bold 12px/1.2 Arial,FreeSans,sans-serif; color: #4665A2; @@ -1300,6 +1481,32 @@ div.toc li.level4 { margin-left: 45px; } +span.emoji { + /* font family used at the site: https://unicode.org/emoji/charts/full-emoji-list.html + * font-family: "Noto Color Emoji", "Apple Color Emoji", "Segoe UI Emoji", Times, Symbola, Aegyptus, Code2000, Code2001, Code2002, Musica, serif, LastResort; + */ +} + +.PageDocRTL-title div.toc li.level1 { + margin-left: 0 !important; + margin-right: 0; +} + +.PageDocRTL-title div.toc li.level2 { + margin-left: 0 !important; + margin-right: 15px; +} + +.PageDocRTL-title div.toc li.level3 { + margin-left: 0 !important; + margin-right: 30px; +} + +.PageDocRTL-title div.toc li.level4 { + margin-left: 0 !important; + margin-right: 45px; +} + .inherit_header { font-weight: bold; color: gray; @@ -1413,7 +1620,7 @@ tr.heading h2 { } #powerTip.n:after, #powerTip.ne:after, #powerTip.nw:after { - border-top-color: #ffffff; + border-top-color: #FFFFFF; border-width: 10px; margin: 0px -10px; } @@ -1441,7 +1648,7 @@ tr.heading h2 { } #powerTip.s:after, #powerTip.se:after, #powerTip.sw:after { - border-bottom-color: #ffffff; + border-bottom-color: #FFFFFF; border-width: 10px; margin: 0px -10px; } @@ -1468,7 +1675,7 @@ tr.heading h2 { left: 100%; } #powerTip.e:after { - border-left-color: #ffffff; + border-left-color: #FFFFFF; border-width: 10px; top: 50%; margin-top: -10px; @@ -1484,7 +1691,7 @@ tr.heading h2 { right: 100%; } #powerTip.w:after { - border-right-color: #ffffff; + border-right-color: #FFFFFF; border-width: 10px; top: 50%; margin-top: -10px; @@ -1517,7 +1724,6 @@ tr.heading h2 { /* @group Markdown */ -/* table.markdownTable { border-collapse:collapse; margin-top: 4px; @@ -1529,15 +1735,10 @@ table.markdownTable td, table.markdownTable th { padding: 3px 7px 2px; } -table.markdownTableHead tr { -} - -table.markdownTableBodyLeft td, table.markdownTable th { - border: 1px solid #2D4068; - padding: 3px 7px 2px; +table.markdownTable tr { } -th.markdownTableHeadLeft th.markdownTableHeadRight th.markdownTableHeadCenter th.markdownTableHeadNone { +th.markdownTableHeadLeft, th.markdownTableHeadRight, th.markdownTableHeadCenter, th.markdownTableHeadNone { background-color: #374F7F; color: #FFFFFF; font-size: 110%; @@ -1545,52 +1746,48 @@ th.markdownTableHeadLeft th.markdownTableHeadRight th.markdownTableHeadCenter th padding-top: 5px; } -th.markdownTableHeadLeft { +th.markdownTableHeadLeft, td.markdownTableBodyLeft { text-align: left } -th.markdownTableHeadRight { +th.markdownTableHeadRight, td.markdownTableBodyRight { text-align: right } -th.markdownTableHeadCenter { +th.markdownTableHeadCenter, td.markdownTableBodyCenter { text-align: center } -*/ - -table.markdownTable { - border-collapse:collapse; - margin-top: 4px; - margin-bottom: 4px; -} -table.markdownTable td, table.markdownTable th { - border: 1px solid #2D4068; - padding: 3px 7px 2px; +.DocNodeRTL { + text-align: right; + direction: rtl; } -table.markdownTable tr { +.DocNodeLTR { + text-align: left; + direction: ltr; } -th.markdownTableHeadLeft, th.markdownTableHeadRight, th.markdownTableHeadCenter, th.markdownTableHeadNone { - background-color: #374F7F; - color: #FFFFFF; - font-size: 110%; - padding-bottom: 4px; - padding-top: 5px; +table.DocNodeRTL { + width: auto; + margin-right: 0; + margin-left: auto; } -th.markdownTableHeadLeft, td.markdownTableBodyLeft { - text-align: left +table.DocNodeLTR { + width: auto; + margin-right: auto; + margin-left: 0; } -th.markdownTableHeadRight, td.markdownTableBodyRight { - text-align: right +tt, code, kbd, samp +{ + display: inline-block; + direction:ltr; } +/* @end */ -th.markdownTableHeadCenter, td.markdownTableBodyCenter { - text-align: center +u { + text-decoration: underline; } - -/* @end */ diff --git a/extras/doc/files.html b/extras/doc/files.html index d242c7d..a468468 100644 --- a/extras/doc/files.html +++ b/extras/doc/files.html @@ -1,9 +1,9 @@ - + - + AccelStepper: File List @@ -26,14 +26,15 @@ - + +/* @license-end */
    @@ -50,9 +51,7 @@
    diff --git a/extras/doc/functions.html b/extras/doc/functions.html index dda93bc..3ecba0c 100644 --- a/extras/doc/functions.html +++ b/extras/doc/functions.html @@ -1,9 +1,9 @@ - + - + AccelStepper: Class Members @@ -26,27 +26,34 @@ - + +/* @license-end */
    Here is a list of all documented class members with links to the class documentation for each member:
    -

    - _ -

    diff --git a/extras/doc/functions_func.html b/extras/doc/functions_func.html index 4eab539..615fa26 100644 --- a/extras/doc/functions_func.html +++ b/extras/doc/functions_func.html @@ -1,9 +1,9 @@ - + - + AccelStepper: Class Members - Functions @@ -26,20 +26,24 @@ - + +/* @license-end */
     

    - a -

    diff --git a/extras/doc/index.html b/extras/doc/index.html index f795f01..3eb6003 100644 --- a/extras/doc/index.html +++ b/extras/doc/index.html @@ -1,9 +1,9 @@ - + - + AccelStepper: AccelStepper library for Arduino @@ -26,24 +26,25 @@ - + +/* @license-end */ -
    +
    -
    AccelStepper library for Arduino
    +
    AccelStepper library for Arduino
    -

    This is the Arduino AccelStepper library. It provides an object-oriented interface for 2, 3 or 4 pin stepper motors and motor drivers.

    +

    This is the Arduino AccelStepper library. It provides an object-oriented interface for 2, 3 or 4 pin stepper motors and motor drivers.

    The standard Arduino IDE includes the Stepper library (http://arduino.cc/en/Reference/Stepper) for stepper motors. It is perfectly adequate for simple, single motor applications.

    -

    AccelStepper significantly improves on the standard Arduino Stepper library in several ways:

    1.21 Fixed a problem where desiredSpeed could compute the wrong step acceleration when _speed was small but non-zero. Reported by Brian Schmalz. Precompute sqrt_twoa to improve performance and max possible stepping speed
    @@ -162,40 +167,40 @@
    1.41 Fixed an error in the acceleration calculations, resulting in acceleration of haldf the intended value
    -1.42 Improved support for FULL3WIRE and HALF3WIRE output pins. These changes were in Yuri's original contribution but did not make it into production.
    +1.42 Improved support for FULL3WIRE and HALF3WIRE output pins. These changes were in Yuri's original contribution but did not make it into production.
    -1.43 Added DualMotorShield example. Shows how to use AccelStepper to control 2 x 2 phase steppers using the Itead Studio Arduino Dual Stepper Motor Driver Shield model IM120417015.
    +1.43 Added DualMotorShield example. Shows how to use AccelStepper to control 2 x 2 phase steppers using the Itead Studio Arduino Dual Stepper Motor Driver Shield model IM120417015.
    -1.44 examples/DualMotorShield/DualMotorShield.ino examples/DualMotorShield/DualMotorShield.pde was missing from the distribution.
    +1.44 examples/DualMotorShield/DualMotorShield.ino examples/DualMotorShield/DualMotorShield.pde was missing from the distribution.
    -1.45 Fixed a problem where if setAcceleration was not called, there was no default acceleration. Reported by Michael Newman.
    +1.45 Fixed a problem where if setAcceleration was not called, there was no default acceleration. Reported by Michael Newman.
    -1.45 Fixed inaccuracy in acceleration rate by using Equation 15, suggested by Sebastian Gracki.
    - Performance improvements in runSpeed suggested by Jaakko Fagerlund.
    +1.45 Fixed inaccuracy in acceleration rate by using Equation 15, suggested by Sebastian Gracki.
    + Performance improvements in runSpeed suggested by Jaakko Fagerlund.
    -1.46 Fixed error in documentation for runToPosition(). Reinstated time calculations in runSpeed() since new version is reported not to work correctly under some circumstances. Reported by Oleg V Gavva.
    +1.46 Fixed error in documentation for runToPosition(). Reinstated time calculations in runSpeed() since new version is reported not to work correctly under some circumstances. Reported by Oleg V Gavva.
    -1.48 2015-08-25 Added new class MultiStepper that can manage multiple AccelSteppers, and cause them all to move to selected positions at such a (constant) speed that they all arrive at their target position at the same time. Suitable for X-Y flatbeds etc.
    - Added new method maxSpeed() to AccelStepper to return the currently configured maxSpeed.
    +1.48 2015-08-25 Added new class MultiStepper that can manage multiple AccelSteppers, and cause them all to move to selected positions at such a (constant) speed that they all arrive at their target position at the same time. Suitable for X-Y flatbeds etc.
    + Added new method maxSpeed() to AccelStepper to return the currently configured maxSpeed.
    -1.49 2016-01-02 Testing with VID28 series instrument stepper motors and EasyDriver. OK, although with light pointers and slow speeds like 180 full steps per second the motor movement can be erratic, probably due to some mechanical resonance. Best to accelerate through this speed.
    - Added isRunning().
    +1.49 2016-01-02 Testing with VID28 series instrument stepper motors and EasyDriver. OK, although with light pointers and slow speeds like 180 full steps per second the motor movement can be erratic, probably due to some mechanical resonance. Best to accelerate through this speed.
    + Added isRunning().
    -1.50 2016-02-25 AccelStepper::disableOutputs now sets the enable pion to OUTPUT mode if the enable pin is defined. Patch from Piet De Jong.
    - Added notes about the fact that AFMotor_* examples do not work with Adafruit Motor Shield V2.
    +1.50 2016-02-25 AccelStepper::disableOutputs now sets the enable pion to OUTPUT mode if the enable pin is defined. Patch from Piet De Jong.
    + Added notes about the fact that AFMotor_* examples do not work with Adafruit Motor Shield V2.
    1.51 2016-03-24 Fixed a problem reported by gregor: when resetting the stepper motor position using setCurrentPosition() the stepper speed is reset by setting _stepInterval to 0, but _speed is not reset. this results in the stepper motor not starting again when calling setSpeed() with the same speed the stepper was set to before.
    -1.52 2016-08-09 Added MultiStepper to keywords.txt. Improvements to efficiency of AccelStepper::runSpeed() as suggested by David Grayson. Improvements to speed accuracy as suggested by David Grayson.
    +1.52 2016-08-09 Added MultiStepper to keywords.txt. Improvements to efficiency of AccelStepper::runSpeed() as suggested by David Grayson. Improvements to speed accuracy as suggested by David Grayson.
    1.53 2016-08-14 Backed out Improvements to speed accuracy from 1.52 as it did not work correctly.
    @@ -213,14 +218,22 @@
    1.60 2020-03-07 Release under GPL V3
    -1.61 2020-04-20 Added yield() call in runToPosition(), so that platforms like esp8266 dont hang/crash during long runs.
    -
    Author
    Mike McCauley (mikem.nosp@m.@air.nosp@m.spayc.nosp@m.e.co.nosp@m.m) DO NOT CONTACT THE AUTHOR DIRECTLY: USE THE LISTS
    - +1.61 2020-04-20 Added yield() call in runToPosition(), so that platforms like esp8266 dont hang/crash during long runs. +
    +1.62 2022-05-22 Added link to AccelStepper - The Missing Manual.
    + Fixed a problem when setting the maxSpeed to 1.0 due to incomplete initialisation. Reported by Olivier Pécheux.
    +
    +
    +1.63 2022-06-30 Added virtual destructor at the request of Jan.
    +
    +
    +1.64 2022-10-31 Patch courtesy acwest: Changes to make AccelStepper more subclassable. These changes are largely oriented to implementing new step-scheduling algorithms.
    +
    Author
    Mike McCauley (mikem.nosp@m.@air.nosp@m.spayc.nosp@m.e.co.nosp@m.m) DO NOT CONTACT THE AUTHOR DIRECTLY: USE THE GOOGLE GROUP
    + + diff --git a/keywords.txt b/keywords.txt index e77e0f1..85d801c 100644 --- a/keywords.txt +++ b/keywords.txt @@ -35,6 +35,7 @@ setMinPulseWidth KEYWORD2 setEnablePin KEYWORD2 setPinsInverted KEYWORD2 maxSpeed KEYWORD2 +isRunning KEYWORD2 ####################################### # Constants (LITERAL1) ####################################### diff --git a/library.properties b/library.properties index 359401d..62debd6 100755 --- a/library.properties +++ b/library.properties @@ -1,5 +1,5 @@ name=AccelStepper -version=1.61 +version=1.64 author=Mike McCauley maintainer=Patrick Wasp sentence=Allows Arduino boards to control a variety of stepper motors. diff --git a/src/AccelStepper.cpp b/src/AccelStepper.cpp index 093d56d..54535cc 100644 --- a/src/AccelStepper.cpp +++ b/src/AccelStepper.cpp @@ -1,6 +1,6 @@ // AccelStepper.cpp // -// Copyright (C) 2009-2013 Mike McCauley +// Copyright (C) 2009-2020 Mike McCauley // $Id: AccelStepper.cpp,v 1.24 2020/04/20 00:15:03 mikem Exp mikem $ #include "AccelStepper.h" @@ -94,7 +94,8 @@ void AccelStepper::setCurrentPosition(long position) _speed = 0.0; } -void AccelStepper::computeNewSpeed() +// Subclasses can override +unsigned long AccelStepper::computeNewSpeed() { long distanceTo = distanceToGo(); // +ve is clockwise from curent location @@ -106,7 +107,7 @@ void AccelStepper::computeNewSpeed() _stepInterval = 0; _speed = 0.0; _n = 0; - return; + return _stepInterval; } if (distanceTo > 0) @@ -174,6 +175,7 @@ void AccelStepper::computeNewSpeed() Serial.println(stepsToStop); Serial.println("-----"); #endif + return _stepInterval; } // Run the motor to implement speed and acceleration in order to proceed to the target position @@ -193,7 +195,7 @@ AccelStepper::AccelStepper(uint8_t interface, uint8_t pin1, uint8_t pin2, uint8_ _currentPos = 0; _targetPos = 0; _speed = 0.0; - _maxSpeed = 1.0; + _maxSpeed = 0.0; _acceleration = 0.0; _sqrt_twoa = 1.0; _stepInterval = 0; @@ -220,6 +222,7 @@ AccelStepper::AccelStepper(uint8_t interface, uint8_t pin1, uint8_t pin2, uint8_ enableOutputs(); // Some reasonable default setAcceleration(1); + setMaxSpeed(1); } AccelStepper::AccelStepper(void (*forward)(), void (*backward)()) @@ -228,7 +231,7 @@ AccelStepper::AccelStepper(void (*forward)(), void (*backward)()) _currentPos = 0; _targetPos = 0; _speed = 0.0; - _maxSpeed = 1.0; + _maxSpeed = 0.0; _acceleration = 0.0; _sqrt_twoa = 1.0; _stepInterval = 0; @@ -254,6 +257,7 @@ AccelStepper::AccelStepper(void (*forward)(), void (*backward)()) _pinInverted[i] = 0; // Some reasonable default setAcceleration(1); + setMaxSpeed(1); } void AccelStepper::setMaxSpeed(float speed) @@ -295,6 +299,11 @@ void AccelStepper::setAcceleration(float acceleration) } } +float AccelStepper::acceleration() +{ + return _acceleration; +} + void AccelStepper::setSpeed(float speed) { if (speed == _speed) @@ -350,6 +359,24 @@ void AccelStepper::step(long step) } } +long AccelStepper::stepForward() +{ + // Clockwise + _currentPos += 1; + step(_currentPos); + _lastStepTime = micros(); + return _currentPos; +} + +long AccelStepper::stepBackward() +{ + // Counter-clockwise + _currentPos -= 1; + step(_currentPos); + _lastStepTime = micros(); + return _currentPos; +} + // You might want to override this to implement eg serial output // bit 0 of the mask corresponds to _pin[0] // bit 1 of the mask corresponds to _pin[1] diff --git a/src/AccelStepper.h b/src/AccelStepper.h index 5ab5aba..42ee37d 100644 --- a/src/AccelStepper.h +++ b/src/AccelStepper.h @@ -23,7 +23,7 @@ /// The latest version of this documentation can be downloaded from /// http://www.airspayce.com/mikem/arduino/AccelStepper /// The version of the package that this documentation refers to can be downloaded -/// from http://www.airspayce.com/mikem/arduino/AccelStepper/AccelStepper-1.61.zip +/// from http://www.airspayce.com/mikem/arduino/AccelStepper/AccelStepper-1.64.zip /// /// Example Arduino programs are included to show the main modes of use. /// @@ -35,6 +35,10 @@ /// - http://www.catb.org/esr/faqs/smart-questions.html /// - http://www.chiark.greenend.org.uk/~shgtatham/bugs.html /// +/// Beginners to C++ and stepper motors in general may find this helpful: +/// - https://hackaday.io/project/183279-accelstepper-the-missing-manual +/// - https://hackaday.io/project/183713-using-the-arduino-accelstepper-library +/// /// Tested on Arduino Diecimila and Mega with arduino-0018 & arduino-0021 /// on OpenSuSE 11.1 and avr-libc-1.6.1-1.15, /// cross-avr-binutils-2.19-9.1, cross-avr-gcc-4.1.3_20080612-26.5. @@ -81,7 +85,7 @@ /// /// \par Copyright /// -/// This software is Copyright (C) 2010-2018 Mike McCauley. Use is subject to license +/// This software is Copyright (C) 2010-2021 Mike McCauley. Use is subject to license /// conditions. The main licensing options available are GPL V3 or Commercial: /// /// \par Open Source Licensing GPL V3 @@ -249,9 +253,18 @@ /// \version 1.61 2020-04-20 /// Added yield() call in runToPosition(), so that platforms like esp8266 dont hang/crash /// during long runs. +/// \version 1.62 2022-05-22 +/// Added link to AccelStepper - The Missing Manual.
    +/// Fixed a problem when setting the maxSpeed to 1.0 due to incomplete initialisation. +/// Reported by Olivier Pécheux.
    +/// \version 1.63 2022-06-30 +/// Added virtual destructor at the request of Jan.
    +/// \version 1.64 2022-10-31 +/// Patch courtesy acwest: Changes to make AccelStepper more subclassable. These changes are +/// largely oriented to implementing new step-scheduling algorithms. /// -/// \author Mike McCauley (mikem@airspayce.com) DO NOT CONTACT THE AUTHOR DIRECTLY: USE THE LISTS -// Copyright (C) 2009-2013 Mike McCauley +/// \author Mike McCauley (mikem@airspayce.com) DO NOT CONTACT THE AUTHOR DIRECTLY: USE THE GOOGLE GROUP +// Copyright (C) 2009-2020 Mike McCauley // $Id: AccelStepper.h,v 1.28 2020/04/20 00:15:03 mikem Exp mikem $ #ifndef AccelStepper_h @@ -429,6 +442,11 @@ class AccelStepper /// root to be calculated. Dont call more ofthen than needed void setAcceleration(float acceleration); + /// Returns the acceleration/deceleration rate configured for this stepper + /// that was previously set by setAcceleration(); + /// \return The currently configured acceleration/deceleration + float acceleration(); + /// Sets the desired constant speed for use with runSpeed(). /// \param[in] speed The desired constant speed in steps per /// second. Positive is clockwise. Speeds of more than 1000 steps per @@ -471,7 +489,10 @@ class AccelStepper /// position. Dont use this in event loops, since it blocks. void runToPosition(); - /// Runs at the currently selected speed until the target position is reached. + /// Executes runSpeed() unless the targetPosition is reached. + /// This function needs to be called often just like runSpeed() or run(). + /// Will step the motor if a step is required at the currently selected + /// speed unless the target position has been reached. /// Does not implement accelerations. /// \return true if it stepped boolean runSpeedToPosition(); @@ -533,6 +554,8 @@ class AccelStepper /// \return true if the speed is not zero or not at the target position bool isRunning(); + /// Virtual destructor to prevent warnings during delete + virtual ~AccelStepper() {}; protected: /// \brief Direction indicator @@ -551,7 +574,8 @@ class AccelStepper /// \li after change to acceleration through setAcceleration() /// \li after change to target position (relative or absolute) through /// move() or moveTo() - void computeNewSpeed(); + /// \return the new step interval + virtual unsigned long computeNewSpeed(); /// Low level function to set the motor output pins /// bit 0 of the mask corresponds to _pin[0] @@ -566,6 +590,16 @@ class AccelStepper /// number of pins defined for the stepper. /// \param[in] step The current step phase number (0 to 7) virtual void step(long step); + + /// Called to execute a clockwise(+) step. Only called when a new step is + /// required. This increments the _currentPos and calls step() + /// \return the updated current position + long stepForward(); + + /// Called to execute a counter-clockwise(-) step. Only called when a new step is + /// required. This decrements the _currentPos and calls step() + /// \return the updated current position + long stepBackward(); /// Called to execute a step using stepper functions (pins = 0) Only called when a new step is /// required. Calls _forward() or _backward() to perform the step @@ -607,7 +641,7 @@ class AccelStepper /// \param[in] step The current step phase number (0 to 7) virtual void step6(long step); - /// Called to execute a step on a 4 pin half-steper motor. Only called when a new step is + /// Called to execute a step on a 4 pin half-stepper motor. Only called when a new step is /// required. Subclasses may override to implement new stepping /// interfaces. The default sets or clears the outputs of pin1, pin2, /// pin3, pin4. @@ -618,6 +652,10 @@ class AccelStepper /// Protected because some peoples subclasses need it to be so boolean _direction; // 1 == CW + /// The current interval between steps in microseconds. + /// 0 means the motor is currently stopped with _speed == 0 + unsigned long _stepInterval; + private: /// Number of pins on the stepper motor. Permits 2 or 4. 2 pins is a /// bipolar, and 4 pins is a unipolar. @@ -650,10 +688,6 @@ class AccelStepper float _acceleration; float _sqrt_twoa; // Precomputed sqrt(2*_acceleration) - /// The current interval between steps in microseconds. - /// 0 means the motor is currently stopped with _speed == 0 - unsigned long _stepInterval; - /// The last step time in microseconds unsigned long _lastStepTime;