Tag Archives: remote control

myR: Remote Control

So I completed the hardware,  let’s now move to the sw part of  project.

The remote control has a very simple scope: receive a command (data.input) from somewhere , check it and store it in the appropriate location , mainly a data  available for the other  objects.Again, this object is running as a parallel thread ( I love parallel threads…).

The code is in rc.py  and rc_data.py  modules.

rc

 

 

Beta2test.Safety connection

Today the remote control of the drone is done  via wifi with my laptop trou ssh.

By the way the software is designed (even if not yet completly developed) to receive commands from any type of devices (smartphone, tablet and so on). See this post for tips.

comm

So it is fundamental that the drone  keep a stable and constant connection with the remote control.

In order to verify a constant connection I created a new class that I called  netscan  that use  the ping command to verify the connection with a given ip address.

This object can work in a parallel thread that can monitor the connection on a fixed time interval.

In the code example you can find the netscan.py and the netscan_test.py

In netscan_test.py  you can see how to createand initialize  the netscan object and start the parallel thread.

I put an important effort on the performance of the system in order to verify that it is not time consuming.The time to perform a task ( in this exemple a basic calculation) does not change if I start or not the netscan.For the moment I tested it only on my laptop and the results are great.

As soon as the communication is lost the netscan  react on this.

This new object will be added to my code in the next coming  beta3_test.py

 

 

 

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.