Autonomous Flight with Swarm

Discussions about autonomous flight in general, regardless of positioning method
Post Reply
undays
Beginner
Posts: 12
Joined: Sat Oct 30, 2021 1:20 am

Autonomous Flight with Swarm

Post by undays »

Hi all,

I have written a script drawing ideas from previous posts on this forum to try to get a swarm to execute the autonomous flight task utilizing the multiranger and flowdeck stem bundle from Bitcraze.

My only issue is that the behavior of the autonomous flight correctly works for one drone, but when observing the other 2 drones (a total of 3 drones) the drones seem to drop and stop running the task or that they do not continuously fly in a direction and are unable to respond to my lines where I utilize the multiranger's sensor readings. Could I get an answer on why that be the case if anyone happens to know? It would be greatly appreciated thanks.

My code is in this link here since it might be long
https://pastebin.com/VXGbTneK

Thanks again.
kristoffer
Bitcraze
Posts: 630
Joined: Tue Jun 30, 2015 7:47 am

Re: Autonomous Flight with Swarm

Post by kristoffer »

Hi!

I'm not sure why you run into problems with more than one CF, but I believe your code probably is not doing what you are hoping for.
In the long list of if-statements, several of them will be true at the same time, so for instance when

Code: Select all

if is_close(multiranger.front) and is_close(multiranger.right) and is_close(multiranger.left)
is true, then

Code: Select all

if is_close(multiranger.front) and is_close(multiranger.right):
and

Code: Select all

if is_close(multiranger.front) and is_close(multiranger.left):
will also be true. This means that you are telling the Motion commander to

Code: Select all

                    motion_commander.turn_right(180, 90)
                    motion_commander.start_forward(0.1)
and then

Code: Select all

                    motion_commander.turn_left(90, 90)
                    motion_commander.start_forward(0.1)
and finally

Code: Select all

                   motion_commander.turn_right(90, 90)
                    motion_commander.start_forward(0.1)
The end result in this case is probably right actually (by accident), but you should most likely use

Code: Select all

elif
statements instead
undays
Beginner
Posts: 12
Joined: Sat Oct 30, 2021 1:20 am

Re: Autonomous Flight with Swarm

Post by undays »

Thanks for catching that I changed it to elif and it works a lot better now.

I also don't know what happened but it managed to start working with the swarm now.

Thanks again.
Post Reply