The idea of this project was inspired in my own backyard. Deer eat every leaf off our fruiting trees until they die, squirrels and birds devour the garden, and we try to raise farm birds but, sparing you the gruesome details, let's just say hawks also enjoy chicken nuggets. There's not a great way to protect all this, and we just have a small half acre. On a larger scale I could only imagine this being exponentially more difficult. Enter "The Ultimate Sentry". I'm disinclined to stand in our yard day and night watching for racoons and such (we get quite a variety of menaces), and a drone that's programmed to harmlessly scare off predators would do a better job than me anyway. That's the idea behind this project; identify predators and protect the yard from harm, without causing harm to the predators either. Let's dig into it.
AssemblyFor this I'm using the KIT-HGDRONEK66 drone kit with NavQPlus, which all starts with assembly. They say a picture's worth a thousand words, and I put together an assembly video for it which has 183, 114 frames, so that's essentially worth 183, 114, 000 words! Obviously I'm kidding around with that, but I did think it'd be helpful to share an up to date assembly video. There are videos provided within the NXP documentation, but they're for a slightly older drone and since this is my first experience with setting up a drone I discovered some helpful notes I think are worth sharing along the way. Hopefully it helps someone out there:
SimulationNow that the drone is put together, it's time to get it connected to the computer. Note, the blades should not be put on for awhile yet. You don't want the drone flying until it's supposed to!
For simulating the drone flight, I utilized jMAVSim. For anyone experiencing difficulty getting this up and running, it's worth noting that on my Windows 10 computer it absolutely did not want to work, but when I tried the same process on my computer running Windows 11 it worked instantly. While Windows 11 is not my favorite, it was nice to have in this instance! It does note in the instructions that Windows 11 is preferred, and it does seem notably easier to get working.
Since the jMAVSim is running on a shell, it made sense to run the Python code with WSL to make things a bit easier. Conveniently, Visual Studio Code has a WSL extension to make this nice and painless.
Once the simulation is setup, it's time to actually come up with something noteworthy for it to simulate!
CodeThis brings us to the code! Typing nerdy stuff on a computer is my comfort zone. I've been enjoying Python more and more as I explore it and, seeing that Python can be utilized for the drone's logic, it seemed like a very appealing option for putting it all together. One thing that I wanted to note though was that my initial plan for the organization of the code was to put together a suite of Python code, but as I wrote each part I realized it was becoming convoluted and this was a situation where a single Python program to rule them all was logical. That is to say, pairing the code down into one file wasn't for the sake of laziness, it was because it felt optimal! Normally I like dividing things up, but at the end of the day I'll do whatever I think provides the best result.
As you'll see shortly, the one code file refers to what runs the drone itself. I have a couple of nice-to-have code files as well.
The Bosch SensorGetting into the code itself, there is obviously a lot it's trying to do so there's a lot going on. First, let's get into the Bosch sensor and the weather code. The initial idea I had for the Bosch BME688 sensor was to continually check for fires. It works out well, because it's not as though I have fire alarms in my yard otherwise and I would strongly prefer my house doesn't burn down. This logic is integrated into the code, but I also realized that it can help check for weather conditions as well which is that much more applicable to the goals of the project. We don't want the drone flying around in a torrential downpour or super high winds, etc. The rain forecast will just provide a percentage, which doesn't necessarily tell me if it's raining or not. If it's a 20% chance, the drone may well be in that 20% area. The Bosche sensor is used to help figure out if it's raining or not. To help get the rest of the weather forecast, I used an api for OpenWeatherMap.
The Drone CodeAs far as the drone itself goes, the idea is that there's a defined safety zone for the drone. There is no situation in which it should leave its safety zone, which in this case is a segment of my backyard. To define the safety zone, we walk the yard and press a button to define the 4 corners. We also set a home location for the drone. This is where we keep it safe from the elements while giving it an area to perch. Throughout flight we also check for obstacles and attempt to avoid them. In the case that something is very awry, we simply land as a failsafe. In order to keep up with the drone's activities, we utilize Twilio to send text messages to a specified user phone number. We only fly when there's a reason to, which is when there's a predator, or if the drone is already in flight and needs to return home.
One thing to point out is that obstacles are not identified separately from predators. This is to help ensure that we never run into anything. Drone blades can really do some damage and, even though deer can be a bit pesky, I don't need to be running a drone into them. We just treat everything seen by the drone as something to avoid running into.
The NavQ+ was utilized throughout the drone code for pretty much all of its functionality that pertained to the drone itself (as opposed to elements like Twilio messaging or checking the weather). The NavQ+ enabled seamless integration with the dronekit library, allowing us to implement essential flight features such as taking off, landing, and navigating. It also helped integrate the external functionality run by other libraries and modules such as object detection and GPS functionality.
OpenCVThis brings us to the more complicated aspects. You'll notice that there's a reference to OpenCV models. Regardless, the next step is to setup an OpenCV model to utilize for identifying important objects. However, I do want to get into my approach for it a little bit. Setting up an OpenCV model is a notable task on its own, so I decided to look to python to make this more painless. Plus then it has the advantage of being useful going forward as well. The approach is to use a free image library to rapidly gather a large dataset and use it to train a Haar Cascade Classifier model. Thus far, the images that are acquired from the image libraries I've tried have been underwhelming, but the basis is there for a reusable OpenCV model-creation solution. This code is included as well.
The main purpose of the drone it to scare off predators, so we have predators we look to identify, but we also want to ensure the safety of pets and humans as well. For example, I don't want the drone mistaking one of my dogs for a coyote. As such, I added safe objects to identify as well such as known people and pets. Lastly, there is a category for uncertain objects. This can include people and dogs that aren't recognized. The idea is that we don't want to approach them with the drone, but in case there's something concerning going on we will take a picture and forward it to the user's phone via Twilio.
Additional Eyes (Security Camera)The drone will only see so much of the yard, and patrolling seemed like an unnecessary use of power. By using a security camera that could interact with the drone when it saw a predator, it would serve multiple purposes (since I wouldn't hate having extra security cameras anyway). The Wyze V2 allows for python coding, so I bought a refurbished one and wrote a separate program for it. It doesn't have a gps, so as is the coordinates for where the drone should fly when it spots a predator need entered within the code. Otherwise, the idea is it uses the same OpenCV libraries as we utilize for the drone itself. It is constantly looking for predators, and if one is seen it tells the drone to go to the position. The drone will be constantly looking for predators, so in flying to the location it will look for and chase any predators that are there.
That's the gist of it! The short of it is that we keep it in a "safety zone" of an area to protect, chase after predators without ever making contact while utilizing safety protocols and obstacle avoidance, send updates and images of predators and unknown humans/dogs, and otherwise stay on patrol with the assistance of a Wyze V2 camera. The code for this is included.
CollaborationLast but not least, this project is my submission into the NXP HoverGames Challenge 3 contest, so there's one more thing to include here, which is the collaboration content. Relevant to helping others, take note of the collaboration section fellow Hovergames Entrants! It's worth 10 points :).
"
Specifically in your final submission give 5 links to where you collaborated or helped others. This can be answering questions, providing a short tutorial video, or providing help with code."
Below are some ways in which I helped out:
- Assembly Tutorial Video - https://youtu.be/6yf_Dke_O2Q
- Noting how to resolve ordering issues (Discord) - https://discord.com/channels/1014291298812960913/1027691375770218638/1049740084636831844
- Answering Contest Discussion Question - https://www.hackster.io/contests/nxp-hovergames-challenge-3/discussion/posts/10222#comment-200199
- Participating in the discussions within the NXP Ethics Workshop
- Adding additional resources within the project that go beyond the scope of the project that could help people accomplish their project goals (eg. the opencv model creation code)
The drone needs to work flawlessly to be able to safely work in the yard. As such, the code needs to be continually iterated until I'm confident it will work 100%.
A nice to have that I started dabbling in is an Android App that allows for monitoring the drone from a smartphone.
In my ideal world, I'd like to utilize a wireless charger setup that is run with solar power such that the drone is charging anytime it's not flying after a predator.
Comments