Friday, June 28, 2013

OpenCV Vision of the future!!

Its been awhile since I made a post, so I will make a few updates
 - pi2go Is working even fixed that pesky GUI not updating issue with a Qthread.
 - pi2go also has its very own 7in screen I have yet to mount. (Ill do a post with updates soon.)

- Halo is now open source!! Yeah, I know its kind of old news but im loving the functionality.

But now its time to describe my latest project and why I havent been around for awhile: OpenCV.

In what else but Python --->> but eventually MATLAB for Simulink reasons.

OpenCV is "Open Computer Vision." The idea behind this is to make most computer vision tasks as easy as possible to complete. So what am I doing with it? I'm trying to integrate object avoidance with stereo vision. So far I have managed to make a disparity map using 2 uncalibrated images.

You really cant see to much relation yet between the 2 figures.

Figure 1

Figure 2

Figure 1 the disparity map shows that close objects as black and farther objects as white, basically the depth of the image using. In order to get a clear image the camera needs to be calibrated. From this map I would like to be able to pick out individual objects that are extremely close by.


I have been testing with 2 close images taken from my nexus 4....sooooo not too accurate. Once I get the stereo vision up/working and calibrated These images will be much better. Stay tuned!!!

**For those that care
OpenCV 4.5.2 ~cv2 , Python2.7, scipy

Sunday, June 9, 2013

Ouch!!! I broke Unity/How to fix it

So as many of you know the dangers of playing with graphic drivers in Linux. They have to potential to render your desktop useless. In fact many remain with open source drivers for this very reason. Well anyway I have been playing around with AMD drivers for the last month and has proven to be a miserable feat. More then once this has rendered Unity broken missing both window decorators and system panels  *weep. To top it all off the Unity plug-in would become disabled from Compiz and would not re-enable for multiple reasons. (Open gl, window shutters, ...blah blah)

Anyway.......
Unity malfunction is not exclusive to graphic driver installations. For this reason I think it is important to know these following 2 commands.
sudo dconf reset -f /org/compiz/
This command resets all dconf settings that may have changed. "dconf" Is a program for editing all of your configuration files. If by chance you are missing this program run the following command.
sudo apt-get install dconf-tools
The second Unity command I believe should be general knowledge is:
 unity --reset-icons &disown
This command may not need to be run after dconf, However it is extremely useful if one decides to play with themes or other basic UI improvements.



I hope these are useful to you. I also hope you will never need them haha.

=================================================
Next I would like to do another write-up on helpful ssh tools including scp and nmap. On another note maybe dd and pv; pretty much anything I find useful and use on an almost daily basis.

Let me know if there is any particular command you would want a write-up on.

Tuesday, June 4, 2013

pi2go Is working 100%

For those that may like an update on how well pi2go is working. Well the answer is quite well actually. For this reason I will walk you through its functionality and how it works. pi2go Is written in python 2.7 utilizing pyQt4 and pySerial for Raspberry Pi. It is being created as an easy UI for a vehicle computer. So far the only feature is reading engine information from the OBDII sensor via Bluetooth.

First off in Figure 1 below  displays the given start screen.

Figure 1
As stated in a previous post I would like to place a clock in the blank space on the right. Before I attempt that I need a little more info on QThreads. Pressing the "OBDII" tab will bring up the OBDII scanning feature displayed in Figure 2 below.
Figure 2
These are the current engine stats that are being read. Currently the values are updated every 1sec, I will be adding selector so this value can be changed to personal preference. Pressing the display "Start" button will initialize the scanning thread. (Thats right this python novice introduced multithreading.) This simply mean the background process is taking place outside the main program so it does not slow itself down.
obdThread = Thread(target=self.write_to_UI(obdValue), args = (self,obdValue)) 
obdEvent = Event()
obdThread.start()
Figure 3 and 4 below display the running program.
Figure 4

Figure 3  
Above Figure 3 displays information as it comes in, before it is updated on Figure 4.
def write_to_UI(self,values):
"""Updates the UI with new values"""
# receive [speed, rpm, intake, coolant, load]
self.ui.lcdNumber_speed.display(values[0])
self.ui.lcdNumber_rpm.display(values[1])
self.ui.lcdNumber_inTemp.display(values[2])
self.ui.lcdNumber_coolTemp.display(values[3])
self.ui.lcdNumber_load.display(values[4])
QtGui.QApplication.processEvents() #Writes all pending changes to QT
return
The guts behind the scanning thread is all in pySerial. The code below show how the scanner obtains values from the OBDII sensor. This example is the speed however the method is the same for all.

First a serial port is connected, "rfcomm0" at a baud rate of "38400".
self.serialIO = serial.Serial('/dev/rfcomm0', 38400, timeout=1)
Then using the serialport you send send a hexadecimal PID which can be found here. In this case we send "01", "0D" and want a return "\r". ("01" stands for the current value, "0D" is speed.)
self.serialIO.write("01 0D \r")
The above line will return a list of 1 string "['410D1D\r\r>']" not including quotes. The bold values are what is needed. They are a hexadecimal value so the code below first pulls the needed values by treating the string as a list. Then converts (Using the example) from a string, '1D', to hex value '0x1D' to an integer, base zero, 29 to a float 29.0 The final answer being in Kph
(I apologize for that long run on sentence I hope you were able to follow)
speed_list = self.serialIO.readline().split(' ')
speed_hex = speed_list[0][4:6]
speed_float = float(int("0x"+speed_hex, 0))
 
I then converted the value to Mph and returned it in a list with other values.
speed_float = speed_float*0.621371 #Comment out if you would rather have Kph
return speed_float
The last feature I added in this version is the ability to clear error codes. It is placed in the setting tab as depicted in Figure 5.
Figure 5
This tab will have more options evenly and will have feedback to the clearing function.

------------------------------------------------------------------------------------------------------------------------------
There you have it the basic functionality of pi2go and how it works. Any feedback will be outstanding!
As always if you would like to follow/keep up on this blog or check out github. I have many new features to add.

**For those that care written in Python2.7 utilizing pyQt4 over pySerial. Issue tracker