Archive

Archive for the ‘Software’ Category

Kubuntu Karmic Koala is out!

October 29th, 2009
Kubuntu Karmic Koala

Kubuntu Karmic Koala

Kubuntu Karmic Koala is finally out! I use it since the Release Candidate came Oct. 22 nd, and it is absolutely awesomely mind-blowingly fabulous. All of the kinks in Jaunty have been fixed and a lot of new features have been added.

Kubuntu?

Why am I talking about Kubuntu and not about its more popular sibling Ubuntu? Well, very simply because KDE kicks Gnome’s ass any day (while blindfolded and with all of its finger stuck in its nose). I know that seems like a very bold and unjustified statement, well it is indeed very bold but totally justified.

The main difference about KDE and Gnome, besides the fact that the KDE foundation is much more solid, flexible and portable, is the mindset. In KDE you can configure (trough a nice GUI) pretty much everything, whereas in Gnome, you get a bunch of very comfortable defaults that (although they can be modified) are not intended to be fiddled with too much.

Also, KDE is much more than a desktop environment and provides a full suite of programs that do almost everything you could want to do. These programs also integrate very well together and provide as many more features and options than any sane person would need or be able to use (but who likes sane people anyway?).

Quick Review

My Desktops (Grid View)

My Desktops (Grid View)

I am currently using the 64-bit version of Kubuntu and it is performing incredibly well. The system (my laptop) boots in around 40 seconds and turns off in less than 15 seconds. The graphical performance is flawless and I can benefit from smooth performance even when doing very processor intensive tasks (such as stitching photos together).

Also, It comes with Ubutu One (a remote storage service) which is pretty convenient for sharing and backing up files.

I’ll try to do a screencast and post it in order to show off the Koala.

Software

Panoramaker

October 4th, 2009

As promised before, here is the Python script that runs my panoramic camera hardware. It is a very quick prototype and is by no means intended for widespread use since it requires manual calibration. Nevertheless, it might be very useful to those seeking to learn how to position the servos or control a digital camera through Python.

This script requires my Pololu library and includes some codes from here in order to control the camera. Besides the basic requirements of lib_pololu, the script also requires gPhoto. If you are running Linux, you most likely already have it but in case you do not, you can install it through your favourite package manager or by using the console (e.g. for Ubuntu/Debian):

sudo apt-get install gphoto

If you are using some other OS, you can download gPhoto from here.

The Code

Download
# Adding the path to the lib_pololu.py file to your modules path.
# Assuming that the file is at /your/path/to/the/library/lib_pololu.py
import sys
sys.path.append(‘/your/path/to/the/library’)

# Import the lib_pololu module
import lib_pololu

# Import the serial communication and time modules
import serial
import time

# Open serial port
port = serial.Serial(‘/dev/ttyUSB1′)
port.baudrate=2400 #set an appropriate baudrate

# Camera Code (from vmlaker.org)
import os, re
from subprocess import call, Popen, PIPE

def run(command):
    print ‘Running:’, command
    p = Popen(command, shell=True, stdout=PIPE)
    lines = p.stdout.readlines()
    for line in lines:
        print ‘Stdout :’, line,
    return lines
def capture():
    c = ‘gphoto2 -capture-image’
    sout = run(c)
    firstLine = sout[0]
   
    expr = ‘New file is in location (.*?) on the camera’
    comp = re.compile(expr, re.DOTALL)
    path = re.findall(comp, firstLine)[0]
    dir, fname = os.path.split(path)
   
    c = ‘gphoto2 -get-file %s -folder %s’%(fname, dir)
    run(c)
   
    c = ‘gphoto2 -delete-file %s -folder %s’%(fname, dir)
    run(c)
   
    c = ‘gphoto2 -storage-info’
    run(c)

# Calibration Parameters
# These parameters set the limits and reference positions of the rig.
# They have been obtained trough trial and error.
horizontal = 93.5
front = 95.5
back_l = 84.5
back_r = 107
top = 70
bottom = 110

# Create two motors
# There are associated to the panning and tilting motion of the rig.
tilt = lib_pololu.Servo(port, 0, 1150, 4650)
pan = lib_pololu.Servo(port, 1, 1200, 4987)

# Define a capture routine
# This is a simple loop that takes pictures in order to produce a
# 360 deg panorama.
def capture_pano():
   
    # Capture parameters
    steps_h = 16
    steps_v = 4
    step_h = (back_r - back_l)/steps_h
    step_v = (bottom - top)/steps_v
    pos_v = bottom

    while (pos_v >=top):
        tilt.set_pos(pos_v)
        pos_v = pos_v - step_v
        pos_h = back_l
        while(pos_h <= back_r):
            pan.set_pos(pos_h)
            pos_h = pos_h + step_h
            time.sleep(2)
            capture()

# Initialize the motors
tilt.set_pos(horizontal)
pan.set_pos(front)
time.sleep(2)

# Capture the panorama
capture_pano()
 

Again, many thanks to RobotShop who provided the hardware that made this project possible.

Project, Robotics, Software

Pololu Python Library

July 16th, 2009
Pololu Micro Serial Servo Controller

Pololu Micro Serial Servo Controller

I started writing a library for controlling the Pololu motor controllers with a computer trough a serial port.

I’m writing this in Python so the code can be cross-platform but I would be very glad to have some feedback about running it on other OSs than Linux. Actually, any feedback would be very welcome.

As of now it can interface with the Pololu Micro Serial Servo Controller that I got form RobotShop. I am planning to use this code in my upcoming project RobotShop is sponsoring. I will supplement this library as I get newer hardware to work with.

I know there is already a python interface for it but I really wanted to have an object oriented way of managing motors (i.e. they can be instantiated and controlled more easily).

You can download the library here: lib_pololu.py (you will need to change the extension of the file to .py instead of txt).

In order to properly use this library you will require:

  1. Python
  2. Pyserial

If you use a civilized OS you may be able to get all this by typing this in a command prompt:

sudo apt-get install idle python-serial

Here is a sample script that will use the library in order to control a servo: servo_example.py (you will need to change the extension of the file to .py instead of txt).

Download
# Adding the path to the lib_pololu.py file to your modules path.
# Assuming that the file is at your/path/to/the/library/lib_pololu.py
import sys
sys.path.append(‘/your/path/to/the/library’)

#Import the lib_pololu module
import lib_pololu

#Import the serial communication module that should already be installed
import serial

#Open serial port
port = serial.Serial(‘/dev/ttyUSB0′)
port.baudrate=2400 #set an appropriate baudrate

#Create a motor assuming that the motor is connected to the connector
#number 0 on the controller. The two numbers (1150 and 4650) are
#the calibration values corresponding to the 0 ans 180 deg positions
#respectively. These are the numbers that should be sent to the servos
#using command 4 with the methos send_command() in lib_pololu
motor = lib_pololu.Servo(port, 0, 1150, 4650)

#Playing around with the motor
motor.set_pos(45) #sets the posotion of the motors in degerees.
motor.set_speed(100) #sets the speed at a value between 0 and 127
 

Note for Redmond OS (aka Window$) users: you will need the Win32 Python extension for pyserial to work.

Project, Robotics, Software

Making Panoramas

May 9th, 2009

In my trip to San Francisco, I had the chance to see many beautiful things. And I wanted to be able to remember them and show them to my friends and family.

San Francisco Seen Form Twin Peaks Park

San Francisco Seen Form Twin Peaks Park

Besides taking simple photos, sometimes you need a wider view- angle to really capture the scenery. The obvious solution to this is making a panorama. This means you take many pictures of different sections of your subject and then align them and stitch them together so to form a bigger picture.

Many people believe this is a very difficult procedure and that the results are never as good as expected, and they are partially correct. In order to get a nice looking panoramic picture hat will align and stitch together correctly you need to follow some rules:

  • Make sure that contiguous pictures have a good 30% overlap between them.
  • Make sure the overlapping areas contains some hard object, like a building. If they overlap only over the sky or some water, then the stitching together will be more difficult.
  • Make sure you follow a simple pattern when shooting the photos. Follow a horizontal line, for instance, and shoot the pictures in order. Also, if your making a taller panorama, I suggest you shoot many horizontal lines that will stack up together. This will make things easier when recognizing which photos to stitch together.
  • Make sure all the pictures have a similar exposure. This should be no problem if you are shooting your pictures all at once.
  • Make sure your subject is always on the same focal plane. You can have many focal panes but it will make the stitching more difficult.

Once you have shot all the pictures you can start the stitching. In order to so so, you can use an excellent software package called Hugin. Of course since I’m using it, Hugin is open source and (thus) cross-platform. Is is a very intuitive program to use and since there are many good tutorials about it, I won’t be outlining the instructions on how to use it.

Once you stitched your images together (which can be done in the three steps the wizards takes you trough) you will end up with a big TIFF or JPG file. Now you are basically done. Now you just need to crop it and made any desired adjustments with a picture editing program lie Gimp.

The only problem is that if you want to share this picture it can be hard since it may be too big for sending by email and will take a long time to (upload and) download if you put it on a website.

Now you can use the Google Maps Image Cutter. This little Java program developed by UCL enables you to use the Google Maps engine as a picture viewing system. It creates many copies of your image at various resolutions and chops those images into small square pieces. Then when you view the image trough the google maps engine, you are only loading the small squares at which you are currently looking at the resolution corresponding to your zoom level.

Here you can enjoy a few examples I made (click on the title to view them in full screen).

Title: Downtown San Francisco
Description: A panorama shot from the Twin Peaks Park.
Title: Downtown and East San Francisco
Description: A larger panorama shot from the Twin Peaks Park.
Title: South San Francisco
Description: Another panorama shot from the Twin Peaks Park.

Keep in mind that Hugin is very powerful and can do much more than simply stitching a few images together. Also, there might be a few issues with the file writing routine when trying to run the Google Maps Image Cutter in Linux.

Info, Project, Software, Work in progress

To WordPress from Blogger

April 17th, 2009

I recently moved my blog from Blogger to an independently hosted WordPress installation and I needed to dynamically redirect the visitors going into the old pages so that the could see the new ones.

There are many tutorials on how to do this on the net but they usually involve fairly complex procedures and require modifying the Blogger HTML code and installing some plug-ins in WordPress. But, what I really wanted was a simple way of redirecting each blog post into its new version.

My solution:

I decided to write a little java script code that will do the job since it is a fairly simple task. All that is required to translate one of my permalinks is to strip the “.blogspot” part, and the “.html” part (see the example below).

Example:

Old address: http://carlitoscontraptions.blogspot.com/2009/03/smoking-cyclops.html

New address: http://carlitoscontraptions.com/2009/03/smoking-cyclops/

The script:

<script type=”text/javascript”>

function redirect()
{
oldURL = document.URL;
oldURL = oldURL.replace(/.blogspot/, “”);
oldURL = oldURL.replace(/.html/, “/”);
window.location.href=oldURL;
}

window.setTimeout(’redirect()’,5000);
</script>

This script consist of two parts: (1) a function that strips the unneeded parts from the current page URL, and (2) a time delay that executes this code after 5 s.

The only thing left to do is to insert this code into an HTML/Java script box in the Blogger layout editor and that’s it. No messy template edition required.

Project, Software