node-red-contrib-keiganmotor 0.2.4

Keigan Motor node-red node.

npm install node-red-contrib-keiganmotor

KeiganMotorをNode-REDから操作するノード

sc_1

概要

KeiganMotorにはBLEで接続する為、BLEアダプタを搭載したデバイス上のNode-REDで動作します。
以下のデバイスで動作検証してます。 + Raspberry Pi 3 Model B + MacBook

インストールA (npmからインストール)

Node-REDのROOT(.node-red)ディレクトリで以下を実行

 $npm install node-red-contrib-keiganmotor

インストールB (フローエディタからインストール)

Node-REDのフローエディタから追加する事ができます。
パレットの管理 > ノードを追加 > ノードを検索 > "keiganmotor"

実行権限の付与 (Raspberry Pi 3)

raspberry piでBLEを実行する場合、スーパーユーザー権限が必要です。 通常のユーザーとしてNode-Redを実行している場合、BLEを実行するためのアクセス許可を与える必要があります。

sudo setcap cap_net_raw+eip $(eval readlink -f `which node`)

依存関係

サンプル

/sample/motor_demo.jsonの中身をNode-REDのクリップボードに貼り付けるか
以下のフローをNode-REDのクリップボードに貼り付けます。

[{"id":"932394d3.0a5078","type":"inject","z":"c50d8323.5e274","name":"Scan 20sec 1Motor","topic":"","payload":"20,1","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":190,"y":120,"wires":[["269a50b1.7679e"]]},{"id":"c3792d6.13938d","type":"km-motor","z":"c50d8323.5e274","name":"","allowConnectMotor":"","x":780,"y":1120,"wires":[["b411dfea.966ed","84f9a18c.60d5c"],["4a86a56f.17bd7c"],["a517cc3e.d4734"],["774b5597.93ec7c"]]},{"id":"219265ad.d081aa","type":"inject","z":"c50d8323.5e274","name":"{\"cmd\":\"cmdLed\",\"arg\":\"1,200,0,0\"}","topic":" ","payload":"{\"cmd\":\"cmdLed\",\"arg\":\"1,200,0,0\"}","payloadType":"json","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":240,"y":1220,"wires":[["c3792d6.13938d"]]},{"id":"5d2e586.261b5a8","type":"inject","z":"c50d8323.5e274","name":"{\"cmd\":\"cmdLed\",\"arg\":[1,200,200,0]}","topic":"cmdLed","payload":"{\"cmd\":\"cmdLed\",\"arg\":[1,200,200,0]}","payloadType":"json","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":250,"y":1260,"wires":[["c3792d6.13938d"]]},{"id":"789212cc.f648ec","type":"comment","z":"c50d8323.5e274","name":"接続例1) 最初に発見したモーターに即座に接続する","info":"※注意 別のノードで既に接続されているモーターは接続されません。一旦接続を切って下さい\n\n### ●Scan injectノードにScan時間,検出モーター数を設定する。  \nex)モーターは1つタイムアウトは20秒(20000ms)\n","x":210,"y":40,"wires":[]},{"id":"fe6ded15.e0554","type":"debug","z":"c50d8323.5e274","name":"status","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","x":990,"y":160,"wires":[]},{"id":"3c58330c.c43fdc","type":"inject","z":"c50d8323.5e274","name":"1) 原点を初期化、10rpmで180度回転","topic":"","payload":"[{\"cmd\":\"cmdPresetPosition\"},{\"cmd\":\"cmdSpeed_rpm\",\"arg\":10},{\"cmd\":\"cmdMoveToPosition\",\"arg\":3.1415}]","payloadType":"json","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":830,"y":1380,"wires":[["c3792d6.13938d"]]},{"id":"fa7374a1.48a848","type":"inject","z":"c50d8323.5e274","name":"","topic":"","payload":"{\"cmd\":\"cmdEnable\"}","payloadType":"json","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":200,"y":1580,"wires":[["c3792d6.13938d"]]},{"id":"69510750.9130e8","type":"inject","z":"c50d8323.5e274","name":"","topic":"","payload":"{\"cmd\":\"cmdDisable\"}","payloadType":"json","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":200,"y":1620,"wires":[["c3792d6.13938d"]]},{"id":"732491f8.51795","type":"inject","z":"c50d8323.5e274","name":"5) 原点に戻る","topic":"","payload":"[{\"cmd\":\"cmdSpeed_rpm\",\"arg\":50},{\"cmd\":\"cmdMoveToPosition\",\"arg\":0}]","payloadType":"json","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":750,"y":1540,"wires":[["c3792d6.13938d"]]},{"id":"366985ac.e324ba","type":"debug","z":"c50d8323.5e274","name":"motorMeasurement1","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","x":1040,"y":200,"wires":[]},{"id":"994b0966.9f4ef8","type":"inject","z":"c50d8323.5e274","name":"{\"cmd\":\"cmdReadRegister\",\"arg\":[29,30]}","topic":"","payload":"{\"cmd\":\"cmdReadRegister\",\"arg\":[29,30]}","payloadType":"json","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":260,"y":1720,"wires":[["c3792d6.13938d"]]},{"id":"e89f24a3.529758","type":"inject","z":"c50d8323.5e274","name":"{\"cmd\":\"disConnect\"}","topic":"","payload":"{\"cmd\":\"disConnect\"}","payloadType":"json","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":200,"y":1080,"wires":[["c3792d6.13938d"]]},{"id":"34c21b75.e3e164","type":"km-motor","z":"c50d8323.5e274","name":"","allowConnectMotor":"","x":760,"y":180,"wires":[["fe6ded15.e0554"],["366985ac.e324ba"],[],[]]},{"id":"58fe836c.8f547c","type":"comment","z":"c50d8323.5e274","name":"接続例2) 全てのモータを検出し、指定した2つのモーターに自動接続する","info":"※注意 別のノードで既に接続されているモーターは接続されません。一旦接続を切って下さい\n\n### ●Scan injectノードにScan時間を設定する。  \nあまり短いとモーターが検出されません、推奨は20秒(20000ms)\n\n### ●Keigan Motorに接続するモーター名を設定する \n(モーター名はScan終了時にスキャナーの下部に表示されます)\n\n\n### ●スキャン終了後にスキャン中に発見したモータを接続する場合。\nKeigan MotorをKeigan BLE scannerの出力に接続\n","x":280,"y":300,"wires":[]},{"id":"8a66afe0.6f829","type":"inject","z":"c50d8323.5e274","name":"","topic":"","payload":"{\"cmd\":\"disConnect\"}","payloadType":"json","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":460,"y":220,"wires":[["34c21b75.e3e164"]]},{"id":"3eb78eb5.a47d62","type":"inject","z":"c50d8323.5e274","name":"Scan 20sec","topic":"","payload":"20","payloadType":"num","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":170,"y":380,"wires":[["aeeba6a3.757698"]]},{"id":"ee182648.eee868","type":"km-motor","z":"c50d8323.5e274","name":"","allowConnectMotor":"KM-1 CIRU","x":760,"y":440,"wires":[["b00dd8cd.17b768"],["49c6d2ee.59afec"],[],[]]},{"id":"49c6d2ee.59afec","type":"debug","z":"c50d8323.5e274","name":"motorMeasurement","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","x":1030,"y":440,"wires":[]},{"id":"ec2a81.8947358","type":"inject","z":"c50d8323.5e274","name":"","topic":"","payload":"{\"cmd\":\"disConnect\"}","payloadType":"json","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":420,"y":480,"wires":[["ee182648.eee868","7321a568.66bb5c"]]},{"id":"b00dd8cd.17b768","type":"debug","z":"c50d8323.5e274","name":"status","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","x":1010,"y":400,"wires":[]},{"id":"7321a568.66bb5c","type":"km-motor","z":"c50d8323.5e274","name":"","allowConnectMotor":"KM-1 175D","x":760,"y":540,"wires":[["8ee4d199.a5092"],["2e3aa6fe.f2af2a"],[],[]]},{"id":"2e3aa6fe.f2af2a","type":"debug","z":"c50d8323.5e274","name":"motorMeasurement","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","x":1030,"y":540,"wires":[]},{"id":"8ee4d199.a5092","type":"debug","z":"c50d8323.5e274","name":"status","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","x":1010,"y":500,"wires":[]},{"id":"98641290.011cd","type":"comment","z":"c50d8323.5e274","name":"制御例1) モーターの制御","info":"※注意 別のノードで既に接続されているモーターは接続されません。一旦接続を切って下さい。 \n\n+ モータの制御コマンド書式は全て\"cmd\"で始まります。 \n  (connect disConnect以外)  \n\n+ 制御出来る全てのコマンドは以下を参照下さい。 \n\n[モーターコマンド](https://document.keigan-motor.com/apiDocument/kmconnector-js/KMMotorOneBLE.html#connect__anchor)\n\n","x":130,"y":880,"wires":[]},{"id":"94fa106c.45b91","type":"debug","z":"c50d8323.5e274","name":"discoverMotor","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","x":740,"y":920,"wires":[]},{"id":"84f9a18c.60d5c","type":"debug","z":"c50d8323.5e274","name":"status","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","x":1050,"y":1100,"wires":[]},{"id":"4a86a56f.17bd7c","type":"debug","z":"c50d8323.5e274","name":"motorMeasurement2","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","x":1100,"y":1140,"wires":[]},{"id":"a517cc3e.d4734","type":"debug","z":"c50d8323.5e274","name":"imuMeasurement","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","x":1090,"y":1180,"wires":[]},{"id":"774b5597.93ec7c","type":"debug","z":"c50d8323.5e274","name":"setting","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","x":1050,"y":1220,"wires":[]},{"id":"7e317a61.31eba4","type":"comment","z":"c50d8323.5e274","name":"例) モーターの無限回転","info":"\n","x":180,"y":1320,"wires":[]},{"id":"ae5118ae.3021b8","type":"trigger","z":"c50d8323.5e274","op1":"{\"cmd\":\"cmdEnable\"}","op2":"0","op1type":"json","op2type":"str","duration":"10","extend":false,"units":"ms","reset":"","bytopic":"topic","name":"{\"cmd\":\"cmdEnable\"}","x":860,"y":1020,"wires":[["c3792d6.13938d"]]},{"id":"b411dfea.966ed","type":"switch","z":"c50d8323.5e274","name":"","property":"payload","propertyType":"msg","rules":[{"t":"eq","v":"connect","vt":"str"}],"checkall":"true","repair":false,"outputs":1,"x":670,"y":1020,"wires":[["ae5118ae.3021b8"]]},{"id":"154f8a46.93e226","type":"comment","z":"c50d8323.5e274","name":"※安全装置 モーターを最初に制御する為に必要","info":"","x":820,"y":980,"wires":[]},{"id":"18441ebf.7dbef1","type":"inject","z":"c50d8323.5e274","name":"LED、10rpm、正回転","topic":"","payload":"[{\"cmd\":\"cmdLed\",\"arg\":\"1,200,0,0\"},{\"cmd\":\"cmdSpeed_rpm\",\"arg\":40},{\"cmd\":\"cmdRunForward\"}]","payloadType":"json","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":200,"y":1360,"wires":[["c3792d6.13938d"]]},{"id":"2bf08ca4.77f7a4","type":"inject","z":"c50d8323.5e274","name":"LED、40rpm、逆回転","topic":"","payload":"[{\"cmd\":\"cmdLed\",\"arg\":\"1,100,0,100\"},{\"cmd\":\"cmdSpeed_rpm\",\"arg\":40},{\"cmd\":\"cmdRunReverse\"}]","payloadType":"json","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":200,"y":1400,"wires":[["c3792d6.13938d"]]},{"id":"5fc83cda.82d064","type":"inject","z":"c50d8323.5e274","name":"{\"cmd\":\"connect\"}","topic":"","payload":"{\"cmd\":\"connect\"}","payloadType":"json","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":190,"y":1120,"wires":[["c3792d6.13938d"]]},{"id":"b9ee3c1.9fd9bc","type":"comment","z":"c50d8323.5e274","name":"例) モーターの切断・手動接続","info":"+ 手動で接続する場合はスキャナーで認識されているモーター名を指定して下さい。  \nex)`{\"cmd\":\"connect\",\"arg\":\"KM-1 175D\"}`\n+ スキャナーで認識されていないモータは接続出来ません。","x":200,"y":1040,"wires":[]},{"id":"e3060647.b92548","type":"comment","z":"c50d8323.5e274","name":"例) モーターのLED変更","info":"\n","x":180,"y":1180,"wires":[]},{"id":"8a082a6d.34c6a8","type":"comment","z":"c50d8323.5e274","name":"例) モーターの有効無効(安全装置)","info":"+ モーター接続時は常に無効(cmdDisable)です。 \n\n+ 最初に有効(cmdEnable)にしない限りモーターは動作しません。\n","x":220,"y":1540,"wires":[]},{"id":"ac549528.913098","type":"comment","z":"c50d8323.5e274","name":"例) モーターの設定値の取得","info":"+ レジスタ番号で指定した設定値をモーターから取得します。 \n\n+ 取得した値はモーターの出力4(settingデバッグノード)に出力されます。  \n\n+ レジスタ番号は下記のリンクを参考に10進数で指定して下さい。  \n\n[レジスター一覧](https://document.keigan-motor.com/apiDocument/kmconnector-js/KMMotorCommandKMOne.html#.cmdReadRegister_COMMAND__anchor)","x":200,"y":1680,"wires":[]},{"id":"6f05e191.ab0bd","type":"comment","z":"c50d8323.5e274","name":"例) モーターの回転 座標指定","info":"電源投入時のモータの座標は0です。  \n\n+ 座標(原点)の初期化はcmdPresetPositionで行えます。  \n\n+ 現在のモーターの座標は、モーターノード.出力2.msg.posionで取得出来ます。  \n\n+ 座標の単位はradian(360度=2π=3.1415*2=6.283)\n\n+ 速度は以前に設定した速度が維持されます。\n\n","x":780,"y":1340,"wires":[]},{"id":"ae90138a.0cff2","type":"inject","z":"c50d8323.5e274","name":"3) 現在位置から90度回転","topic":"","payload":"[{\"cmd\":\"cmdMoveByDistance\",\"arg\":1.57}]","payloadType":"json","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":790,"y":1460,"wires":[["c3792d6.13938d"]]},{"id":"c5970907.645ab8","type":"inject","z":"c50d8323.5e274","name":"2) 速度を40rpmに変更","topic":"","payload":"[{\"cmd\":\"cmdSpeed_rpm\",\"arg\":40}]","payloadType":"json","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":780,"y":1420,"wires":[["c3792d6.13938d"]]},{"id":"9e219b8.6db2d68","type":"inject","z":"c50d8323.5e274","name":"4) 現在位置から-90度回転","topic":"","payload":"[{\"cmd\":\"cmdMoveByDistance\",\"arg\":-1.57}]","payloadType":"json","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":790,"y":1500,"wires":[["c3792d6.13938d"]]},{"id":"d880398d.b4b018","type":"inject","z":"c50d8323.5e274","name":"Scan Stop","topic":"","payload":"0","payloadType":"num","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":160,"y":180,"wires":[["269a50b1.7679e"]]},{"id":"cd467ad9.4a50e8","type":"inject","z":"c50d8323.5e274","name":"","topic":"","payload":"{\"cmd\":\"connect\"}","payloadType":"json","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":410,"y":580,"wires":[["ee182648.eee868","7321a568.66bb5c"]]},{"id":"1d775264.9c6e4e","type":"comment","z":"c50d8323.5e274","name":"スキャン終了後にモーターを自動接続","info":"### ●スキャン終了後にスキャン中に発見したモータを接続。\nRaspberryPi3のBLEデバイスではスキャン中に接続を行うと、  \n接続に失敗したりBLE動作が不安定になる為、BLE scannerのスキャン終了後に接続します。","x":770,"y":120,"wires":[]},{"id":"1636f7b.3141208","type":"comment","z":"c50d8323.5e274","name":"前回接続のモーターに再接続","info":"‘{\"cmd\":\"connect\",arg:\"モーター名\"}‘\n\n指定したモーターに接続する。  \n\n引数argを省略すると、前回接続したモータに接続します。","x":400,"y":540,"wires":[]},{"id":"6c81eb9.f3f2a14","type":"comment","z":"c50d8323.5e274","name":"接続を許可するモーター名を指定","info":"スキャナーのタイムアウト時には、検出されたモーター全てが一括で出力されます。\n\n従って、モーターノードの \"Allow Connect Motor\"に接続許可するモーター名を指定する事で、個々のモーターノードに指定したモーターのみを接続させます。\n","x":770,"y":380,"wires":[]},{"id":"d4278d35.1b1e5","type":"inject","z":"c50d8323.5e274","name":"Scan Stop","topic":"","payload":"0","payloadType":"num","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":160,"y":420,"wires":[["aeeba6a3.757698"]]},{"id":"a3c6db58.9efa48","type":"inject","z":"c50d8323.5e274","name":"Scan 20sec 1Motor","topic":"","payload":"20,1","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":190,"y":940,"wires":[["7ebc282c.f290c8"]]},{"id":"b4619b97.a2b108","type":"inject","z":"c50d8323.5e274","name":"Scan Stop","topic":"","payload":"0","payloadType":"num","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":160,"y":980,"wires":[["7ebc282c.f290c8"]]},{"id":"269a50b1.7679e","type":"km-BLEscan","z":"c50d8323.5e274","name":"","x":460,"y":120,"wires":[["34c21b75.e3e164"]]},{"id":"aeeba6a3.757698","type":"km-BLEscan","z":"c50d8323.5e274","name":"","x":400,"y":380,"wires":[["ee182648.eee868","7321a568.66bb5c"]]},{"id":"7ebc282c.f290c8","type":"km-BLEscan","z":"c50d8323.5e274","name":"","x":420,"y":960,"wires":[["c3792d6.13938d","94fa106c.45b91"]]},{"id":"fa2b11a2.de2b4","type":"inject","z":"c50d8323.5e274","name":"減速停止","topic":"","payload":"{\"cmd\":\"cmdStop\"}","payloadType":"json","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":160,"y":1440,"wires":[["c3792d6.13938d"]]},{"id":"4d9d93e9.c52edc","type":"inject","z":"c50d8323.5e274","name":"強制停止","topic":"","payload":"{\"cmd\":\"cmdFree\"}","payloadType":"json","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":160,"y":1480,"wires":[["c3792d6.13938d"]]},{"id":"82d4efce.c21d2","type":"comment","z":"c50d8323.5e274","name":"接続例3) 指定したモータに手動で接続する","info":"※注意 別のノードで既に接続されているモーターは接続されません。一旦接続を切って下さい\n\n","x":180,"y":660,"wires":[]},{"id":"b44f3431.419fd8","type":"inject","z":"c50d8323.5e274","name":"Scan 20sec","topic":"","payload":"20","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":170,"y":740,"wires":[["18221f7d.7f3ac1"]]},{"id":"10c95.4285e36bc","type":"debug","z":"c50d8323.5e274","name":"status","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","x":1334.2857666015625,"y":719.9999961853027,"wires":[]},{"id":"8a90a785.be0f98","type":"debug","z":"c50d8323.5e274","name":"motorMeasurement1","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","x":1384.2857666015625,"y":759.9999961853027,"wires":[]},{"id":"95e96a31.6ce088","type":"km-motor","z":"c50d8323.5e274","name":"","allowConnectMotor":"","x":1164.2857666015625,"y":739.9999961853027,"wires":[["10c95.4285e36bc"],["8a90a785.be0f98"],[],[]]},{"id":"f3e06823.1ce9e8","type":"inject","z":"c50d8323.5e274","name":"","topic":"","payload":"{\"cmd\":\"disConnect\"}","payloadType":"json","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":740,"y":800,"wires":[["95e96a31.6ce088"]]},{"id":"a29b9f51.58702","type":"inject","z":"c50d8323.5e274","name":"Scan Stop","topic":"","payload":"0","payloadType":"num","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":160,"y":780,"wires":[["18221f7d.7f3ac1"]]},{"id":"7bb66b96.5cd524","type":"comment","z":"c50d8323.5e274","name":"スキャン終了(停止)後にモーターを手動接続","info":"###スキャナーを停止後、発見したモータ名を指定して接続。\n+ \"KM-1 175D\"の部分は実際に検出したモータ名に変更して下さい。\n+ モーター名はScan終了時にスキャナーの下部に表示されます。\n+ RaspberryPi3のBLEデバイスではスキャン中に接続を行うと、接続に失敗したりBLE動作が不安定になる為、BLE scannerのスキャン終了後に接続します。","x":770,"y":700,"wires":[]},{"id":"18221f7d.7f3ac1","type":"km-BLEscan","z":"c50d8323.5e274","name":"","x":460,"y":740,"wires":[[]]},{"id":"11861528.6cbe6b","type":"inject","z":"c50d8323.5e274","name":"{\"cmd\":\"connect\", arg:\"KM-1 175D\"}","topic":"","payload":"{\"cmd\":\"connect\", \"arg\":\"KM-1 175D\"}","payloadType":"json","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":790,"y":740,"wires":[["95e96a31.6ce088"]]}]

Author

Keigan Inc.

License

MIT

Node Info

Version: 0.2.4
Updated 3 weeks, 5 days ago
License: MIT
Rating:

Downloads

2 in the last day
6 in the last week
107 in the last month

Nodes

  • km-motor
  • km-BLEscan

Keywords

  • node-red
  • motor
  • keigan

Maintainers

  • keigan-motor