Executing pylib script on python client(cfclient)

Discussions about all things Bitcraze
Post Reply
Sexydove
Beginner
Posts: 10
Joined: Wed Apr 25, 2018 10:36 pm

Executing pylib script on python client(cfclient)

Post by Sexydove » Fri Jun 01, 2018 6:45 pm

Can I run a Python script from within a client?

The original purpose of mine was to represent the spatial coordinates information obtained from the 6 anchor LPS system in a 3D plot.
However, I think that it would be much better to create another UI tab of the client and it will be more orderly and less laborious.

Then I have a problem that I can not think of. There is a problem that can not execute the script of the library separately while communicating with the client. It happens because it uses only one communication port, but I would like to know if you can run Python scripts in the client. If so, I'd like to put a list of scripts into ui so that it runs ... Does anybody know the relevant information?

Extra
I am wondering how to(how it) send a packet to crazyflie in python. The packets from crazyflie are part of the wiki, but no description of the message queue from Python was found. Could anybody give me a brief summary?

Extra.2
I also wonder how to get the lps system's update cycle faster. The refresh rate of the lps plot in the python client (cfclient) seems to be about 0.5(numerically 100ms) seconds slower.


**Thanks for the fast replies so far. I Really appreciate to you.

arnaud
Bitcraze
Posts: 1706
Joined: Tue Feb 06, 2007 12:36 pm

Re: Executing pylib script on python client(cfclient)

Post by arnaud » Mon Jun 04, 2018 11:34 am

You can write your own tab for the Crazyflie client, there is and example tab in the code: https://github.com/bitcraze/crazyflie-c ... mpleTab.py

There is an old video tutorial that shows how to add a tab in the client, it is outdated for the details (ie. files have moved), but it should give you an idea of the procedure: https://www.youtube.com/watch?v=cutgIMfHwyQ.

For the packet transmision from python, you can look in the source code of the lib, it is pretty easy to find places that send packets. For example the localization module is pretty simple and implements both receiving and sending packets: https://github.com/bitcraze/crazyflie-l ... #L107-L111

I do not understand the question about the logging of the position. Are you referring to update rate or to latency? The rate can be setup up to 100Hz by setting up a new log block. If you want faster than 100Hz you need to write custom code but note that the radio link is limited to about ~800 packet per second each way and that the kalman filter in the Crazyflie is running at 100Hz.

Sexydove
Beginner
Posts: 10
Joined: Wed Apr 25, 2018 10:36 pm

Re: Executing pylib script on python client(cfclient)

Post by Sexydove » Mon Jun 04, 2018 6:42 pm

Thanks for the reply.

However, I decided that there is a still narrow way to create a tab and run a Python script in it.
In the example video on your suggestion, it simply manipulated the motor control variables. The way to continuing manipulating variable is obviously extended to controlling the motor pwm individually, and it seems like a way to redevelop the flight control algorithm from base. Is it the best way to control it? Is there any way to take advantage of using existing Python scripts on the client?

Anyway, I decided to work with matplotlib in Python script, since it is unknown whether we get the desired result in the client. But the problem is that I do not know how to log in and fly when crazyflie is connected in a script. Do I need some sort of multithreading?

To be precise, I want to run a script that expresses data and a script that controls flight data in the same script. However, the problem is that when one of def_connected logs is executed, flight control is not executed and conversely, it is not logged during flight control.
Do I have to implement logging and flight control in a different thread(logging, flight) then use two thread

Code: Select all

Thread (target = self._logging) .start ()
Thread (target = self._flight) .start ()
#in python
to both working of logging and flight simultaneously?

***
When you answer a question, a few questions pop out.
I always thank you for your reply each time, also I hope you to think of these questions as something I am interested in your crazyflie.

Sexydove
Beginner
Posts: 10
Joined: Wed Apr 25, 2018 10:36 pm

Re: Executing pylib script on python client(cfclient)

Post by Sexydove » Thu Jun 07, 2018 10:51 am

Found way using multi threading and message queue.

but still don't know how to import python script on the cfclient.(Even I confirmed to use own python drone managing script)
Maybe it would also related with sort of button activates some threads using commander.py

Getting some answers from the developers is always much appreciated one for me, but finding it myself is likewise better.

Post Reply