Tag Archives: rqaspberry pi remote control

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.

Advertisements