Python Scripting in Mission Planner

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.


M. Hefny

Views: 14655

Comment by Bim on November 11, 2013 at 2:34pm

Was not aware of that feature, pretty awesome!

Can you use python to interface with the mission planner with an external script? Some sort of an API I guess.

Comment by Rana on November 11, 2013 at 6:33pm

Excellent ! This will open limitless scope for those RC pilots who have some developer flare in them.

Comment by MHefny on November 12, 2013 at 12:25am

@Bim, sure you can interface with any external API. This will be by adding this DLL to mission planner project and use Scope.SetVariable to connect it to Python.

u will need to recompile mission planner.

maybe if I dig deeper I find a fast way, but this way will work for sure.

Comment by Brandon on November 12, 2013 at 9:38am

Great stuff!  I've been looking for this!

Comment by Bim on November 12, 2013 at 11:25am

@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' on command line, not on mission planner), do some calculation and add another way point.

Comment by MHefny on November 12, 2013 at 1:53pm

@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.

Comment by Bim on November 12, 2013 at 2:46pm

I'm not a very adapt programmer but I'll see what I can muster up.

Your feedback (& post) was very helpful, much obliged.

Comment by Jack Crossfire on November 12, 2013 at 6:33pm

There definitely have been a lot of scripting languages.  What was the one for programming flight paths?

Comment by MHefny on November 12, 2013 at 11:35pm

@Bim for Python this link it is a simple nice language.

however C# is not that easy but everything is achievable ... goodluck.

Comment by MHefny on November 12, 2013 at 11:37pm

@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.


You need to be a member of DIY Drones to add comments!

Join DIY Drones

© 2019   Created by Chris Anderson.   Powered by

Badges  |  Report an Issue  |  Terms of Service