Good day all
I am new here and not a programmer at all.
I have asked the following on other forums with very little success. Most of the replies suggested that I use C++. I have no idea what C++ is all about and have very limited knowledge of Python but prefer Python as the little I do in Python makes sense. Live data streams however is out of my league
I have developed a low cost sub decimeter accurate navigation device using GNSS satellites.
A basic robotic vehicle has been build and consists of a Raspberry Pi 3b, a Sense Hat (hopefully temporary), L298NHbridge, 4 12 Volt DC motors and employs Skid Steering. Components are a problem in South Africa and the vehicle was built with what was available locally. Some components were sourced from Ebay and Aliexpress, the delivery times were from 2 weeks to 7 months.
The navigation device provides accurate Position Navigation and Time (PNT) data to the Raspberry via a USB port.
The data provided is Latitude, Longitude (Decimal format), PPS pulse, Track and altitude
The device is capable of providing ECEF X, Y and Z data as well, (long term it would be better to use ECEF according to the survey community) How to do so in Python is next on the list.
The idea is to write a Python program to do the following:
- Calculate the distance and bearing between the vehicle position and a user provided GPS target coordinate. (Or is could be a CSV file with a list of coordinates)
- Align the vehicle to the target coordinates
- Walk / drive the vehicle to the target coordinates
- Do minor course corrections
- Stop when the vehicle is less than 40mm from the target coordinates.
The calculation is straight forward
Python 3
Anton Strydom
2022/08/01
Part of Autonomous Robot GPS Navigation System
Routine to calculate Distance and Bearing Between 2 sets of Coordinates
import math
x1 = -26.1704925
y1 = 28.17704589
x2 = -26.1705061
y2 = 28.17719069
dist = math.sqrt((x2 - x1)**2 + (y2 - y1)**2) *100000
bearing = math.atan2( y2 - y1, x2 - x1 ) * ( 180 / math.pi )
if bearing < 0:
bearing = (bearing + 360)
elif bearing > 0:
bearing = bearing
print (‘Distance:’, dist)
print (‘Bearing:’, bearing)
Controlling the motors is also straight forward and I am using GPIO 6,13,19 and 26 to control the motors connected to IN1, IN2, IN3 and IN4 respectively and GPIO 18 and 12 connected to ENA and ENB respectively to try and use PWM for more accurate control of the motors.
Also the thinking is that in order to achieve sub decimeter accuracy, the device’s time synchronization with the GNSS satellites must be sub nano second taken into account that 1 nano second in time equals just on 300 mm. The device has a PPS port therefor the Raspberry time can be synchronized to the navigation device.
The reason is that using PWM to control the motors requires stable frequency in order to be accurately controlled.
Frequency equals time therefor the better the time pulse the better the frequency the better the control
PWM control has not been implemented as yet and is a definite for the future.
I have never worked with live data and the use of live data in calculations as well as applying the results to effect course directions autonomously.
My knowledge of python is restricted to the above.
What would be most simplistic way in Python be capturing live data, latitude, longitude and track values from the navigation device data stream and store it temporally. Acquire the target coordinates (either user entered or read from CSV type file) and calculate the distance and bearing from the present position of the vehicle (the vehicle position is determined by the GNSS antenna mounted in the front of the vehicle and aligned with the center of the vehicle) to the target.
Turn the vehicle to align the “track” value with the “bearing” value to ± 0.5 of a degree. Once aligned the vehicle must start moving towards the target and at the same time continuously calculate bearing and distance values at set intervals (the navigation device is capable of 20Hz update rates) using the target coordinates and the vehicle’s then present position applying course corrections through slowing and speeding up either port or starboard motors to change the course of the vehicle to align to the target.
Once the vehicle is within 40 mm’s from the target it must automatically stop. For now that would totally suffice for demonstration of the navigation device’s capabilities.
Any assistance or collaboration would be greatly appreciated
Thank you in advance
Sincerely
Anton