View on GitHub

WaterAutoTurret

Auto Tracking Water Turret

Software Description

The software for the Water Auto Turret has been implemented in four main parts:

The code has been pretty thoroughly commented so should be relatively self explanatory however and overview is given below. I am not a software developer and have self taught myself python so welcome any feedback on improvements and or better ways of implementing this code!

Web Application

This is a standard Flask web application that is started using the command python3 autoturret.py

Within the __init__.py file the following are initialised:

After this initialisation the Flask app is started and the system is ready for targets!

In the routes.py file the generate() function attempts to grabs video frames from the Queue and allows them to be displayed on the web front end. The rate this grab happens is adjusted to slightly faster than the current frame rate to get a decent refresh rate on the screen without this function looping instantly and using all processing power (as it did when I first wrote it…)

KSNN Yolov3

The Water Auto Turret uses the Yolo v3 model to carry out the object detection and tracking. The code for this can be found in the turret_controller.py file and draws on the Khadas examples. The Yolo v3 model and lib files are the standard Khadas provided ones.

The detection works as follows:

Turret Controller

The turret control software can also be found in the turret_controller.py file. The target detection loop through all the object detections passed out from the neural network processing and does the following checks on each to identify targets:

Low Level Drivers

TMC5160

The driver for this is provided in TMC5160_driver.py. The driver exposes all the functions of the TMC5160 that are currently used and have been used in development but does not provide all features of the TMC5160 device. The internal __read_from_TMC_5160 and __write_to_TMC5160 functions provide the interface direct to the chip. Other higher level functions are exposed from the driver such as “home”. The code in this file is well documented and is directly derived from the TMC5160 datasheet so should be read in conjunction with the datasheet to get a full understanding of how it works.

DRV8806

The driver for this is provided in the DRV8806_driver.py. This should again be read in conjunction with the datasheet for the DRV8806 but this is much simpler than the TMC5160 as the interface is essentially - set or reset the data bit to indicate a solenoid driving being on or off respectively, clock this data bit into the device by strobing the clock line, repeat this 3 times more to get data bits for all 4 outputs into the device and then latch that data into the outputs. Again the code is documented so should be easy to understand.

Tests

In the “Tests” folder there are some standalone test files that can be used when debugging the system or for testing during assembly

Future Software Development

The Water Auto Turret is currently fully functional, however its always possible to get better! For this reason the following areas of software are currently under development:

{Home} {Next}