Adventures in tech 

Home Courses CS373 2D Robot localization
formats

2D Robot localization

The first week of CS373 at Udacity was fun… and tough! Homework 1.4 is about the localization of a robot in a 2D red-and-green world, you have to calculate the probability distribution given the “world”, a list of measurements and a list of motions. Your sensor is pretty broken (senses right only 7 times out of 10) and the 2D robot really moves only four times out of five. You have to write some Python code that will calculate and show the distribution.

I couldn’t help but play a bit around it: I decided to develop a webpage that would allow you to see the world and the distribution, and to interactively move a robot in this 2D world. Mostly, I wanted this page to help test the Python code, so first of all I needed an embedded Python interpreter in Javascript. Embedded, because I do not have the skills or the willingness to secure my website so that I would execute anyone’s Python code on my backend host :-D

There are several projects online projects that allow you to execute Python code, such as Codepad, TryPython and Ideone jsut to name a few, but I needed something that I could embed in my page and where I could access the Python environment from Javascript, so I ended up choosing Skulpt: it’s small, downloadable, open source and Javascript-scriptable. If you check their website they even have a very neat editor with syntax highlighting. The code is hosted on Googlecode and you can check it here, but if you want to use it beware: user documentation is zero, so you really have to dive in the Javascript code and find your way around, it requires some skills. Nice thing is that the Python functions are implemented using standard JS code, so once you find the right place, you can really tweak it.

And the reason that I bothered tweaking it is that the modulo operator does not behave in the expected way for negative left-hand operand:

-1 % 5 == 1

while, according to Python, it should be 4. Also, booleans are not promoted to integers, so I patched those two things to make it work. If you’ve seen the code in Unit 1 you know why those patches are needed. Still, the modulo operator doesn’t work as expected for negative right-hand operators, but it really doesn’t matter in this case.

Check my 2D robot localization demo here.

 

 
 Share on Facebook Share on Twitter Share on Reddit Share on LinkedIn
2 Comments  comments 

2 Responses

  1. I conceive this internet site has some real excellent info for everyone. “To be able to be caught up into the world of thought — that is being educated.” by Edith Hamilton.

  2. Hi Anna Chiara,
    I’m doing (by now have done) CS373, and I wanted to let you know I enjoyed your blog. Thanks for that and all the contributions on the discussion forum.
    All the best,
    Neale

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

© Anna Chiara Bellini 2012-2013