/home/piディレクトリに start.sh を作ります
cd ~/python/mjpg-streamer/mjpg-streamer-experimental/
./start.sh
コマンドから起動するには、実行権限を付与します
$ chmod +x start.sh
真ん中センサー
[{"id":"b68d58b3.8c6558","type":"ui_gauge","z":"25ca1f95.edd2f","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":400,"y":280,"wires":[]},{"id":"aafdb873.ca6ff8","type":"ui_gauge","z":"25ca1f95.edd2f","name":"","group":"14b2f627.536eba","order":3,"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":400,"y":320,"wires":[]},{"id":"6c38e2e1.23df7c","type":"ui_switch","z":"25ca1f95.edd2f","name":"","label":"Auto Drive ??","tooltip":"","group":"919a5620.d1a0e8","order":1,"width":3,"height":1,"passthru":true,"decouple":"false","topic":"autodrive","topicType":"str","style":"","onvalue":"true","onvalueType":"bool","onicon":"","oncolor":"","offvalue":"false","offvalueType":"bool","officon":"","offcolor":"","animate":false,"className":"","x":100,"y":80,"wires":[["ec6655cd.c45368"]]},{"id":"27b725c3.bc812a","type":"rpi-gpio in","z":"25ca1f95.edd2f","name":"障害物センサー右","pin":"26","intype":"down","debounce":"25","read":true,"x":110,"y":180,"wires":[["ec6655cd.c45368","aafdb873.ca6ff8"]]},{"id":"e1f82d55.0da74","type":"rpi-gpio in","z":"25ca1f95.edd2f","name":"障害物センサー左","pin":"24","intype":"down","debounce":"25","read":true,"x":110,"y":140,"wires":[["ec6655cd.c45368","b68d58b3.8c6558"]]},{"id":"27e6dfc4.2b81b","type":"rpi-gpio out","z":"25ca1f95.edd2f","name":"左1(GPIO 27)","pin":"13","set":true,"level":"0","freq":"","out":"out","x":770,"y":60,"wires":[]},{"id":"2a1655d8.e7723a","type":"rpi-gpio out","z":"25ca1f95.edd2f","name":"左2(GPIO 17)","pin":"11","set":true,"level":"0","freq":"","out":"out","x":770,"y":100,"wires":[]},{"id":"15568c32.36ab24","type":"rpi-gpio out","z":"25ca1f95.edd2f","name":"右1(GPIO 21)","pin":"40","set":true,"level":"0","freq":"","out":"out","x":770,"y":160,"wires":[]},{"id":"1fe88042.30a39","type":"rpi-gpio out","z":"25ca1f95.edd2f","name":"右2(GPIO 20)","pin":"38","set":true,"level":"0","freq":"","out":"out","x":770,"y":200,"wires":[]},{"id":"ec6655cd.c45368","type":"function","z":"25ca1f95.edd2f","name":"進路を決定","func":"// 変数の定義\nvar msgL1 = { payload:0 };\nvar msgL2 = { payload:0 };\nvar msgR1 = { payload:0 };\nvar msgR2 = { payload:0 };\nvar msgST = { payload:null };\n\n// もし左右ともに障害物を検知したら[回避先を探す]\n// 回避先を探すが、今は一旦停止する\ncontext.init = context.init || false;\ncontext.L = context.L || 0;\ncontext.R = context.R || 0;\ncontext.F = context.F || 0;\n\n// センサーメッセージのトピックに基づいてpayload[1, 0]を更新\nif (msg.topic === \"pi/24\") {\n context.L = msg.payload;\n}\nif (msg.topic === \"pi/26\") {\n context.R = msg.payload;\n}\nif (msg.topic === \"pi/22\") {\n context.F = msg.payload;\n}\n\n// もし手動運転(自動運転はOFF)ならnullを返しモーターに指示しない\nif (msg.topic == \"autodrive\") {\n if (msg.payload == true) {\n context.init = true;\n } else {\n context.init = false;\n }\n}\n\n// なにもしない(起動直後の動作)\nif (context.init == false) {\n msgL1.topic = \"Auto OFF\";\n msgL1.payload = 0 ;\n msgL2.payload = 0 ;\n msgR1.payload = 0 ;\n msgR2.payload = 0 ;\n msgST.payload = null ;\n return [msgL1, msgL2, msgR1, msgR2, msgST];\n}\n\n// センサーを元に進行報告を決める\n// L, Rともに障害検知(0)ならSTOP\nif (context.L == 0 && context.R == 0) {\n msgL1.topic = \"Stop\";\n msgL1.payload = 0 ;\n msgL2.payload = 1 ;\n msgR1.payload = 0 ;\n msgR2.payload = 1 ;\n msgST.payload = 1000 ;\n return [msgL1, msgL2, msgR1, msgR2, msgST];\n}\n\n// L検知(0), Fなし(1)なら Right\nif (context.L == 0 && context.F == 1) {\n msgL1.topic = \"Right\";\n msgL1.payload = 0 ;\n msgL2.payload = 1 ;\n msgR1.payload = 1 ;\n msgR2.payload = 0 ;\n msgST.payload = null ;\n return [msgL1, msgL2, msgR1, msgR2, msgST];\n}\n\n// Fなし(1), R検知(0)なら Left\nif (context.F == 1 && context.R == 0) {\n msgL1.topic = \"Left\";\n msgL1.payload = 1 ;\n msgL2.payload = 0 ;\n msgR1.payload = 0 ;\n msgR2.payload = 1 ;\n msgST.payload = null ;\n return [msgL1, msgL2, msgR1, msgR2, msgST];\n}\n\n// LRともになし(1)なら Forward\nif (context.L == 1 && context.R == 1 && context.F ==1) {\n msgL1.topic = \"Forward\";\n msgL1.payload = 1 ;\n msgL2.payload = 0 ;\n msgR1.payload = 1 ;\n msgR2.payload = 0 ;\n msgST.payload = null ;\n return [msgL1, msgL2, msgR1, msgR2, msgST];\n}\n","outputs":5,"noerr":0,"initialize":"","finalize":"","libs":[],"x":390,"y":80,"wires":[["f6c5e00a.9fd31","27e6dfc4.2b81b"],["2a1655d8.e7723a","f6c5e00a.9fd31"],["15568c32.36ab24","f6c5e00a.9fd31"],["1fe88042.30a39","f6c5e00a.9fd31"],[]]},{"id":"f6c5e00a.9fd31","type":"debug","z":"25ca1f95.edd2f","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":750,"y":340,"wires":[]},{"id":"697b3ee8.47915","type":"rpi-gpio in","z":"25ca1f95.edd2f","name":"障害物センサー正面","pin":"22","intype":"down","debounce":"25","read":true,"x":110,"y":240,"wires":[["f88536ce.7eca88","ec6655cd.c45368"]]},{"id":"f88536ce.7eca88","type":"ui_gauge","z":"25ca1f95.edd2f","name":"","group":"14b2f627.536eba","order":2,"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":400,"y":380,"wires":[]},{"id":"14b2f627.536eba","type":"ui_group","name":"障害物センサー","tab":"1ca0e03a.98b22","order":6,"disp":true,"width":9,"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}]
GPIOの出力(1, 0)が機械的に動作するかLEDで検査する
$ cat ledtest.py
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# GPIOの出力にLEDを接続してON,OFFを検査するプログラム
import RPi.GPIO as GPIO
import sys
import time
import readchar
constLeftIN1 = 27 #GPIO27, 13pin
constLeftIN2 = 17 #GPIO17, 11pin
constRightIN1 = 21 #GPIO21, 40pin
constRightIN2 = 20 #GPIO20, 38pin
GPIO.setwarnings( False )
GPIO.setmode( GPIO.BCM )
GPIO.setup( constLeftIN1, GPIO.OUT )
GPIO.setup( constLeftIN2, GPIO.OUT )
GPIO.setup( constRightIN1, GPIO.OUT )
GPIO.setup( constRightIN2, GPIO.OUT )
def end():
GPIO.cleanup()
sys.exit(0)
#####################################
# メインルーチン
######################################
if __name__ == '__main__':
print(' [W]27\n[A]17\n[S]21\n[D]20\n[X]OFF to STOP\n[Q] to QUIT')
try:
while True:
kb = readchar.readchar()
sys.stdout.write(kb)
if kb == 'w':
GPIO.output(constLeftIN1,1)
if kb == 's':
GPIO.output(constLeftIN2,1)
if kb == 'a':
GPIO.output(constRightIN1,1)
if kb == 'd':
GPIO.output(constRightIN2,1)
if kb == 'x':
GPIO.output(constLeftIN1,0)
GPIO.output(constLeftIN2,0)
GPIO.output(constRightIN1,0)
GPIO.output(constRightIN2,0)
if kb == 'q':
end()
except KeyboardInterrupt:
end()