# RF Remote 遙控器發射端
--------------------------------------------------------
StartUp 當啟動時()
sendZeroSet搖桿校正
Radio Group 廣播群組設為 = 1
--------------------------------------------------------
Forever 重複無限次()
X1 Y1 = (x,y)
buttonProc按鈕程序
--------------------------------------------------------
KEY D
sendZeroSet搖桿校正
--------------------------------------------------------
buttonProc 按鈕程序()
KEY 1 2 3 45670
--------------------------------------------------------
sendZeroSet 搖桿校正()
X0 Y0 = (x,y)
--------------------------------------------------------
# RF Car 機器人接收端
# Variables 變數定義
----------------------------------------
KEY 0=未按下 1=A,2=B,..34567(按鍵)
X0,Y0 類比搖桿初始位置值
X,Y 類比搖桿移動位置值 X=X1-X0,Y=Y1=Y0
speed = min(abs(Y)*2,1023)
speed_L = speedFitRange(speed+(X*2))
speed_R = speedFitRange(speed-(X*2))
----------------------------------------
# Status Flag 狀態旗標
flag_set_zero 類比搖桿是否有歸零
flag_update 是否有收到更新值
flag_run 馬達是否啟動
----------------------------------------
--------------------------------------------------------
StartUp 當啟動時()
flag_set_zero = false
flag_update = false
flag_run = false
Radio Group 廣播群組設為 = 1
--------------------------------------------------------
Forever 重複無限次()
If flag_set_zero
setEnable
If flag_update
If flag_run
speed = min(abs(Y)*2,1023)
speed_L = speedFitRange(speed+(X*2))
speed_R = speedFitRange(speed-(X*2))
Y>32
正轉 = speed_L
正轉 = speed_R
Y<-32
反轉 = speed_L
反轉 = speed_R
If KEY = 3
...
If KEY = 4
setDisable
--------------------------------------------------------
Radio Received 當收到廣播鍵值(name,value)
If name=X0,
X0=value
flag_set_zero = true
If name=Y0,
Y0=value
flag_set_zero = true
If name=X1,
X=X1-Y0
flag_update = true
If name=Y1,
Y=Y1-Y0
flag_update = true
--------------------------------------------------------
Radio Received 當收到廣播數字(reveivedNumber)
KEY
--------------------------------------------------------
setEnable()
flag_run = true
--------------------------------------------------------
setDisable()
flag_run = false
--------------------------------------------------------
Comments
Post a Comment