Category Archives: Programming

Python intro

First of all python is free! Then, I think of python as a super cool programming language that is also a super calculator. It allows you to do higher level math calculations but it can also help find cheaper airplane tickets in the Internet (ask me if you’re interested). Here is a short tutorial to get you started with python after you have installed canopy.

Quick start:

  1. Install Enthought Canopy Express from
  2. Open the Canopy editor and create a new file.
  3. Read the following mini tutorial and try some commands in the prompt.
  4. Type in the given equations from 1 to 6 and check the results with print statements. Don’t forget to hit run (Ctr + R or Cmd + R).

mini tutorial continued …

variables in python

you can basically use any typical variable name in python such as ‘perigee’ or ‘radius_earth’. Try to give descriptive variable names so your code is easily readable by others.

assign numerical values to variables

it’s as easy as you’d expect

perigee = 418.0

important note: in python 2 an integer number (such as ’18’) is treated differently than a floating number (such as ‘18.0’). To do math with floating numbers in python 2 you can’t have integers in the mix. So that’s why I usually initialize my integer variables with a ‘.0’ at the end so I won’t get strange results. You should try to see what I mean.

math calculations in python

To do math in python is also very simple and as expected


Rp = perigee + radius_earth
R = a*(1-e**2)/(1+e*cos(nu))

important note: in python the exponent operator is ‘**’ instead of ‘^’ as in other programming languages. Here is a short list of the operators you  can use in python:

print your results

The way you print in python 2 is different from python 3. This example is for python 2:

print 'Period = ',P,' min'

last but not the least: numpy

numpy is a python library that helps you do math. You can read more about it here:

For now you just need to import this python library and use it blindly. On the first line of your script type:

from numpy import *

this will import all the functionality of numpy into your python script. For this tutorial it’s specially useful to be able to use the constant ‘pi’ and also for the function ‘cos’. Otherwise you would have to make your own ‘pi’ and ‘cos’.

Here is the source code to make the magic happen:

#iss orbital speed and period
from numpy import *

perigee = 418.0 #km
apogee  = 426.0 #km
radius_earth = 6371.0 #km
mu_earth = 3.986e5 # km^3/s^2

Rp = perigee + radius_earth
Ra = apogee  + radius_earth

print 'Radius Perigee: ', Rp, 'km'
print 'Radius Apogee : ', Ra, 'km'

# 1) eccentricity
e = (Ra - Rp)/(Ra + Rp)
print 'eccentricity: ', e

# 2) semimajor axis
a = (Ra+Rp)/2.0
print 'a =', a, ' km'

# 3) mechanical energy
epsilon = -mu_earth/(2*a)

# 4) altitude at nu=90deg
nu = 90*pi/180
R = a*(1-e**2)/(1+e*cos(nu))

print 'R =', R, 'km'

# 5) orbital speed
V = sqrt(2*(mu_earth/R + epsilon))
print("V = {:2f} km/s".format(V))

# 6) orbital period
P  = 2*pi*sqrt(a**3/mu_earth)
print("P = {:.2f} sec = {:.2f} min = {:.2f} hr".format(P, P/60, P/60/60))

Cross Compiling for Embedded Devices

I’ve learned a few things recently about cross-compilation for embedded devices. I think this will become more and more a hot topic because of the Internet of Things (IoT) is boosting through the charts and many people are jumping into that. Here are some of the lessons learned (not all). Let me know if you have more insights into this exciting topic.

The Qt IDE is a great open source tool for software development. What if it would also become a great tool for cross software development? This makes perfect sense because Qt has the only IDE that works on all platforms. This was the question that triggered my pursuit in making the Qt IDE work to cross compile software for ARM devices running linux. Here are some of the lessons learned (as of Aug 2014):

  1. The best I could do so far is to use the Qt IDE on Ubuntu (working as either on a virtual machine or a real boot) to cross compile the code for the ARM and automatically deploy it on the ARM device. I’ve used a standard Qt project and also Cmake, both work great. With Cmake there might be a few tweaks if you want to deploy only one program instead of the whole project. More on this latter. Use the toolchain from linaro.
  2. Use gdbserver to debug, on the Qt IDE you must use a gdb with python enabled. It’s not to hard to compile gdb with the python extension (most cross compiler toolkits available don’t have gdb with python enabled, let me know if you find one)
  3. Don’t try the Qt IDE  on Windows to cross compile. It’s possible but there is a lot of pain involved. This Qt bug report gives you a interesting  perspective of what’s going on. Just accept the fact that it’s best to cross compile from linux (x32,x64) to linux (arm) – for the moment, I think this will change soon. I will post some instructions on this latter. But if you really, really want to spear head this start by  downloading the toolchain for windows from Linaro or the Sourcery CodeBench toolchain and use Cmake instead of a Qt project.
  4. Eclipse seems to be more appropriate to use for the development of embedded applications (in either Windows and Linux) but Qt creator will also get there soon I think. But if you just want something working you are better off with Eclipse at this time.

Here are some links to help you set up

Qt Creator


Real time trajectory in Google Earth

Google Earth allows you to display coordinates saved into a kml file. Even better you can choose the refresh rate on GE so that you can see your path in real time. This is useful for GPS data tracking or even just for fun.

Google Earth Real Time Trajectory
Google Earth Real Time Trajectory
Here are the steps to show a path in real time on Google Earth:
  1. Go to “Add” -> “Network link”
  2. Browse the kml file you want to lead. Here is an example: GPS-Dolphin.kml.
  3. Go to the “Refresh” tab and choose your refresh rate. This will load the file at every x-seconds you choose.
  4. now just make your software update the file as frequently as you want … or for basic testing just open the KML file in some text editor and change the coordinates to see what happens.

Have fun!