Page 1 of 1

Print Swarm Position - Individual position

Posted: Tue Nov 19, 2019 2:43 pm
by faria
Hello All,

I want to print the position of each drone of my swarm using swarm lib. I tried using log lib etc, but without success (a lot of problems). How i can do it?

Thanks a lot

Re: Print Swarm Position - Individual position

Posted: Thu Nov 21, 2019 8:09 am
by arnaud
I think you will have to setup an async log block for each Crazyflie. Using the swarm API you can run a function for each Crazyflie in the swarm (https://github.com/bitcraze/crazyflie-l ... rm.py#L110) so you can write a function that setups a log block containing the position estimate variables.

An example of such a function can be found in the autonomous sequence example: https://github.com/bitcraze/crazyflie-l ... #L109-L124. One trick when dealing with multiple Crazyflies is to use the python lambda function to call a callback with an extra argument: you want your log callback to be called with the identity of the Crazyflie and this could be achieved with lambda:

Code: Select all

    # In this context, the current URI of the crazyflie is in the 'uri' variable
    log_conf.data_received_cb.add_callback( lambda timestamp, data, logconf: position_callback(uri, timestamp, data, logconf) )

Re: Print Swarm Position - Individual position

Posted: Thu Nov 21, 2019 12:30 pm
by aidos
Hello Arnaud,

Thank you for the quick reply!

We were using the code from "hl-commander-swarm.py" to which we now added the "automousSequence.py"'s functions "start_position_printing" and "position_callback" as suggested in your post.

They seem to work fine when the swarm is constituted by one drone alone, but not when the swarm is bigger. I assume that is why we would have to add the "uri" parameter via the lambda function? We did try that but we get the error "NameError: name 'uri' is not defined". I suppose we're missing something?

We have used the uris to construct the Swarm object, and then call its method "parallel_safe" with the" start_position_printing" function as an argument.
We also tried with the "sequential" method as you referred but with the same result.

Any thought on what we're doing wrong?

Re: Print Swarm Position - Individual position

Posted: Fri Nov 22, 2019 8:53 am
by arnaud
When using parallel_safe, the same way it is used in other part of the code, you can get the URI from "scf.cf.link_uri". This should allow you to setup the log block the same way it is done in autonomousSequence but with the Crazyflie URI parameter

Re: Print Swarm Position - Individual position

Posted: Fri Nov 22, 2019 12:49 pm
by aidos
Hello Arnaud,

It did work out, we are finally able to get each drone's position!

Thank you loads for your help, it is greatly appreciated.

InĂªs