# Tag Archives: drone control

I’d like to put here some consideration about the imu calibration, that means how  it is mounted the imu on the drone respect the propeller plane. This information is fundamental to garanty a perfect hover position without lateral mevement of the drone.

In other words, if I set roll=0 and pitch=0  I want that the prop plane is aligned with the  world, evenif the sensor can be not perfectly aligned with the world (and also with the propeller plane).

In this pictures you can see this case: the world (blue) , the sensor (red) and the prop plane ( orange).

In the next picture let’s put some names to the angles: Important: Note that gamma is the angle measured by the accelerometer.

The most important information I need to know is the angle beta : the offset between the sensor and the prop plane . this is the error  generated to the mechanical installation of the imu.

This value is used to compensate the measured value from the accelerometer.

alpha and beta are the 2 unknowns  so I need 2 equations to solve this problem.

I decide to use this simple method  to calibrate imu:

1) Take a reference plane ( my kitchen table) . It does not metter if it is not perfect alingned to the world, it is just enough it is stable.

2)Place from behind the prop plane on the “table roof”. 3) Measure the angles  of the accelerometer (gamma1).

4)turn the drone 180 degree respect yaw and place it again on the table roof.

5)Measure the angles again ( gamma2) .

6)consider that, in those 2 measurements, the alpha angle is constant ( i do not move the table…) , while the angle beta is equal but inverted ( due to the rotation of the drone).So the result is: In order to  manage this  method in a easy way  I added in the code the option called “fine calibration” .

The last  version is now on github.

Just run the myQrc.py , move to the new mode “IMU”  and follow the instructions.

# 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):

self.param1=0

self.param2=0

Second, I create my webserver.

The class is in the webserver.py 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 webserver_test.py 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 webserver_test.py

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

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