Fix accelerometer staleness and IMU list aliasing, free all servos on reset, GNU GPL v3 License#105
Open
SaintSampo wants to merge 4 commits into
Open
Fix accelerometer staleness and IMU list aliasing, free all servos on reset, GNU GPL v3 License#105SaintSampo wants to merge 4 commits into
SaintSampo wants to merge 4 commits into
Conversation
Extend reset_servos in XRPLib/resetbot.py to free any third and fourth servos if the board exposes SERVO_3 or SERVO_4.
Avoid exposing internal irq_v buffers and reduce per-tick allocations. get_acc_x_rate and get_gyro_x_rate now return list copies. Introduced _read_acc_gyro to perform an in-place burst read that updates irq_v without allocating on each timer tick. get_acc_gyro_rates now calls _read_acc_gyro and returns 2D list copies. _update_imu_readings was updated to use _read_acc_gyro. These changes prevent accidental external mutation of internal state and reduce GC pressure in callbacks.
This was referenced Jul 24, 2026
KalticCodes
requested changes
Jul 24, 2026
KalticCodes
left a comment
Member
There was a problem hiding this comment.
For publically facing functions, please use Sphinx-format doc commwnts for auto-generated API docs
Clarified and expanded IMU method docstrings in XRPLib/imu.py to explicitly state return formats and units for get_gyro_rates and get_acc_gyro_rates. Simplified reset_servos in XRPLib/resetbot.py to only free the two default servos (1 and 2) and removed conditional checks for SERVO_3 and SERVO_4. These changes improve documentation clarity and streamline servo reset logic for boards that only expose two servos.
Collaborator
Author
|
Done. I clarified and expanded IMU method docstrings in XRPLib/imu.py Also removed the servo fix since frank did that in a different PR |
KalticCodes
approved these changes
Jul 25, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Accelerometer returns stale values
Fixes the "accelerometer requests seem to return accumulated value" report. Reads looked correct in a loop but returned old data when called one-off.
Block Data Update is enabled, so the LSM6DSO's output registers don't refresh until both bytes of the previous sample have been read. The timer callback only drained the gyro, so the accelerometer registers stayed latched on a sample captured right after the previous read. Read once, turn the robot, read again, and you got the orientation from before you moved it.
The timer now calls
_read_acc_gyro(), which burst-reads both sensors every tick, capping staleness at one timer period (~4.8 ms at 208 Hz). BDU stays enabled, so MSB and LSB still come from the same sample and burst reads can't tear.IMU accessors returned their internal lists
get_acc_rates(),get_gyro_rates()andget_acc_gyro_rates()returnedself.irq_vdirectly, so a caller who stored the result saw it mutate on the next call or asynchronously from the timer callback. They now return copies.The copy would otherwise have landed in the 208 Hz timer path, so the register read moved into a private
_read_acc_gyro()that updatesirq_vin place and returns nothing. The timer allocates no more than it did before.License
Adds GNU GPL v3.