Looking for feedback: MAVFleetControl Mulitple aircraft

Hi all!

Looking for some feedback on some code. Most of the frameworks I saw to control multiple aircraft (swarm) were all using ROS. I wanted to use MAVSDK-Python. I wrote a wrapper around it to allow for threaded awaitable control of the aircraft to control a small swarm.

Link: https://github.com/julianblanco/MAVFleetControl

Hoping to see if this is useful for anyone / how it can be improved

1 Like

Nice, thanks for sharing!

The current version of MAVSDK-Python does not allow for multiple aircraft because a user can not specify the desired port. Please use my fork (GitHub - julianblanco/MAVSDK-Python: MAVSDK client for Python.) until the PR is hopefully merged.

Is that still true? Or what can we do to fix this?

No that is not true anymore. Thanks for merging my code! It was a small change but now one can spawn 20+ aircraft without a bunch of terminals and manually starting mavsdk_server

1 Like

The one thing that I need to test more is the override_action method in the craft class.

When assigning actions to the craft, it adds them to a thread safe queue. In the case of emergency action such as RTB or land, the override action should grab the thread lock, signal to the current task to cancel and then immediately queue the override action such as land. It works on my simulated aircraft in Gazebo, need to test it on a real aircraft.

Can you point me to where that happens in your code? Sounds interesting.

Of course!

The queue gets created in the construtor for the craft class. Each aircraft is run in it’s own thread to allow for simultaneous control.

The “run” function will connect to the aircraft, then runs an infinite loop (with an exit parameter that can be passed to exit cleanly)

Still in the run function (lines 42 -45 of craft,py) it grabs the thread lock, grabs the action from the queue and then attempts to run it

				with self.current_task_lock:
					self.current_task = self.loop.create_task(action(self))
				try:
					self.loop.run_until_complete(self.current_task)

The add action method, simply adds actions to the queue,

	def add_action(self, action):
		self.tasking.put(action)

and the override action should grab the thread lock, clear the queue, put the emergency action in the queue and then cancel the current action.

	def override_action(self,action):

		with self.current_task_lock:
			self.tasking.queue.clear()
			self.tasking.put(action)

                        #signal to the current task to end early
			if self.current_task is not None:
				self.current_task.cancel()

The check for None is for the edge case that the queue is empty.

I plan on having a button in my ground control station that when tripped, will tell all the aircraft to land as a safety feature.
Probably and arduino and some prompt tool kit /pyserial magic.

1 Like