I like the idea of having a script to your ground station. It is a way to implement some logic that your original GUI does not enable directly. It can also enable integration easily with other dlls and modules far beyond the original scope of the Mission Planner. The first thing I asked myself about when I found this "treasure" is what were the available variables and classes that I can already access, well I could not find a clear list, maybe I am not good at googling -which is true-. So I opened the source and tried to figure out myself.
The main start here is Script.cs it is where the engine class and scope class exist. what we want here is the scope class, it is the INTERFACE point where you can LINK outter world with PYTHON script.
scope.SetVariable (varname, realobject);
Using above function you can add more objects to link with and define names for it in Python. See the below figure where all objects are defined - and where you can add more if u want.
I traced back the added classes MainV2.comPort, MainV2.comPort.MAV.cs, this, this that are mapped to MavLink.cs , CurrentState.cs,Script.cs that means any public variable of function in these classes can be accessed from python script.
Lets open Mission Planner and open the script window and check the above conclusion:
In the above image you can see Script.SendRC …. You can find this function in Script.cs
Same for cs.alt which should exist in CurrentState.cs
Now you can get all the functions you want from these classes, you can even add your own classes and functions.
I hope you find my small blog is useful.
Thanks,
M. Hefny
Comments
very happy to b able to contribute :)
Thank u
I would like to for sure.
MHefny: This is great! It's definitely time to flesh out the MP Python scripting documentation. Would you like to add this (or something else) to the manual? I can have the team give you edit access.
I'm trying this myself and am also not quite sure which Python libraries are supported (or even whether that is Python 2.x or 3.x) so it would be good to flesh it out.
Added to my too-big-and-growing list of cool stuff to play with
Cheers
@Jack sorry I could not get the question right.
but flight pathes are programmed in C++ inside arducopter board, and C# in mission planner and can be controlled using Python from the Python window. I hope this helps.
@Bim for Python this link it is a simple nice language.
however C# is not that easy but everything is achievable ... goodluck.
There definitely have been a lot of scripting languages. What was the one for programming flight paths?
I'm not a very adapt programmer but I'll see what I can muster up.
Your feedback (& post) was very helpful, much obliged.
@Bim, everything can be done in programming, but using script engine in Mission Planner you can link it with dlls from outside and start calling them within mission planner.
The other way around is possible but u should develop ur own solution and try to "automate" mission planner -programatical automation not UAV I mean- to start and connect to it, similar to automating excel for example. but I believe this is not the scope I mean within this blog.
I hope my feedback helps.
@MHefny, I actually meant the opposite. I want to write a stand-alone python script that could use the mission planner functions (A completely separate process).
For example run a mission to navigate somewhere, read flight data from a script ('python foo.py' on command line, not on mission planner), do some calculation and add another way point.