Library for STMicroelectronics dSPIN L6470 stepper driver. "daisy-chain" supported.
Dependents: L6470_daisy_chain l6470
Diff: L6470SDC.h
- Revision:
- 3:486fb90dc7d5
- Parent:
- 2:2af83d3ccd97
- Child:
- 4:4127dd195311
--- a/L6470SDC.h Tue Jun 09 06:10:11 2015 +0000 +++ b/L6470SDC.h Tue Jan 12 11:27:01 2016 +0000 @@ -1,16 +1,45 @@ +/* Copyright (c) 2014 Yajirushi(Cursor) + * + * Released under the MIT license + * http://opensource.org/licenses/mit-license.php + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ #include "mbed.h" #ifndef L6470SDC_H #define L6470SDC_H -//デバッグモード(GetParamやSetParamの値をシリアル出力する) -//ONにするとそれなりに動作が遅くなる -//デバッグモードOFF:コメントアウトする +/* ------------------------------------------------------------------ +The code below, please be rewritten to match your environment +------------------------------------------------------------------ */ + +//If not using Serial-print debugging: DEBUG_L6470SDC to comment out +//If Serial-print debugging, must be connected "USBTX"(tx), "USBRX"(rx). //#define DEBUG_L6470SDC -//L6470のSPI通信のクロック周波数(1MHz以上、5MHz未満であること) +//SPI signal frequency: Less than 5MHz(5,000,000) #define L6470_SPI_FREQ 4960000 +/* ------------------------------------------------------------------ +No need to change the below code +------------------------------------------------------------------ */ #define CMD_NOP 0x0 #define CMD_SETPARAM 0x00 #define CMD_GETPARAM 0x20 @@ -64,154 +93,348 @@ #define REG_CONFIG 0x18 #define REG_STATUS 0x19 -/** Library for STMicroelectronics dSPIN L6470 stepper driver. "daisy-chain" supported. +//DaisyChain CommandQueue Structure +typedef struct L6470CommandQueue{ + unsigned char addr; + unsigned long val; + int bitLen; +}L6470CMDQ; + +/** + * @~japanese + * STマイクロエレクトロニクス社製のL6470ステッピングモーターコントローラー用ライブラリ + * 真の意味でデイジーチェーンをサポートしています(もちろん個別結線でも使用可能です) + * + * @~english + * Library for STMicroelectronics "L6470" stepper motor controller. + * This library supported "SPI Daisy-Chain". * * Example: * @code + * //case: Using "Daisy-Chained" 2 motors. not use Serial-Debugging. * #include "mbed.h" * #include "L6470SDC.h" * - * L6470SDC l6470(USBTX, USBRX, SPI_MOSI, SPI_MISO, SPI_SCK, D10); + * int main(){ + * //create instance(Not use Serial-Debugging) + * L6470SDC l6470(SPI_MOSI, SPI_MISO, SPI_SCK, D10); * - * int main() { - * //initialize + * wait(1); + * + * //L6470 initialize * l6470.init(); * - * //set maximum speed - * l6470.setMaximumSpeed(1, l6470.calcMaxSpd(100)); + * wait(5); * - * //run 300step/s,clockwise - * l6470.run(1, l6470.calcSpd(300), true); + * //Set the rotation speed of the motor to 100step/s. (Daisy-chained motor No.1) + * l6470.setMaximumSpeed(1, l6470.calcMaxSpd(100)); + * //Set the rotation speed of the motor to 200step/s. (Daisy-chained motor No.2) + * l6470.setMaximumSpeed(2, l6470.calcMaxSpd(200)); + * + * //Running motor 5seconds. + * //Maximum speed = 300step/s + * //!!Start timing deviate, because it does not use the "Queue" + * l6470.run(1, l6470.calcSpd(300), true); //clockwise No.1 + * l6470.run(2, l6470.calcSpd(300), false); //counter-clockwise No.2 * wait(5.0); + * l6470.stop(1); + * l6470.stop(2); * - * //motor stop - * l6470.stop(1); + * //Waiting... until motor "absolute stop". + * while(l6470.isBusy(1) || l6470.isBusy(2)); + * + * wait(3.0); + * + * //Enqueue: Motor No.1 -> 7 rev rotation.(200step/rev * microstep-count * rev count), clockwise. + * l6470.ENQ_move(1, 200*128*7, true); + * + * //Enqueue: Motor No.2 -> 7 rev rotation.(200step/rev * microstep-count * rev count), clockwise. + * l6470.ENQ_move(2, 200*128*7, true); * - * //motor return home position. + * //Execute Queue + * l6470.Qexec(); + * + * //Waiting... until motor "absolute stop". + * while(l6470.isBusy(1) || l6470.isBusy(2)); + * + * //Set the rotation speed of the motor No.2 to motor No.1. + * l6470.setMaximumSpeed(1, l6470.getMaximumSpeed(2)); + * + * //Back to HOME_POS.("home" is aliase "zero") * l6470.home(1); + * l6470.zero(2); * } * @endcode */ class L6470SDC{ public: - /** Constructor:(Serial, SPI, CS) PinName - * - * @param tx Serial USB_TX PinName - * @param rx Serial USB_RX PinName - * @param mosi SPI Master-out PinName - * @param miso SPI Slave-out PinName - * @param sclk SPI Clock PinName - * @param csel SPI ChipSelect PinName - */ - L6470SDC(PinName tx, PinName rx, PinName mosi, PinName miso, PinName sclk, PinName csel); - - /** Constructor:(Serial, SPI, CS) PinName & DigitalOut* + /** Constructor:(Serial, SPI, CS) + * @~japanese + * @param tx シリアル通信で使用するTXピン(シリアルデバッグを使用する際は、#define DEBUG_L6470SDCのコメントアウトを解除してください) + * @param rx シリアル通信で使用するRXピン(シリアルデバッグを使用する際は、#define DEBUG_L6470SDCのコメントアウトを解除してください) + * @param mosi SPIのmosiピン + * @param miso SPIのmisoピン + * @param sclk SPIのsclkピン + * @param csel SPIのChipSelectピン * - * @param tx Serial USB_TX PinName - * @param rx Serial USB_RX PinName - * @param mosi SPI Master-out PinName - * @param miso SPI Slave-out PinName - * @param sclk SPI Clock PinName - * @param *csel SPI ChipSelect - * Example: - * DigitalOut my_cs(D10); - * L6470SDC stepper(USBTX, USBRX, SPI_MOSI, SPI_MISO, SPI_SCLK, &my_cs); - */ - L6470SDC(PinName tx, PinName rx, PinName mosi, PinName miso, PinName sclk, DigitalOut *csel); - - /** Constructor:(Serial, SPI, CS) Serial* & PinName - * - * @param *serial Serial + * @~english + * @param tx Serial USB_TX PinName (If using Serial-debugging. must be #define DEBUG_L6470SDC) + * @param rx Serial USB_RX PinName (If using Serial-debugging. must be #define DEBUG_L6470SDC) * @param mosi SPI Master-out PinName * @param miso SPI Slave-out PinName * @param sclk SPI Clock PinName * @param csel SPI ChipSelect PinName + * * Example: - * Serial usb_serial(USBTX, USBRX); - * L6470SDC stepper(&usb_serial, SPI_MOSI, SPI_MISO, SPI_SCLK, D10); + * @code + * //create instance(case:NXP mbed LPC1768) + * //hardware-SPI -> MOSI:p5, MISO:p6, SCK:p7 + * //ChipSelect -> select pin as you like. + * L6470SDC l6470(USBTX, USBRX, p5, p6, p7, p8); + * @endcode + */ + L6470SDC(PinName tx, PinName rx, PinName mosi, PinName miso, PinName sclk, PinName csel); + + /** Constructor:(Serial, SPI, CS) overlaod + * @~japanese + * @param tx シリアル通信で使用するTXピン(シリアルデバッグを使用する際は、#define DEBUG_L6470SDCのコメントアウトを解除してください) + * @param rx シリアル通信で使用するRXピン(シリアルデバッグを使用する際は、#define DEBUG_L6470SDCのコメントアウトを解除してください) + * @param mosi SPIのmosiピン + * @param miso SPIのmisoピン + * @param sclk SPIのsclkピン + * @param *csel SPIのChipSelectピンのアドレス + * + * @~english + * @param tx Serial USB_TX PinName (If using Serial-debugging. must be #define DEBUG_L6470SDC) + * @param rx Serial USB_RX PinName (If using Serial-debugging. must be #define DEBUG_L6470SDC) + * @param mosi SPI Master-out PinName + * @param miso SPI Slave-out PinName + * @param sclk SPI Clock PinName + * @param *csel SPI ChipSelect Pin Addr + * + * Example: + * @code + * //create instance(case:NXP mbed LPC1768) + * //hardware-SPI -> MOSI:p5, MISO:p6, SCK:p7 + * + * //ChipSelect -> select pin as you like. + * DigitalOut l6470cs(p8); + * + * L6470SDC l6470(USBTX, USBRX, p5, p6, p7, &l6470cs ); + * @endcode + */ + L6470SDC(PinName tx, PinName rx, PinName mosi, PinName miso, PinName sclk, DigitalOut *csel); + + /** Constructor:(Serial, SPI, CS) overlaod + * @~japanese + * @param *serial USBシリアルのアドレス(シリアルデバッグを使用する際は、#define DEBUG_L6470SDCのコメントアウトを解除してください) + * @param mosi SPIのmosiピン + * @param miso SPIのmisoピン + * @param sclk SPIのsclkピン + * @param *csel SPIのChipSelectピンのアドレス + * + * @~english + * @param *serial USB Serial Addr (If using Serial-debugging. must be #define DEBUG_L6470SDC) + * @param mosi SPI Master-out PinName + * @param miso SPI Slave-out PinName + * @param sclk SPI Clock PinName + * @param *csel SPI ChipSelect Pin Addr + * + * Example: + * @code + * //create instance(case:NXP mbed LPC1768) + * //hardware-SPI -> MOSI:p5, MISO:p6, SCK:p7 + * + * //USB Serial + * Serial l6470Serial(USBTX, USBRX); + * + * L6470SDC l6470( &l6470Serial , p5, p6, p7, p8); + * @endcode */ L6470SDC(Serial *serial, PinName mosi, PinName miso, PinName sclk, PinName csel); - /** Constructor:(Serial, SPI, CS) Serial* & PinName & DigitalOut* + /** Constructor:(Serial, SPI, CS) overlaod + * @~japanese + * @param *serial USBシリアルのアドレス(シリアルデバッグを使用する際は、#define DEBUG_L6470SDCのコメントアウトを解除してください) + * @param mosi SPIのmosiピン + * @param miso SPIのmisoピン + * @param sclk SPIのsclkピン + * @param *csel SPIのChipSelectピンのアドレス * - * @param *serial Serial + * @~english + * @param *serial USB Serial Addr (If using Serial-debugging. must be #define DEBUG_L6470SDC) * @param mosi SPI Master-out PinName * @param miso SPI Slave-out PinName * @param sclk SPI Clock PinName - * @param *csel SPI ChipSelect + * @param *csel SPI ChipSelect Pin Addr + * * Example: - * Serial usb_serial(USBTX, USBRX); - * DigitalOut my_cs(D10); - * L6470SDC stepper(&usb_serial, SPI_MOSI, SPI_MISO, SPI_SCLK, &my_cs); + * @code + * //create instance(case:NXP mbed LPC1768) + * //hardware-SPI -> MOSI:p5, MISO:p6, SCK:p7 + * + * //USB Serial + * Serial l6470Serial(USBTX, USBRX); + * + * //ChipSelect pin + * DigitalOut l6470cs(p8); + * + * L6470SDC l6470( &l6470Serial , p5, p6, p7, &l6470cs ); + * @endcode */ L6470SDC(Serial *serial, PinName mosi, PinName miso, PinName sclk, DigitalOut *csel); - /** Constructor:(Serial, SPI, CS) Serial* & SPI* & PinName + /** Constructor:(Serial, SPI, CS) overlaod + * @~japanese + * @param *serial USBシリアルのアドレス(シリアルデバッグを使用する際は、#define DEBUG_L6470SDCのコメントアウトを解除してください) + * @param *spi SPIのアドレス + * @param csel SPIのChipSelectピン * - * @param *serial Serial - * @param *spi SPI + * @~english + * @param *serial USB Serial Addr (If using Serial-debugging. must be #define DEBUG_L6470SDC) + * @param *spi SPI Addr * @param csel SPI ChipSelect PinName + * * Example: - * Serial usb_serial(USBTX, USBRX); - * SPI my_spi(SPI_MOSI, SPI_MISO, SPI_SCLK); - * L6470SDC stepper(&usb_serial, &my_spi, D10); + * @code + * //create instance(case:NXP mbed LPC1768) + * //hardware-SPI -> MOSI:p5, MISO:p6, SCK:p7 + * SPI l6470spi(p5, p6, p7); + * + * //USB Serial + * Serial l6470Serial(USBTX, USBRX); + * + * L6470SDC l6470( &l6470Serial , &l6470spi , p8); + * @endcode */ L6470SDC(Serial *serial, SPI *spi, PinName csel); - /** Constructor:(Serial, SPI, CS) Serial* & SPI* & DigitalOut* + /** Constructor:(Serial, SPI, CS) overlaod + * @~japanese + * @param *serial USBシリアルのアドレス(シリアルデバッグを使用する際は、#define DEBUG_L6470SDCのコメントアウトを解除してください) + * @param *spi SPIのアドレス + * @param *csel SPIのChipSelectピンのアドレス + * + * @~english + * @param *serial USB Serial Addr (If using Serial-debugging. must be #define DEBUG_L6470SDC) + * @param *spi SPI Addr + * @param *csel SPI ChipSelect Pin Addr * - * @param *serial Serial - * @param *spi SPI - * @param *csel SPI ChipSelect * Example: - * Serial usb_serial(USBTX, USBRX); - * SPI my_spi(SPI_MOSI, SPI_MISO, SPI_SCLK); - * DigitalOut my_cs(D10); - * L6470SDC stepper(&usb_serial, &my_spi, &my_cs); + * @code + * //create instance(case:NXP mbed LPC1768) + * //hardware-SPI -> MOSI:p5, MISO:p6, SCK:p7 + * SPI l6470spi(p5, p6, p7); + * + * //USB Serial + * Serial l6470Serial(USBTX, USBRX); + * + * //ChipSelect pin + * DigitalOut l6470cs(p8); + * + * L6470SDC l6470( &l6470Serial , &l6470spi , &l6470cs ); + * @endcode */ L6470SDC(Serial *serial, SPI *spi, DigitalOut *csel); - /** Constructor: without Debug Serial (SPI, CS) PinName + /** Constructor:(SPI, CS) overload + * @~japanese + * @param mosi SPIのmosiピン + * @param miso SPIのmisoピン + * @param sclk SPIのsclkピン + * @param csel SPIのChipSelectピン * + * @~english * @param mosi SPI Master-out PinName * @param miso SPI Slave-out PinName * @param sclk SPI Clock PinName * @param csel SPI ChipSelect PinName + * + * Example: + * @code + * //create instance(case:NXP mbed LPC1768) + * //hardware-SPI -> MOSI:p5, MISO:p6, SCK:p7 + * //ChipSelect -> select pin as you like. + * L6470SDC l6470(p5, p6, p7, p8); + * @endcode */ L6470SDC(PinName mosi, PinName miso, PinName sclk, PinName csel); - /** Constructor: without Debug Serial (SPI, CS) PinName & DigitalOut* + /** Constructor:(SPI, CS) overlaod + * @~japanese + * @param mosi SPIのmosiピン + * @param miso SPIのmisoピン + * @param sclk SPIのsclkピン + * @param *csel SPIのChipSelectピンのアドレス * + * @~english * @param mosi SPI Master-out PinName * @param miso SPI Slave-out PinName * @param sclk SPI Clock PinName - * @param *csel SPI ChipSelect + * @param *csel SPI ChipSelect Pin Addr + * * Example: - * DigitalOut cs1(D10); - * L6470SDC stepper(SPI_MOSI, SPI_MISO, SPI_SCLK, &cs1); + * @code + * //create instance(case:NXP mbed LPC1768) + * //hardware-SPI -> MOSI:p5, MISO:p6, SCK:p7 + * + * //ChipSelect -> select pin as you like. + * DigitalOut l6470cs(p8); + * + * L6470SDC l6470(p5, p6, p7, &l6470cs ); + * @endcode */ L6470SDC(PinName mosi, PinName miso, PinName sclk, DigitalOut *csel); - /** Constructor: without Debug Serial (SPI, CS) SPI* & PinName + /** Constructor:(SPI, CS) overlaod + * @~japanese + * @param *spi SPIのアドレス + * @param csel SPIのChipSelectピン * - * @param *spi SPI + * @~english + * @param *spi SPI Addr * @param csel SPI ChipSelect PinName + * * Example: - * SPI spi1(SPI_MOSI, SPI_MISO, SPI_SCLK); - * L6470SDC stepper(&spi1, D10); + * @code + * //create instance(case:NXP mbed LPC1768) + * //hardware-SPI -> MOSI:p5, MISO:p6, SCK:p7 + * SPI l6470spi(p5, p6, p7); + * + * L6470SDC l6470( &l6470spi , p8); + * @endcode */ L6470SDC(SPI *spi, PinName csel); - /** Constructor: without Debug Serial (SPI, CS) SPI* & DigitalOut* + /** Constructor:(SPI, CS) overlaod + * @~japanese + * @param *spi SPIのアドレス + * @param *csel SPIのChipSelectピンのアドレス + * + * @~english + * @param *spi SPI Addr + * @param *csel SPI ChipSelect Pin Addr * - * @param *spi SPI - * @param *csel SPI ChipSelect * Example: - * SPI spi1(SPI_MOSI, SPI_MISO, SPI_SCLK); - * DigitalOut cs1(D10); - * L6470SDC stepper(&spi1, &cs1); + * @code + * //create instance(case:NXP mbed LPC1768) + * //hardware-SPI -> MOSI:p5, MISO:p6, SCK:p7 + * SPI l6470spi(p5, p6, p7); + * + * //ChipSelect pin + * DigitalOut l6470cs(p8); + * + * L6470SDC l6470( &l6470Serial , &l6470spi , &l6470cs ); + * @endcode */ L6470SDC(SPI *spi, DigitalOut *csel); + + /** Destructor + * @~japanese デストラクター(ユーザーが直接呼ぶ必要はありません) + * + * @~english Destructor. may be not called by user. + */ + ~L6470SDC(); private: Serial *pc; @@ -220,6 +443,8 @@ bool hasSerial; int motor_count; + + L6470CMDQ *Queue; //ADD void setCmd(int motorNumber, unsigned char cmdAddress, unsigned long value, int bitLen); void setParam(int motorNumber, unsigned char regAddress, unsigned long value, int bitLen); @@ -228,49 +453,88 @@ public: /** Initialize L6470 + * @~japanese + * @param initSPI SPIに関するパラメーター(クロックやモード)を初期化しない場合はfalseに(デフォルトはtrue) * + * @~english * @param initSPI If initialize SPI parameters.(e.g. clockspeed and mode) = true(default) */ - void init(bool initSPI = true); + void init(bool initSPI=true); /** Get connected(daisy-chained) motor count. + * @~japanese + * @returns デイジーチェーン接続されたモーター(ドライバー)の個数 * + * @~english * @returns Connected(daisy-chained) motor count. If not using daisy-chain, return always 1. maybe... */ int getMotorCount(); /** Get motor Busy-flag status + * @~japanese + * @param motorNumber 1から始まるモーター番号(デイジーチェーン接続していない場合は1を指定) + * @returns 指定したモーター番号のBUSYフラグ(false = Busy-flag 0, true = Busy-flag 1) * + * @~english * @param motorNumber Chained motor-number. If not using daisy-chain, you must be motorNumber = 1. * @returns Busy status.(false = Busy-flag 0, true = Busy-flag 1) */ bool isBusy(int motorNumber); /** Run motor rotate + * @~japanese + * モーターを指定した速度で回転させます + * @param motorNumber 1から始まるモーター番号(デイジーチェーン接続していない場合は1を指定) + * @param hex_speed 16進数指定でのモーターの回転速度(step毎秒) 。関数 "calcSpd(stepPerSecond)" を使用して16進数換算の値を求めてください。 + * @param isClockwise 回転方向。true = 時計まわり. false = 反時計回り。(メーカーによって回転方向が違うかも) * + * @~english + * At the specified speed, run the motor rotation. * @param motorNumber Chained motor-number. If not using daisy-chain, you must be motorNumber = 1. * @param hex_speed Motor rotate speed(hex_value Step/s). -> please use "calcSpd(stepPerSecond)" method. * @param isClockwise Rotate direction. true = clockwise. false = counter-clockwise. + * * Example: - * unsigned long calculatedValue = motor.calcSpd(200); - * motor.run(1, calculatedValue, true); //200step/s, clockwise + * @code + * unsigned long calculatedValue = l6470.calcSpd(200); //Calculated "hex value" from "real value". + * l6470.run(1, calculatedValue, true); //200step/s, clockwise + * @endcode */ void run(int motorNumber, unsigned long hex_speed, bool isClockwise); /** Run motor steps + * @~japanese + * 指定したステップの数だけモーターを回します + * @param motorNumber 1から始まるモーター番号(デイジーチェーン接続していない場合は1を指定) + * @param count 回転させるステップ数。マイクロステップモードを使用している場合は、その値を掛けなければなりません。 + * @param isClockwise 回転方向。true = 時計まわり. false = 反時計回り。(メーカーによって回転方向が違うかも) * + * @~english + * At the specified step count, run the motor rotation. * @param motorNumber Chained motor-number. If not using daisy-chain, you must be motorNumber = 1. * @param count Steps count. If using Microstep-mode, "count" must be multiplied by Microstep-value. * @param isClockwise Rotate direction. true = clockwise. false = counter-clockwise. + * * Example: - * motor.stop(1); - * motor.setStepMode(1, 0x07); //set microstep-mode 0x07 = 1/128 microstep. - * motor.step(1, 256, false); //(256/128)=2 step, counter cloclwise. + * @code + * l6470.stop(1); + * l6470.setStepMode(1, 0x07); //set microstep-mode 0x07 = 1/128 microstep. + * l6470.step(1, 256, false); //(256/128)=2 step, counter cloclwise. + * @endcode */ void step(int motorNumber, unsigned int count, bool isClockwise); /** Run motor move + * @~japanese + * 指定したステップの数だけモーターを回します + * @param motorNumber 1から始まるモーター番号(デイジーチェーン接続していない場合は1を指定) + * @param stepsCount 回転させるステップ数。マイクロステップモードを使用している場合は、その値を掛けなければなりません。 + * @param isClockwise 回転方向。true = 時計まわり. false = 反時計回り。(メーカーによって回転方向が違うかも) + * ステップ数が5未満 の場合 -> 関数 "step(int motorNumber, unsigned int count, bool isClockwise)" を使用 + * ステップ数が5以上 の場合 -> この関数を使用したほうがいい(ズレが生じるため) * + * @~english + * At the specified step count, run the motor rotation. * @param motorNumber Chained motor-number. If not using daisy-chain, you must be motorNumber = 1. * @param stepsCount Steps count. If using Microstep-mode, "stepsCount" must be multiplied by Microstep-value. * @param isClockwise Rotate direction. true = clockwise. false = counter-clockwise. @@ -280,7 +544,14 @@ void move(int motorNumber, unsigned long stepsCount, bool isClockwise); /** Go to motor ABS position (shortest path) + * @~japanese + * 最短パスで指定した座標まで回転します + * @param motorNumber 1から始まるモーター番号(デイジーチェーン接続していない場合は1を指定) + * @param ABSPos 停止させる絶対座標 + * 注意: 絶対座標への回転方向は不定です。移動距離が短いほうに回転します。 * + * @~english + * Motor rotation to the specified position in the shortest path. * @param motorNumber Chained motor-number. If not using daisy-chain, you must be motorNumber = 1. * @param ABSPos Motor Absolute position. * CAUTION: This method a motion to ABS position through the shortest path. Rotate direction is not constant. @@ -288,7 +559,14 @@ void goto1(int motorNumber, unsigned long ABSPos); /** Go to motor ABS position (Specify the rotate direction) + * @~japanese + * 指定した座標まで回転します + * @param motorNumber 1から始まるモーター番号(デイジーチェーン接続していない場合は1を指定) + * @param ABSPos 停止させる絶対座標 + * @param isClockwise 回転方向。true = 時計まわり. false = 反時計回り。(メーカーによって回転方向が違うかも) * + * @~english + * Motor rotation to the specified position. * @param motorNumber Chained motor-number. If not using daisy-chain, you must be motorNumber = 1. * @param ABSPos Motor Absolute position. * @param isClockwise Rotate direction. true = clockwise. false = counter-clockwise. @@ -296,7 +574,13 @@ void goto2(int motorNumber, unsigned long ABSPos, bool isClockwise); /** ???Run motor rotate. Until external switch status change??? + * @~japanese + * @param motorNumber 1から始まるモーター番号(デイジーチェーン接続していない場合は1を指定) + * @param hex_speed 16進数指定でのモーターの回転速度(step毎秒) 。関数 "calcSpd(stepPerSecond)" を使用して16進数換算の値を求めてください。 + * @param isClockwise 回転方向。true = 時計まわり. false = 反時計回り。(メーカーによって回転方向が違うかも) + * @param setMark 外部スイッチのステータス? ごめん。よくわかんないからデータシート見てね。 * + * @~english * @param motorNumber Chained motor-number. If not using daisy-chain, you must be motorNumber = 1. * @param hex_speed Motor rotate speed(hex_value Step/s). -> please use "calcSpd(stepPerSecond)" method. * @param isClockwise Rotate direction. true = clockwise. false = counter-clockwise. @@ -305,7 +589,12 @@ void goUntil(int motorNumber, unsigned long hex_speed, bool isClockwise, bool setMark); /** ???Release external switch??? + * @~japanese + * @param motorNumber 1から始まるモーター番号(デイジーチェーン接続していない場合は1を指定) + * @param isClockwise 回転方向。true = 時計まわり. false = 反時計回り。(メーカーによって回転方向が違うかも) + * @param setMark 外部スイッチのステータス? ごめん。よくわかんないからデータシート見てね。 * + * @~english * @param motorNumber Chained motor-number. If not using daisy-chain, you must be motorNumber = 1. * @param isClockwise Rotate direction. true = clockwise. false = counter-clockwise. * @param setMark External switch status?...??.. Sorry... I could not understand. Please see L6470 datasheet. @@ -313,79 +602,473 @@ void releaseSwitch(int motorNumber, bool isClockwise, bool setMark); /** Go to motor home-position + * @~japanese + * モーターを原点復帰させます + * @param motorNumber 1から始まるモーター番号(デイジーチェーン接続していない場合は1を指定) * + * @~english + * Return the motor to the zero-potition. * @param motorNumber Chained motor-number. If not using daisy-chain, you must be motorNumber = 1. */ void home(int motorNumber); /** Go to motor home-position [alias: home(int motorNumber)] + * @~japanese + * モーターを原点復帰させます + * @param motorNumber 1から始まるモーター番号(デイジーチェーン接続していない場合は1を指定) * + * @~english + * Return the motor to the zero-potition. * @param motorNumber Chained motor-number. If not using daisy-chain, you must be motorNumber = 1. */ void zero(int motorNumber); /** Go to motor marked-position + * @~japanese + * 指定されたマーク位置まで回転します + * @param motorNumber 1から始まるモーター番号(デイジーチェーン接続していない場合は1を指定) + * マーク位置: -> 関数 "setMarkPosition(int motorNumber, unsigned long value)" を使用してください * + * @~english + * Motor rotation to the specified MARK Position. * @param motorNumber Chained motor-number. If not using daisy-chain, you must be motorNumber = 1. - * Mark Position: -> Please use setMarkPosition(int motorNumber, unsigned long value). + * MARK Position: -> Please use setMarkPosition(int motorNumber, unsigned long value). */ void gotoMark(int motorNumber); /** Reset the ABS_POS register to zero (ABS_POS zero = home-position) + * @~japanese + * 現在位置を原点に設定します + * @param motorNumber 1から始まるモーター番号(デイジーチェーン接続していない場合は1を指定) * + * @~english + * Set the zero-position to current position. * @param motorNumber Chained motor-number. If not using daisy-chain, you must be motorNumber = 1. */ void resetHome(int motorNumber); - /** Reset the ABS_POS register to zero [alias: resetHome(int motorNumber)] + /** Reset the ABS_POS register to zero (ABS_POS zero = home-position) [alias: resetHome(int motorNumber)] + * @~japanese + * キューに追加:現在位置を原点に設定します + * @param motorNumber 1から始まるモーター番号(デイジーチェーン接続していない場合は1を指定) * + * @~english + * Set the zero-position to current position. * @param motorNumber Chained motor-number. If not using daisy-chain, you must be motorNumber = 1. */ void resetZero(int motorNumber); - /** Reset motor device.(software reset) + /** Reset L6470.(software reset) + * @~japanese + * デバイスをリセットします + * @param motorNumber 1から始まるモーター番号(デイジーチェーン接続していない場合は1を指定) * + * @~english + * Reset L6470 driver & motor. * @param motorNumber Chained motor-number. If not using daisy-chain, you must be motorNumber = 1. */ void motorReset(int motorNumber); /** Stop rotation (soft-stop) + * @~japanese + * モーターを停止 + * @param motorNumber 1から始まるモーター番号(デイジーチェーン接続していない場合は1を指定) * + * @~english + * Stop motor. * @param motorNumber Chained motor-number. If not using daisy-chain, you must be motorNumber = 1. */ void stop(int motorNumber); /** Stop rotation. Ignore deceleration (hard-stop) + * @~japanese + * 減速を無視して停止 + * @param motorNumber 1から始まるモーター番号(デイジーチェーン接続していない場合は1を指定) * + * @~english + * Stop immediately motor. * @param motorNumber Chained motor-number. If not using daisy-chain, you must be motorNumber = 1. */ void stopImmidiate(int motorNumber); /** Stop rotation (soft-stop) state sets HighImpedance. + * @~japanese + * モーターを停止し、実行後ハイインピーダンス状態にします + * @param motorNumber 1から始まるモーター番号(デイジーチェーン接続していない場合は1を指定) * + * @~english + * Stop motor. Set state "High Impedance" after stop. * @param motorNumber Chained motor-number. If not using daisy-chain, you must be motorNumber = 1. */ void stop_HighImpedance(int motorNumber); /** Stop rotation. Ignore deceleration (hard-stop) state sets HighImpedance. + * @~japanese + * 減速を無視して停止し、実行後ハイインピーダンス状態にします + * @param motorNumber 1から始まるモーター番号(デイジーチェーン接続していない場合は1を指定) * + * @~english + * Stop immediately motor. Set state "High Impedance" after stop. * @param motorNumber Chained motor-number. If not using daisy-chain, you must be motorNumber = 1. */ void stopImmidiate_HighImpedance(int motorNumber); - // calc method ----------------------------------------------------------------------------- - unsigned long calcSpd(float stepPerSecond); //回転速度(step/s)をParam形式に変換 - unsigned short calcAcc(float stepPerSecond_2); //加速(step/s^2)をParam形式に変換 - unsigned short calcDec(float stepPerSecond_2); //減速(step/s^2)をParam形式に変換 - unsigned short calcMaxSpd(float stepPerSecond); //最大回転速度(step/s)をParam形式に変換 - unsigned short calcMinSpd(float stepPerSecond); //最低回転速度(step/s)をParam形式に変換 - unsigned short calcIntSpd(float stepPerSecond); //加減速曲線の切り替わる速度(step/s)をParam形式に変換 - unsigned short calcFullStepSpd(float stepPerSecond); //フルステップに切り替わる速度(step/s)をParam形式に変換 + //Daisy-chain Queue Method ----------------------------------------------------- + /** Enqueue Command [NOP] + * @~japanese + * キューに追加:何も実行しない + * @param motorNumber 1から始まるモーター番号(デイジーチェーン接続していない場合は1を指定) + * + * @~english + * Add Queue:No operation. + * @param motorNumber Chained motor-number. If not using daisy-chain, you must be motorNumber = 1. + */ + int ENQ_nop(int motorNumber); + + /** Enqueue Command [run] + * @~japanese + * キューに追加:モーターを指定した速度で回転させます + * @param motorNumber 1から始まるモーター番号(デイジーチェーン接続していない場合は1を指定) + * @param hex_speed 16進数指定でのモーターの回転速度(step毎秒) 。関数 "calcSpd(stepPerSecond)" を使用して16進数換算の値を求めてください。 + * @param isClockwise 回転方向。true = 時計まわり. false = 反時計回り。(メーカーによって回転方向が違うかも) + * + * @~english + * Add Queue:At the specified speed, run the motor rotation. + * @param motorNumber Chained motor-number. If not using daisy-chain, you must be motorNumber = 1. + * @param hex_speed Motor rotate speed(hex_value Step/s). -> please use "calcSpd(stepPerSecond)" method. + * @param isClockwise Rotate direction. true = clockwise. false = counter-clockwise. + * + * Example: + * @code + * unsigned long calculatedValue = l6470.calcSpd(200); //Calculated "hex value" from "real value". + * l6470.ENQ_run(1, calculatedValue, true); //200step/s, clockwise + * l6470.ENQ_NOP(2); + * l6470.Qexec(); + * @endcode + */ + int ENQ_run(int motorNumber, unsigned long hex_speed, bool isClockwise); + + /** Enqueue Command [move] + * @~japanese + * キューに追加:指定したステップの数だけモーターを回します + * @param motorNumber 1から始まるモーター番号(デイジーチェーン接続していない場合は1を指定) + * @param stepsCount 回転させるステップ数。マイクロステップモードを使用している場合は、その値を掛けなければなりません。 + * @param isClockwise 回転方向。true = 時計まわり. false = 反時計回り。(メーカーによって回転方向が違うかも) + * + * @~english + * Add Queue:At the specified step count, run the motor rotation. + * @param motorNumber Chained motor-number. If not using daisy-chain, you must be motorNumber = 1. + * @param stepsCount Steps count. If using Microstep-mode, "stepsCount" must be multiplied by Microstep-value. + * @param isClockwise Rotate direction. true = clockwise. false = counter-clockwise. + * + * Example: + * @code + * l6470.stop(1); + * l6470.setStepMode(1, 0x07); //set microstep-mode 0x07 = 1/128 microstep. + * l6470.step(1, 256, false); //(256/128)=2 step, counter cloclwise. + * l6470.step(2, 1024, true); //(1024/128)=8 step, clockwise. + * l6470.Qexec(); + * @endcode + */ + int ENQ_move(int motorNumber, unsigned long stepsCount, bool isClockwise); + + /** Enqueue Command [Goto] (shortest path) + * @~japanese + * キューに追加:最短パスで指定した座標まで回転します + * @param motorNumber 1から始まるモーター番号(デイジーチェーン接続していない場合は1を指定) + * @param ABSPos 停止させる絶対座標 + * 注意: 絶対座標への回転方向は不定です。移動距離が短いほうに回転します。 + * + * @~english + * Add Queue:Motor rotation to the specified position in the shortest path. + * @param motorNumber Chained motor-number. If not using daisy-chain, you must be motorNumber = 1. + * @param ABSPos Motor Absolute position. + * CAUTION: This method a motion to ABS position through the shortest path. Rotate direction is not constant. + */ + int ENQ_goto1(int motorNumber, unsigned long ABSPos); + + /** Enqueue Command [Goto] + * @~japanese + * キューに追加:最短パスで指定した座標まで回転します + * @param motorNumber 1から始まるモーター番号(デイジーチェーン接続していない場合は1を指定) + * @param ABSPos 停止させる絶対座標 + * @param isClockwise 回転方向。true = 時計まわり. false = 反時計回り。(メーカーによって回転方向が違うかも) + * + * @~english + * Add Queue:Motor rotation to the specified position. + * @param motorNumber Chained motor-number. If not using daisy-chain, you must be motorNumber = 1. + * @param ABSPos Motor Absolute position. + * @param isClockwise Rotate direction. true = clockwise. false = counter-clockwise. + */ + int ENQ_goto2(int motorNumber, unsigned long ABSPos, bool isClockwise); + + /** Enqueue Command [???go Until] + * @~japanese + * @param motorNumber 1から始まるモーター番号(デイジーチェーン接続していない場合は1を指定) + * @param hex_speed 16進数指定でのモーターの回転速度(step毎秒) 。関数 "calcSpd(stepPerSecond)" を使用して16進数換算の値を求めてください。 + * @param isClockwise 回転方向。true = 時計まわり. false = 反時計回り。(メーカーによって回転方向が違うかも) + * @param setMark 外部スイッチのステータス? ごめん。よくわかんないからデータシート見てね。 + * + * @~english + * @param motorNumber Chained motor-number. If not using daisy-chain, you must be motorNumber = 1. + * @param hex_speed Motor rotate speed(hex_value Step/s). -> please use "calcSpd(stepPerSecond)" method. + * @param isClockwise Rotate direction. true = clockwise. false = counter-clockwise. + * @param setMark External switch status?...??.. Sorry... I could not understand. Please see L6470 datasheet. + */ + int ENQ_goUntil(int motorNumber, unsigned long hex_speed, bool isClockwise, bool setMark); + + /** Enqueue Command [???Release external switch] + * @~japanese + * @param motorNumber 1から始まるモーター番号(デイジーチェーン接続していない場合は1を指定) + * @param isClockwise 回転方向。true = 時計まわり. false = 反時計回り。(メーカーによって回転方向が違うかも) + * @param setMark 外部スイッチのステータス? ごめん。よくわかんないからデータシート見てね。 + * + * @~english + * @param motorNumber Chained motor-number. If not using daisy-chain, you must be motorNumber = 1. + * @param isClockwise Rotate direction. true = clockwise. false = counter-clockwise. + * @param setMark External switch status?...??.. Sorry... I could not understand. Please see L6470 datasheet. + */ + int ENQ_releaseSwitch(int motorNumber, bool isClockwise, bool setMark); + + /** Enqueue Command [Goto HOME] + * @~japanese + * キューに追加:モーターを原点復帰させます + * @param motorNumber 1から始まるモーター番号(デイジーチェーン接続していない場合は1を指定) + * + * @~english + * Add Queue:Return the motor to the zero-potition. + * @param motorNumber Chained motor-number. If not using daisy-chain, you must be motorNumber = 1. + */ + int ENQ_home(int motorNumber); + + /** Enqueue Command [Goto HOME] [aliase: ENQ_home(int motorNumber)] + * @~japanese + * キューに追加:モーターを原点復帰させます + * @param motorNumber 1から始まるモーター番号(デイジーチェーン接続していない場合は1を指定) + * + * @~english + * Add Queue:Return the motor to the zero-potition. + * @param motorNumber Chained motor-number. If not using daisy-chain, you must be motorNumber = 1. + */ + int ENQ_zero(int motorNumber); + + /** Enqueue Command [Goto MARK] + * @~japanese + * キューに追加:指定されたマーク位置まで回転します + * @param motorNumber 1から始まるモーター番号(デイジーチェーン接続していない場合は1を指定) + * マーク位置: -> 関数 "setMarkPosition(int motorNumber, unsigned long value)" を使用してください + * + * @~english + * Add Queue:Motor rotation to the specified MARK Position. + * @param motorNumber Chained motor-number. If not using daisy-chain, you must be motorNumber = 1. + * MARK Position: -> Please use setMarkPosition(int motorNumber, unsigned long value). + */ + int ENQ_gotoMark(int motorNumber); + + /** Enqueue Command [Reset HOME] (ABS_POS zero = home-position) + * @~japanese + * キューに追加:現在位置を原点に設定します + * @param motorNumber 1から始まるモーター番号(デイジーチェーン接続していない場合は1を指定) + * + * @~english + * Add Queue:Set the zero-position to current position. + * @param motorNumber Chained motor-number. If not using daisy-chain, you must be motorNumber = 1. + */ + int ENQ_resetHome(int motorNumber); + + /** Enqueue Command [Reset HOME] [alias: ENQ_resetHome(int motorNumber)] + * @~japanese + * キューに追加:現在位置を原点に設定します + * @param motorNumber 1から始まるモーター番号(デイジーチェーン接続していない場合は1を指定) + * + * @~english + * Add Queue:Set the zero-position to current position. + * @param motorNumber Chained motor-number. If not using daisy-chain, you must be motorNumber = 1. + */ + int ENQ_resetZero(int motorNumber); - // set method ------------------------------------------------------------------------------ + /** Enqueue Command [Reset L6470] (software reset) + * @~japanese + * キューに追加:デバイスをリセットします + * @param motorNumber 1から始まるモーター番号(デイジーチェーン接続していない場合は1を指定) + * + * @~english + * Add Queue:Reset L6470 driver & motor. + * @param motorNumber Chained motor-number. If not using daisy-chain, you must be motorNumber = 1. + */ + int ENQ_motorReset(int motorNumber); + + /** Enqueue Command [stop] (soft-stop) + * @~japanese + * キューに追加:モーターを停止 + * @param motorNumber 1から始まるモーター番号(デイジーチェーン接続していない場合は1を指定) + * + * @~english + * Add Queue:Stop motor. + * @param motorNumber Chained motor-number. If not using daisy-chain, you must be motorNumber = 1. + */ + int ENQ_stop(int motorNumber); + + /** Enqueue Command [hard stop] + * @~japanese + * キューに追加:減速を無視して停止 + * @param motorNumber 1から始まるモーター番号(デイジーチェーン接続していない場合は1を指定) + * + * @~english + * Add Queue:Stop immediately motor. + * @param motorNumber Chained motor-number. If not using daisy-chain, you must be motorNumber = 1. + */ + int ENQ_stopImmidiate(int motorNumber); + + /** Enqueue Command [HIZ stop] + * @~japanese + * キューに追加:モーターを停止し、実行後ハイインピーダンス状態にします + * @param motorNumber 1から始まるモーター番号(デイジーチェーン接続していない場合は1を指定) + * + * @~english + * Add Queue:Stop motor. Set state "High Impedance" after stop. + * @param motorNumber Chained motor-number. If not using daisy-chain, you must be motorNumber = 1. + */ + int ENQ_stop_HighImpedance(int motorNumber); + + /** Enqueue Command [HIZ hard stop] + * @~japanese + * キューに追加:減速を無視して停止し、実行後ハイインピーダンス状態にします + * @param motorNumber 1から始まるモーター番号(デイジーチェーン接続していない場合は1を指定) + * + * @~english + * Add Queue:Stop immediately motor. Set state "High Impedance" after stop. + * @param motorNumber Chained motor-number. If not using daisy-chain, you must be motorNumber = 1. + */ + int ENQ_stopImmidiate_HighImpedance(int motorNumber); + + /** Clear Queue + * @~japanese コマンドキューを全てクリアします + * @~english Command Queue all zero clear. + */ + void Qclear(); + + /** Execute Queue + * @~japanese + * コマンドキューに格納されたコマンドを一度に実行します + * @param finallyClearQueue 実行後にキューをクリアする(デフォルトはtrue) + * + * @~english + * Execute Command Queue. + * @param finallyClearQueue Clear Queue after execution.(default=true) + */ + int Qexec(bool finallyClearQueue=true); + + // calc method ----------------------------------------------------------------- + /** Caluculate HEX value from Speed value + * @~japanese + * 速度(step/s)をパラメーター用数値に変換します + * @param stepPerSecond 回転速度(step/s) + * + * @returns 変換された16進数値 + * + * @~english + * Convert to Param(Hex) value from real speed value(step/s). + * @param stepPerSecond Motor rotate speed(step/s). + * + * @returns Converted value. + */ + unsigned long calcSpd(float stepPerSecond); + + /** Caluculate HEX value from Acceleration speed value + * @~japanese + * 加速速度(step/s^2)をパラメーター用数値に変換します + * @param stepPerSecond 加速速度(step/s^2) + * + * @returns 変換された16進数値 + * + * @~english + * Convert to Param(Hex) value from acceleration speed value(step/s^2). + * @param stepPerSecond rotate acceleration speed(step/s^2). + * + * @returns Converted value. + */ + unsigned short calcAcc(float stepPerSecond_2); + + /** Caluculate HEX value from Deceleration speed value + * @~japanese + * 減速速度(step/s^2)をパラメーター用数値に変換します + * @param stepPerSecond 減速速度(step/s^2) + * + * @returns 変換された16進数値 + * + * @~english + * Convert to Param(Hex) value from deceleration speed value(step/s^2). + * @param stepPerSecond rotate deceleration speed(step/s^2). + * + * @returns Converted value. + */ + unsigned short calcDec(float stepPerSecond_2); + + /** Caluculate HEX value from MAX speed value + * @~japanese + * 最大速度(step/s)をパラメーター用数値に変換します + * @param stepPerSecond 最大回転速度(step/s) + * + * @returns 変換された16進数値 + * + * @~english + * Convert to Param(Hex) value from maximum speed value(step/s). + * @param stepPerSecond Motor rotate maximum speed(step/s). + * + * @returns Converted value. + */ + unsigned short calcMaxSpd(float stepPerSecond); + + /** Caluculate HEX value from MIN speed value + * @~japanese + * 最低速度(step/s)をパラメーター用数値に変換します + * @param stepPerSecond 最低回転速度(step/s) + * + * @returns 変換された16進数値 + * + * @~english + * Convert to Param(Hex) value from minimum speed value(step/s). + * @param stepPerSecond Motor rotate minimum speed(step/s). + * + * @returns Converted value. + */ + unsigned short calcMinSpd(float stepPerSecond); + + /** Caluculate HEX value from acceleration and deceleration switched point speed + * @~japanese + * 加減速曲線が切り替わる速度を指定します + * @param stepPerSecond 加減速曲線が切り替わる速度(step/s) + * + * @returns 変換された16進数値 + * + * @~english + * Convert to Param(Hex) value from acceleration and deceleration switched point speed(step/s). + * @param stepPerSecond switched point speed(step/s). + * + * @returns Converted value. + */ + unsigned short calcIntSpd(float stepPerSecond); + + /** Caluculate HEX value from full-step mode switched point speed + * @~japanese + * フルステップモードに切り替わる速度を指定します + * @param stepPerSecond フルステップモードに切り替わる速度(step/s) + * + * @returns 変換された16進数値 + * + * @~english + * Convert to Param(Hex) value from full-step mode switched point speed(step/s). + * @param stepPerSecond switched point speed(step/s). + * + * @returns Converted value. + */ + unsigned short calcFullStepSpd(float stepPerSecond); + + // set method ------------------------------------------------------------------ void setAbsPosition(int motorNumber, unsigned long value); //絶対座標設定 void setElecPosition(int motorNumber, unsigned short value); //マイクロステップ位置設定 - void setMarkPosition(int motorNumber, unsigned long value); //ホームポジション設定 + void setMarkPosition(int motorNumber, unsigned long value); //マークポジション設定 void setAcceleration(int motorNumber, unsigned short value); //加速設定 void setDeceleration(int motorNumber, unsigned short value); //減速設定 void setMaximumSpeed(int motorNumber, unsigned short value); //最大回転速度設定 @@ -411,13 +1094,13 @@ void setAlermEnable(int motorNumber, unsigned char value); //アラームの有効無効 void setSystemConfig(int motorNumber, unsigned short value); //ドライバシステム設定 - // get method ------------------------------------------------------------------------------ + // get method ------------------------------------------------------------------ unsigned long getSpeed(int motorNumber); //現在の回転スピード unsigned short getADC(int motorNumber); //ADCの取得 unsigned short getStatus(int motorNumber); //ステータス読み取り unsigned long getAbsPosition(int motorNumber); //絶対座標 unsigned short getElecPosition(int motorNumber); //マイクロステップ位置 - unsigned long getMarkPosition(int motorNumber); //ホームポジション + unsigned long getMarkPosition(int motorNumber); //マークポジション unsigned short getAcceleration(int motorNumber); //加速 unsigned short getDeceleration(int motorNumber); //減速 unsigned short getMaximumSpeed(int motorNumber); //最大回転速度