Unpack requires a buffer of 4 bytes

Firmware/software/electronics/mechanics
Post Reply
GIduarte
Beginner
Posts: 13
Joined: Mon Aug 17, 2020 6:18 pm

Unpack requires a buffer of 4 bytes

Post by GIduarte »

Hello, I have a problem.

I want to receive by log block this values:
  • rateYaw
  • rateRoll
  • ratePitch
  • pitch
  • roll
  • vx
  • vy
  • vz
  • quat
  • batteryLevel
So I use basiclog.py and replace :

Code: Select all

	self._lg_stab.add_variable('stabilizer.roll', 'float')
        self._lg_stab.add_variable('stabilizer.pitch', 'float')
        self._lg_stab.add_variable('stabilizer.yaw', 'float')
by

Code: Select all

	self._lg_stab.add_variable('pm.batteryLevel', 'uint8_t')
        self._lg_stab.add_variable('stateEstimateZ.quat', 'uint32_t')
        self._lg_stab.add_variable('stateEstimateZ.vx', 'int16_t')
        self._lg_stab.add_variable('stateEstimateZ.vy', 'int16_t')
        self._lg_stab.add_variable('stateEstimateZ.vz', 'int16_t')
        self._lg_stab.add_variable('stateEstimateZ.rateYaw', 'int16_t')
        self._lg_stab.add_variable('stateEstimateZ.rateRoll', 'int16_t')
        self._lg_stab.add_variable('stateEstimateZ.ratePitch', 'int16_t')
        self._lg_stab.add_variable('stateEstimate.pitch', 'float')
        self._lg_stab.add_variable('stateEstimate.roll', 'float')
But I have this error:
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/log.py", line 580, in _new_packet_cb
block.unpack_log_data(logdata, timestamp)
File "/home/bitcraze/.local/lib/python3.6/site-packages/cflib/crazyflie/log.py", line 307, in unpack_log_data
unpackstring, log_data[data_index:data_index + size])[0]
struct.error: unpack requires a buffer of 4 bytes
I tried into client too, but although the program accepted, the file in which the log block was written contained only the header.

Does anyone have any suggestions??
kristoffer
Bitcraze
Posts: 630
Joined: Tue Jun 30, 2015 7:47 am

Re: Unpack requires a buffer of 4 bytes

Post by kristoffer »

Hi!

There is a limit to how many log variables that can be addd to one block, the total size must be max 26 bytes. Unfortunately the error reporting is not stellar for this...
You simply have to use two log blocks instead.
If you are using the SyncLogger class, you can pass in an array of log blocks.
GIduarte
Beginner
Posts: 13
Joined: Mon Aug 17, 2020 6:18 pm

Re: Unpack requires a buffer of 4 bytes

Post by GIduarte »

Hi, thanks for the reply.

I readed about the limit of 26 bytes per block.

But, 1 (uint8_t) + 4 (uint32_t) + 6 x 2 (int16_t) + 2 x 4 (float) = 25 bytes, which is below the limit ...
kristoffer
Bitcraze
Posts: 630
Joined: Tue Jun 30, 2015 7:47 am

Re: Unpack requires a buffer of 4 bytes

Post by kristoffer »

You are right, my bad! I created an issue https://github.com/bitcraze/crazyflie-l ... issues/164 for it.
It seems to work if you remove one of the variables in the log config, a work around may be to use two log blocks instead.
Post Reply