Aeroplane DIY Using Raspberry Pi

 hello everybody this is Tiziano of Xworks and today I'm going to release my Python library for auto ArduPlane.  In my previous videos I've always talked about multicopter and one might wonder are plane's compatible with companion PCs? Of course the answer is yes. Here at Xworks where I work we've been collaborating with the University of Tulsa and we're providing the support for their experimental setup. One of my recent tasks was creating a Python library for connecting with ArduPlane and making things more explicit for developers to set up their code and grab variables from the plane and write their autonomous scripts. Today I'm going to share this library on my github account with you. As you will see there's nothing extraordinary, it's just a wraparound the Drpnkit toolkit where I simplified variables name and functions. For example in order to get the position latitude rather than writing vehicle.location.global_relative_frame.l

at you simply write plane.pos_lat, easy. Furthermore I added a couple of very useful functions for example arming takeoff. You know that for plane you cannot arm and take off like you do for the copter? You need to add a takeoff item in the mission and then set the vehicle to auto mode. In this video I will quickly go through my library and we will just have a quick look to the main functions and variable then we're gonna write a simple script for testing our library and later we're gonna simulate everything in our software in the loop and for the first time we're going to have a 3d visualization using the open-source flight simulator Flight Gear. 

And now if you're excited follow me in the next tutorial. let's start up by initializing our vehicle passing either the connection string or the vehicle object. the vehicle object can have been defined in your script before and so if you're already connected with a vehicle you just pass it during the initialization method otherwise you just pass the connection string that could be your UART and baud rate or the TCP or UDP address and port. Second thing I do I set up listeners. Now the listeners we already talked about that, they are a very good way to listen to a telemetry message when is coming from the vehicle so that we can deal with it, rather than having something that always runs in background it just it's something that it awakes only when it receives a certain message. Then here I have my internal variables like air speed, ground speed, the position latitude longitude, the relative altitude above takeoff point and the absolute altitude relative to mean sea level. then I have the attitude roll, pitch and yaw in degrees and I have the wind information like the speed and the direction both going to and coming from, depending on what you're gonna be using I have both of them then I have the climb rate in meters per second and the throttle, then have the autopilot mode.

 then here I store  the mission items in the vehicle and then two extra fields that are the location home and location current that are both in global relative type. Now let's go ahead and see in detail those methods for example connect, this is pretty easy it just connects using the Dronekit and setup_listeners, what I define is for example a listener for the attitude where as you see it just store roll pitch and yaw in degrees into my attitude_roll attitude_pitch and attitude_yaw in degrees and information from the wind where I have wind speed and then I have the the direction that is the direction coming from that comes from the vehicle and I transform this direction coming from into go to direction here it is adding just adding 180 degrees and then having a module 360 degrees. 

Okay so the main function I want to introduce you arm and take off now arm and take off is very useful I feel because arm_and_takeoff command works great for copter and it what it does it just arms the vehicle takes off and puts the vehicle other purifying altitude and weights there in guided moment I want to do the same thing for the plane so I created this arm and take off for a plane and you wonder why you can I just call the vehicle arm and takeoff function well because it doesn't work for plane plane Tecna matically takes off if you have a take off item in their mission and you set the VIN the vehicle into Auto mode and this is exactly what I do and the second function I want introduced is a very simple function called set ground course lets you set the ground the direction the flight direction in terms of ground course no no heading because heading the vehicle has to compensate for wind when it flies and so setting the heading doesn't do any good for what I'm gonna do I just create a target that is look at it far away from me at the course that is provided by this angle dag so it's like creating you know it's like trying to chase this target and I would never reach but in this way the vehicle actually in there for my autonomous script just creating and setting the ground course for me vehicle how does it do it well it first calls this go to function as nothing more than a vehicle simple go to to a location a location that I create using this other method ground course the location where I the angle and the altitude the altitude can be done as if it's none actually it keeps the current altitude as default so the ground corstel location what it does it just calls another function that is get target from bearing a target from bearing creates this location that is based is located 

5,000 meters from the vehicle at an angle that is the angle Dec rotate translated into radians I pass my location current as the original location and there's get targets from bearing it just cold get location meters and this get location meters actually does the job so I don't want to go into much detail if you're free to explore the code it's pretty easy and you'll see that it's very very useful for you guys again we're gonna now create a script and we're gonna explore this system working in front of us here's what I want to do I want to create a script for testing my library and I'm gonna create this script right here we start off by checking whether name is equal main in this case we're going to create a parser for parsing our arguments main argument is connect where the default is the TCP port 5762 on localhost then we're going to create our object plane passing the connection string now in case the vehicle is not armed we arm and take off then we wait for five seconds and then we start testing our ground course we set our cruise altitude at 100 meters we start our ground course at zero degrees and we set a delta angle of 20 degrees then in a while loop we just call the method sell ground course passing the current reference angle and the cruise altitude then we wait for five seconds and then we increase the cruise angle by the delta angle and we repeat and let's print out the current reference course let's browse in the autopilot repository and then browsing tools and auto test and select the batch file FG plane view this will launch flight gear and make it listen to the properly DP port then as usual select the simulation paint emission planner and start the simulation for a plane then browse on the folder lips where there is the library 

plane of py then keeping shift pressed right-click and select open common window here now we'll just write Python planed out py and that's it the system takes off and then starts giving ground course references by steps of 20 degrees and I have some wind coming from east so the system will drift toward west so I hope that this library of mine would make things a little bit easier for whoever is dealing with auto plane today we recently had a lot of fun find this library at the airfield with a foamy fpp plane so I hope it's fully debugged if you want to know more about setting up your companion PC and connecting with our tow plane or the copter just check out my other videos and also if you want to download my free software just check out my DTaP webpage don't forget to subscribe and for now I thank you for watching I'll see you next time