Where’s Susi? Airborne Orangutan Tracking with Python and React.js

camp-from-above-smallUpdate: read part II here

TL;DR: You are faced with a few thousand hectares of rainforest that you know harbours one or more orangutans that you need to track down. Where, how, and why do you start looking?

Background

About a year ago I was doing a lot of drone related work and was presented with the following problem: Would it be possible to use a drone to fly above the Bornean jungle and search for tagged orangutans?

To understand the motivation behind the question we need some background.

Continue reading

Deep Drone v2

2015-12-20 13.18.35In my last post I discussed my little flying object detector project that I’ve been doing for fun. While it worked it relied on communication with an external laptop in order to work (the on board odroid was not powerful enough to run the convnet model).

Hence, what better excuse to buy an NVIDIA Jetson TK1 dev board which should have more than enough juice to run everything on board the drone itself. As added benefit it should come in useful for my litter robot. I then added websocket support to the flask web app and you can now see the detections appear in real time on a map.

It took some fiddling to get the wifi to work with the Jetson and Im still surprised at how quickly the wifi degrades (even though Im using the 5GHz band to avoid collisions with the Tx/Rx). But it did work in the end:

It wasn’t the best place to test it out but I was short on time and it should be good enough to illustrate the concept

Still lots to do and too little time, but we keep chipping away. In particular the awesome folk from ErleBotics were kind enough to send me a Brain2, looking forward to try that out as well.

–Dirk

PS: on a related note, love what the guys from vertical.ai are working on

Deep Drone: A Flying Object Detector with caffe, dronekit, and zeromq

mapAbout a year and a half ago I saw Jetpac’s video of their Spotter app and I remember thinking at the time that it would be so cool to get this flying on a drone. I didn’t have the bandwidth to work on it at the time but ended up poking at it with Markus Aschinger at the ASI and with two A level students (Jawad / Isaac) from the Nuffield Foundation. While they did good work and it got me a step closer, it still hadn’t quite come together. Hence I sat down the past week to do a full rewrite, integrate it with a quad I had lying around and do a little demo. The result can be seen in the video below.

Continue reading

Taarifa Hackathons: Boston, London, Dar Es Salaam

taarifa_logoA lot has changed since I last blogged about Taarifa. We have been the recipient of a World Bank Innovation Fund grant and are going through the Geeks Without Bounds Humanitarian Accelerator. Work is really kicking off in earnest now and if you follow the project you will see much happening over the next two months.

In order to improve the platform and grow the community we are running a number hackathons around the world. You are hereby cordially invited to come hack on data, software (front and back end), hardware, and all the bits between in

The Challenge

There’s not much in the way of access to clean water in Tanzania. In the informal settlements, there are a bunch of water points, but many of them are broken. Rather than a continual process of putting in new ones, the local water engineers want to fix the existing ones – but they don’t know where the broken points are. This also prevents large-scale response organizations from accurately deploying resources (and seeing what initiatives are already working).

Continue reading

Raspberry Pi GPIO Workshop

Update: a writeup of the event by Lorraine is here.

A shot post to say that I am co-organizing a Raspberry Pi workshop with The IET Solent Branch at the University of Southampton on 25 April. For personal reasons I cannot make it myself that day but do go along if you want to learn about how to use the GPIO pins on your Pi board!

Raspberry Pi - 25 April Poster

Btw, if you can’t make it but live in the area, do checkout somakeit.org.uk. Recently launched and we now have a space!

–Dirk

Rewired State Parliament hack weekend 2012

Its 8:44 am and after 5 hours of sleep on my trusty Thermarest I feel quite refreshed, which is more than I can say about the people around me. Some have capitulated and lay scattered around the brightly lit room under their coats in front of their MacBook Air’s. Others are still in exactly the same position I left them 5 hours ago but the intensity has gone and eyes have glazed over. At least one person confirmed the geek stereotype and didn’t manage to hold his beer.

Update: Apparently Parlycloud won a special mention during the judging, thanks!

Continue reading

Coursera-dl: A Coursera download script

I have blogged about coursera.org in the past and as part of signing up to a number of courses I felt the need to easily download the videos, quizzes, notes, etc. locally for later use offline.

I quickly found a project on github (and there are a few) but wasn’t quite happy with the code. I cleaned it up to a relatively sensible state and it now does what I wanted it to do. The main additional features I wanted were: easily download multiple courses, support for quizzes/homeworks, and support for links to extra material (e.g, 3rd party sites, papers, etc).

Just do a “pip install coursera-dl” and then run as follows:

coursera-dl -u myusername -p mypassword -d /my/courses/ algo-2012-001 ml-2012-002

Code is in python and can be found on Github.

Some people have asked if they could donate something. If you wish you can do that here:

Donate Button

Update: if you have a feature request or want to report a bug please use the github issue system

–Dirk

Bridging Python and Matlab: Passing callbacks and optimization

This blog post is about a bridge I created that allows you to pass callbacks to Python functions directly to Matlab code without having to resort to things like sockets or COM.

Background

Designing our UAVs involves a number of different codes that interact & must be coordinated to solve what is essentially a Multidisciplinary Design Optimization (MDO) problem.  One of those codes is written in Python and involves a constrained optimization problem of the following kind:

Find the minimum of a problem specified by

xbbeqlb, and ub are vectors, A and Aeq are matrices, c(x) and ceq(x) are functions that return vectors, and f(x) is a function that returns a scalar. f(x), c(x), and ceq(x) can be nonlinear functions.

In our case we have 10 variables (x has length 10), 28 nonlinear constraint functions c(x), 4 nonlinear equality constraint functions ceq(x) and box constraints on most variables.  The objective function f(x) and all constraint functions are pure python functions.

Thus to optimize f(x) you need an optimizer that can handle python functions, and for that there is the excellent openopt library.  This is what I did and after trying out the different NLP solvers I settled on the scipy_slsqp solver for most runs as it seemed to consistently give the best results.

However, as the optimization problem was tweaked and as we did more runs, we did run into cases where it would not solve and the aeronautical engineers I work with were not always happy with its robustness.  Also nobody had ever worked with the openopt library but everybody knew and trusted the various Matlab solvers.  Besides, us being part of the Computational Engineering Design Group, a number of powerful in-house Matlab solvers had been developed and were available to me.  Thus, the least I could do was to try to use those and see if that improved anything.

Python-Matlab bridge

So I started searching the web for tools / libraries that allowed me to bridge python/Matlab, specifically tools that supported passing callbacks between the two languages.  A promising project seemed mlabwrap but while it was great for evaluating Matlab expressions,  it does (at the time of writing) not support callbacks.

In the end I decided to see if I could scratch my own itch.  I really did not want to deal with sockets or any kind of network protocol and I also wanted the solution to be crossplatform, so no COM.  Since both Python and Matlab have well documented interfaces with C/C++ code, that seemed to be the way to go.

So I sat down with the ctypes & mex documentation and with a little help from Mathworks support was able to cobble together a simple example using fminsearch.  By the way, I had never done any Python – C work before, but ctypes is awesome and a joy to use.  The little trick to make it all work is that you just have to treat the function handle as an integer (it’s just a memory address after all).  Then all you are really doing is passing an integer around which is straightforward.

With fminsearch working the goal was to extend to fmincon since that would give us all the basic functionality needed.  This took a bit of debugging and deciphering Matlab crash dumps but I finally got it working.  The final flow of events looks like this:

You start off with writing a matlab file that wraps the optimizer you are interested in (in this case fmincon) and exposes its signature.  This m file forwards all function handle arguments to a mex file which converts the integer to a function pointer and calls it.  This is how we get the callback to a C function.  A simple bridge library is then needed which is loaded by ctypes and converts the arguments into something the Matlab shared library file understands.

From my initial tests I see it is finding the same optima as scipy_slsqp was using openopt. Now I just need to do more extensive testing to see if performance is any more robust. After that I can start looking into the other solvers provided by Matlabs optimization toolboxes as well as our own solvers.

Source code

All the code is available on github.  I hope it is useful to somebody and I’d be very happy to receive patches or improvements.  I guess this may even be of use to the mlabwrap / openopt projects.

–Dirk

“Click here” to design and build your UAV

This blog post summarizes the work I have been doing the past 8 months or so on an automated design system for (civillian) UAVs.  Ive been meaning to do this post for a long time but wanted the tools to be in a beta quality state before writing about them.  In good software engineering tradition there have been a few hiccups and detours along the way but Im happy to say beta stage has been reached.

I will go over the vision behind the system, its architecture, and the various tools I have used to put it together.  For the impatient, this is the idea: we need a system that allows us to rapidly go through this process:

Agile UAV design if you want to call it that. Tools I will talk about include PythonNumpy, RabbitMQ, Redis, Flask, Django, Bootstrap,  Knockout.jsVagrant and how they link up with application specific codes such as Ansys Fluent, SolidWorks, Vanguard and Anylogic.

This post is an extension of the talk I gave at PyConUK 2011 a couple of months ago and is also what I will cover in my upcoming talk at Imperial College and at the upcoming AIAA conference in Honolulu in April 2012.

Continue reading

Solving Boggle with Python

I attended my first Python Dojo in London last night and have to say it was great fun.  As I’ve said before these kinds of events are great to get to know people and learn something new.

The challenge settled on for last night was to solve a Boggle puzzle. For those not familiar with the game, the idea is that you get an n-by-n grid of letters and you have to form as many words as you can by ‘snaking’ through the grid.  Every grid cell may only be used once for a word.  For example, this is how you would form the word MURALS, starting from M:

Everybody got about an hour to hack on a solution after which each team presented their code to the rest.  It was interesting to see the diversity of style and solution. There was a team that used 5 or 6 classes in their solution with extra facilities for caching, ours was more straightforward & procedural, while another did the proper thing and used a Trie.

Since our code did not quite work yet I finished it on the train home and then took some time this morning to clean it up.  For kicks I also used python’s multiprocessing module to have a version that would solve large grids in paralllel.

I pushed the code to github and, while nothing fancy or super optimized, it should do the job.  As always, patches & improvements are welcome 🙂

Props to @ntoll and @tjguk for organizing the event and hopefully I can make the next one as well.

–Dirk