緣起
介面
命令定義
命令格式說明: 為跟 FarmBot 統一,用空白分隔。
為了能更加整合 FarmBot 原有 Arduino commands, 目前相容原有 Commands
意思是用原有的 FarmBot commands 會直接送到 Arduino 並取得結果回傳,當個 repeater 的概念。也因為如此,目前 G, F, R, E 開頭的命令都保留給 Arduino
Command Type | Command Number | Parameters definition | Reference Response | Function | Examples | |
G | 相容 Arduino Commands, 送給 Arduino 並取得回傳值 | |||||
F | 相容 Arduino Commands, 送給 Arduino 並取得回傳值 | |||||
R | 相容 Arduino Commands, 送給 Arduino 並取得回傳值 | |||||
E | Emergency stop, 也送到 Arduino | |||||
I | Image related functions | |||||
00 | pathname | R01-R04 | current capture save to file | I00 now.jpg | ||
V | Video related functions | |||||
00 | pathname second | R01-R04 | record video for x seconds | V00 now.mpeg 60 | ||
N | Recognition Processing related functions | |||||
00 | 雜草 offsets | 雜草辨識 | N00 | |||
01 | -g 140 -r 150 -i IMAG2562.jpg | tuple value: (green-Area, red-Area, overlap-Area) | 植栽覆蓋率 (unit %) 格式: (綠色植物%, 紅色植物%, 重疊%) |
N01 now.jpg | https://github.com/ch-tseng/farmbot | |
02 | [pathname] | 分析結果文字 | 種子出土分析 | N02 now.jpg | ||
M | Machine learning related funcitions | |||||
S | Report related functions, 儘量保持跟 FarmBot R command 相似,此主體為 Camera Comander | |||||
01 | Current command started | |||||
02 | Current command finished successfully | |||||
03 | Current command finished with error | |||||
04 | Current command running | |||||
11 | [mini-seconds] | delay mini-second | ||||
12 | [pathname] | run script file | ||||
83 | V0.0.4 | Report software version | ||||
99 | Debug message | |||||
C | Commander related functions | |||||
10 | type | R01-R04 | video streaming start. h.264 | C00 h264 | ||
11 | R01-R04 | video streaming stop | ||||
P | Scheduler/Period related functions | |||||
00 | directory minutes | take images every x minutes | S00 images_dir 60 | |||
U | Upload related functions |
命令細部說明與參考資料
N01-植栽覆蓋率
系統架構
使用 python, python-camera, opencv
Prototype
Features:
# 1. Support CLI
# 2. start/stop socket command interface
# 3. support socket input command and response
# 4. CLI and socket command can be support at the same time.
python camera_commander_prototype.py
----- FarmBot Camera Commander V0.0.4 -----
FCC>help
Documented commands (type help <topic>):
========================================
help net_open quit r83 stop
FCC>r83
V0.0.4
FCC>net_open
FCC>starting up on localhost port 10000
waiting for a connection...
connection from 127.0.0.1,58884
received:R83
demo code: echo data back to client
V0.0.4
stop
quitFCC>quit
--- 執行 client
python echo_client.py
connecting to localhost port 10000
sending "R83
"
received "V0.0.4
"
closing socket
-- 使用 netcat 來測試也可以
echo "R83" | nc localhost 10000
V0.0.4
周期執行系統設計
test_serial.py
既然 FarmBot 的 Arduino 是 G-Code processor, 只需從 UART 餵給 Commands 就可以驅動
所以如果我們有一個程式能夠把編好的Commands檔案 讀進來,一個一個命令去執行,那好像就是簡單的自動化了
目前所有讀進來的命令,都直接往 Arduino 送,所以只支援 Arduino code 內支援的 command set, 也就是 FarmBot Arduino Commands
本程式有幾個簡單的驗證功能
test_serial_cmdgen.py
那如果再有一個程式,能夠產生走到每個植物上,然後澆水的命令檔,那好像就能自動澆水了
希望支援矩陣模式的種植安排,以及直接預設好位置的種植安排。
可產生到每個植物位置,然後執行幾個命令的 script 產生
video_count_sprout.py
要是有隻程式,分析記錄發芽縮圖軟體的影像,每個小時計算已發芽的總數,然後輸出分析結果。來畫出一個發芽總數的圖表。
’exe_cmd [ -h ] [ -v ] [ -d ] [ -t ] [-g]’
-v: video pathname
-d: output directory
-t: start time, ex: 20170507010203’
-g: frames gap time in seconds. default: 3600’
-r: reference frame. default: first frame’
1. Video 轉出 images - OK
2. 配上對的時間檔名 - OK
3. 每個檔案去跑一下 CH 的種子計算 - OK
程式需使用 CH 的 library 目前需要執行在這個目錄上,請手動配置
https://github.com/ch-tseng/farmbot
輸出範例:
遠端 SSH 連入,會有沒有 X 的問題,暫時用以下技巧躲過
在本地端使用 X Window 環境,在 Mac 上可以使用 XQuartx
在本地終端機
> xhost +
> ssh pi@[ip]
> export DISPLAY=:0.0
> python video_count_sprout.py
參考