New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Optimize interrupt time #5483
Comments
I completely agree with the idea of reducing the amount of computation done in _read_fifo(). While we are in _read_fifo() we hold the lock on the bus, so we're preventing other bus activity. |
All data for RevoMini so STM32F405 (hard float) and MPU6000. Fast sampling is off in this configuration. Long story :) See - last task uses ~70% of all interrupt time and unlike all another has a highly different execution times with huge maximum of 3474uS than makes impossible loop time 500Hz without jitter. By its address I found a task - yes this is _read_fifo(). (task 3 is a baro and task 4 is a compass, tasks 0-2 are HAL internal) You know better than me that these tasks is not only reads data, but also provides significant work - normalizes and turns vectors. IMHO the best way is to move out all calculations from interrupt time to main loop, but if it impossible then that calculations can be optimized by some pre-calculations. PS, GCC at -Os optimization level don't like to inline functions so all mathematics with vectors translated to individual functions with load before and store after, example: mov r0, r4
vldr s13, [r0] which more than doubles execution time |
How much of this has been changed in recent commits ? |
Issue details
execution time of AP_InertialSensor_Invensense::_read_fifo() can be up to 1286uS so it is hard to schedule it at 1KHz. So I propose the following optimization, which will reduce this time by almost half.
exclude "accel *= _accel_scale;" and "gyro *= GYRO_SCALE;" from AP_InertialSensor_Invensense::_accumulate() and AP_InertialSensor_Invensense::_accumulate_fast_sampling(). Instead, publish that scales to backend and take in into accoiunt in _rotate_and_correct_accel() and _rotate_and_correct_gyro(). If that scales will be 1 by default it will not affect other sensors.
in AP_InertialSensor_Backend::_rotate_and_correct_accel() and AP_InertialSensor_Backend::_rotate_and_correct_gyro() pre-calculate at init() all rotations and scales into one transform matrix, so instead of 2 vector*scalar and 2 rotations we got only one matrix multiplication. Offsets can be at init() rotated back to real accel/gyro orientation and thus applied before other calculations
Version
git
Platform
[X] All
[ ] AntennaTracker
[ ] Copter
[ ] Plane
[ ] Rover
The text was updated successfully, but these errors were encountered: