0
$\begingroup$

I would like to define stateEstimate.vx, stateEstimate.vy, and stateEstimate.vz variables to access those data. I used the following code parts.

def _connected(self, link_uri):

        self.get_logger().info('Connected!')
        self._lg_stab = LogConfig(name='Stabilizer', period_in_ms=100)
        self._lg_stab.add_variable('stateEstimate.x', 'float')
        self._lg_stab.add_variable('stateEstimate.y', 'float')
        self._lg_stab.add_variable('stateEstimate.z', 'float')
        self._lg_stab.add_variable('stateEstimate.vx', 'float')
        self._lg_stab.add_variable('stateEstimate.vy', 'float')
        self._lg_stab.add_variable('stateEstimate.vz', 'float')        
        self._lg_stab.add_variable('stateEstimate.roll', 'float')
        self._lg_stab.add_variable('stateEstimate.pitch', 'float')
        self._lg_stab.add_variable('stateEstimate.yaw', 'float')
               
        self._lg_range = LogConfig(name='Range', period_in_ms=100)
        self._lg_range.add_variable('range.zrange', 'uint16_t')
        self._lg_range.add_variable('range.front', 'uint16_t')
        self._lg_range.add_variable('range.right', 'uint16_t')
        self._lg_range.add_variable('range.left', 'uint16_t')
        self._lg_range.add_variable('range.back', 'uint16_t')
        try:
            self._cf.log.add_config(self._lg_stab)
            self._lg_stab.data_received_cb.add_callback(self._stab_log_data)
            self._lg_stab.error_cb.add_callback(self._stab_log_error)
            self._lg_stab.start()
            self._cf.log.add_config(self._lg_range)
            self._lg_range.data_received_cb.add_callback(self._range_log_data)
            self._lg_range.error_cb.add_callback(self._range_log_error)
            self._lg_range.start()

        except KeyError as e:
            print('Could not start log configuration,'
                  '{} not found in TOC'.format(str(e)))
        except AttributeError:
            print('Could not add Stabilizer log config, bad configuration.')

When I run my python file via ROS2, I saw the following part on the terminal (Could not add Stabilizer log config, bad configuration). I could not get why it happens. However, whenver I use the above code part without stateEstimate.vx, stateEstimate.vy, and stateEstimate.vz, it works pretty well. Could you help us to fix it, thanks.

ntukenmez3@ae-icps-407120:~/Documents/2023-crazy-flie-1/crazyflie_ros2_experimental_2/crazyflie_ros2$ ros2 run crazyflie_ros2 crazyflie_publisher 
[INFO] [1698871075.735318053] [crazyflie_publisher]: Connected!
Could not add Stabilizer log config, bad configuration.
$\endgroup$
1
  • 1
    $\begingroup$ hmm.... strange I didn't get a notification of this support question... I'm even monitoring the UAV tag!. If it takes too long, make an issue on the experimental repository or start a thread on the bitcraze forum $\endgroup$ Nov 13, 2023 at 13:47

1 Answer 1

1
$\begingroup$

The error itself comes from your own (or the copied) script

        except AttributeError:
            print('Could not add Stabilizer log config, bad configuration.')`

This is an error but it is not clear why it fails. Here is the API documentation of the crazyflie python library logging functionality:

https://www.bitcraze.io/documentation/repository/crazyflie-lib-python/master/user-guides/python_api/#logging

Here it says that you can only create logblocks for messages that are no larger than 30 bytes. the logblock 'Stabilizer' contains 36 bytes (9 x float which is 4 bytes each). So therefore it fails.

If you look in the documentation, you can see that there is a possibility of declaring a 16 - bit (2 byte) float. In the logblock declaration, you can replace 'float' with 'FP16', and reduce the total message size. This should fix it.

$\endgroup$
2
  • $\begingroup$ Yes, you are right. I changed the data type and it worked. $\endgroup$ Nov 13, 2023 at 17:21
  • 1
    $\begingroup$ great! good to hear $\endgroup$ Nov 14, 2023 at 9:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.