Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
deltaflight
deltaflight
Commits
ba3d0ab5
Unverified
Commit
ba3d0ab5
authored
Feb 24, 2021
by
Paweł Spychalski
Committed by
GitHub
Feb 24, 2021
Browse files
Merge pull request #6636 from iNavFlight/dzikuvx-fix-mag-gain-calibration
Fix mag gain computation for negative mag zero
parents
0a284d39
1a5133fa
Changes
1
Show whitespace changes
Inline
Side-by-side
src/main/sensors/compass.c
View file @
ba3d0ab5
...
...
@@ -350,7 +350,7 @@ void compassUpdate(timeUs_t currentTimeUs)
static
sensorCalibrationState_t
calState
;
static
timeUs_t
calStartedAt
=
0
;
static
int16_t
magPrev
[
XYZ_AXIS_COUNT
];
static
int
mag
Gai
n
[
XYZ_AXIS_COUNT
]
=
{
-
4096
,
-
4096
,
-
4096
}
;
static
int
mag
AxisDeviatio
n
[
XYZ_AXIS_COUNT
];
// Check magZero
if
(
...
...
@@ -381,6 +381,7 @@ void compassUpdate(timeUs_t currentTimeUs)
compassConfigMutable
()
->
magZero
.
raw
[
axis
]
=
0
;
compassConfigMutable
()
->
magGain
[
axis
]
=
1024
;
magPrev
[
axis
]
=
0
;
magAxisDeviation
[
axis
]
=
0
;
// Gain is based on the biggest absolute deviation from the mag zero point. Gain computation starts at 0
}
beeper
(
BEEPER_ACTION_SUCCESS
);
...
...
@@ -400,9 +401,9 @@ void compassUpdate(timeUs_t currentTimeUs)
diffMag
+=
(
mag
.
magADC
[
axis
]
-
magPrev
[
axis
])
*
(
mag
.
magADC
[
axis
]
-
magPrev
[
axis
]);
avgMag
+=
(
mag
.
magADC
[
axis
]
+
magPrev
[
axis
])
*
(
mag
.
magADC
[
axis
]
+
magPrev
[
axis
])
/
4
.
0
f
;
const
int32_t
sample
=
ABS
(
mag
.
magADC
[
axis
]);
if
(
sample
>
magGai
n
[
axis
])
{
mag
Gain
[
axis
]
=
sample
;
// Find the biggest sample deviation together with sample' sign
if
(
ABS
(
mag
.
magADC
[
axis
])
>
ABS
(
magAxisDeviatio
n
[
axis
])
)
{
mag
AxisDeviation
[
axis
]
=
mag
.
magADC
[
axis
]
;
}
}
...
...
@@ -429,7 +430,7 @@ void compassUpdate(timeUs_t currentTimeUs)
* It is dirty, but worth checking if this will solve the problem of changing mag vector when UAV is tilted
*/
for
(
int
axis
=
0
;
axis
<
XYZ_AXIS_COUNT
;
axis
++
)
{
compassConfigMutable
()
->
magGain
[
axis
]
=
magGai
n
[
axis
]
-
compassConfig
()
->
magZero
.
raw
[
axis
];
compassConfigMutable
()
->
magGain
[
axis
]
=
ABS
(
magAxisDeviatio
n
[
axis
]
-
compassConfig
()
->
magZero
.
raw
[
axis
]
)
;
}
calStartedAt
=
0
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment