Category Archives: sw dev

myQrc – test completed

I just upload the last and final version of the myQ release candidate on github


All the software has been debugged and  tested.

All the functionalities are now stable.

I tested in different options (debug mode, netscan activated, sensor log)  and the result is that I can run the main loop every 10 ms and  get sensor data every 6 ms.

It can happen to have a delay on the  sensor data loop  when a log is added ( 2/3 ms).


I removed the webserver from the list of test to do, so it is not supported in this version of the software. The main reason is an instability when runnin gon raspberry. I have to investigate a more robust way to manage the comunication via browser.


Next time I will write a post the drone will be just landed…(after its first flight!!!)

myQrc. Release Candidate on Github

Hello, I just upload the myQ release candidate on GitHub. (see permanent link on the right).

It is derived by my but includes many additional features:

  • a new display  that can  show the current state of the quadcopter( orientation and motors)
  • The possibility to switch between modes (init ESC, test Motors, tune PID an so on) .Any mode has got its own tab with an explanation of what yuo can do.
  • a web server that can provide a web page to be used as remote control.From any device using browser just connect to and you get the command page. (honestly it could be a little too slow for a quadcopter, it should be better to use socket messaging )


  • a netscan functionality in oder to be sure that quadcopter did not loose connection with the remote control

So finally it is time to move back to the field, load all this new things on the rpi and deeply test it!!!



The last missing class is ready: Display

In those days I’m working mainly on the software in order to prepare the release candidate version for myQPI.

I’m going to merge all the functionalities (like motor test, pid tuning etc.)  in one place.

So the last brick is  a  nice and smart user interface :


It is possible to read info about:

  • motor speed
  • roll,pitch and yaw from IMU ( the current value)
  • roll,pitch and yaw from remote controller ( the target value)
  • selected mode  and commands from rc
  • PID values

Using the kayboard arrows, it is possible to switch between modes :

  • Init – where it is possible to load save and modify options (not implemented)
  • ESC – where it is possible to init the  esc
  • Motor – wher it ispossible to move the motor singularly,for testing purpose
  • PID- where it is possible to tune all the pid parameters (implemented for roll and roll rate only).this is thinked to help during the testing phase with quad tied up on 2 side
  • Flying – where it is possible to guide the myQPI  using the joystick command
  • UAV – where it is possible to define a specific path . This has been implemented by changing angles and trottle respect time.

Every mode has got its specific UI.For example in the picture you can see the PID  mode, where the user has to ackwoledge the motor start,  can start the PID control  and then tune the kp,ki,and kd.

This module called  is available on my Github repo. In addition you can find the whole current development (not yet  completed tested on the real quad!) .

If you are curious, yuo should be able to run it by the command python . I can see the program running also in my development pc, without raspberry connected.It should work also for you.

So the appointment is for the next post where I’ll officially launch the release candidate!


Beta2test.Before going on Vacation

During the last week  I  made some improvements on the code that I need to report here in order to avoid any  oversights after the upcoming vacations…

  • Added a function to tune manually the P,I and D  on the run.
  • in added a function to calculate an average during the D_correction calculation. This help to have a smoother value.
  • Display results every 0.2 sec, instead every cycle (trying to reduce cpu load).
  • improved log
  • Calculation of  the angular speed (roll_rate, pitch_rate and yaw_rate) in the sensor_py. Those values are coming from the derivate of the roll,pitch and yaw already filtered with the complementary filter. they are not the row  roll_rate,pithc_rate and yaw rate  from the gyroscope.

The main improvement has been the introduction of the  PID  for the roll_rate.I did a new  module called  where I put  two PIDs in series. This is a typical approach in the quadcopter controller. The first PID  returns the  Roll_correction. (this number represent the angle variation that I ‘d like to have in one step).

Dividing the  Roll_correction for the cycletime, it represent the angular speed (roll_rate) I’d like to have in one step.It is the target for my new roll_rate PID.The feedback is the angular speed calculated in the result is a really more stable quadcopter, less nervous and more quick on the response.

Below the graph that show the current state of the tuning.



As you can see, there is still an oscillation, but it is  between +/- 1 degree.Where I need to work is  fact that  the system never reach the target.(now I have a very simple roll_Pid , with I=0 and D=0. I’m thinking to set a v alue for the I also).

Beta1test. Bugs and a steps ahead

Yesterday I got this result:


Thanks to the following actions:

1)The test with the ball on the bottom of the drone,did not convince me. the friction on the ball, the  rotation limits due to the basement, were all components that are not present during the flight.

So I decided to switch to the more used and recognized  solution with the quadcopter tied up with 2 wires.


2) I realized  that something was wrong on the motors behaviour.When I  run the   the motor sound  was unstable and unconstant evenif  I was not  controlling it with PID ,just make them run in throttle speed.

This is not happening if I run the

Finally I was able to reproduce the problem and I realized there is a bug (or better an unexpected behaviour)  in the  library RPIO. If I run this loop (that reproduces the main loop of the beta1) I got the unstable motor rotation:

while true:

mymotor.servo.set_servo(, PW)



My explanation is everytime  calling the set_servo()  function, it resets to zero the signal than set it to the desired value PW).

Instead of that funciont I introduced the lower level function


When I put it in the test loop I got a perfect, stable, constant sound for the motor rotation.

This 2 improvements gave me the opportunity to move  a  great step haed. Now the tuning can be faster and more consistent.

Above just a graph showing the current behavior.In blue the requested   roll , in red the real roll when  the quadcopter is  using the pid controller. I still need to  tune it to reduce the time to reach the target (5/6 seconds)  and to avioid the oscillation ( +/- 3 degrees).But I’m really satisfy about the current situation.

Beta1 test. SW introduction

Here it comes the Beta1 Software.

The preliminary test on the software has been completed.I  validated the following functionalities:

  • 4 motors management
  • IMU, inential measurament unit  Interface (MPU6050).
  • Remote control (done using ssh and the laptop).I can modify roll and pitch target. Yaw is not for the moment part of this test session.I can start the Pid control for roll or for roll+pitch.
  • PID for roll and pitch.
  • Display  with current info
  • log file
  • arg params ( -s = save log, -c = calibrate IMU)

I added a new  module called where I put all the necessary components already tested in the past. So i can access  them for exemple by myQ.motor or myQ.sensor.roll  etc.

I remember that the Imu and rc are now running in a parallel thread.

The main loop is now running every 10ms, but I have to investigate if this is stable and mainly if this is enough for the control of quadcopter.

A new display can show the current status of  the drone, including   roll, pitch and yaw , motors rate , throttle  and the commands from the remote control (target values).

beta1 display

Now the main target for this  test session is to tune the pid  for balancing the structure ( remember that in this phase I placed a semi-sphere under the drone in order to verify the balancing without flying).



Tutorial: How to create a webserver for robots, rovers, drones

The main scope of this tutorial is described in the title.

The architecture I have in mind is the following:

  • raspeberry pi is the main controller of a device (like car, robot, rover or in my specific case, a quadcopter).
  • raspberry pi is connected to a local wifi network.
  • My  pc or my smartphone are connectd also to the same wifi network.
  • Using the browser of pc/smartphone I want to pilot the device.
  • The development is done using python

To do this approach it is necessary a webserver running on the raspberry and at least a  web page as user interface.

Let’s start assuming I need to manage some parameters (for example the speed of the wheels, the angle of a robot arm).

First of all a created a generic  class  that  includes the parameters to be managed:

class mydataclass(object):

def __init__(self):



Second, I create my webserver.

The class is in the module. It is managed as a parallel thread.

You can find an init() routine that get the data class as input and have a start() and stop() routine.You can use it as is, since is not related to the data structure of the mydataclass.

Then , I created a  class MyHandler(BaseHTTPRequestHandler). This is where it is necessary to implement  specific code in order to manage the specific parameters. In this example , there is a param1 that can be incremented or decreased  from teh user and a second param2 that is managed somewhere else (in the main loop).

It is implemented a  do_GET() routine  where it get the  command coming from the client (web page )  and according to the command, it performs the necessary action.

Finally I created a module that  is used as main loop that mainly initialize mydata and  mywebserver and execute an example of basic control.

that’s it!

Ops, of course you need a (better than mine) web page for the command. In this link  you can find a really basic webpage and all the code: webserver_test.

To test it, just run:  python

Than launch a browser and  open :  http://localhost/index.html   or  put the ip address where your server is running  :

In the next post I ‘ ll replace this basic example with a case specific for a drone.