Ready to take your JavaScript development to the next level? Meet npm Enterprise - the ultimate in enterprise JavaScript. Learn more »

node-red-contrib-keiganmotor

0.2.6 • Public • Published

KeiganMotor for Node-RED

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

sc_1

概要

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

  • Raspberry Pi 3 Model B
  • MacBook

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

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

 $npm install node-red-contrib-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"]]}]

差動二輪

[{"id":"7affae99.0d185","type":"tab","label":"2-Wheeled Car","disabled":false,"info":""},{"id":"111cb572.6cc96b","type":"comment","z":"7affae99.0d185","name":"接続","info":"","x":103,"y":44,"wires":[]},{"id":"21225e2e.32b672","type":"km-motor","z":"7affae99.0d185","name":"","allowConnectMotor":"KM-1 D5EP","x":853,"y":324,"wires":[["aa917535.b47b78","ad8654f3.6262c8"],[],[],[]]},{"id":"aa917535.b47b78","type":"debug","z":"7affae99.0d185","name":"status","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","x":1129,"y":312,"wires":[]},{"id":"c7371099.41c5d","type":"km-BLEscan","z":"7affae99.0d185","name":"BLE scanner","x":443,"y":104,"wires":[["21225e2e.32b672","3d2c566d.7d385a","aae6bba.1fad148"]]},{"id":"1336dafe.0ddc85","type":"trigger","z":"7affae99.0d185","op1":"{\"cmd\":\"cmdEnable\"}","op2":"0","op1type":"json","op2type":"str","duration":"100","extend":false,"units":"ms","reset":"","bytopic":"topic","name":"{\"cmd\":\"cmdEnable\"}","x":993,"y":224,"wires":[["21225e2e.32b672"]]},{"id":"ad8654f3.6262c8","type":"switch","z":"7affae99.0d185","name":"","property":"payload","propertyType":"msg","rules":[{"t":"eq","v":"connect","vt":"str"}],"checkall":"true","repair":false,"outputs":1,"x":803,"y":224,"wires":[["1336dafe.0ddc85"]]},{"id":"7bbd798a.9f9468","type":"comment","z":"7affae99.0d185","name":"※安全装置","info":"※注意 別のノードで既に接続されているモーターは接続されません。一旦接続を切って下さい\n\n","x":813,"y":184,"wires":[]},{"id":"aae6bba.1fad148","type":"km-motor","z":"7affae99.0d185","name":"","allowConnectMotor":"KM-1 MCKI","x":880,"y":520,"wires":[["626958cb.dd8f88","5f0bfe61.15afa"],[],[],[]]},{"id":"d58ccf9.8a73b3","type":"trigger","z":"7affae99.0d185","op1":"{\"cmd\":\"cmdEnable\"}","op2":"0","op1type":"json","op2type":"str","duration":"10","extend":false,"units":"ms","reset":"","bytopic":"topic","name":"{\"cmd\":\"cmdEnable\"}","x":993,"y":424,"wires":[["aae6bba.1fad148"]]},{"id":"626958cb.dd8f88","type":"switch","z":"7affae99.0d185","name":"","property":"payload","propertyType":"msg","rules":[{"t":"eq","v":"connect","vt":"str"}],"checkall":"true","repair":false,"outputs":1,"x":803,"y":424,"wires":[["d58ccf9.8a73b3"]]},{"id":"5f0bfe61.15afa","type":"debug","z":"7affae99.0d185","name":"status","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","x":1108,"y":527,"wires":[]},{"id":"b7b0e515.ed0948","type":"comment","z":"7affae99.0d185","name":"※安全装置","info":"※注意 別のノードで既に接続されているモーターは接続されません。一旦接続を切って下さい\n\n","x":813,"y":384,"wires":[]},{"id":"efa0b20e.48196","type":"ui_slider","z":"7affae99.0d185","name":"maxSpeed","label":"SPEED","tooltip":"","group":"8f350e48.d2eda","order":1,"width":"6","height":"1","passthru":false,"outs":"all","topic":"default","min":"10","max":"50","step":1,"x":143,"y":444,"wires":[["a9401f69.73b07"]]},{"id":"ede1e76b.f55698","type":"comment","z":"7affae99.0d185","name":"UI入力","info":"","x":103,"y":384,"wires":[]},{"id":"2f28765b.a31bca","type":"ui_button","z":"7affae99.0d185","name":"F","group":"8f350e48.d2eda","order":3,"width":"6","height":"2","passthru":false,"label":"↑","tooltip":"","color":"","bgcolor":"","icon":"","payload":"F","payloadType":"str","topic":"","x":209,"y":600,"wires":[["22536473.646fcc"]]},{"id":"7bb41773.801a38","type":"ui_button","z":"7affae99.0d185","name":"B","group":"8f350e48.d2eda","order":6,"width":"6","height":"2","passthru":false,"label":"↓","tooltip":"","color":"","bgcolor":"","icon":"","payload":"B","payloadType":"str","topic":"","x":209,"y":680,"wires":[["22536473.646fcc"]]},{"id":"7f312a7.d6c09d4","type":"ui_button","z":"7affae99.0d185","name":"L","group":"8f350e48.d2eda","order":4,"width":"3","height":"2","passthru":false,"label":"←Left","tooltip":"","color":"","bgcolor":"","icon":"","payload":"L","payloadType":"str","topic":"0","x":129,"y":640,"wires":[["22536473.646fcc"]]},{"id":"1ce31ac2.2b5f45","type":"ui_button","z":"7affae99.0d185","name":"R","group":"8f350e48.d2eda","order":5,"width":"3","height":"2","passthru":false,"label":"Right→","tooltip":"","color":"","bgcolor":"","icon":"","payload":"R","payloadType":"str","topic":"","x":269,"y":640,"wires":[["22536473.646fcc"]]},{"id":"22536473.646fcc","type":"function","z":"7affae99.0d185","name":"Diff two wheel Robo","func":" let arrowCmd = msg.payload ;\n \n let maxSpeed=context.get('maxSpeed')||20;\n let moveTime=context.get('moveTime')||1;\n let motorLeftRevers=true;\n let motorRightRevers=false;\n\nlet ans_x=0,ans_y=0;\nswitch(arrowCmd){\n    case 'F':\n        ans_x=1;ans_y=1;\n    break;\n    \n    case 'R':\n         ans_x=-0.5;ans_y=0.5;\n    break;\n    \n    case 'L':\n        ans_x=0.5;ans_y=-0.5;\n    break;\n    \n    case 'B':\n        ans_x=-1;ans_y=-1;\n    break;\n    \n    case \"STOP\":\n         return [{\"payload\":{\"cmd\":\"cmdFree\"}}, {\"payload\":{\"cmd\":\"cmdFree\"}} ];\n    break;\n    \n    default:\n    if( typeof arrowCmd===\"object\" && arrowCmd[\"maxSpeed\"]!==undefined){\n       \n      maxSpeed= parseInt(arrowCmd[\"maxSpeed\"]);\n      context.set('maxSpeed',maxSpeed);\n    }else if( typeof arrowCmd===\"object\" && arrowCmd[\"moveTime\"]!==undefined){\n      moveTime= parseFloat(arrowCmd[\"moveTime\"]);\n      context.set('moveTime',moveTime);\n    }\n}\n\nconsole.log(\"maxSpeed\",maxSpeed,\"moveTime\",moveTime);\n \n\nlet lr=motorLeftRevers?ans_x*maxSpeed*-1:ans_x*maxSpeed;\nlet rr=motorRightRevers?ans_y*maxSpeed*-1:ans_y*maxSpeed;\n\n//速度 rpm ->radian/sec(Math.PI*2/60)\n\nlet leftDistance=lr * 0.10471975511965977*moveTime;\nlet rightDistance=rr * 0.10471975511965977*moveTime;\nlet leftSpeed=Math.abs(lr) * 0.10471975511965977;\nlet rightSpeed=Math.abs(rr) * 0.10471975511965977;\n\n\nreturn [{\"payload\":{\"cmd\":\"cmdMoveByDistance\",\"arg\":[leftDistance,leftSpeed]}},{\"payload\":{\"cmd\":\"cmdMoveByDistance\",\"arg\":[rightDistance,rightSpeed]}}];\n \n \n ","outputs":2,"noerr":0,"x":420,"y":360,"wires":[["21225e2e.32b672"],["aae6bba.1fad148"]],"inputLabels":["{}"],"outputLabels":["{}","{}"]},{"id":"b3eb751b.023e78","type":"ui_button","z":"7affae99.0d185","name":"STOP","group":"8f350e48.d2eda","order":7,"width":"6","height":"2","passthru":false,"label":"STOP","tooltip":"","color":"","bgcolor":"","icon":"","payload":"STOP","payloadType":"str","topic":"","x":210,"y":720,"wires":[["22536473.646fcc"]]},{"id":"a1446462.573788","type":"inject","z":"7affae99.0d185","name":"Scan 20sec 10Motor","topic":"","payload":"20,10","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":175,"y":96,"wires":[["c7371099.41c5d"]]},{"id":"44f13cad.775814","type":"inject","z":"7affae99.0d185","name":"Scan Stop","topic":"","payload":"0","payloadType":"num","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":143,"y":143,"wires":[["c7371099.41c5d"]]},{"id":"593f5579.bbbf9c","type":"inject","z":"7affae99.0d185","name":"","topic":"","payload":"{\"cmd\":\"disConnect\"}","payloadType":"json","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":140,"y":200,"wires":[["21225e2e.32b672","aae6bba.1fad148"]]},{"id":"a9401f69.73b07","type":"function","z":"7affae99.0d185","name":"{\"speed\":msg.payload}","func":"\nreturn {\"payload\":{\"maxSpeed\":msg.payload}};","outputs":1,"noerr":0,"x":370,"y":440,"wires":[["22536473.646fcc"]]},{"id":"2537f7ab.6c5358","type":"ui_slider","z":"7affae99.0d185","name":"moveTime","label":"moveTime","tooltip":"","group":"8f350e48.d2eda","order":2,"width":"6","height":"1","passthru":false,"outs":"all","topic":"default","min":"0.2","max":"1.5","step":"0.2","x":132,"y":514,"wires":[["5de6d1a3.c517d"]]},{"id":"5de6d1a3.c517d","type":"function","z":"7affae99.0d185","name":"{\"moveTime\":msg.payload}","func":"\nreturn {\"payload\":{\"moveTime\":msg.payload}};","outputs":1,"noerr":0,"x":372,"y":507,"wires":[["22536473.646fcc"]]},{"id":"ef8d672e.c96d48","type":"inject","z":"7affae99.0d185","name":"","topic":"","payload":"{\"cmd\":\"cmdEnable\"}","payloadType":"json","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":140,"y":260,"wires":[["21225e2e.32b672","aae6bba.1fad148"]]},{"id":"38894487.a3d81c","type":"comment","z":"7affae99.0d185","name":"ティーチング","info":"","x":110,"y":800,"wires":[]},{"id":"ef03c3df.57bcb","type":"ui_button","z":"7affae99.0d185","name":"1 REC","group":"8f350e48.d2eda","order":9,"width":"2","height":"1","passthru":false,"label":"1 REC","tooltip":"","color":"","bgcolor":"","icon":"","payload":"{\"cmd\":\"cmdStartTeachingMotion\",\"arg\":[0,10000]}","payloadType":"json","topic":"","x":90,"y":880,"wires":[["21225e2e.32b672","aae6bba.1fad148"]]},{"id":"b8e5ee0c.cb1cd","type":"ui_button","z":"7affae99.0d185","name":"1 PLAY","group":"8f350e48.d2eda","order":10,"width":"2","height":"1","passthru":false,"label":"1 PLAY","tooltip":"","color":"","bgcolor":"","icon":"","payload":"{\"cmd\":\"cmdStartPlaybackMotion\",\"arg\":[0,1,1]}","payloadType":"json","topic":"","x":100,"y":920,"wires":[["21225e2e.32b672","aae6bba.1fad148"]]},{"id":"3d2c566d.7d385a","type":"debug","z":"7affae99.0d185","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":840,"y":100,"wires":[]},{"id":"336d5bb5.f772c4","type":"ui_button","z":"7affae99.0d185","name":"2 REC","group":"8f350e48.d2eda","order":12,"width":"2","height":"1","passthru":false,"label":"2 REC","tooltip":"","color":"","bgcolor":"","icon":"","payload":"{\"cmd\":\"cmdStartTeachingMotion\",\"arg\":[1,10000]}","payloadType":"json","topic":"","x":270,"y":880,"wires":[["aae6bba.1fad148","21225e2e.32b672"]]},{"id":"ff10712e.03655","type":"ui_button","z":"7affae99.0d185","name":"2 PLAY","group":"8f350e48.d2eda","order":13,"width":"2","height":"1","passthru":false,"label":"2 PLAY","tooltip":"","color":"","bgcolor":"","icon":"","payload":"{\"cmd\":\"cmdStartPlaybackMotion\",\"arg\":[1,1,1]}","payloadType":"json","topic":"","x":260,"y":920,"wires":[["aae6bba.1fad148","21225e2e.32b672"]]},{"id":"83a3cc8e.b15b3","type":"ui_button","z":"7affae99.0d185","name":"1 Erase","group":"8f350e48.d2eda","order":8,"width":"2","height":"1","passthru":false,"label":"1 Erase","tooltip":"","color":"","bgcolor":"","icon":"","payload":"{\"cmd\":\"cmdEraseMotion\",\"arg\":[0]}","payloadType":"json","topic":"","x":100,"y":840,"wires":[["21225e2e.32b672","aae6bba.1fad148"]]},{"id":"deadd703.af8228","type":"ui_button","z":"7affae99.0d185","name":"2 Erase","group":"8f350e48.d2eda","order":11,"width":"2","height":"1","passthru":false,"label":"2 Erase","tooltip":"","color":"","bgcolor":"","icon":"","payload":"{\"cmd\":\"cmdEraseMotion\",\"arg\":[1]}","payloadType":"json","topic":"","x":260,"y":840,"wires":[["aae6bba.1fad148","21225e2e.32b672"]]},{"id":"8f350e48.d2eda","type":"ui_group","z":"","name":"コントローラー","tab":"26971cf1.8d1c64","disp":false,"width":"6","collapse":false},{"id":"26971cf1.8d1c64","type":"ui_tab","z":"","name":"ホーム","icon":"dashboard"}]

Author

Keigan Inc.

License

MIT

install

npm i node-red-contrib-keiganmotor

Downloadsweekly downloads

2

version

0.2.6

license

MIT

homepage

github.com

repository

Gitgithub

last publish

collaborators

  • avatar
Report a vulnerability