Showing posts with label Python. Show all posts
Showing posts with label Python. Show all posts

Thursday, 1 March 2012

Robot Localization using Montecarlo Localization

The problem of localising a robot in a known environment is quite interesting. I would like to share with you my solution to the homework assignment for the unit 1 of the "CS 373 Programming a Robotic Car".

The environment is a discrete map (colours matrix) where each area can be green or red. The robot can sense the colour (sense function) of the area where is currently on and can move in any directions (move function). To make things more interesting and close to reality the measurements and the motions are subjected to errors and this is represented by the variables sensor_right and p_move. Given a list of measurements and a list of motions the problem is to create a matrix of probability that describe where the robot is likely to be after all the specified moves.

More information about the definition of the problem can be found on Udacity.

I used the python module unittest for this purpose. This is one of the unit tests that I defined for the problem:



This is the main code that does the actual calculation:


The current algorithm used to solve this problem is called Montecarlo Localization.

You can find the full code in my personal repository.




Tuesday, 14 February 2012

Learning the basics of Python in an evening

I decided to enroll the free two courses delivered by Udacity: Building a Search Engine and Programming a Robotic Car. There will be programming contests and the language used will be Python. I never programmed in Python before and so I decided to start learning the language.

If you already know a language like Java, C# or C++ learning Python is relatively easy.

I started to quickly read the official tutorial:
I think that it is quite good as a starting point and teach you all the basics: control flows, data structures, modules, input and output, errors and exceptions, classes and standard library.

An another interesting resource is Learning Python in 10 minutes. This collects in a single post the basic Python syntax.

After the following reading I decided to start doing a simple coding session. I decided to implement a Code Kata and in particular the Kata Four: Data Munging.

First of all, I installed the python engine:
I decided to use the version 2.7 instead of the latest 3.2. It seems that the latest is quite recent and there are lots of breaking changes and the conversation process of many libraries is still in progress.

The next step is installing the development environment. It seems that there is a unproportional list of editors out there to develop in Python. I personally love Visual Studio and the idea of a single integrated environment and for this reason I found a Python extension for Visual Studio that was perfect for me:
Ready !!!

You can create a new project in the usual way:


and start adding files in the solution explorer:


The tool has also some good intellisense that helps in writing code. Considering that Python is a dynamic language this is quite impressive.

Here few examples:






This is an extract of the code:



You can find the complete source code in my personal repository:
I think that the best way to learn Python is using it. I am looking forward to play with it during the courses.