AccelStepper功能及函数功能(三)

AccelStepper() [2/2]

AccelStepper::AccelStepper ( void(*)()  forward,
    void(*)()  backward 
  )    

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.

备用构造函数,它将调用您自己的函数进行前进和后退步进数。 您可以同时有多个步进步进电机,只要以足够频率的间隔调用它们的run()函数,它们就可以以不同的速度和加速度运动。 当前位置设置为0,目标位置设置为0。MaxSpeed和Acceleration默认为1.0。 任何电动机初始化都应在运行之前进行,不要使用引脚或初始化。

Parameters 参数

[in] forward    向前 void-returning procedure that will make a forward step 返回一个向前的步进
[in] backward 向后 void-returning procedure that will make a backward step 返回一个向后的步进

References _directionDIRECTION_CCW, and setAcceleration().

Member Function Documentation  成员函数

◆ computeNewSpeed()

void AccelStepper::computeNewSpeed 计算新的速度 (   )  
protected

Forces the library to compute a new instantaneous speed and set that as the current speed. It is called by the library:

强制库计算新的瞬时速度并将其设置为当前速度。 它由库调用:

  • after each step 每次步进之后
  • after change to maxSpeed through setMaxSpeed()  通过setMaxSpeed()函数改变最大速度之后
  • after change to acceleration through setMaxSpeed() 通过setMaxSpeed()函数改变加速度之后
  • after change to target position (relative or absolute) through move() or moveTo() 通过move() 或者 moveTo()函数改变目标位置后(相对的或者绝对的)

References _directionDIRECTION_CCWDIRECTION_CW, and distanceToGo().

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

◆ currentPosition() 当前位置

long AccelStepper::currentPosition (   )  

The current motor position.目前电机的位置

Returns 返回值

the current motor position in steps. Positive is clockwise from the 0 position.

当前电机位置,以步数表示。顺时针旋转为正。

Referenced by MultiStepper::moveTo().

◆ disableOutputs() 禁用输出引脚

void AccelStepper::disableOutputs (   )  
virtual

Disable motor pin outputs by setting them all LOW Depending on the design of your electronics this may turn off the power to the motor coils, saving power. This is useful to support Arduino low power modes: disable the outputs during sleep and then reenable with enableOutputs() before stepping again. If the enable Pin is defined, sets it to OUTPUT mode and clears the pin to disabled.

根据您的电子设备的设计,通过将电机销的输出设置为低电平来禁用电机销,这样可以关闭电机线圈的电源,节约电能。这对于支持Arduino低功耗模式非常有用:在睡眠期间禁用输出,然后在再次步进之前使用enableoutput()重新启用。如果定义了enable Pin,则将其设置为输出模式并将该Pin清除为disabled。

References setOutputPins().

◆ distanceToGo()

long AccelStepper::distanceToGo (   )  

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

◆ enableOutputs()

void AccelStepper::enableOutputs (   )  
virtual

Enable motor pin outputs by setting the motor pins to OUTPUT mode. Called automatically by the constructor. If the enable Pin is defined, sets it to OUTPUT mode and sets the pin to enabled.

通过将电机引脚设置为输出模式,使电机引脚输出。由构造函数自动调用。如果定义了使能引脚,则将其设置为输出模式并将引脚设置为使能。

References FULL3WIREFULL4WIREHALF3WIRE, and HALF4WIRE.

Referenced by AccelStepper().

◆ isRunning()

bool AccelStepper::isRunning (   )  

Checks to see if the motor is currently running to a target

检查电机是否正在向目标运行

Returns

true if the speed is not zero or not at the target position

如果速度不是零或者不在目标位置,则为真

◆ maxSpeed()

float AccelStepper::maxSpeed (   )  

Returns the maximum speed configured for this stepper that was previously set by setMaxSpeed();

返回值为该步进电机配置的最大速度,该速度以前是由setMaxSpeed()设置的;

Returns

The currently configured maximum speed

当前配置的最大速度

Referenced by MultiStepper::moveTo().

◆ move()

void AccelStepper::move ( long  relative )  

Set the target position relative to the current position.

设置相对于当前位置的目标位置。

Parameters

[in] relative The desired position relative to the current position. Negative is anticlockwise from the current position.相对于当前位置的期望位置。从当前位置逆时针为负。

References moveTo().

Referenced by stop().

◆ moveTo()

void AccelStepper::moveTo ( long  absolute )  

Set the target position. The run() function will try to move the motor (at most one step per call) from the current position to the target position set by the most recent call to this function. Caution: moveTo() also recalculates the speed for the next step. If you are trying to use constant speed movements, you should call setSpeed() after calling moveTo().

设置目标位置。run()函数将尝试将电机(每次调用最多移动一步)从当前位置移动到该函数最近一次调用所设置的目标位置。注意:mo否决权()还会重新计算下一步的速度。如果您试图使用恒速移动,您应该在调用mo否决()之后调用setSpeed()。

Parameters

[in] absolute The desired absolute position. Negative is anticlockwise from the 0 position.

References computeNewSpeed().

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

◆ run()

boolean AccelStepper::run (   )  

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.

转到电机,并在需要步进时步进,执行加速和减速操作以达到目标位置。 您必须尽可能频繁地调用此函数,但每个最小步进时间间隔至少调用一次,最好在主循环中调用一次。 请注意,每次调用run()最多只会执行一个步进,然后仅在当前步进到期时才根据当前速度和自上一步进以来的时间进行。

Returns

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

如果电机仍然正在运行到目标位置,则为真。

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

Referenced by runToPosition().

◆ runSpeed()

boolean AccelStepper::runSpeed (   )  

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,

转动电机,如果有步进需要执行,则执行步进,实现最近一次调用setSpeed()所设置的恒定速度。你必须尽可能频繁地调用它,但每一步间隔至少要调用一次,

Returns

true if the motor was stepped. 如果电机步进过,返回真

References _directionDIRECTION_CW, and step().

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

◆ runSpeedToPosition()

boolean AccelStepper::runSpeedToPosition (   )  

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

以当前选定的速度运行,直到到达目标位置。不实现加速。

Returns

true if it stepped

References _directionDIRECTION_CCWDIRECTION_CW, and runSpeed().

◆ runToNewPosition()

void AccelStepper::runToNewPosition ( long  position )  

Moves the motor (with acceleration/deceleration) to the new target position and blocks until it is at position. Dont use this in event loops, since it blocks.

将电机(带加速/减速)移动到新的目标位置,并阻塞,直到到达新目标位置。不要在事件循环中使用它,因为它会阻塞。

Parameters

[in] position The new target position.

References moveTo(), and runToPosition().

◆ runToPosition()

void AccelStepper::runToPosition (   )  

Moves the motor (with acceleration/deceleration) to the target position and blocks until it is at position. Dont use this in event loops, since it blocks.

将电机(带加/减速)移动到目标位置,并阻塞,直到到达目标位置。不要在事件循环中使用它,因为它会阻塞。

References run().

Referenced by runToNewPosition().

◆ setAcceleration()

void AccelStepper::setAcceleration ( float  acceleration )  

Sets the acceleration/deceleration rate.设置加速/减速速率。

Parameters

[in] acceleration

The desired acceleration in steps per second per second. Must be > 0.0. This is an expensive call since it requires a square root to be calculated. Dont call more ofthen than needed

期望的加速度,单位是每秒钟的步数。必须是> 0.0。这是一个好资源的调用,因为它需要一个平方根来计算。不要打太频繁调用。

References computeNewSpeed().

Referenced by AccelStepper().

◆ setCurrentPosition()

void AccelStepper::setCurrentPosition ( long  position )  

Resets the current position of the motor, so that wherever the motor happens to be right now is considered to be the new 0 position. Useful for setting a zero position on a stepper after an initial hardware positioning move. Has the side effect of setting the current motor speed to 0.

重置电机的当前位置,使电机当前的位置被认为是新的0位置。用于在初始硬件定位移动后在步进电机上设置零位置。具有将当前电机速度设置为0的副作用。

Parameters

[in] position The position in steps of wherever the motor happens to be right now.电机现在的位置。

Referenced by MultiStepper::run().

◆ setEnablePin()

void AccelStepper::setEnablePin ( uint8_t  enablePin = 0xff )  

Sets the enable pin number for stepper drivers. 0xFF indicates unused (default). Otherwise, if a pin is set, the pin will be turned on when enableOutputs() is called and switched off when disableOutputs() is called.

设置步进驱动器的使能引脚。0xFF表示未使用(默认值)。否则,如果设置了引脚,则在调用enableoutput()时将打开引脚,在调用disableexports()时将关闭引脚。

Parameters

[in] enablePin Arduino digital pin number for motor enable

See also

setPinsInverted

◆ setMaxSpeed()

void AccelStepper::setMaxSpeed ( float  speed )  

Sets the maximum permitted speed. The run() function will accelerate up to the speed set by this function. Caution: the maximum speed achievable depends on your processor and clock speed. The default maxSpeed is 1.0 steps per second.

设置最大允许速度。run()函数将加速到该函数设置的速度。注意:最大速度取决于您的处理器和时钟速度。默认的最大速度是每秒1.0步。

Parameters

[in] speed

The desired maximum speed in steps per second. Must be > 0. Caution: Speeds that exceed the maximum speed supported by the processor may Result in non-linear accelerations and decelerations.

每秒所需的最大速度(以步为单位)。必须是> 0。注意:超过处理器支持的最大速度可能会导致非线性的加速和减速。

References computeNewSpeed(), and speed().

◆ setMinPulseWidth()

void AccelStepper::setMinPulseWidth ( unsigned int  minWidth )  

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.

设置步进驱动器允许的最小脉冲宽度。实际的最小脉冲宽度约为20微秒。乘以小于20微秒通常会得到20微秒左右。

Parameters

[in] minWidth The minimum pulse width in microseconds.

◆ setOutputPins()

void AccelStepper::setOutputPins ( uint8_t  mask )  
protectedvirtual

Low level function to set the motor output pins bit 0 of the mask corresponds to _pin[0] bit 1 of the mask corresponds to _pin[1] You can override this to impment, for example serial chip output insted of using the output pins directly

低电平功能,设置电机输出引脚的第0位对应的是_pin[0]位对应的是_pin[1]位,您可以将此重写执行,例如,串行芯片输出设置为直接使用输出引脚

References FULL3WIREFULL4WIREHALF3WIRE, and HALF4WIRE.

Referenced by disableOutputs()step1()step2()step3()step4()step6(), and step8().

◆ setPinsInverted() [1/2]

void AccelStepper::setPinsInverted ( bool  directionInvert = false,
    bool  stepInvert = false,
    bool  enableInvert = false 
  )    

Sets the inversion for stepper driver pins 设置步进驱动器引脚的反转

Parameters

[in] directionInvert

True for inverted direction pin, false for non-inverted

翻转引脚为真,非翻转引脚为假

[in] stepInvert

True for inverted step pin, false for non-inverted

翻转步进针为真,非翻转为假

[in] enableInvert

True for inverted enable pin, false (default) for non-inverted

翻转使能引脚为真,非翻转引脚为假(默认)

◆ setPinsInverted() [2/2]

void AccelStepper::setPinsInverted ( bool  pin1Invert,
    bool  pin2Invert,
    bool  pin3Invert,
    bool  pin4Invert,
    bool  enableInvert 
  )    

Sets the inversion for 2, 3 and 4 wire stepper pins

设置2、3、4线步进针脚的反转

Parameters

[in] pin1Invert True for inverted pin1, false for non-inverted
[in] pin2Invert True for inverted pin2, false for non-inverted
[in] pin3Invert True for inverted pin3, false for non-inverted
[in] pin4Invert True for inverted pin4, false for non-inverted
[in] enableInvert True for inverted enable pin, false (default) for non-inverted

◆ setSpeed()

void AccelStepper::setSpeed ( float  speed )  

Sets the desired constant speed for use with runSpeed().

使用runSpeed()设置所需的恒定速度。

Parameters

[in] speed

The desired constant speed in steps per second. Positive is clockwise. Speeds of more than 1000 steps per second are unreliable. Very slow speeds may be set (eg 0.00027777 for once per hour, approximately. Speed accuracy depends on the Arduino crystal. Jitter depends on how frequently you call the runSpeed() function. The speed will be limited by the current value of setMaxSpeed()

所需的恒定速度(以步/秒为单位)。顺时针为正。每秒超过1000步的速度是不可靠的。非常慢的速度可以设置(例如0.00027777,大约每小时一次)。速度精度取决于Arduino晶振。抖动取决于调用runSpeed()函数的频率。速度将受到setMaxSpeed()的当前值的限制

References _directionDIRECTION_CCWDIRECTION_CW, and speed().

Referenced by MultiStepper::moveTo().

◆ speed()

float AccelStepper::speed (   )  

The most recently set speed. 最新设定的速度。

Returns

the most recent speed in steps per second 以每秒步数为单位的最新速度

Referenced by setMaxSpeed(), and setSpeed().

◆ step()

void AccelStepper::step ( long  step )  
protectedvirtual

Called to execute a step. Only called when a new step is required. Subclasses may override to implement new stepping interfaces. The default calls step1()step2()step4() or step8() depending on the number of pins defined for the stepper.

调用来执行一个步进。只在需要新步进时调用。子类可以重写以实现新的步进接口。默认调用step1()、step2()、step4()或step8(),具体取决于为步进电机定义的引脚数量。

Parameters

[in] step The current step phase number (0 to 7)

References DRIVERFULL2WIREFULL3WIREFULL4WIREFUNCTIONHALF3WIREHALF4WIREstep0()step1()step2()step3()step4()step6(), and step8().

Referenced by runSpeed().

◆ step0()

void AccelStepper::step0 ( long  step )  
protectedvirtual

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

只有在需要新步进时才调用步进电机函数(pins = 0)来执行步进。调用_forward()或_back()来执行该步步进

Parameters

[in] step The current step phase number (0 to 7)

Referenced by step().

◆ step1()

void AccelStepper::step1 ( long  step )  
protectedvirtual

Called to execute a step on a stepper driver (ie where pins == 1). Only called when a new step is required. Subclasses may override to implement new stepping interfaces. The default sets or clears the outputs of Step pin1 to step, and sets the output of _pin2 to the desired direction. The Step pin (_pin1) is pulsed for 1 microsecond which is the minimum STEP pulse width for the 3967 driver.

Parameters

[in] step The current step phase number (0 to 7)

References _direction, and setOutputPins().

Referenced by step().

◆ step2()

void AccelStepper::step2 ( long  step )  
protectedvirtual

Called to execute a step on a 2 pin 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 and pin2

Parameters

[in] step The current step phase number (0 to 7)

References setOutputPins().

Referenced by step().

◆ step3()

void AccelStepper::step3 ( long  step )  
protectedvirtual

Called to execute a step on a 3 pin motor, such as HDD spindle. 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

Parameters

[in] step The current step phase number (0 to 7)

References setOutputPins().

Referenced by step().

◆ step4()

void AccelStepper::step4 ( long  step )  
protectedvirtual

Called to execute a step on a 4 pin 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] step The current step phase number (0 to 7)

References setOutputPins().

Referenced by step().

◆ step6()

void AccelStepper::step6 ( long  step )  
protectedvirtual

Called to execute a step on a 3 pin motor, such as HDD spindle. 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

Parameters

[in] step The current step phase number (0 to 7)

References setOutputPins().

Referenced by step().

◆ step8()

void AccelStepper::step8 ( long  step )  
protectedvirtual

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

[in] step The current step phase number (0 to 7)

References setOutputPins().

Referenced by step().

◆ stop()

void AccelStepper::stop (   )  

Sets a new target position that causes the stepper to stop as quickly as possible, using the current speed and acceleration parameters.

使用当前速度和加速度参数,设置一个新的目标位置,使步进器尽可能快地停止运行。

References move().

◆ targetPosition()

long AccelStepper::targetPosition (   )  

The most recently set target position.最近设定的目标位置。

Returns

the target position in steps. Positive is clockwise from the 0 position.

目标位置的步进。顺时针旋转为正。

Member Data Documentation

◆ _direction

boolean AccelStepper::_direction
protected

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

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章