Tag Archives: python

Alfa3.test. Here it comes the python code

So now ,after some additional tests, here I added the software code: alfa3

All the basic components necessary to build a quadcipter sw are now implemented.
This is list of the modules developed:

  • motor.py
  • sensor.py
  • MPU6050.py
  • pid.py
  • rc.py

Any of those modules includes a specific object.I’ll plan some time to review the python page with a detailed help for each module.

Here I want just to summarise the main aspects.

rc is the new entry in this alfa3test session.it is an object that works in parallel thread.It is just waiting for input from user. In this particular case the input is coming from the keyboard,but the same approach it is possible (I’ m working on it and a tutorial is close to be ready) to get input from a webserver running on rpi.

Motor is an object that manages the motor speed trou ESC. It uses the RPIO library to generate the PWM.

Sensor is an object that works in a parallel thread. Every around 6ms it can update the info from the gyroscope and the accelerometer ,quadcopter inclination and rotational speed.

MPU6050 is a pure interface between raspberry and sensor hardware. If you want to use a different sensor it is just needed to build this specific class.

Pid is the object that includes the calculatio for the proportional , integral and derivative control.


SW Dev 2: quadcopter.py

Hello ,  I’m publishing the new module quadcopter.py.

This object  has the main scope to be the controller of the quadcopter.

It includes 4 motors (from motor.py class) and the necessary interface for manage the commands coming from user.

This version is preliminary since it does not iplements all the functionality  but it can be considered the first step for the qpi logics.

Let’s see in details what is included in the modules for qpi_test2

motor.py is getting more robust. i added some procedures to manage the motor  parameters like setSimulation and getSimulation.

I also added a check to verify if the RPIO library is available.In case it can work anyway in simulation mode.

Procedure  motor.start  implements a sequence for initialize the ESC (it must to be verified yet)

Procedure motor.stop  that stops immediatly the motors.

quadcopter.py can manage 4 motors. the motors are defined as a list (array) so it is possible to direct access any  motor  with its index, for exemple:  self.motor[1].start

it includes procedures to move the quadcopter, like increaseThrottle,decreaseThrottle, increaseRoll,decreaseRoll ,increasePitch,decrease Pithc, increaseYaw,decreaseYaw and hover.

For the moment those procedures are used directly on the motor speed, but in next releases they will work  on angles and the conversion has to be managed

For this reason this class can be used only for development activity to have an overview of the whole flow.

qpi.py is  again the user interface, but i added a minimal graphical interface.

it is possible start the motors by pushing 0-1-2-3

  • increase motor rotation with a-z , s-x,d-c,f-v
  • play with throttle y-n, roll i-m, pitch j-k yaw g-j, hover h

you can test it even if no motor is connected, but also in a pc running linux, different from raspberry pi

SW Installation

Hello, today I inaugurate the english version of my blog.

As soon as I can I’ll translate also the static pages.

By the way, consider that this project is based on raspberry pi (rev B) for the motion control of the quadcopter.

Here there is a description of the necessary sw installation.

I’m using a laptop with ubuntu, and there I installed  ninja IDE, direcly from  ubuntu software center.

On this laptop I create a folder home /home/pyton/qpi.

Considering the rpi installation:

I copied a 2013-02-09-wheezy-raspbian.img on a  2GB SD.(right now you can find an updated verison of raspbian, on the rpi website  here: link

Start rpi connected on a monitor,my case was tv  via hdmi wire , mouse and keyboard and a ethernet cable.

Leave the default setting in the config.

Now you can disconnect all from rpi except the ethernet wire.

On the router  I defined a static address : , related with rpi mac address. (i have a netgear router and it waas really intuitive to set it ).

From the laptop , on the terminal use [See note below if you encounter problem with ssh]:

ssh pi@
password : raspberry

Now yuo are using rpi from the laptop


$ sudo apt-get undate
$ sudo apt-get upgrade

The update/upgrade can take up to one hour.

Since I ‘ll use rpi to pilot the motors I ‘nned to install the library that can manage the GPIO in rpi.

This library  RPIO allows to set any output as PWM:

$ sudo apt-get install python-setuptools
$ sudo easy_install -U RPIO

Now let’s see how to set up the Wifi Connection via usb dongle.

Do not connect the usb dongle.

Install the  wpa_supplicant  utility:

$ apt-get install wpasupplicant

Run the utility to create the password_phrase:

$  wpa_passphrase My_WiFi_SSID mypassword

Yuo will get this output.


Copy the  psk value.

Run the editor to modify the  /etc/network/interfaces

$ sudo nano /etc/network/interfaces

Modify the file (pasting the psk value):


auto wlan0
allow-hotplug wlan0
iface wlan0 inet dhcp
  wpa-ssid "My_WiFi_SSID"
  wpa-psk b2abb0fcd2f4527e11817de0823a57bb19ba4622f4595062c94ec4dd1370b5fe

Switch off  RPi.

Connect teh dongle and disconnet the ethernet wire.

Restart rpi and you are on line.

Set the router in case you want a fixed ip address for the wifi connection.


ninja IDE


NOTE: recently I clean up my laptop and installed ubuntu 13.10 on it.

From that moment it has been not possible to use ssh using wired connection.

So I solve it modifying the rpi eth0 configuration manually.

pi@raspberrypi ~ $ sudo nano /etc/network/interfaces
iface lo inet loopback
#iface eth0 inet dhcp
allow-hotplug eth0
iface eth0 inet static

In the same way, in the laptop I defined a static ip address