1
0
Fork 0
mirror of https://github.com/betaflight/betaflight.git synced 2025-07-23 00:05:33 +03:00
Commit graph

287 commits

Author SHA1 Message Date
Míguel Ángel Mulero Martínez
802edf236b Fix Blackbox P interval (#5645) 2018-04-10 00:35:54 +12:00
etracer65
c8a646ebc3 Cleanup 32K capable gyro includes (#5523)
Added a `USE_32K_CAPABLE_GYRO` define set in `common_fc_post.h` that replaces the repeated testing for each gyro define wherever 32KHz compatibility is checked.
2018-03-24 18:02:27 +13:00
etracer65
062ef77276 Rework gyro sample rate and DLPF configuration and expose additional filter cutoffs (#5483)
The old gyro_lpf setting was based on the DLPF_CFG values for the MPU6050 gyro and the enumeration was inaccurate and misleading.  For example, the default "OFF" setting did not disable the DLPF, but actually set it to around 250hz.  The actual cutoff frequency for each setting varies by gyro hardware so the literal frequencies in the enumeration were also incorrect.

Removed gyro_lpf and replaced it with gyro_hardware_lpf (8KHz) and gyro_32khz_hardware_lpf (32KHz).  The parameters were renamed to indicate that they are hardware filtering options to differentiate from the many software lowpass filtering options.

gyro_hardware_lpf - This parameter sets the filtering and sample rate options for 8KHz gyros (or 32KHz capable gyros running in 8KHz mode).

- NORMAL - default setting that is equivalent to the previous "OFF" setting.  Configures 8KHz sampling with ~250Hz filter cutoff.
- EXPERIMENTAL - 8KHz sampling with a higher frequency filter cutoff (around 3000hz).  Considerably more noisy and requires additional software filtering.  Note that for the MPU6000 Invensense doesn't officially document the filter cutoff frequency for this selection and simply lists it as "reserved".  In testing it's clear that a higher frequency filter cutoff is being selected due to the increased noise, but the actual cutoff frequency is unknown.
- 1KHZ_SAMPLING - 1KHz sample rate with and approximate 188Hz filter cutoff.

Note that the following additional 1KHz sample rate options with lower filter cutoffs have been eliminated - "98HZ", "42HZ", "20HZ", "10HZ", "5HZ".  It seems unlikely that these are still needed are probably no longer viable and flight performance would be very poor.

gyro_32khz_hardware_lpf - This parameter sets the filtering options while running in 32KHz mode on capable gyros.  It also exposes a new high frequency filter cutoff mode.

- NORMAL - The default and matches the current settings used for 32KHz mode.  Provides a filter cutoff around 3000Hz.
- EXPERIMENTAL - Selects a filter cutoff around 8000Hz.  This is a very noisy setting and will require substantial software filtering.

The default values for both 8KHz and 32KHz sample rates were chosen to match the previous defaults and users should not experience any performance differences.

Normalized the gyro initialization.  Previously there was little consistency on how the initialization was performed and the settings interpreted.  For example, MPU9250 used a completely different logic tree when configuring the registers.

Disconnected the literal parameter value from the gyro initialization.  The gyro_lpf parameter contained a number from 0-7 that was literally applied to the configuration register during the gyro initialization.  This caused some older gyro initializations to be incorrect as they used a different register layout (MPU3050 and L3G4200D).  By transitioning to a logical selection the actual value applied to the hardware register is abstracted.  This will better future-proof the design as new gyros may have a different register structure that may be incompatible with the old method.

Added a gyroregisters command to the CLI that is used to read the current register settings from the gyro and dump them to the CLI.  This is used to verify the configuration in comparison to the datasheets for the various gyros.  Testing empirically by looking at the relative noise from the gyros can give a rough estimate whether the different options are selecting correctly, but it's not very precise.  The code for the gyroregisters CLI command is wrapped inside #ifdef USE_GYRO_REGISTER_DUMP blocks to allow easy disabling.  It's currently enabled for all targets but we may decide to disable before release or only limit to targets with more available space (>=F4).
2018-03-22 14:02:30 +13:00
AJ Christensen
46291a8374 Dual-stage Gyro Filtering: PT1, Biquad, Butterworth, Denoise (FIR), FKF (fixed K), and Biquad RC+FIR2 (#5391)
* Dual-stage Gyro Filtering: PT1, FKF, and Biquad RC+FIR2

* Builds on the previous work of apocolipse.
* Fixes 'stage2'/'stage1' mis-naming to reflect where it is applied in the loop.
  That is, the older Biquad, PT1, Denoise (FIR) filters are 'stage2' - applied
  after dynamic and static notches (if enabled), and the controversial PT1,
  'fast Kalman' filter, and Biquad RC+FIR2 filters, are 'stage1'. e.g. before
  dynamic notch.
* FKF bruteforce Kalman gain removed. Calculate from half of PT1 RC constant,
  automatically taking loop-time into account.
* New union type definition for stage1 filtering.
* New gyro sensor members for stage1 filter application function and states for
  all three supported filter types
* New enum types for stage1 v. stage2. dterm lowpass type references 'stage2'.
* updates to CMS/MSP/FC to allow compilation (untested, probably breaks
  MSP, Lua, and ~comms with BFC~).
* Refactors FKF initialization, update and associated structures to be faster by
  not continuously calculating 'k'. Filter gain is calculated once during
  initialization from RC constant as per PT1 and Biquad RC+FIR2. It was
  discovered this converges to static value within 100 samples at 32kHz, so can
  be removed. Remove related interface (CLI) settings.
* update dterm_lowpass_type to use new 'TABLE_LOWPASS2_TYPE' (biquad/pt1/FIR)
* Stage 1 defaults to PT1, 763Hz (equivalent to Q400 / R88 from quasi-kalman
  filter) - suitable for 32kHz sampling modes. Can be switched to Biquad
  RC+FIR2, and FKF.
* Update `#if defined(USE_GYRO_SLEW_LIMITER) to `#ifdef`.
* Includes optional Lagged Moving Average 'smoothing' pipeline step, applied (in
  code) after the output of stage1.
* (diehertz): Removed redundant pointers from gyro filtering

* blackbox: fix indentation

* cms IMU menu: fix indentation

* filters: remove USE_GYRO_FIR_FILTER_DENOISE in filter type enum

* gyro sensors: go back to `if defined()` form. for slew limiter

* gyro sensors: increment parameter group version

* due to non-appending changes, the version must be bumped.
2018-03-21 15:52:59 +13:00
ctzsnooze
ab231b7c84 Second dterm pt1 (#5458)
* Second PT1 on DTerm

This PR replaces the default biquad filter with a second PT1 set to
200Hz.

Basically allows the user to enable a second, set point configurable,
PT1 type first order low-pass filter on DTerm.

This is useful because most noise in most logs arises from D, not P.

The default is set to on, at twice the normal Dterm setpoint.  This
provides greater Dterm cut than a single PT1, and twice the steepness
of cut above the second setpoint.  Modelling shows significant
reductions in higher frequency Dterm noise with only minor additional
delay.

The improvement in noise performance will be less than for biquad, but
the delay is considerably less.

If with the default settings the overall noise improves a lot, it may
be possible bring D both filtering set points to higher numbers (e.g.
140/280), or alternatively remove other filters such as the notch
filters, while maintaining an adequate level of control over noise.

* Update names, old defaults, fix whitespace

Defaults restored to biquad with second PT1 off.  ‘lpf’ retained as
abbreviation for values, otherwise generally remove ‘Filter’ where
redundant, replace ‘FilterLpf’ with ‘Lowpass’, etc, thanks Fujin and
DieHertz

* Remove underscore in lowpass_2, add hz to setpoint for lowpass

Thanks DieHertz

* completed replacing lpf with lowpass, added _hz to all lowpass set points in profile

Thanks DieHertz

* fix whitespace

fixed whitespace in settings.c

* whitespace attempt #57

* change lpf to lowpass where appropriate elsewhere

Note did not change OSD abbreviations, they are still LPF, and did not
change gyro_lpf anywhere.

* second attempt at a simple PT1 implementation

Basically copied from the DtermNotch implementation

* Second PT1 on DTerm

This PR replaces the default biquad filter with a second PT1 set to
200Hz.

Basically allows the user to enable a second, set point configurable,
PT1 type first order low-pass filter on DTerm.

This is useful because most noise in most logs arises from D, not P.

The default is set to on, at twice the normal Dterm setpoint.  This
provides greater Dterm cut than a single PT1, and twice the steepness
of cut above the second setpoint.  Modelling shows significant
reductions in higher frequency Dterm noise with only minor additional
delay.

The improvement in noise performance will be less than for biquad, but
the delay is considerably less.

If with the default settings the overall noise improves a lot, it may
be possible bring D both filtering set points to higher numbers (e.g.
140/280), or alternatively remove other filters such as the notch
filters, while maintaining an adequate level of control over noise.

* Rebase

* Remove underscore in lowpass_2, add hz to setpoint for lowpass

Thanks DieHertz

* completed replacing lpf with lowpass, added _hz to all lowpass set points in profile

Thanks DieHertz

* fix whitespace

fixed whitespace in settings.c

* whitespace attempt #57

* change lpf to lowpass where appropriate elsewhere

Note did not change OSD abbreviations, they are still LPF, and did not
change gyro_lpf anywhere.

* second attempt at a simple PT1 implementation

Basically copied from the DtermNotch implementation

* Whitespace fix - thanks, Ledvinap

* Fix PG issue

by moving added dterm_lowpass2_hz to bottom of struct

* Got rid of redundant indirection

* Fixed indentantion shifts
2018-03-21 01:40:23 +13:00
adrianmiriuta
c2898a4fd9 review of #4986 (#5422)
* review #4986 v1

* jfliper requested changes

* correction
2018-03-15 02:37:39 +13:00
Charles K Stevenson
33ee5efa17 Don't close blackbox log on disarm if mode is ALWAYS_ON (#5341) 2018-03-04 11:48:09 +13:00
mikeller
ee65eba88d Added selectable RaceFlight rates. 2018-01-19 00:38:14 +13:00
Martin Budden
d90b42970c Acc fn/variable renames to align with iNav 2017-12-29 10:23:51 +00:00
Martin Budden
671382234a Enabled switch fallthrough checking by compiler 2017-12-23 19:46:40 +00:00
jflyper
11c47c631b Port iNav's rangefinder 2017-12-20 12:54:19 +09:00
mikeller
b489d0ba9d Renamed 'parameter_group' to 'pg'. 2017-12-19 23:36:31 +13:00
Martin Budden
f527455d34 Blackbox header tidy 2017-11-23 18:24:09 +00:00
Martin Budden
cfc87d1891 Better separation between GPS and NAV 2017-11-18 08:00:31 +00:00
mikeller
c6b88e5d04 Cleaned up handling of RSSI, added resetting to 0 for RSSI over MSP. 2017-11-12 01:22:12 +13:00
Michael Keller
f4bb2f92bf
Merge pull request #4498 from mikeller/add_blackbox_always_on_option
Added option to have blackbox always on.
2017-11-07 18:06:38 +13:00
Bas Delfos
800e44906d Timer implementation from INAV 2017-11-06 20:09:24 +01:00
mikeller
a9c3e1a7a7 Fixed logging of 'amperageLatest' when non-ADC source is used. 2017-11-07 00:34:12 +13:00
mikeller
e9727b5313 Added option to have blackbox always on. 2017-11-07 00:05:48 +13:00
mikeller
a8d34dabb0 Changed defines for GYRO/ACC/MAG/BARO/GPS/SONAR/OSD/BLACKBOX/CMS to conform to the USE_ convention. 2017-11-05 10:15:24 +13:00
Michael Keller
ce824a60d6 Fixed mixer for 3D / Dshot. (#4161) 2017-09-17 15:45:39 +01:00
Martin Budden
a9d56097d1 Renamed CLI setting blackbox_p_denom to blackbox_p_ratio 2017-09-15 09:31:37 +01:00
mikeller
c8f528c0af Inhibit Dshot motor beeping while motors are running (armed or motor test). 2017-08-25 09:16:43 +12:00
Martin Budden
8dd4a584c1 Fixed whitespace 2017-08-17 08:32:37 +01:00
Martin Budden
0118af7eb3 Blackbox header and function name tidy 2017-07-29 13:33:19 +01:00
blckmn
7a5d1d9b8e Moving boardIdentifier out of config header and into systemConfig (for generic targets) 2017-07-25 09:05:12 +10:00
Martin Budden
20748dcf9a Merge pull request #3000 from martinbudden/bf_blackbox_iterations
Better handling of I-frame and P-frame iterations
2017-07-20 19:42:33 +01:00
Martin Budden
6943fb8e56 Split MSP box code into separate module 2017-07-20 13:33:34 +01:00
Martin Budden
3d4f0bb137 Whitespace tidy 2017-07-05 06:36:22 +01:00
Martin Budden
1085b73c25 Added start datetime 2017-06-29 14:00:44 +01:00
Martin Budden
4ca1553115 Added old blackbox rate_num and rate_denom into header. Allowed p_denom of zero in CLI. 2017-06-29 14:00:04 +01:00
Martin Budden
f6097cba18 Calculate blackbox rate_num and rate_denom for MSP 2017-06-29 13:58:18 +01:00
Martin Budden
c1f8e56b7f Changes as suggested by @ledvindap 2017-06-29 13:58:18 +01:00
Martin Budden
fa1514c083 Better handling of I-frame and P-frame interations 2017-06-29 13:57:21 +01:00
Martin Budden
564e0c94b8 Move some GPS variables into struct. Some alignment with iNav 2017-06-25 14:44:04 +01:00
Martin Budden
58fdace43c Minor tidy of blackbox code. iNav alignment 2017-06-25 05:15:19 +01:00
borisbstyle
b21877438e Convert motor values at the final stage // Increase resolution 2017-06-19 09:51:17 +02:00
Dominic Clifton
db006b1585 Merge pull request #2856 from ledvinap/improvement-64bit-boxid
array based box masks
2017-06-19 13:31:08 +12:00
Martin Budden
39d6b31036 Code tidy 2017-06-04 14:12:56 +01:00
Martin Budden
23f158913e Moved time functions out of system.h into time.h 2017-05-26 14:03:28 +01:00
Martin Budden
71546410de Rearrange PID array to be array of PIDs 2017-05-06 11:06:47 +01:00
Anders Hoglund
abd03ab558 Fixed compiler warning on unused blackboxShouldLogGpsHomeFrame function. 2017-05-03 17:16:58 +02:00
Martin Budden
c48826a739 Minor tidy of blackbox 2017-05-02 07:40:11 +01:00
Martin Budden
50ac13d79b Minor blackbox code tidy 2017-05-02 07:13:55 +01:00
Martin Budden
40a96dbf68 Merge pull request #2993 from martinbudden/bf_blackbox_encoding_split
Split blackbox encoding into separate module
2017-05-01 09:18:57 +01:00
Martin Budden
b1f290d218 Split blackbox encoding into separate module 2017-05-01 08:57:44 +01:00
Martin Budden
e2fbd1a152 Further CLI/blackbox parameter renames 2017-05-01 08:42:29 +01:00
Martin Budden
d0d44efc46 Reamed some CLI/blackbox params to better align with blackbox viewer 2017-04-30 07:45:18 +01:00
Martin Budden
7058657a9b Added blackbox acc field condition 2017-04-29 15:47:09 +01:00
Martin Budden
b76e1b837c Merge pull request #2933 from martinbudden/bf_blackbox_debug_condition
Added blackbox debug field condition
2017-04-29 15:43:47 +01:00