I use motor driver IC (TOSHIBA TA7291P) to control the BeagleBone tank.
Motor driver needs two control signal. Because beaglebone has many GPIO pins, I use it to control each motor driver.
To use GPIO pin on Ubuntu , we have to do below step per each pin.
change omap_mux
export pin
decide signal direction
input/output signal
It is time-consuming steps to do by hand, so I made a GPIO helper class.
"""
webcamera server
for opencv 2.3
"""
import SocketServer
import cv2.cv as cv
import numpy
import socket
import sys
#for OpenCV2.3 python interface
class TCPHandler(SocketServer.BaseRequestHandler):
capture=''
def handle(self):
# self.request is the TCP socket connected to the client
self.data = self.request.recv(1024).strip()
print "%s connected:" % self.client_address[0]
frame=cv.QueryFrame(capture)
jpegstring=cv.EncodeImage('.jpeg',frame).tostring()
print len(jpegstring)
self.request.send(jpegstring)
if __name__ == "__main__":
HOST, PORT = '192.168.111.40', 12345
#init camera
cameraid=0
capture=cv.CreateCameraCapture(0)
cv.SetCaptureProperty(capture,cv.CV_CAP_PROP_FRAME_WIDTH,320)
cv.SetCaptureProperty(capture,cv.CV_CAP_PROP_FRAME_HEIGHT,240)
if not capture:
print "Could not open camera"
exit()
server = SocketServer.TCPServer((HOST, PORT), TCPHandler)
# Activate the server; this will keep running until you
# interrupt the program with Ctrl-C
server.capture=capture
server.serve_forever()
コマンドセンター側
'''
Image receiver
for OpenCV 2.4 python interface
'''
import socket
import sys
import numpy
import cv2
# for opencv 2.4.2
HOST, PORT = "192.168.111.40", 12345
# Receive data from the server and shut down
quitflag=False
recvlen=1
def getImageFromServer():
sock=socket.socket(socket.AF_INET,socket.SOCK_STREAM)
sock.connect((HOST,PORT))
sock.send('HELLO\n')
recvlen=100
buffer=''
while recvlen>0:
receivedstr=sock.recv(1024*8)
recvlen=len(receivedstr)
buffer +=receivedstr
print '%d bytes received' %len(buffer)
narray=numpy.fromstring(buffer,dtype='uint8')
decimg=cv2.imdecode(narray,1)
sock.close()
return decimg
while 1:
img=getImageFromServer()
cv2.imshow('Capture',img)
key=cv2.waitKey(100)
if(int(key)>27): break
img=''
'''
python-opencv tutorial
Make gaussian pyramid
Usage:
05_GaussianPyramid.py
'''
#import opencv library
import cv2
import numpy
imgwidth=800
imgheight=800
img_original= numpy.zeros((imgheight,imgwidth,1),numpy.uint8)
#draw some circle
for i in range(1,6):
cv2.circle(img_original,(20*2**i,20*2**i),i*10,(255,255,255),2)
#pyrDown(...)
# pyrDown(src[, dst[, dstsize[, borderType]]]) -> dst
#make half size and quater size
img_half=cv2.pyrDown(img_original)
img_quat=cv2.pyrDown(img_half)
cv2.imshow('original',img_original)
cv2.imshow('Half size',img_half)
cv2.imshow('Quater size',img_quat)
cv2.waitKey()
cv2.destroyAllWindows()
Webカメラからの画像取り込み
'''
python-opencv tutorial
Get image from web camera
Usage:
06_webcamera.py
'''
#import opencv library
import cv2
#VideoCapture(...)
# VideoCapture() ->
# or VideoCapture(filename) ->
# or VideoCapture(device) ->
#get capture object
cameraid=0
capture=cv2.VideoCapture(cameraid)
isopen=capture.isOpened()
if(False==isopen):
#retry to open camera
capture.open(cameraid)
isopen=capture.isOpened()
if(False==isopen):
#could not open camera...
print 'Could not open camera.'
exit()
#get camera attribute
imwidth=capture.get(cv2.cv.CV_CAP_PROP_FRAME_WIDTH)
imheight=capture.get(cv2.cv.CV_CAP_PROP_FRAME_HEIGHT)
print 'img width %d height %d ' % (imwidth,imheight)
print 'press ESC or q to quit'
#capture image and display to monitor
while True:
ret,frame=capture.read()
if not ret:
print 'Could not capture frame.'
exit()
cv2.imshow('Captured Frame',frame)
inputkey=cv2.waitKey(100)
c=chr(inputkey & 255)
if c in ['q',chr(27)]:
break
#release capture
if(capture.isOpened()):
capture.release()
cv2.destroyAllWindows()
GPIO access that may sleep Claiming and Releasing GPIOs GPIOs mapped to IRQs Emulating Open Drain Signals What do these conventions omit? GPIO implementor's framework (OPTIONAL) Controller Drivers: gpio_chip Platform Support Board Support
全部パス。
以下の項目が一番疑問に思ってたところの解答っぽいです。 Paths in Sysfs
以下の3種類のエントリーが /sys/class/gpio 内にあります。