Mostrando entradas con la etiqueta BeagleBone_Black. Mostrar todas las entradas
Mostrando entradas con la etiqueta BeagleBone_Black. Mostrar todas las entradas

miércoles, 9 de septiembre de 2015

Firing Up (BeagleBone Black, WebCam, Missile Launcher and OpenCV)

This post was originally posted on Firing Up (BeagleBone Black, WebCam, Missile Launcher and OpenCV).



If you are an SAP Employee, please follow us on Jam.


My good friend John Astill came to visit us at d-shop some time ago…and he saw the Thunder Missile Launcher that I bought as a Christmas present for my team dinner. He told me…”Blag…you should build that app that fires up missiles when you put a color or object in front of the camera”…that got me thinking of course -;)

So John…this blog is for you 

So, let’s start…

You will need OpenCV installed…so the regular way should work…

sudo apt-get install opencv

And OpenCV should be installed and ready to use now…

Next…I needed to hack the Missile Launcher in order to be able to make it fire…so this is where the fun begins…I hooked the Missile Launcher to my Linux box on VMWare and made a lsusb -vv command to get the information about the USB device…


Here we can see that the IdVendor is 0x2123 and the idProduct is 0x1010. This doesn’t really give us anything as we don’t know to pass the information we need in order to make it work…so next step was to sniff the device in order to get the USB commands…I did this using SnoopyPro a USB Sniffer Tools for Windows…and just notice that I couldn’t make it work properly on Windows 7, so I need to use my old and nice Windows XP VMWare Image…and install the Dream Cheeky software...


Once we have SnoopyPro running, need to connect the Missile Launcher and click on File --> Unpack Drivers…


Next, we need to look for the correct IdVendor and IdProduct and right-click to select Install and Restart.


This will allow us to log everything that happens while using the device. By default, at least for the Missile Launcher…it will log 14 lines that don’t matter much to us…but when we hit for example the Up button…then we get more interesting info…


This is basically saying that to make the launcher move up, we need to pass the following…

0x02 0x02 0x00 0x00 0x00 0x00 0x00 0x00

Now…the part that interests us is the Fire action…so let’s explore it…


This one is

0x02 0x10 0x00 0x00 0x00 0x00 0x00 0x00

Cool…now we’re getting closer…but…there’s a piece that it’s missing…how do we send this command? Easy…just take a look at the Transfer command…


This command tells us that we need to pass the information like this…

0x21 0x09 0 0

Followed by the action we want to perform…

In order to use the device on our BeagleBone…we need to install something first…

pip install pysub

This library will allow us to connect and more important, send commands to our device.

As we’re going to use a Camera and the Missile Launcher both at the same time…we need a USB Hub that it’s powered…otherwise, it will never work…I got this one from Amazon.

So…power up the USB Hub and connect both WebCam and Missile Launcher, connect the Hub to your BeagleBone Black and then connect the BeagleBone to your laptop…

Use Nano or any other editor of your choice and create a file called Thunder.py

Thunder.py
import cv2
import numpy as np
import usb.core

cam = cv2.VideoCapture(-1)
cam.set(3, 960)
cam.set(4,720)
s, img = cam.read()

dev = usb.core.find(idVendor=0x2123,idProduct=0x1010)
try:
            dev.detach_kernel_driver(0)
except Exception, e:
            pass

winName = "Thunder"
cv2.namedWindow(winName, cv2.CV_WINDOW_AUTOSIZE)
while s:
        s, img = cam.read()
        key = cv2.waitKey(10)
        if key == 27:
                cv.destroyWindow(winName)
                break
        hsv = cv2.cvtColor(img, cv2.COLOR_BGR2HSV)
              lower_green = np.array([38, 100, 50])
              upper_green = np.array([75, 255, 255])

        mask = cv2.inRange(hsv, lower_green, upper_green)
        res = cv2.bitwise_and(img,img, mask=mask)
        cv2.imshow(winName, res)

        if cv2.countNonZero(mask) > 61000:
                dev.ctrl_transfer(0x21, 0x09, 0, 0,
                                  [0x02, 0x010, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00])


This code will basically open up the camera connection, and turn the display black so only the color that we want to track is shown. In this case, we want to fire up the missile launcher only when we see something “green”. As you can see we’re passing the transfer command as single parameters but the fire command as an array.

Now…the BeagleBone doesn’t have a display…so you could attach a monitor and a keyboard or you could do something more interesting and smart…

We’re going to install Tight VNC Server

sudo apt-get install tightvncserver

The first time you run it, it will ask you for a password for the current user, so go ahead and provide one…

And it will start running…so you will be able to open a Remote Desktop connection to your BeagleBone…now you only need a client to connect to it...

If you’re using Windows you can download the TightVNC Client from here…

http://www.tightvnc.com/download/2.7.10/tightvnc-2.7.10-setup-64bit.msi

http://www.tightvnc.com/download/2.7.10/tightvnc-2.7.10-setup-32bit.msi

If you’re using Linux you can simply download it using apt-get install like this…

sudo apt-get install xtightvncviewer

Run it on the terminal

Just provide the IP for your BeagleBone which should be 192.168.7.2:1 on the small box that will appear, provide the password that you setup for the VNCServer on the next screen and you’re all set…




If you’re using Windows…simply double click the tightvnc-jviewer.jar file and enter the following information…




In order to test this, we need to simply print a nice green box…


Then we can run the app…


And put the green box in front of the camera -;)


Sorry for the flaky picture…but the Missile Launcher was firing off and I had my phone on one hand and the green box paper in the other one -;)

Greetings,

Blag.
Development Culture.

miércoles, 3 de diciembre de 2014

Keep going with BeagleBone Black - Small Midi Piano

Looks like I'm on fire these days -;) I got somehow the plan of building new things on the BeagleBone Black as fast and often as I can...better way to learn for sure -:)

This time I have made a small Midi Piano...and excuse my total lack of Piano skills -:(


For this I used Python, AdaFruit_BBIO, PyGame and Timidity++.

Greetings,

Blag.
Development Culture.

martes, 2 de diciembre de 2014

DYI Simon Says - Using BeagleBone Black

Today...I was thinking what else could I built using the BeagleBone Black...and what came out was...making a Simon Says game! -:D


For this I simply used Python and AdaFruit_BBIO -:)

Of course...I need to add music and put a new color LED -;)

Greetings,

Blag.
Development Culture.

My first BeagleBone Black Project

As you may know...I started with the BeagleBone Black, almost a month ago...and of course...I have a project done already -;)

Sorry for the crappy quality of the video...but I shot it with my IPhone and uploaded to YouTube...


As you can see...it will play the Happy Birthday song while lighting the LEDs simulating a keyboard...not way cool...but it was a really good start for me -:)

I used Python, AdaFruit_BBIO, PyGame and Pyknon.

Greetings,

Blag.
Development Culture.

martes, 11 de noviembre de 2014

Starting up with the BeagleBone Black

I have always been a software guy...always immersed in programming and cool projects...but a couple of days ago I start playing with my first electronics toy...a BeagleBone Black...

I got myself The Ultimate BeagleBone Black Development Kit from Amazon which is really good to get you started...the only problem is that it comes with an PTBB-170B breadboard which is really small and doesn't really come with the ground and positive rails...so I have no clue how to use it...yet -:(



Good thing is...I work at the d-shop in SAP Labs Palo Alto...so we have plenty of regular and extra big breadboards -;)

Anyway...I started building up my first simple projects and using Adafruit BBIO on Python to code...which is really nice -:)





Of course...I still have a very long to go...but I have a couple ideas on my mind that could become really nice projects...let's see what becomes on my first adventure on electronics -;)

Greetings,

Blag.
Development Culture.