ラズタンク(24’完成形)

24年版Node-REDフローを掲載します。
間に合わなかった人、フローが消えちゃった人、完成版を改造するのもいいかな。

  • カメラ映像を表示する
  • デュアルモーターは、PWMで速度が可変
  • カメラ用左右上下のサーボモーター2個搭載
  • キー操作:[W]前進 [S]ストップ [X]後進 [A]左旋回 [D]右旋回
  • ハンマー用サーボモーター170度
  • スピーカー搭載(音楽やR2D2音)
  • 音声合成[入力したテキスト]を話します
  • 障害物センサー左右1個ずつ計2個
  • [Auto Drive]自動走行モードON/OFF切り替え
  • ダッシュボード起動時に[pigpiod]を起動しています
  • カメラ映像は ssh接続後、[$ ./start.sh]スクリプトで mjpg-streamer を起動してください

フロー

フロー読み込み方

Node-REDフローの右上メニュー[読み込み]で下記JSONをコピペしてください。

JSONフロー

[{"id":"80e0dd0b.9b91a","type":"tab","label":"ラズタンク(キー)","disabled":false,"info":"# ラズタンク操作パネル\n"},{"id":"5e1855b0.abb99c","type":"http in","z":"80e0dd0b.9b91a","name":" ストップ","url":"/stop","method":"get","upload":false,"swaggerDoc":"","x":120,"y":160,"wires":[["644d8e9f.75ffe"]]},{"id":"644d8e9f.75ffe","type":"template","z":"80e0dd0b.9b91a","name":"ストップ","field":"payload","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"<html>\n    <head></head>\n    <body>\n        <h1>ストップ!</h1>\n    </body>\n</html>","output":"str","x":320,"y":160,"wires":[["5bc23ec3.d42f7","be7a9504.2bfa78"]]},{"id":"5bc23ec3.d42f7","type":"http response","z":"80e0dd0b.9b91a","name":"HTTP 200","statusCode":"200","headers":{},"x":330,"y":240,"wires":[]},{"id":"be7a9504.2bfa78","type":"change","z":"80e0dd0b.9b91a","name":"0","rules":[{"t":"set","p":"payload","pt":"msg","to":"0","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":510,"y":160,"wires":[["6270c510.2dc7ac","e2ee847d.e68648","d1b5b6a2.85b988","d35501c0.49"]]},{"id":"6270c510.2dc7ac","type":"rpi-gpio out","z":"80e0dd0b.9b91a","name":"左1(GPIO 27)","pin":"13","set":true,"level":"0","freq":"","out":"out","x":870,"y":160,"wires":[]},{"id":"e2ee847d.e68648","type":"rpi-gpio out","z":"80e0dd0b.9b91a","name":"左2(GPIO 17)","pin":"11","set":true,"level":"0","freq":"","out":"out","x":870,"y":200,"wires":[]},{"id":"d1b5b6a2.85b988","type":"rpi-gpio out","z":"80e0dd0b.9b91a","name":"右1(GPIO 21)","pin":"40","set":true,"level":"0","freq":"","out":"out","x":870,"y":240,"wires":[]},{"id":"d35501c0.49","type":"rpi-gpio out","z":"80e0dd0b.9b91a","name":"右2(GPIO 20)","pin":"38","set":true,"level":"0","freq":"","out":"out","x":870,"y":280,"wires":[]},{"id":"45c9028f.0da04c","type":"http in","z":"80e0dd0b.9b91a","name":"前進","url":"/forward","method":"get","upload":false,"swaggerDoc":"","x":110,"y":400,"wires":[["82ad3228.e0474"]]},{"id":"82ad3228.e0474","type":"template","z":"80e0dd0b.9b91a","name":"前進","field":"payload","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"<html>\n    <head></head>\n    <body>\n        <h1>前進</h1>\n    </body>\n</html>","output":"str","x":310,"y":400,"wires":[["a12476cc.df2778","2bc14611.6464ea","a22df2cd.68df6"]]},{"id":"a12476cc.df2778","type":"http response","z":"80e0dd0b.9b91a","name":"HTTP 200","statusCode":"200","headers":{},"x":330,"y":480,"wires":[]},{"id":"2bc14611.6464ea","type":"change","z":"80e0dd0b.9b91a","name":"1","rules":[{"t":"set","p":"payload","pt":"msg","to":"1","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":510,"y":400,"wires":[["c2cdc290.8ea0a","4d5d195.36557e8"]]},{"id":"c2cdc290.8ea0a","type":"rpi-gpio out","z":"80e0dd0b.9b91a","name":"左1(GPIO 27)","pin":"13","set":true,"level":"0","freq":"","out":"out","x":870,"y":400,"wires":[]},{"id":"c05e1cb.061e0e","type":"rpi-gpio out","z":"80e0dd0b.9b91a","name":"左2(GPIO 17)","pin":"11","set":true,"level":"0","freq":"","out":"out","x":870,"y":440,"wires":[]},{"id":"4d5d195.36557e8","type":"rpi-gpio out","z":"80e0dd0b.9b91a","name":"右1(GPIO 21)","pin":"40","set":true,"level":"0","freq":"","out":"out","x":870,"y":480,"wires":[]},{"id":"c07dc791.9b6978","type":"rpi-gpio out","z":"80e0dd0b.9b91a","name":"右2(GPIO 20)","pin":"38","set":true,"level":"0","freq":"","out":"out","x":870,"y":520,"wires":[]},{"id":"a22df2cd.68df6","type":"change","z":"80e0dd0b.9b91a","name":"0","rules":[{"t":"set","p":"payload","pt":"msg","to":"0","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":510,"y":440,"wires":[["c07dc791.9b6978","c05e1cb.061e0e"]]},{"id":"7ed2d839.86e5e8","type":"http in","z":"80e0dd0b.9b91a","name":"WEB操作画面を実行","url":"/","method":"get","upload":false,"swaggerDoc":"","x":150,"y":60,"wires":[["f2a3605c.c5a63"]]},{"id":"f2a3605c.c5a63","type":"ui_template","z":"80e0dd0b.9b91a","group":"9ed9db6d.aa47b8","name":"キー操作","order":3,"width":2,"height":2,"format":"<!DOCTYPE html>\n<html lang=\"jp\">\n<head>\n    <meta charset=\"utf-8\">\n    <title>キーボード入力をトリガーにするサンプルコード</title>\n\n    <script>\n    function callAPI( strKey, strAPI) {\n        messageReturn = \"[\" + strKey + \"]キーが押されました??\";\n        const Http = new XMLHttpRequest();\n        <!-- ↓このURLは自分のラズパイのIPアドレスかホスト名[razpi10:1880]に置き換えること -->\n        const url='http://192.168.0.244:1880/' + strAPI;\n        Http.open(\"GET\", url);\n        Http.send();\n        Http.onreadystatechange = (e) => {\n            console.log(Http.responseText)\n        }\n    }\n\n    function KanoAutoStart() {\n        var messageReturn = \"<h2>この行のメッセージはJavaScriptで表示しています</h2>\";\n\n        document.addEventListener( 'keydown', function(event) {\n          if ( event.key === 'w' ) {\n              callAPI( 'w', 'forward' );\n          } else if ( event.key === 's' ) {\n              callAPI( 's', 'stop' );\n          } else if ( event.key === 'x' ) {\n              callAPI( 'x', 'back' );\n          } else if ( event.key === 'd' ) {\n              callAPI( 'd', 'right' );\n          } else if ( event.key === 'a' ) {\n              callAPI( 'a', 'left' );\n          } else if ( event.key === 'q' ) {\n              callAPI( 'q', 'leftfront' );\n          }\n          messageReturn = event.key;\n          document.getElementById(\"ReturnMessageHere\").innerHTML = messageReturn;\n        });\n\n        <!--console.log(\"test.js; KanoAutoStart()\", messageReturn);-->\n        document.getElementById(\"ReturnMessageHere\").innerHTML = messageReturn;\n      }\n    </script>\n\n</head>\n<body>\n  <!-- <h1>キーボード入力をトリガーにするサンプルコード -JavaScript-</h1>\n  <p>コード言語はJavaScript。[w][s]もしくは何かキーを入力してください。</p>-->\n  <!-- ここにメッセージ返答を表示する -->\n  <div id=\"ReturnMessageHere\"></div>\n  <!-- ブラウザを起動したら自動実行する コード -->\n  <script type=\"text/javascript\">KanoAutoStart();</script>\n\n<p id=\"msg\"></p>\n\n</body>\n</html>","storeOutMessages":true,"fwdInMessages":true,"resendOnRefresh":true,"templateScope":"local","className":"","x":480,"y":60,"wires":[["d2b272bd.b4674"]]},{"id":"d2b272bd.b4674","type":"ui_template","z":"80e0dd0b.9b91a","group":"f73d73b7.59938","name":"カメラ映像","order":1,"width":13,"height":9,"format":"<iframe width=\"640\" height=\"480\" src=\"http://192.168.0.244:8080/?action=stream\"></iframe>","storeOutMessages":true,"fwdInMessages":true,"resendOnRefresh":true,"templateScope":"local","className":"","x":750,"y":60,"wires":[[]]},{"id":"cd72d3da.fa2f3","type":"http in","z":"80e0dd0b.9b91a","name":"バック","url":"/back","method":"get","upload":false,"swaggerDoc":"","x":110,"y":620,"wires":[["1cffc407.61d59c"]]},{"id":"1cffc407.61d59c","type":"template","z":"80e0dd0b.9b91a","name":"バック","field":"payload","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"<html>\n    <head></head>\n    <body>\n        <h1>バック</h1>\n    </body>\n</html>","output":"str","x":310,"y":620,"wires":[["62a77b66.f16174","1e9514c2.7c940b","c5cb3931.5ecf28"]]},{"id":"62a77b66.f16174","type":"http response","z":"80e0dd0b.9b91a","name":"HTTP 200","statusCode":"200","headers":{},"x":330,"y":700,"wires":[]},{"id":"1e9514c2.7c940b","type":"change","z":"80e0dd0b.9b91a","name":"1","rules":[{"t":"set","p":"payload","pt":"msg","to":"1","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":510,"y":620,"wires":[["b470d032.90cf","f8520bd2.5ab258"]]},{"id":"b3c70da0.36f13","type":"rpi-gpio out","z":"80e0dd0b.9b91a","name":"左1(GPIO 27)","pin":"13","set":true,"level":"0","freq":"","out":"out","x":870,"y":620,"wires":[]},{"id":"b470d032.90cf","type":"rpi-gpio out","z":"80e0dd0b.9b91a","name":"左2(GPIO 17)","pin":"11","set":true,"level":"0","freq":"","out":"out","x":870,"y":660,"wires":[]},{"id":"a50b5145.d412e","type":"rpi-gpio out","z":"80e0dd0b.9b91a","name":"右1(GPIO 21)","pin":"40","set":true,"level":"0","freq":"","out":"out","x":870,"y":700,"wires":[]},{"id":"f8520bd2.5ab258","type":"rpi-gpio out","z":"80e0dd0b.9b91a","name":"右2(GPIO 20)","pin":"38","set":true,"level":"0","freq":"","out":"out","x":870,"y":740,"wires":[]},{"id":"c5cb3931.5ecf28","type":"change","z":"80e0dd0b.9b91a","name":"0","rules":[{"t":"set","p":"payload","pt":"msg","to":"0","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":510,"y":660,"wires":[["b3c70da0.36f13","a50b5145.d412e"]]},{"id":"f10d8399.38518","type":"http in","z":"80e0dd0b.9b91a","name":"左旋回","url":"/left","method":"get","upload":false,"swaggerDoc":"","x":110,"y":840,"wires":[["cc8d8ff0.c9d07"]]},{"id":"cc8d8ff0.c9d07","type":"template","z":"80e0dd0b.9b91a","name":"左旋回","field":"payload","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"<html>\n    <head></head>\n    <body>\n        <h1>左旋回</h1>\n    </body>\n</html>","output":"str","x":310,"y":840,"wires":[["9d7f4542.613068","b4fd69ca.6a19d8","8d1767d0.968978"]]},{"id":"9d7f4542.613068","type":"http response","z":"80e0dd0b.9b91a","name":"HTTP 200","statusCode":"200","headers":{},"x":330,"y":920,"wires":[]},{"id":"b4fd69ca.6a19d8","type":"change","z":"80e0dd0b.9b91a","name":"1","rules":[{"t":"set","p":"payload","pt":"msg","to":"1","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":510,"y":840,"wires":[["c9c6c69a.621b08","4181d0d0.c64f9"]]},{"id":"4181d0d0.c64f9","type":"rpi-gpio out","z":"80e0dd0b.9b91a","name":"左1(GPIO 27)","pin":"13","set":true,"level":"0","freq":"","out":"out","x":870,"y":840,"wires":[]},{"id":"281337bb.b7d4d8","type":"rpi-gpio out","z":"80e0dd0b.9b91a","name":"左2(GPIO 17)","pin":"11","set":true,"level":"0","freq":"","out":"out","x":870,"y":880,"wires":[]},{"id":"acc0438a.f86","type":"rpi-gpio out","z":"80e0dd0b.9b91a","name":"右1(GPIO 21)","pin":"40","set":true,"level":"0","freq":"","out":"out","x":870,"y":920,"wires":[]},{"id":"c9c6c69a.621b08","type":"rpi-gpio out","z":"80e0dd0b.9b91a","name":"右2(GPIO 20)","pin":"38","set":true,"level":"0","freq":"","out":"out","x":870,"y":960,"wires":[]},{"id":"8d1767d0.968978","type":"change","z":"80e0dd0b.9b91a","name":"0","rules":[{"t":"set","p":"payload","pt":"msg","to":"0","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":510,"y":880,"wires":[["acc0438a.f86","281337bb.b7d4d8"]]},{"id":"c4280f02.2eeff","type":"http in","z":"80e0dd0b.9b91a","name":"右旋回","url":"/right","method":"get","upload":false,"swaggerDoc":"","x":110,"y":1060,"wires":[["51f28e32.4992"]]},{"id":"51f28e32.4992","type":"template","z":"80e0dd0b.9b91a","name":"右旋回","field":"payload","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"<html>\n    <head></head>\n    <body>\n        <h1>右旋回</h1>\n    </body>\n</html>","output":"str","x":310,"y":1060,"wires":[["9b0ce61e.114eb8","628b2351.87d11c","4ec894bb.aecc3c"]]},{"id":"9b0ce61e.114eb8","type":"http response","z":"80e0dd0b.9b91a","name":"HTTP 200","statusCode":"200","headers":{},"x":330,"y":1140,"wires":[]},{"id":"628b2351.87d11c","type":"change","z":"80e0dd0b.9b91a","name":"1","rules":[{"t":"set","p":"payload","pt":"msg","to":"1","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":510,"y":1060,"wires":[["4eae1e29.5628f","b96cc19f.b1d1d"]]},{"id":"38777b84.a90ca4","type":"rpi-gpio out","z":"80e0dd0b.9b91a","name":"左1(GPIO 27)","pin":"13","set":true,"level":"0","freq":"","out":"out","x":870,"y":1060,"wires":[]},{"id":"4eae1e29.5628f","type":"rpi-gpio out","z":"80e0dd0b.9b91a","name":"左2(GPIO 17)","pin":"11","set":true,"level":"0","freq":"","out":"out","x":870,"y":1100,"wires":[]},{"id":"b96cc19f.b1d1d","type":"rpi-gpio out","z":"80e0dd0b.9b91a","name":"右1(GPIO 21)","pin":"40","set":true,"level":"0","freq":"","out":"out","x":870,"y":1140,"wires":[]},{"id":"aada96ba.858ae8","type":"rpi-gpio out","z":"80e0dd0b.9b91a","name":"右2(GPIO 20)","pin":"38","set":true,"level":"0","freq":"","out":"out","x":870,"y":1180,"wires":[]},{"id":"4ec894bb.aecc3c","type":"change","z":"80e0dd0b.9b91a","name":"0","rules":[{"t":"set","p":"payload","pt":"msg","to":"0","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":510,"y":1100,"wires":[["38777b84.a90ca4","aada96ba.858ae8"]]},{"id":"bc019cb0.6bd7b","type":"ui_button","z":"80e0dd0b.9b91a","name":"","group":"fb9b90cd.419f5","order":1,"width":1,"height":1,"passthru":false,"label":"エレクトロ♪","tooltip":"","color":"","bgcolor":"","className":"","icon":"","payload":"","payloadType":"str","topic":"topic","topicType":"msg","x":130,"y":1240,"wires":[["d704b44b.c48558"]]},{"id":"d704b44b.c48558","type":"exec","z":"80e0dd0b.9b91a","command":" omxplayer /home/pi/Music/disney-electric.mp3","addpay":"","append":"","useSpawn":"false","timer":"","oldrc":false,"name":"","x":460,"y":1240,"wires":[[],[],[]]},{"id":"c7f2f15a.27e53","type":"ui_button","z":"80e0dd0b.9b91a","name":"","group":"fb9b90cd.419f5","order":3,"width":1,"height":1,"passthru":false,"label":"R2D2_long","tooltip":"","color":"","bgcolor":"","className":"","icon":"","payload":"","payloadType":"str","topic":"topic","topicType":"msg","x":130,"y":1300,"wires":[["33056c48.b33cc4"]]},{"id":"33056c48.b33cc4","type":"exec","z":"80e0dd0b.9b91a","command":" omxplayer /home/pi/Music/r2d2_002.mp3","addpay":"","append":"","useSpawn":"false","timer":"","oldrc":false,"name":"","x":440,"y":1300,"wires":[[],[],[]]},{"id":"26509da6.28a4f2","type":"ui_button","z":"80e0dd0b.9b91a","name":"","group":"fb9b90cd.419f5","order":2,"width":1,"height":1,"passthru":false,"label":"R2D2_Short","tooltip":"","color":"","bgcolor":"","className":"","icon":"","payload":"","payloadType":"str","topic":"topic","topicType":"msg","x":130,"y":1360,"wires":[["be596356.5ad6c"]]},{"id":"be596356.5ad6c","type":"exec","z":"80e0dd0b.9b91a","command":" omxplayer /home/pi/Music/r2d2_001.mp3","addpay":"","append":"","useSpawn":"false","timer":"","oldrc":false,"name":"","x":440,"y":1360,"wires":[[],[],[]]},{"id":"afac8a6f.9ac4d8","type":"ui_slider","z":"80e0dd0b.9b91a","name":"","label":"回転","tooltip":"","group":"a3a39bfe.f51168","order":4,"width":3,"height":1,"passthru":true,"outs":"all","topic":"topic","topicType":"msg","min":0,"max":"100","step":1,"className":"","x":110,"y":1460,"wires":[["1a72aa17.f42546","c4f6f8e2.8c0de8"]]},{"id":"1a72aa17.f42546","type":"ui_gauge","z":"80e0dd0b.9b91a","name":"","group":"a3a39bfe.f51168","order":1,"width":3,"height":3,"gtype":"gage","title":"ハンマー角度","label":"units","format":"{{value}}","min":0,"max":"100","colors":["#00b500","#e6e600","#ca3838"],"seg1":"","seg2":"","diff":false,"className":"","x":380,"y":1440,"wires":[]},{"id":"c4f6f8e2.8c0de8","type":"pi-gpiod out","z":"80e0dd0b.9b91a","name":"サーボモーター本体","host":"localhost","port":"8888","pin":"18","set":"","level":"0","out":"ser","sermin":"1000","sermax":"2000","freq":"800","x":400,"y":1480,"wires":[]},{"id":"9a7b8a8a.64f288","type":"exec","z":"80e0dd0b.9b91a","command":"sudo pigpiod","addpay":"","append":"","useSpawn":"false","timer":"","oldrc":false,"name":"$ sudo pigpiod","x":540,"y":1960,"wires":[[],[],[]]},{"id":"be07dbc1.5705b8","type":"inject","z":"80e0dd0b.9b91a","name":"緊急停止","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":120,"y":120,"wires":[["644d8e9f.75ffe"]]},{"id":"ff0b5fb6.ef2e7","type":"ui_slider","z":"80e0dd0b.9b91a","name":"","label":"左右","tooltip":"","group":"a3a39bfe.f51168","order":5,"width":3,"height":1,"passthru":true,"outs":"all","topic":"topic","topicType":"msg","min":"0","max":"100","step":1,"className":"","x":110,"y":1560,"wires":[["2b0a688.7553e98","afd776a5.2a0b18"]]},{"id":"2b0a688.7553e98","type":"pi-gpiod out","z":"80e0dd0b.9b91a","name":"カメラ左右","host":"localhost","port":8888,"pin":"6","set":"","level":"0","out":"ser","sermin":"1000","sermax":"2000","freq":"800","x":370,"y":1600,"wires":[]},{"id":"afd776a5.2a0b18","type":"ui_gauge","z":"80e0dd0b.9b91a","name":"","group":"a3a39bfe.f51168","order":2,"width":3,"height":3,"gtype":"gage","title":"カメラ左右","label":"units","format":"{{value}}","min":0,"max":"120","colors":["#00b500","#e6e600","#ca3838"],"seg1":"","seg2":"","diff":false,"className":"","x":370,"y":1560,"wires":[]},{"id":"6894b58c.7dd1ac","type":"ui_slider","z":"80e0dd0b.9b91a","name":"","label":"上下","tooltip":"","group":"a3a39bfe.f51168","order":6,"width":3,"height":1,"passthru":true,"outs":"all","topic":"topic","topicType":"msg","min":"0","max":"100","step":1,"className":"","x":110,"y":1660,"wires":[["a778854e.8db1a8","2c86c29b.a9274e"]]},{"id":"a778854e.8db1a8","type":"pi-gpiod out","z":"80e0dd0b.9b91a","name":"カメラ上下","host":"localhost","port":8888,"pin":"5","set":"","level":"0","out":"ser","sermin":"1000","sermax":"2000","freq":"800","x":370,"y":1700,"wires":[]},{"id":"2c86c29b.a9274e","type":"ui_gauge","z":"80e0dd0b.9b91a","name":"","group":"a3a39bfe.f51168","order":3,"width":3,"height":3,"gtype":"gage","title":"カメラ上下","label":"units","format":"{{value}}","min":0,"max":"120","colors":["#00b500","#e6e600","#ca3838"],"seg1":"","seg2":"","diff":false,"className":"","x":370,"y":1660,"wires":[]},{"id":"a2361053.edeed","type":"rpi-gpio out","z":"80e0dd0b.9b91a","name":"","pin":"33","set":"","level":"0","freq":"100","out":"pwm","x":520,"y":1840,"wires":[]},{"id":"da507ca9.e781a","type":"rpi-gpio out","z":"80e0dd0b.9b91a","name":"","pin":"35","set":"","level":"0","freq":"100","out":"pwm","x":520,"y":1900,"wires":[]},{"id":"8137dbf3.21de38","type":"ui_slider","z":"80e0dd0b.9b91a","name":"","label":"速度","tooltip":"","group":"9ed9db6d.aa47b8","order":2,"width":3,"height":1,"passthru":true,"outs":"all","topic":"topic","topicType":"msg","min":"50","max":"100","step":"5","className":"","x":110,"y":1780,"wires":[["a2361053.edeed","da507ca9.e781a","6acfcef0.aeabd"]]},{"id":"93f4a191.92621","type":"inject","z":"80e0dd0b.9b91a","name":"起動時1回だけ実行","props":[{"p":"payload"}],"repeat":"","crontab":"","once":true,"onceDelay":0.1,"topic":"","payload":"50","payloadType":"num","x":180,"y":1900,"wires":[["a2361053.edeed","da507ca9.e781a","9a7b8a8a.64f288"]]},{"id":"6acfcef0.aeabd","type":"ui_gauge","z":"80e0dd0b.9b91a","name":"","group":"9ed9db6d.aa47b8","order":1,"width":3,"height":3,"gtype":"gage","title":"速度","label":"units","format":"{{value}}","min":"50","max":"100","colors":["#00b500","#e6e600","#ca3838"],"seg1":"","seg2":"","diff":false,"className":"","x":510,"y":1780,"wires":[]},{"id":"6217c536.f795dc","type":"ui_button","z":"80e0dd0b.9b91a","name":"","group":"44556a65.4279c4","order":3,"width":2,"height":1,"passthru":false,"label":"音声合成","tooltip":"","color":"","bgcolor":"","className":"","icon":"","payload":"text","payloadType":"flow","topic":"topic","topicType":"msg","x":120,"y":2080,"wires":[["6466051a.6526dc"]]},{"id":"59c130a2.d8bcf","type":"exec","z":"80e0dd0b.9b91a","command":"/home/pi/python/jtalk.sh","addpay":"payload","append":"","useSpawn":"false","timer":"","oldrc":false,"name":"","x":570,"y":2080,"wires":[[],[],[]]},{"id":"c8e17de6.a6499","type":"debug","z":"80e0dd0b.9b91a","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":530,"y":2140,"wires":[]},{"id":"3f72395d.650736","type":"ui_text_input","z":"80e0dd0b.9b91a","name":"","label":"音声合成","tooltip":"","group":"44556a65.4279c4","order":1,"width":4,"height":1,"passthru":true,"mode":"text","delay":300,"topic":"","sendOnBlur":true,"className":"","topicType":"str","x":120,"y":2020,"wires":[["d7f08e40.ef71e"]]},{"id":"d7f08e40.ef71e","type":"change","z":"80e0dd0b.9b91a","name":"","rules":[{"t":"set","p":"speechText","pt":"flow","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":310,"y":2020,"wires":[[]]},{"id":"6466051a.6526dc","type":"change","z":"80e0dd0b.9b91a","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"speechText","tot":"flow"}],"action":"","property":"","from":"","to":"","reg":false,"x":300,"y":2080,"wires":[["c8e17de6.a6499","59c130a2.d8bcf"]]},{"id":"664957b.5b5eba8","type":"rpi-gpio in","z":"80e0dd0b.9b91a","name":"障害物センサー左","pin":"24","intype":"down","debounce":"25","read":true,"x":150,"y":2200,"wires":[["dad97686.a1ff48"]]},{"id":"dad97686.a1ff48","type":"ui_gauge","z":"80e0dd0b.9b91a","name":"","group":"14b2f627.536eba","order":1,"width":"3","height":"3","gtype":"donut","title":"障害物(⇦)","label":"units","format":"{{value}}","min":"1","max":"0","colors":["#00b500","#e6e600","#ca3838"],"seg1":"","seg2":"","diff":false,"className":"","x":410,"y":2200,"wires":[]},{"id":"dfd68858.f06a88","type":"rpi-gpio in","z":"80e0dd0b.9b91a","name":"障害物センサー右","pin":"26","intype":"down","debounce":"25","read":true,"x":150,"y":2260,"wires":[["52bbad7e.dc58b4"]]},{"id":"52bbad7e.dc58b4","type":"ui_gauge","z":"80e0dd0b.9b91a","name":"","group":"14b2f627.536eba","order":1,"width":"3","height":"3","gtype":"donut","title":"障害物(⇨)","label":"units","format":"{{value}}","min":"1","max":"0","colors":["#00b500","#e6e600","#ca3838"],"seg1":"","seg2":"","diff":false,"className":"","x":410,"y":2260,"wires":[]},{"id":"35ae730b.4ee1bc","type":"ui_switch","z":"80e0dd0b.9b91a","name":"","label":"Auto Drive 🛻","tooltip":"","group":"919a5620.d1a0e8","order":1,"width":"3","height":"1","passthru":true,"decouple":"false","topic":"topic","topicType":"msg","style":"","onvalue":"true","onvalueType":"bool","onicon":"","oncolor":"","offvalue":"false","offvalueType":"bool","officon":"","offcolor":"","animate":false,"className":"","x":140,"y":2480,"wires":[["af1c45f3.652f98"]]},{"id":"38016be1.da3044","type":"rpi-gpio in","z":"80e0dd0b.9b91a","name":"障害物センサー右","pin":"26","intype":"down","debounce":"25","read":true,"x":150,"y":2560,"wires":[["d39adb6.c93de28"]]},{"id":"8226321e.045cb","type":"rpi-gpio in","z":"80e0dd0b.9b91a","name":"障害物センサー左","pin":"24","intype":"down","debounce":"25","read":true,"x":150,"y":2400,"wires":[["3beb0f8c.8782c"]]},{"id":"758bbb73.6b6634","type":"rpi-gpio out","z":"80e0dd0b.9b91a","name":"左1(GPIO 27)","pin":"13","set":true,"level":"0","freq":"","out":"out","x":810,"y":2400,"wires":[]},{"id":"ffb4b89c.27c468","type":"rpi-gpio out","z":"80e0dd0b.9b91a","name":"左2(GPIO 17)","pin":"11","set":true,"level":"0","freq":"","out":"out","x":810,"y":2440,"wires":[]},{"id":"82642611.345d88","type":"rpi-gpio out","z":"80e0dd0b.9b91a","name":"右1(GPIO 21)","pin":"40","set":true,"level":"0","freq":"","out":"out","x":810,"y":2560,"wires":[]},{"id":"932669de.5a6cc8","type":"rpi-gpio out","z":"80e0dd0b.9b91a","name":"右2(GPIO 20)","pin":"38","set":true,"level":"0","freq":"","out":"out","x":810,"y":2600,"wires":[]},{"id":"3beb0f8c.8782c","type":"function","z":"80e0dd0b.9b91a","name":"AND","func":"// 2つのメッセージを受け取るための変数を初期化\ncontext.payload1 = context.payload1 || null;\ncontext.payload2 = context.payload2 || null;\n\n// メッセージのトピックに基づいてpayloadを保存\nif (msg.topic === \"autodrive\") {\n    context.payload1 = msg.payload;\n}\nif (msg.topic === \"pi/24\") {\n    context.payload2 = msg.payload;\n}\n\n// 両方のpayloadが揃ったら掛け算を行う\nif (context.payload1 !== null && context.payload2 !== null) {\n    msg.topic = \"motor\";\n    msg.payload = context.payload1 * context.payload2;\n    return msg;\n}","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":530,"y":2400,"wires":[["758bbb73.6b6634","d916abc.5ea4558"]]},{"id":"af1c45f3.652f98","type":"function","z":"80e0dd0b.9b91a","name":"autodrive:0,1","func":"msg.topic = \"autodrive\";\nif (msg.payload === true) {\n    msg.payload = 1;\n} else {\n    msg.payload = 0;\n}\n\nreturn msg;\n","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":330,"y":2480,"wires":[["3beb0f8c.8782c","d39adb6.c93de28","1883f380.59b79d","d916abc.5ea4558","7c4a1106.545b4"]]},{"id":"d39adb6.c93de28","type":"function","z":"80e0dd0b.9b91a","name":"AND","func":"// 2つのメッセージを受け取るための変数を初期化\ncontext.payload1 = context.payload1 || null;\ncontext.payload2 = context.payload2 || null;\n\n// メッセージのトピックに基づいてpayloadを保存\nif (msg.topic === \"autodrive\") {\n    context.payload1 = msg.payload;\n}\nif (msg.topic === \"pi/26\") {\n    context.payload2 = msg.payload;\n}\n\n// 両方のpayloadが揃ったら掛け算を行う\nif (context.payload1 !== null && context.payload2 !== null) {\n    msg.topic = \"motor\";\n    msg.payload = context.payload1 * context.payload2;\n    return msg;\n}","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":530,"y":2560,"wires":[["82642611.345d88","7c4a1106.545b4"]]},{"id":"d916abc.5ea4558","type":"function","z":"80e0dd0b.9b91a","name":"NOT","func":"// 2つのメッセージを受け取るための変数を初期化\ncontext.payload1 = context.payload1 || null;\ncontext.payload2 = context.payload2 || null;\n\n// メッセージのトピックに基づいてpayloadを保存\nif (msg.topic === \"autodrive\") {\n    context.payload1 = msg.payload;\n}\nif (msg.topic === \"motor\") {\n    context.payload2 = msg.payload;\n}\n\n// 両方のpayloadが揃ったら掛け算を行う\nif (context.payload1 !== null && context.payload2 !== null) {\n    // センサーがONなら逆転、OFFなら正転する\n    if (context.payload2 === 1) {\n        msg.payload = 0;\n    } else {\n        msg.payload = 1;\n    }\n    // もし自動運転がOFFなら止める\n    if (context.payload1 === 0) {\n        msg.payload = 0;\n    }\n    return msg;\n}","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":630,"y":2440,"wires":[["ffb4b89c.27c468"]]},{"id":"7c4a1106.545b4","type":"function","z":"80e0dd0b.9b91a","name":"NOT","func":"// 2つのメッセージを受け取るための変数を初期化\ncontext.payload1 = context.payload1 || null;\ncontext.payload2 = context.payload2 || null;\n\n// メッセージのトピックに基づいてpayloadを保存\nif (msg.topic === \"autodrive\") {\n    context.payload1 = msg.payload;\n}\nif (msg.topic === \"motor\") {\n    context.payload2 = msg.payload;\n}\n\n// 両方のpayloadが揃ったら掛け算を行う\nif (context.payload1 !== null && context.payload2 !== null) {\n    // センサーがONなら逆転、OFFなら正転する\n    if (context.payload2 === 1) {\n        msg.payload = 0;\n    } else {\n        msg.payload = 1;\n    }\n    // もし自動運転がOFFなら止める\n    if (context.payload1 === 0) {\n        msg.payload = 0;\n    }\n    return msg;\n}","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":630,"y":2600,"wires":[["932669de.5a6cc8"]]},{"id":"1883f380.59b79d","type":"rpi-gpio out","z":"80e0dd0b.9b91a","name":"モニタ","pin":"23","set":"","level":"0","freq":"","out":"out","x":350,"y":2520,"wires":[]},{"id":"9ed9db6d.aa47b8","type":"ui_group","name":"運転パネル","tab":"1ca0e03a.98b22","order":2,"disp":true,"width":3,"collapse":false,"className":""},{"id":"f73d73b7.59938","type":"ui_group","name":"カメラ映像","tab":"1ca0e03a.98b22","order":1,"disp":true,"width":13,"collapse":false,"className":""},{"id":"fb9b90cd.419f5","type":"ui_group","name":"音楽","tab":"1ca0e03a.98b22","order":5,"disp":true,"width":"6","collapse":false,"className":""},{"id":"a3a39bfe.f51168","type":"ui_group","name":"サーボ(カメラ&ハンマー)","tab":"1ca0e03a.98b22","order":3,"disp":true,"width":9,"collapse":false,"className":""},{"id":"44556a65.4279c4","type":"ui_group","name":"音スピーカー","tab":"1ca0e03a.98b22","order":4,"disp":true,"width":"4","collapse":false,"className":""},{"id":"14b2f627.536eba","type":"ui_group","name":"障害物センサー","tab":"1ca0e03a.98b22","order":6,"disp":true,"width":"6","collapse":false,"className":""},{"id":"919a5620.d1a0e8","type":"ui_group","name":"自動運転","tab":"1ca0e03a.98b22","order":7,"disp":true,"width":"6","collapse":false,"className":""},{"id":"1ca0e03a.98b22","type":"ui_tab","name":"ラズタンク十号","icon":"dashboard","disabled":false,"hidden":false}]

Node-REDを自動起動するには

sudo systemctl status nodered.service

▼ラズパイ起動時に、Node-REDを自動起動させる
[Node-red]サービスを常に有効化[Enable]します。

$ sudo systemctl enable nodered.service

再起動したときに
$ sudo systemctl status nodered.service

Active: active (running)
が表示されれば、Node-REDが起動しています。


コメントを残す