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

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