|Terms of service|
|Let's keep it simple
I made a waypoint app in Visual Studio for the YMFC-32 Arduino drone
Hello and welcome to another one of my videos. In the previous video I showed you my simple flight monitor program while I was testing my new quadcopter frame. In this video I will explain how I build it and how to fly waypoints with.
First things first. Please understand that I'm not a professional programmer and I'm not trying to be one. This means that the code is not perfect and you simply have to deal with it. Sorry.
So let me explain how it works.
This quadcopter uses the YMFC-32 flight controller code and it has a 9600bps telemetry connection that sends telemetry data to the ground station. Because it uses a transceiver it can also receive data form the ground station.
To get this to work I needed to connect the TX output of the APC 220 transceiver to port A6 of the STM32. Because the APC220 modules work on 3.3V no level converter is needed.
If you are using other transceivers make sure that the voltage on the A6 pin does not exceed the 3.3V level as it is not 5V tolerant.
In de YMFC-32 flight controller code I setup another timer and made a small software serial interrupt handler that reads the incoming data. This way I still have the programming port available for serial output during programming and testing.
When the input handler received 12 bytes the flight controller will check the data for waypoint information.
As an error check all the received bytes are run through an xor operator.
This is also done by the flight monitor as you can see here. The data is only excepted as valid when both checks give the same result. This should prevent a false reading and an unwanted fly away.
Basically what happens in the YMFC-32 flight controller is this: when the quadcopter is hovering in GPS hold, the GPS location is stored in the l_lat_waypoint and l_lon_waypoint variables. As long as these waypoints are not changed the quadcopter will hover at that position.
When the lat and lon waypoins variables are changed the GPS PID controller will reposition the quadcopter to the new location. This technique is also used for the GPS cruise and return to home function.
So, when a new waypoint is received via the telemetry receiver, this part of the code will adjust the current waypoint slowly to the new waypoint.
I added these lines because we need an gentle start and finish at the beginning and end of the waypoint flight.
During the adjustment of the waypoint the waypoint_monitor variable is set to 6.
Because the waypoint_monitor value is added to the flight mode the result during a waypoint flight is 9. This is a conformation for the ground station that the waypoint is received and is currently executed.
Ok, safety first. When the return to home switch is activated or the flight mode is not 3, meaning GPS hold, the waypoint flight is canceled immediately. This way you can always fly your quadcopter back to the home location when something goes sideways.
And basically that's all I changed in the flight controller code.
To make programming and testing a lot easier I made this. A quadcopter simulator that simulates real feedback and the behavior of the original YMFC-32 flight controller. The only change that I made in the code is the waypoint feedback from the telemetry send code. During normal flight the YMFC-32 sends the real GPS location. Instead of the real location this simulator sends the GPS waypoint location that we want to change.
Second thing that I did is to put the manual_takeoff_throttle variable to 1500. This way they flight controller doesn't need to detect a real take-off.
In short, what you see on the screen is the real behavior of the waypoint variables in the flight controller. Because the quadcopter automatically follows these waypoints it's also the behavior of the quadcopter.
Now let's have a look at the Flight Monitor software.
I made this program with visual studio 2019. As already explained, I'm not a professional programmer and it took me some time to get used to the new environment. But as I always do, I set myself a goal and work as hard as needed to get to that goal. I will learn everything I need to know during my journey.
When I start the flight monitor I can select the correct port where the APC 220 is connected. Because the telemetry runs on 9600bps only I don't have to change the communication speed.
When I click connect the program will wait for a telemetry signal. When I now connect power to the flight controller simulator the data receive light will blink and the data fields are filled.
In the background almost the same code as on the Arduino telemetry receiver is running for gathering the individual variables.
When there are enough satellites in view the flight monitor will show the location of the quadcopter on the map. For your information, I shifted the longitude and latitude so I can simulate a flight in this park.
And just to make it clear, I want to build something simple and spare me the hassle of creating an Google API and find some way to implement this in the code and share this to you. Because the procedure for it changes so often I simply refuse to use it.
Now that we have that out of the way let's focus on visual studio. When you create a program in Visual studio you have a web browser tool that can be used to show a webpage. So that is what I used to show the map.
In fact, I used two of them. This way I can reload one browser in the background and show the other one. This will give a solid image on the screen as the loading of the map happens in the background.
Luckily there are some very useful map alternatives because basically all I need is a map that I can locate on the screen and put a marker on it that will represent my quadcopter.
Long story short, I went with openstreetmap. When I go to the openstreetmap address you get something like this. If I now zoom in on the park that I showed in the flight monitor you see something like this in the address bar.
This is the zoom level and the center latitude and longitude of the map. If I now go to the share button I can click the add marker button. I can now move the marker and copy the link to another tab.
Here you can see the latitude and longitude of the marker. By changing these numbers we can change the location of the marker while the map stays on the same location.
After I resized the screen we get something like this.
And that is exactly what I used in the flight monitor program. The stuff on the sides that I did not want to show are covered with these panels. Is this cheating by the way? Well, whatever it is, it's working.
Ok, let have a look at the flight monitor. On the transmitter I will change the flight mode to GPS hold. This is confirmed here.
When I start the motors this icon changes color and the flight timer starts to tick. The home position is marked by the quadcopter flight controller and also marked on the map by the flight monitor. The map is now centered and fixed on the home location and the quadcopter is now flying. Because it's flying in simulator mode I can now change the location of the waypoint with the pitch and roll stick.
To fly a single waypoint I can simply click on the map and a marker is placed. The flight monitor sends the specific latitude and longitude location to the quadcopter.
Because the map has a fixed ratio at different zoom levels it's possible to calculate the clicked latitude and longitude. We already know that the map is centered at the home location coordinates. So when I click on the map I get a x-y location in pixels.
When calculated from the center of the map and the ratio of the map I can calculate the clicked latitude and longitude coordinates. This part is needed because the distance between the longitude coordinates changes when we move further away from the equator.
The calculated coordinates are send to the quadcopter via the transceivers and finally a label is placed on the x-y location of the mouse click.
When the data is received correctly the quadcopter will fly to its new waypoint location and the flight mode changes from 3 to 9. If for some reason the new location data didn't make it to the flight controller the data is send again up to a maximum of 10 times. After ten times the flight monitor will give an error.
When the quadcopter arrives at the waypoint location the flight mode automatically changed back to flight mode 3. This is also the signal for the flight monitor to send a new data location.
To create a multipoint waypoint list I need to click the make list button first. I can now place a maximum of 8 markers on the map.
After placing the markers I can click the fly waypoints button. The flight monitor will now send the first waypoint and waits for the flight mode to become 9. When the flight mode changes to 9 the flight monitor will wait until the flight mode changes back to 3. After that the second waypoint is send. and so on.
Ok, very important and as already explained: during a waypoint flight the return to home switch will always override the waypoint input. This is to make sure that the pilot always have the ability to manually takeover the quadcopter. The same is true for the return to home on signal lost. So if the transmitter fails or you fly out of range the quadcopter will fly back home. And as always, make sure you test this before you rely on it.
So, when I activate the return to home during the waypoint flight, the waypoint flight is canceled and flight mode 5 is activated. The quadcopter will first gain altitude and later fly back to the home location.
You can follow the steps as they appear on the flight monitor screen.
When I now deactivate the return to home I can restart the waypoint flight.
When the quadcopter finished al the waypoint the message waypoints ready is shown.
And that's it for this video.
In the future I will make serious modifications to code as there is a lot to improve. Because this was just a study project for me and I will post the full code of this Visual Studio project on my website under the download section of the YMFC-32 autonomous. This download will also include the modified YMFC-32 flight controller code. So basically if you want to use it you only have to connect the TX of the APC220 to the A6 pin of the STM32.
Please note that you have to figure it out for yourself how it works as I'm not supporting it in any way.
I hope you enjoyed this video and if so please take the time to give this video a thumbs up and don't forget to subscribe.
I always ask myself why some Youtubers say that. Please subscribe? Like you don't understand how to click this button? When you made it till the end of this video I'm sure you are smart enough and that you can make your own decision if you want to subscribe. So thank you for watching and see you next time.