3
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

AccelStepper.hの使い方(関数一覧を自動翻訳したものつき)

Last updated at Posted at 2023-10-18

arduino ライブラリの1つの AccelStepper.h に関する日本語記事があまり見当たらないので、まったく詳しく無いですが自分へのメモ書きの意味も含めて投稿します。
このライブラリを使用することで速度制御しながら、複数のステッピングモータを同時駆動できます。(おそらく)

この記事は AccelStepper.h ver1.64 に基づいています。
関数一覧は下記リンクのライブラリ内にある説明を自動翻訳したものになります。
参照:https://github.com/waspinator/AccelStepper.git

目次

1. テストコード
2. 関数一覧
    2.0) MotorInterfaceTypeの種類
    2.1) AccelStepper()
    2.2) AccelStepper() 特殊バージョン
  ▽目標値設定
    2.3) 絶対位置指定:moveTo()
    2.4) 相対位置指定:move()
  ▽動かす
    2.5) 加減速しながら回す:run()
    2.6) ブロックされた回転:runToPosition()
    2.7) ブロックされた回転:runToNewPosition()
    2.8) 定速回転:runSpeed()
    2.9) 定速回転:runSpeedToPosition()
    2.10) 停止:stop()
  ▽速度関係
    2.11) 最大速度指定:setMaxSpeed()
    2.12)    〃   取得:maxSpeed()
    2.13) 速度指定:setSpeed()
    2.14)  〃 取得:speed()
    2.15) 加速度指定:setAcceleration()
    2.16)  〃 取得:acceleration()
  ▽モーターの状態関係
    2.17) 回転しているか:isRunning()
    2.18) 残りステップ数:distanceToGo()
    2.19) 目標位置取得:targetPosition()
    2.20) 現在位置取得:currentPosition()
    2.21) 原点リセット:setCurrentPosition()
  ▽モーターの設定
    2.22) 出力無効化:disableOutputs()
    2.23) 出力有効化:enableOutputs()
    2.24) 最低パルス幅指定:setMinPulseWidth()
    2.25) イネーブルピン指定:setEnablePin()
    2.26) 出力反転:setPinsInverted()
    2.27) 出力反転:setPinsInverted() その2
3. ライブラリ付属のスケッチ例

1. テストコード

4~1番ピンにつながったユニポーラ式4相ステッピングモータをフルステップで駆動するプログラム。
(arduino とステッピングモータの間にフルパラレル制御用のモータードライバが入っています。)

10番ピンにつながったボタンを押すと 200 ステップ時計回りします。
定期的に(できれば最短ループで).run()する必要があることに注意してください。

#include <AccelStepper.h>
AccelStepper stepperA(4, 4, 3, 2, 1); //下記参照

void setup() {
  stepperA.setMaxSpeed(1000); //最大回転速度を指定(1000step/s)
  stepperA.setAcceleration(1000); //加速度を指定(1000step/ss)
  pinMode(10, INPUT_PULLUP); //10番ピンを内部プルアップ
}

void loop() {
  //もし10番ピンが押されていてかつ、ステッピングモータが目標位置にいれば
  if ((digitalRead(10) == LOW) && (stepperA.distanceToGo() == 0)) {
    stepperA.move(200); //目標値を現在値から200ステップ時計回りしたところに指定
  }
  stepperA.run(); //ステッピングモータを回す
}

AccelStepper stepperA(4, 4, 3, 2, 1);の引数についてです。
この宣言自体の存在意義については説明する技量を持ち合わせてないので割愛させてください。ゴメンネ

第一引数はMotorInterfaceTypeです。詳細はそちらのタブで確認してください。
第二引数以降は、第一引数で指定したものによって変わります。
モータードライバを使用している場合だとSTEP/DIRのピン番号を2つ。
今回は4相ユニポーラなので、A, Aバー, B, Bバーの順番で出力ピン番号を4つ指定します。

▲目次に戻る

2. 関数一覧

2.0) MotorInterfaceTypeの種類

FUNCTION = 0

機能インターフェイスを使用し、独自のドライバ関数を実装する(内部使用のみ)

DRIVER = 1

ステッパードライバ、ドライバピンが2つ必要

FULL2WIRE = 2

2線式ステッパー、モーターピンが2つ必要

FULL3WIRE = 3

HDD スピンドルなどの3線式ステッパー、モーターピンが3つ必要

FULL4WIRE = 4

4線式フルステッパー、モーターピンが4つ必要

HALF3WIRE = 6

HDD スピンドルなど3線式ハーフステッパー、モーターピンが3つ必要

HALF4WIRE = 8

4線式ハーフステッパー、モーターピンが4つ必要

FUNCTION  = 0, ///< Use the functional interface, implementing your own driver functions (internal use only)
DRIVER    = 1, ///< Stepper Driver, 2 driver pins required
FULL2WIRE = 2, ///< 2 wire stepper, 2 motor pins required
FULL3WIRE = 3, ///< 3 wire stepper, such as HDD spindle, 3 motor pins required
FULL4WIRE = 4, ///< 4 wire full stepper, 4 motor pins required
HALF3WIRE = 6, ///< 3 wire half stepper, such as HDD spindle, 3 motor pins required
HALF4WIRE = 8  ///< 4 wire half stepper, 4 motor pins required

▲目次に戻る

2.1) 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);

コンストラクタ。
十分な頻度で run() 関数を呼び出せば、異なる速度と加速度で動く複数のステッパーを同時に使用できます。
MaxSpeed と Acceleration のデフォルトは 1.0 です。
モーターピンは、コンストラクタ中に enableOutputs() を呼び出すことによって OUTPUT モードに初期化されます。

\param[in] interface インタフェースするピンの数。整数値もサポートされていますが、MotorInterfaceType のシンボリック名を使用することが好ましいです。

AccelStepper::DRIVER (1) はステッパードライバ( Step と Direction ピンを持つ)を意味します。Enable 信号も必要な場合は、構築後に setEnablePin() を呼び出します。また、setPinsInverted() を使用して、ピンを反転させることもできます。
注意:DRIVER は、各ステップに対して minPulseWidth で指定されたマイクロ秒単位(デフォルト 1us )のブロッキング遅延を実行します。これは setMinPulseWidth() で変更できます。
AccelStepper::FULL2WIRE (2) は、2線式ステッパーを意味します(2ピン必要)。
AccelStepper::FULL3WIRE (3) は、HDDスピンドルなどの3線式ステッパーを意味します(3ピン必要)。
AccelStepper::FULL4WIRE (4) は、4線式ステッパーを意味します(4ピン必要)。
AccelStepper::HALF3WIRE (6)は、HDDスピンドルなどの3線式ハーフステッパーを意味します (3ピン必要)。
AccelStepper::HALF4WIRE (8)は、4線式ハーフステッパーを意味します (4つピン必要)
デフォルトは、AccelStepper::FULL4WIRE (4) です。

\Param[in] pin1 モーターピン1の Arduino デジタルピン番号。デフォルトは2番ピンです。 AccelStepper::DRIVER (interface==1)の場合、ドライバへの STEP 入力です。Low から High への遷移はステップを意味します。

\param[in] pin2 モーターピン2の Arduino デジタルピン番号。デフォルトは3番ピンです。
AccelStepper::DRIVER (interface==1)の場合、ドライバの Direction 入力です。High は正転を意味します。

\param[in] pin3 モーターピン3の Arduino デジタルピン番号。デフォルトは4番ピンです。

\param[in] pin4 モーターピン4の Arduino デジタルピン番号。デフォルトは5番ピンです。

\param[in] enable このパラメータが true の場合、enableOutputs() が呼び出され、構築時に出力ピンが有効になります。デフォルトは true です。

/// Constructor. You can have multiple simultaneous steppers, all moving
/// at different speeds and accelerations, provided you call their run()
/// functions at frequent enough intervals. Current Position is set to 0, target
/// position is set to 0. MaxSpeed and Acceleration default to 1.0.
/// The motor pins will be initialised to OUTPUT mode during the
/// constructor by a call to enableOutputs().
/// \param[in] interface Number of pins to interface to. Integer values are
/// supported, but it is preferred to use the \ref MotorInterfaceType symbolic names. 
/// AccelStepper::DRIVER (1) means a stepper driver (with Step and Direction pins).
/// If an enable line is also needed, call setEnablePin() after construction.
/// You may also invert the pins using setPinsInverted().
/// 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.
/// \param[in] pin1 Arduino 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)
/// \param[in] pin2 Arduino 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.
/// \param[in] pin3 Arduino digital pin number for motor pin 3. Defaults
/// to pin 4.
/// \param[in] pin4 Arduino digital pin number for motor pin 4. Defaults
/// to pin 5.
/// \param[in] enable If this is true (the default), enableOutputs() will be called to enable
/// the output pins at construction time.
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);

▲目次に戻る

2.2) AccelStepper() 特殊バージョン

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

前進と後進のために独自の関数を呼び出す代替コンストラクタ。
十分な間隔で run() 関数を呼び出せば、異なる速度と加速度で動く複数のステッパーを同時に使用できます。
MaxSpeed と Acceleration のデフォルトは 1.0 です。
ピンは使用せず、初期化も行いません。

\param[in] forward 前進ステップを生成する void を返すプロージャ。

\param[in] backward 後進ステップを生成する void を返すプロージャ。

/// 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.
/// \param[in] forward void-returning procedure that will make a forward step
/// \param[in] backward void-returning procedure that will make a backward step
AccelStepper(void (*forward)(), void (*backward)());

▲目次に戻る

2.3) moveTo()

void    moveTo(long absolute);

目標位置を設定する。
run() 関数は、現在の位置からこの関数の直近の呼び出しによって設定された目標絶対位置まで、モータの移動を試みます(呼び出しごとに最大1ステップ)。
注意:moveTo() は、次のステップの速度も再計算します。定速移動を使用する場合は、moveTo() を呼び出した後に setSpeed() を呼び出す必要があります。

\param[in] absolute 希望する絶対位置。負値は0位置から反時計回り。

/// 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().
/// \param[in] absolute The desired absolute position. Negative is
/// anticlockwise from the 0 position.
void    moveTo(long absolute); 

▲目次に戻る

2.4) move()

void    move(long relative);

現在の位置からの相対的な目標位置を設定する。

\param[in] relative 現在位置からの相対位置を設定する。負値は現在位置から反時計回りです。

/// Set the target position relative to the current position.
/// \param[in] relative The desired position relative to the current position. Negative is
/// anticlockwise from the current position.
void    move(long relative);

▲目次に戻る

2.5) run();

boolean run();

モータをポーリングし、必要に応じてステップし、目標位置を達成するために加速と減速を実行する。
これはできるだけ頻繁に呼び出す必要がありますが、最低でも最小ステップ時間間隔ごとに1回、できればメインループ内で呼び出す必要があります。
run() を呼び出すたびに、現在の速度と最後のステップからの時間に基づいて、最大で1つのステップを実行します。ステップするタイミングが来たときだけ実行することに注意してください。

\return モーターがまだ目標位置まで動いている場合は、true を返します。

/// 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.
/// \return true if the motor is still running to the target position.
boolean run();

▲目次に戻る

2.6) runToPosition()

void    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.
void    runToPosition();

▲目次に戻る

2.7) runToNewPosition()

void    runToNewPosition(long position);

モーターを(加減速しながら)新しい目標位置に移動し、その位置になるまでブロックする。
ブロックされるので、イベントループでは使用しないでください。

\param[in] 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.
/// \param[in] position The new target position.
void    runToNewPosition(long position);

▲目次に戻る

2.8) runSpeed()

boolean runSpeed();

直近の setSpeed() の呼び出しによって設定された一定の速度を実装する。
これはできるだけ頻繁に呼び出す必要があり、少なくともステップ間隔ごとに1回呼び出す必要があります。

\return モータがステップされた場合はtrueを返す。

/// 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,
/// \return true if the motor was stepped.
boolean runSpeed();

▲目次に戻る

2.9) runSpeedToPosition()

boolean runSpeedToPosition();

targetPosition に到達しない限り runSpeed() を実行する。
この関数は、runSpeed() や run() のように頻繁に呼び出す必要がある。
目標位置に到達しない限り、現在指定されている速度でステップが必要ならモータをステップさせる。
加速度は実装されていません。

\return ステップした場合はtrueを返す。

/// 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();

▲目次に戻る

2.10) stop()

void stop();

現在の速度と加速度パラメーターを使用して、ステッパーをできるだけ早く停止させる新しい目標位置を設定する。

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

▲目次に戻る

2.11) setMaxSpeed()

void    setMaxSpeed(float speed);

許容最高速度を設定します。
run() 関数は、この関数で設定された速度まで加速します。
注意:達成可能な最高速度は、プロセッサとクロック速度に依存します。デフォルトの maxSpeed は 1.0 ステップ/秒です。

\param[in] speed 希望する最高速度を1秒あたりのステップ数で指定します。
注意:プロセッサがサポートする最大速度を超える速度は、非線形の加減速になる可能性があります。

/// 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.
/// \param[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.
void    setMaxSpeed(float speed);

▲目次に戻る

2.12) maxSpeed()

float   maxSpeed();

setMaxSpeed() によって以前に設定された、このステッパーに設定された最高速度を返します。

\return 現在設定されている最高速度

/// Returns the maximum speed configured for this stepper
/// that was previously set by setMaxSpeed();
/// \return The currently configured maximum speed
float   maxSpeed();

▲目次に戻る

2.13) setSpeed()

void    setSpeed(float speed);

runSpeed() で使用する定速を設定します。

\param[in] speed 希望する一定速度を1秒あたりのステップ数で指定する。正の値は時計回りです。
1000ステップ/秒を超える速度は信頼できません。
非常に遅い速度を設定することもできます(例:0.00027777で1時間に1回程度)。
速度の精度は Arduino の水晶振動子に依存します。
ジッターは runSpeed() 関数を呼び出す頻度に依存します。
速度は setMaxSpeed() の現在の値によって制限されます。

/// 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
/// 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()
void    setSpeed(float speed);

▲目次に戻る

2.14) speed()

float   speed();

直近に設定された速度。

\return 直近に設定された速度を1秒あたりのステップ数で返します。

/// The most recently set speed.
/// \return the most recent speed in steps per second
float   speed();

▲目次に戻る

2.15) setAcceleration()

void    setAcceleration(float acceleration);

加速度を設定します。

\param[in] acceleration 希望する加速度を1秒あたりのステップ数で指定します。
注意:0.0 以上である必要があります。これは平方根を計算する必要があるため高負荷な呼び出しです。必要以上に呼び出さないでください。

/// Sets the acceleration/deceleration rate.
/// \param[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
void    setAcceleration(float acceleration);

▲目次に戻る

2.16) acceleration()

float   acceleration();

setAcceleration() によって設定された、このステッパーに設定されている加速度を返します。

\return 現在設定されている加速度を返します。

/// Returns the acceleration/deceleration rate configured for this stepper
/// that was previously set by setAcceleration();
/// \return The currently configured acceleration/deceleration
float   acceleration();

▲目次に戻る

2.17) isRunning()

bool    isRunning();

モータが現在目標位置まで回転しているかチェックする。

\return 速度がゼロでないか、目標位置にない場合はtrueを返す

/// Checks to see if the motor is currently running to a target
/// \return true if the speed is not zero or not at the target position
bool    isRunning();

▲目次に戻る

2.18) distanceToGo()

long    distanceToGo();

現在位置から目標位置までの距離。

\return 現在位置から目標位置までの距離をステップで返します。正の値は現在位置から時計回りです。

/// The distance from the current position to the target position.
/// \return the distance from the current position to the target position
/// in steps. Positive is clockwise from the current position.
long    distanceToGo();

▲目次に戻る

2.19) targetPosition()

long    targetPosition();

直近に設定された目標位置。

\return 目標位置をステップ数で返します。正の値は0位置から時計回りです。

/// The most recently set target position.
/// \return the target position
/// in steps. Positive is clockwise from the 0 position.
long    targetPosition();

▲目次に戻る

2.20) currentPosition()

long    currentPosition();  

現在のモーター位置。

\return 現在のモーター位置をステップ数で返します。正の値は0位置から時計回りです。

/// The current motor position.
/// \return the current motor position
/// in steps. Positive is clockwise from the 0 position.
long    currentPosition();  

▲目次に戻る

2.21) setCurrentPosition()

void    setCurrentPosition(long position);  

モータの現在位置をリセットし、モータが現在どこにあっても新しい0位置とみなされるようにする。
最初のハードウェア位置決め移動の後、ステッパーのゼロ位置を設定するのに便利。
現在のモータ速度を0に設定する副作用があります。

\param[in] 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.
/// \param[in] position The position in steps of wherever the motor
/// happens to be right now.
void    setCurrentPosition(long position);  

▲目次に戻る

2.22) disableOutputs()

virtual void    disableOutputs();

モーターピンの出力をすべてLOWにして無効にする。
電子機器の設計によっては、モーターコイルへの電力をオフにして電力を節約できます。
これは、Arduino の低電力モードをサポートするのに便利です。
スリープ中に出力を無効にし、再びステップする前に enableOutputs() で出力を有効にします。
enable Pin が定義されている場合は、OUTPUT モードに設定し、ピンを disabled にクリアします。

/// 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.
virtual void    disableOutputs();

▲目次に戻る

2.23) enableOutputs()

virtual void    enableOutputs();

モータピンを OUTPUT モードに設定することにより、モータピン出力を有効にする。
コンストラクタから自動的に呼び出される。
enable Pin が定義されている場合、OUTPUT モードに設定し、ピンを enabled に設定します。

/// 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.
virtual void    enableOutputs();

▲目次に戻る

2.24) setMinPulseWidth()

void    setMinPulseWidth(unsigned int minWidth);

ステッパードライバが許容する最小パルス幅を設定する。
実用的な最小パルス幅は約20マイクロ秒である。
20 マイクロ秒未満の時間は、通常 20 マイクロ秒程度になる。

\param[in] 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.
/// \param[in] minWidth The minimum pulse width in microseconds. 
void    setMinPulseWidth(unsigned int minWidth);

▲目次に戻る

2.25) setEnablePin()

void    setEnablePin(uint8_t enablePin = 0xff);

ステッパードライバのenableピン番号を設定する。0xFF は未使用(デフォルト)を示す。
それ以外のピンが設定されている場合、enableOutputs() が呼び出されるとそのピンはオンになり、 disableOutputs() が呼び出されるとオフになります。

\param[in] enablePin モータイネーブル用 Arduino デジタルピン番号 ¦ setPinsInverted

/// 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.
/// \param[in] enablePin Arduino digital pin number for motor enable
/// \sa setPinsInverted
void    setEnablePin(uint8_t enablePin = 0xff);

▲目次に戻る

2.26) setPinsInverted()

void    setPinsInverted(bool directionInvert = false, bool stepInvert = false, bool enableInvert = false);

ステッパードライバピンの反転方向を設定します。

\param[in] directionInvert 方向反転ピンの場合は真、非反転の場合は偽。
\param[in] stepInvert ステップピンが反転している場合は真、反転していない場合は偽。
\param[in] enableInvert イネーブルピンの反転で真,非反転で偽(デフォルト)

/// Sets the inversion for stepper driver pins
/// \param[in] directionInvert True for inverted direction pin, false for non-inverted
/// \param[in] stepInvert      True for inverted step pin, false for non-inverted
/// \param[in] enableInvert    True for inverted enable pin, false (default) for non-inverted
void    setPinsInverted(bool directionInvert = false, bool stepInvert = false, bool enableInvert = false);

▲目次に戻る

2.27) setPinsInverted() その2

void    setPinsInverted(bool pin1Invert, bool pin2Invert, bool pin3Invert, bool pin4Invert, bool enableInvert);

2, 3, 4線式ステッパーピンの反転を設定します。

\param[in] pin1Invert ピン1が反転している場合は真、反転していない場合は偽。
\param[in] pin2Invert ピン2が反転している場合は真、反転していない場合は偽。
\param[in] pin3Invert ピン3が反転している場合は真,反転していない場合は偽
\param[in] pin4Invert ピン4が反転している場合は真,反転していない場合は偽
\param[in] enableInvert イネーブルピンが反転している場合は真,反転していない場合は偽(デフォルト)

/// Sets the inversion for 2, 3 and 4 wire stepper pins
/// \param[in] pin1Invert True for inverted pin1, false for non-inverted
/// \param[in] pin2Invert True for inverted pin2, false for non-inverted
/// \param[in] pin3Invert True for inverted pin3, false for non-inverted
/// \param[in] pin4Invert True for inverted pin4, false for non-inverted
/// \param[in] enableInvert    True for inverted enable pin, false (default) for non-inverted
void    setPinsInverted(bool pin1Invert, bool pin2Invert, bool pin3Invert, bool pin4Invert, bool enableInvert);

▲目次に戻る

3. ライブラリ付属のスケッチ例

Random
単一のステッパーに、速度、位置、加速度のランダムな変化を実行させる。

Overshoot
新しい目標位置を設定し、ステッパーがそれを達成するまで待機するオーバーシュート処理をチェックします。
これはオーバーシュートの処理をテストするために使用されます。

MultipleSteppers
複数のステッパーを同時に動作させる方法を示します。
1つのステッパーを前進・後退させ、限界で加速・減速します。

ConstantSpeed
加速なしの最もシンプルな固定スピード・モードで AccelStepper を動作させる方法を示します。

Blocking
新しい目標位置を設定し、ステッパーがそれを達成するまで待機するブロッキングされた呼び出し。runToNewPosition の使用方法を示します。

AFMotor_MultiStepper
異なる速度と加速度で両方のステッピングモーターを同時に制御します。

AFMotor_ConstantSpeed
加速なしの最もシンプルな固定スピード・モードで AccelStepper を動作させる方法を示します。

ProportionalControl
単一のステッパーを、ポットなどから読み取ったアナログ値に追従させる。
ステッパーは、読み取った値に応じて、新しく設定された各ポジションに一定の速度で移動します。

Bounce
1つのステッパーをある限界から別の限界までバウンスさせ、移動の両端での加速度を観察します。

Quickstop
停止処理のチェック。ステッパーがフルスピードで移動している間に stop() を呼び出し、ステッパーを現在の加速度の制約内で可能な限り迅速に停止させます。

MotorShield
HDD スピンドルモーターなどの3相モーターを AccelStepper で制御する方法を紹介します。Adafruit Motor Shield:http://www.ladyada.net/make/mshield/index.html

DualMotorShield
Itead Studio の Arduino Dual Step Motor Driver Shield IM120417015 を使用して、2 x 2 フェーズ・ステッパーを制御するために AccelStepper を使用する方法を示します。

▲目次に戻る

3
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?