📜 ⬆️ ⬇️

Raspberry-pi-tank and GPS navigation

After experimenting with the artificial intelligence of the autopilot of my tank, I decided to take a step back and learn to navigate through the good old satellites.

The picture is staged, hinting that any GPS vehicle can independently burn in under the control of the navigator.



Raspberry Pi + GPS


First, a simple USB GPS module was purchased.
')
Guided by the article on Adafrukt , I began to implement.

Despite the fact that the article was written 6 years ago, nothing much changed in the world of old school navigation.

Only some nuances did not match:


The device itself looks like a regular USB flash drive:



And then I stuck for a long time, because my GPS did not see the coordinates.

The device worked, reported the version, the manufacturer and other useful information, but nothing more.

At first, I thought he was still defective. From previous experiments, I still have an SD card with Raspbian 2017, on which GPS worked.

I logged in from it and — oh, a miracle — the GPS came to life and blinked a light bulb, and fell into the log coordinates.
I racked my brains for a week, compared all the configs, began to sin on a new buggy Raspbian and was already preparing to reassemble gpsd in debug, when suddenly on the Raspberry-forum in one of the topics on GPS issues (and there are quite a few) I came across a tip to take the device the street in clear weather and let him find satellites, which can take up to half an hour.

I already had such an idea, but apparently the weather was not clear enough, but it all matched, and the device came to life. If you dig a little deeper, it turns out that the necessary information about the satellites is cached in the firmware of the device and can not be controlled by Raspbian.

How can my application get almanac / ephemeris / pseudorange data?


Sorry, there's no easy way to go through GPSD yet. GPS receivers report this information.

Many don't ship it at all. Others shipments for IS-GPS-200E (s) -the-air protocol used by GPS (satellites) is extremely obscure. Still others report vary This is a correlation of the correlation of the correlation pathway and the correlation pathway. documented.
The cunning mechanism has earned and it is time to benefit from it.
The script for reading data from gpsd on python is very simple:

 import gps gs = gps.gps("localhost", "2947") gs.stream(gps.WATCH_ENABLE | gps.WATCH_NEWSTYLE) for i in range(0,10): report = gs.next() print (report) 

Google Maps API


I control the tank from the phone, so I had to study working with Google Maps.
Google did a good job of simplifying the work with maps, so there were no problems.
Android Studio can create an empty project with a map, from where you need to carefully transfer all important details to the main project.

Google requires registration of the key to work with the Maps API, it is done for free (for now).

Expanded the REST interface of the tank so that it would give its coordinates, transfer the coordinates to the map, draw a tank icon and everything looks quite decent.

Further it is necessary to pave the way.

A click on the map selects the target and is fed in the Directions API .

Directions is a web service that takes the coordinates of two points and in response throws out a bunch of information about the paved route, including addresses, notable names and explanations. But I only needed a sequence of steps. Select the coordinates and draw them on the map.

Now for visual control and management has everything you need.



GPS Navigation


Then the first point of the route is transmitted from the phone to the tank.

The tank has a small problem - at the initial moment of time, it does not know its direction.
The problem is easily solved by a compass, but with a compass, anyone will cope ...

It was possible to get out of the fact that for the first few seconds the tank just passed forward, getting the coordinates of the beginning and end of the path and calculating its direction from them. It is worth noting that the same data can be obtained directly from the GPS, there is a track field, which shows the deviation from the angle to the north pole.

But in any case, so that after filling it, you need to move.

Calculation of the direction:

 def azimuth(pos1, pos2): lat1 = toRadians(pos1["lat"]) lon1 = toRadians(pos1["lon"]) lat2 = toRadians(pos2["lat"]) lon2 = toRadians(pos2["lon"]) dlat = lat2 - lat1 dlon = lon2 - lon1 x = math.sin(dlon) * math.cos(lat2) y = math.cos(lat1) * math.sin(lat2) - math.sin(lat1) * math.cos(lat2) * math.cos(dlon) return math.atan2(x, y) 

I will note that GPS does not always work accurately, and it may well turn out that the coordinates of the beginning and end of the test path will be with an error that makes the measurements senseless (to the extent that when moving forward, the coordinate of the end of the path is behind).

With this GPS it gives direction through track fairly reliably, so this field was used by default, and if it was not there, you had to navigate by the difference in coordinates.

Orienting on the ground, the tank turns approximately where necessary (approximately - because without a compass or a gyroscope it is difficult to measure the direction accurately) and moves for a few seconds. After that, he gets the coordinates again, checks the direction, turns, rides. And so on until the target is within the error radius.

In general, the biggest problem is the accuracy of the GPS coordinates, due to which the tank now and then loses direction and begins to rush in different directions.

Everything goes to the fact that without a compass can not survive.

Links


  1. Introduction article on setting up a GPS module for the Raspberry Pi
  2. Service for working with GPS on Linux
  3. A useful site with formulas for calculating the distance and direction of the coordinates of two points
  4. The source code of the tank firmware with GPS support
  5. Google Maps documentation for Android

Source: https://habr.com/ru/post/447654/


All Articles