Control Commands and Logging in the same python script

Firmware/software/electronics
Post Reply
RSOCAS
Beginner
Posts: 6
Joined: Wed Nov 29, 2017 3:09 pm

Control Commands and Logging in the same python script

Post by RSOCAS » Tue May 01, 2018 1:07 am

Dear all,
I have been using the examples of https://github.com/bitcraze/crazyflie-l ... r/examples. In my project I can send commands to the CF2 for exmaple modifying the script ramp.py. On the other hand, with the script basiclog.py I can read pediodically the log of the copter. My problem now is that I do not know how I can read the sensor information by logging function and at the same time send commands to the copter in the same script. I need this functionality to implement a controller like PID or others in a python script to control the copter.

Somebody can help me to this issue

Best regards,
Rafael Socas

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

Re: Control Commands and Logging in the same python script

Post by arnaud » Wed May 02, 2018 8:15 am

You can setup log block callbacks and control the Crazyflie in a loop, the callbacks will be called when a log packet arrives. An example of that can be found in the autonomous sequence example, if you uncomment the start_position_printing line a log block is created and started, then the crazyflie is controlled and logs are received at the same time: https://github.com/bitcraze/crazyflie-l ... ce.py#L151

If you only need one log block, another solution is to use the synchronous API. The multiranger_push.py example controls the Crazyflie velocity using the distances logged from the multiranger: https://github.com/bitcraze/crazyflie-l ... er_push.py.

RSOCAS
Beginner
Posts: 6
Joined: Wed Nov 29, 2017 3:09 pm

Re: Control Commands and Logging in the same python script

Post by RSOCAS » Wed May 02, 2018 11:39 am

Thank you so much,
you are very kind. This information is very useful for my project.

Best regards,
Rafael Socas

Post Reply