2015年5月25日 星期一

Bluetouth Joystick on RPi2 (Python)

網路上找到一個有趣的一段程式碼

import subprocess
import pygame
pygame.init()
ps3 = pygame.joystick.Joystick(0)
ps3.init()
while True:
  try:
      pygame.event.pump()
      buttons = [ps3.get_button(0),ps3.get_button(1),ps3.get_button(2),ps3.get_button(3),ps3.get_button(4),ps3.get_button(5),ps3.get_button(6),ps3.get_button(7),ps3.get_button(8),ps3.get_button(9),ps3.get_button(10),ps3.get_button(11),ps3.get_button(12),ps3.get_button(13),ps3.get_button(14),ps3.get_button(15),ps3.get_button(16)]
      axis = [ps3.get_axis(0),ps3.get_axis(1),ps3.get_axis(2),ps3.get_axis(3)]
      print(buttons)
      print(axis)
      subprocess.call("clear")
   except KeyboardInterrupt:
      print("Exiting")
      raise

首先先將Bluetouch搖桿與RPi2連線,目前我是使用startx的方式,以圖形介面的方式去操作抓到藍芽週邊.希望有文字模式的操作方法.有空再研究
確定手把連線後.接者使用python執行這段描述.
針對Button的這個矩陣.總共會有16個參數.對應axis這各參數總共有4個參數.
目前針對WAMO Pro這隻藍芽手把抓到的位置對應為
Button=[A,B,BL,X,Y,BR,LB,RB,LT,RT,LA,RA,0,0,0,0]
Axis=[LX-,LX+,LY+,LY-,RX-,RX+,RY+,RY-]
X-min=-1;
X+max=999969482421875
Y-min=-1;
Y+max=999969482421875
這樣看來Axis為類比訊號.
Button只有On/Off的1 or 0差異.
這樣子藍芽手把可以當作搖控的設備了.現在已經知道python與手把的對應關係了.
要弄出一部藍芽遙控車也不是不可能了.
萬事不具,更欠東風啊…神啊~請賜給我一個車體基盤,加上一個L298N馬達驅動版吧..
我的霹靂車計畫就可以開動.
霹靂車,尖端科技的結晶,是一部人性化的萬能電腦車。笑~~~

1 則留言:

  1. http://www.correlatedcontent.com/blog/bluetooth-keyboard-on-the-raspberry-pi/

    回覆刪除

2024東京迪士尼,愛與夢想的樂園行

疫情的關係, 很多年沒有出國旅遊了.這回計畫出遊日本.歷經磨難的挑選.最後勝出的行程是五福旅行社的"銀色雪東京五日-戲雪,和服體驗,迪士尼"這標題簡單的標註出此行的目的. 上回去東京是20年前了.可以參考一下過去 2004年的Blog紀錄 心中的願景是能看到前...