Minimum sampling time

Firmware/software/electronics/mechanics
Post Reply
MoscardelliStefano
Beginner
Posts: 1
Joined: Wed Nov 27, 2019 9:00 am

Minimum sampling time

Post by MoscardelliStefano » Wed Nov 27, 2019 9:31 am

Hello everyone,

I'm working on a model identification algorithm using data coming from the crazyflie (Accelerometers, gyro and zrange). I have 2 questions about the samping data:
1) Starting from the basiclog.py example i wrote a code that creates data blocks in and log the variables writing them on a txt file. When chosing the sampling time i realized that for times less than 10ms the code gives always this error:

Code: Select all

ERROR:cflib.crazyflie:Exception while doing callback on port [2]

Traceback (most recent call last):
  File "/home/bitcraze/workspace/Prova Python/logData.py", line 149, in _connected
    self._cf.log.add_config(self._lg2)
  File "/home/bitcraze/.local/lib/python3.6/site-packages/cflib/crazyflie/log.py", line 467, in add_config
    'The log configuration is too large or has an invalid '
AttributeError: The log configuration is too large or has an invalid parameter

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/bitcraze/.local/lib/python3.6/site-packages/cflib/crazyflie/__init__.py", line 396, in run
    cb.callback(pk)
  File "/home/bitcraze/.local/lib/python3.6/site-packages/cflib/crazyflie/toc.py", line 176, in _new_packet_cb
    self._toc_fetch_finished()
  File "/home/bitcraze/.local/lib/python3.6/site-packages/cflib/crazyflie/toc.py", line 153, in _toc_fetch_finished
    self.finished_callback()
  File "/home/bitcraze/.local/lib/python3.6/site-packages/cflib/crazyflie/__init__.py", line 169, in _param_toc_updated_cb
    self.connected.call(self.link_uri)
  File "/home/bitcraze/.local/lib/python3.6/site-packages/cflib/utils/callbacks.py", line 54, in call
    cb(*args)
  File "/home/bitcraze/workspace/Prova Python/logData.py", line 181, in _connected
    Thread(target=self._ramp_motors).start()
AttributeError: 'Logger' object has no attribute '_ramp_motors'
Arethere any limitations onthe sampling time?

2) if yes, is it possible via firmware to avoid this and sample at a higher frequency?
Thank you all
Stefano



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

Re: Minimum sampling time

Post by arnaud » Thu Nov 28, 2019 7:43 am

Hi,

1) Yes, on the protocol side sampling time is expressed in multiple of 10ms so the minimum achievable logging period is 10ms.

2) If you need faster logs you can easily hack it by removing the *10 where log block is started in the firmware: https://github.com/bitcraze/crazyflie-f ... log.c#L392. If you do this change, asking for a log block every 50ms will actually set it up every 5ms. Note that the radio communication is limited to about 800 packets per seconds max, so 1ms logging will likely not work.

giandoman
Member
Posts: 36
Joined: Wed Sep 27, 2017 1:23 pm

Re: Minimum sampling time

Post by giandoman » Tue Dec 03, 2019 11:48 am

arnaud wrote:
Thu Nov 28, 2019 7:43 am
Hi,

1) Yes, on the protocol side sampling time is expressed in multiple of 10ms so the minimum achievable logging period is 10ms.

2) If you need faster logs you can easily hack it by removing the *10 where log block is started in the firmware: https://github.com/bitcraze/crazyflie-f ... log.c#L392. If you do this change, asking for a log block every 50ms will actually set it up every 5ms. Note that the radio communication is limited to about 800 packets per seconds max, so 1ms logging will likely not work.
Hello Arnaud i want to attach another question on the previous one asked by Stefano, always regarding the sampling time.
In the basiclog.py code, in the method connected, when I initialize an instance of LogConfig I pass also the sampling time "period_in_ms" which, is set at 10 by you guys. In the declaration of the LogConfig class this value is then further divided by 10 and rounded as an integer "self.period = int(period_in_ms/10)".
What does it mean? What will be the sampling time used if I pass for example 50ms as parameter? 50 or 5ms?
Is it a "trick" to limit, from the python side, the sampling time to 10ms? indeed if I set a sampling time less than 10ms I have an Attribute error "The log configuration is too large or has an invalid parameter" https://github.com/bitcraze/crazyflie-l ... og.py#L467
Am I correct?

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

Re: Minimum sampling time

Post by arnaud » Tue Dec 03, 2019 1:01 pm

This is not a trick, it is an implementation of the Crazyflie Log protocol: the packet that contains the log block period encodes the period as a 8bit unsigned interger in 10ms steps. So for example if you ask for a period of 150ms, the packet sent to the Crazyflie will contain a period of 15 which is then interpreted as 150ms by the Crazyflie. This encoding also impose a minimum period of 10ms since it is not possible to encode lower periods.

If you would implement the firmware hack I tacked about in my previous message, you would need to pass 10 times the period on the python side. So, a realistic example, would be to setup a log with a 5ms period. In that case you will enter 50ms in the python API and since the Crazyflie do not multiply by 10 anymore it would result with a period/sampling time of 5ms.

giandoman
Member
Posts: 36
Joined: Wed Sep 27, 2017 1:23 pm

Re: Minimum sampling time

Post by giandoman » Tue Dec 03, 2019 1:34 pm

arnaud wrote:
Tue Dec 03, 2019 1:01 pm
This is not a trick, it is an implementation of the Crazyflie Log protocol: the packet that contains the log block period encodes the period as a 8bit unsigned interger in 10ms steps. So for example if you ask for a period of 150ms, the packet sent to the Crazyflie will contain a period of 15 which is then interpreted as 150ms by the Crazyflie. This encoding also impose a minimum period of 10ms since it is not possible to encode lower periods.

If you would implement the firmware hack I tacked about in my previous message, you would need to pass 10 times the period on the python side. So, a realistic example, would be to setup a log with a 5ms period. In that case you will enter 50ms in the python API and since the Crazyflie do not multiply by 10 anymore it would result with a period/sampling time of 5ms.
perfect Thank you.

Post Reply