How to rewrite the examples to get the position of the crazy

All discussions related to the Loco Positioning system
Post Reply
Jun-ichi Toji
Beginner
Posts: 4
Joined: Wed Jul 01, 2020 6:24 am

How to rewrite the examples to get the position of the crazy

Post by Jun-ichi Toji »

I have a question about rewriting the program to get the position of the crazyflie.

I browsed this post
viewtopic.php?t=2867.
I understood that parameters in any example python file need rewriting to stateEstimate.x, stateEstimate.y and stateEstimate.z, but I don’t know which part on files.
The variables list of logTOC tab in the client includes stateEstimate.x, stateEstimate.y and stateEstimate.z.
I’m a program beginner, so I would like to know in detail.

Thank you.
kimberly
Bitcraze
Posts: 1050
Joined: Fri Jul 06, 2018 11:13 am

Re: How to rewrite the examples to get the position of the crazy

Post by kimberly »

Hi!

So you need to look at the examples folder of this repository. Make sure that the you follow the readme to install cflib or have done

Code: Select all

pip3 install cflib
You can use both the basiclog.py or basiclogSync.py (the last one is easier to understand I think). Make sure that you try out one of these to check if you can connect to your crazyflie (if you haven't changed your uri yet:

Code: Select all

python3 examples/basiclog.py
In both files you have the following lines:

Code: Select all

        self._lg_stab = LogConfig(name='Stabilizer', period_in_ms=10)
        self._lg_stab.add_variable('stabilizer.roll', 'float')
        self._lg_stab.add_variable('stabilizer.pitch', 'float')
        self._lg_stab.add_variable('stabilizer.yaw', 'float')
You simply change those to:

Code: Select all

        self._lg_stab = LogConfig(name='Position', period_in_ms=10)
        self._lg_stab.add_variable('stateEstimate.x', 'float')
        self._lg_stab.add_variable('stateEstimate.y', 'float')
        self._lg_stab.add_variable('stateEstimate.z', 'float')
hope this is clear enough to get you started!
Jun-ichi Toji
Beginner
Posts: 4
Joined: Wed Jul 01, 2020 6:24 am

Re: How to rewrite the examples to get the position of the crazy

Post by Jun-ichi Toji »

Thank you for your kind reply.
Thanks to you, we can now see the positions of crazie.

I have additional quastion.
I want to get the flight position at the same time when performing flight control using initial_position.py, but I don't know how to rewrite it.

Could you give me some insight into this?
kimberly
Bitcraze
Posts: 1050
Joined: Fri Jul 06, 2018 11:13 am

Re: How to rewrite the examples to get the position of the crazy

Post by kimberly »

You can setup a callback function for your logging variable in that case.

By the way, I would highly suggest you to try out this new tutorial: https://www.bitcraze.io/documentation/r ... log_param/. It is brand new and still tested, so therefore not in the tutorial list yet, but teaches you how to work with the parameters and logging framework, so afterwards you will be able to implement this in your own code.
Post Reply