I was wondering what is the inertial measurement unit sampling rate, because for my project I need 800 Hertz. I tried to look in the firmware file but I didn’t find anything. I use the pybricks
firmware on a Lego Spike Prime hub.
2 Answers
Digging a bit into the C source code for the pybricks
firmware, I was able to find these two lines:
PT_SPAWN(pt, &child, lsm6ds3tr_c_xl_data_rate_set(&child, ctx, LSM6DS3TR_C_XL_ODR_833Hz));
PT_SPAWN(pt, &child, lsm6ds3tr_c_gy_data_rate_set(&child, ctx, LSM6DS3TR_C_GY_ODR_833Hz));
...which means that the IMU is set to a sampling rate of 833Hz.
Please note that this is how the IMU electronics are configured when pybricks
starts - this does not necessarily mean that the pybricks
firmware nor the hub's microcontroller CPU can keep up with that rate, or that they can run some of your python code 833 times per second, or that pybricks
will run python code at that rate.
It should be possible to change the sampling rate by modifying the pybricks
C code and recompiling the firmware. If you want/need to take on this endeavour, read https://github.com/pybricks/pybricks-micropython#development first.
In the comments of one of the accepted answer on the question here: What internal electronics do Spike Prime and Mindstorms Robot Inventor use? it's mentioned that the pybricks people have determined that the IMU module is a STMicroelectronics LSM6DS3TR-C.
Googling for this I found the following document on the manufacturers website: https://www.st.com/resource/en/datasheet/lsm6ds3tr-c.pdf Which list output data rates from 1.6 Hz to 6.6kHz, probably depending on which mode the chip is configured in... I have no way off knowing which mode/value applies, but perhaps someone else does...