Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
F
Firmware
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Alberto Ruiz Garcia
Firmware
Commits
ef2a5599
Commit
ef2a5599
authored
8 years ago
by
pixhawk
Committed by
Lorenz Meier
8 years ago
Browse files
Options
Downloads
Patches
Plain Diff
mag_calibration: Make sure calibration fails if any mag fails; More checks on calibration results
parent
fded0222
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/modules/commander/mag_calibration.cpp
+61
-20
61 additions, 20 deletions
src/modules/commander/mag_calibration.cpp
with
61 additions
and
20 deletions
src/modules/commander/mag_calibration.cpp
+
61
−
20
View file @
ef2a5599
...
...
@@ -277,6 +277,55 @@ static unsigned progress_percentage(mag_worker_data_t *worker_data)
return
100
*
((
float
)
worker_data
->
done_count
)
/
calibration_sides
;
}
// Returns calibrate_return_error if any parameter is not finite
// Logs if parameters are out of range
static
calibrate_return
check_calibration_result
(
float
offset_x
,
float
offset_y
,
float
offset_z
,
float
sphere_radius
,
float
diag_x
,
float
diag_y
,
float
diag_z
,
float
offdiag_x
,
float
offdiag_y
,
float
offdiag_z
,
orb_advert_t
*
mavlink_log_pub
,
size_t
cur_mag
)
{
float
must_be_finite
[]
=
{
offset_x
,
offset_y
,
offset_z
,
sphere_radius
,
diag_x
,
diag_y
,
diag_z
,
offdiag_x
,
offdiag_y
,
offdiag_z
};
float
should_be_not_huge
[]
=
{
offset_x
,
offset_y
,
offset_z
};
float
should_be_positive
[]
=
{
sphere_radius
,
diag_x
,
diag_y
,
diag_z
};
// Make sure every parameter is finite
const
int
num_finite
=
sizeof
(
must_be_finite
)
/
sizeof
(
*
must_be_finite
);
for
(
unsigned
i
=
0
;
i
<
num_finite
;
++
i
)
{
if
(
!
PX4_ISFINITE
(
must_be_finite
[
i
]))
{
calibration_log_emergency
(
mavlink_log_pub
,
"ERROR: Retry calibration (sphere NaN, #%u)"
,
cur_mag
);
return
calibrate_return_error
;
}
}
// Notify if offsets are too large
const
int
num_not_huge
=
sizeof
(
should_be_not_huge
)
/
sizeof
(
*
should_be_not_huge
);
for
(
unsigned
i
=
0
;
i
<
num_not_huge
;
++
i
)
{
if
(
fabsf
(
should_be_not_huge
[
i
])
>
MAG_MAX_OFFSET_LEN
)
{
calibration_log_critical
(
mavlink_log_pub
,
"Warning: %s mag with large offsets"
,
(
internal
[
cur_mag
])
?
"autopilot, internal"
:
"GPS unit, external"
);
break
;
}
}
// Notify if a parameter which should be positive is non-positive
const
int
num_positive
=
sizeof
(
should_be_positive
)
/
sizeof
(
*
should_be_positive
);
for
(
unsigned
i
=
0
;
i
<
num_positive
;
++
i
)
{
if
(
should_be_positive
[
i
]
<=
0.0
f
)
{
calibration_log_critical
(
mavlink_log_pub
,
"Warning: %s mag with non-positive scale"
,
(
internal
[
cur_mag
])
?
"autopilot, internal"
:
"GPS unit, external"
);
break
;
}
}
return
calibrate_return_ok
;
}
static
calibrate_return
mag_calibration_worker
(
detect_orientation_return
orientation
,
int
cancel_sub
,
void
*
data
)
{
calibrate_return
result
=
calibrate_return_ok
;
...
...
@@ -632,26 +681,18 @@ calibrate_return mag_calibrate_all(orb_advert_t *mavlink_log_pub)
worker_data
.
calibration_counter_total
[
cur_mag
],
100
,
0.0
f
,
&
sphere_x
[
cur_mag
],
&
sphere_y
[
cur_mag
],
&
sphere_z
[
cur_mag
],
&
sphere_radius
[
cur_mag
],
&
diag_x
[
cur_mag
],
&
diag_y
[
cur_mag
],
&
diag_z
[
cur_mag
],
&
offdiag_x
[
cur_mag
],
&
offdiag_y
[
cur_mag
],
&
offdiag_z
[
cur_mag
]);
if
(
!
PX4_ISFINITE
(
sphere_x
[
cur_mag
])
||
!
PX4_ISFINITE
(
sphere_y
[
cur_mag
])
||
!
PX4_ISFINITE
(
sphere_z
[
cur_mag
]))
{
calibration_log_emergency
(
mavlink_log_pub
,
"ERROR: Retry calibration (sphere NaN, #%u)"
,
cur_mag
);
result
=
calibrate_return_error
;
}
if
(
fabsf
(
sphere_x
[
cur_mag
])
>
MAG_MAX_OFFSET_LEN
||
fabsf
(
sphere_y
[
cur_mag
])
>
MAG_MAX_OFFSET_LEN
||
fabsf
(
sphere_z
[
cur_mag
])
>
MAG_MAX_OFFSET_LEN
)
{
calibration_log_critical
(
mavlink_log_pub
,
"Warning: %s mag with large offsets"
,
(
internal
[
cur_mag
])
?
"autopilot, internal"
:
"GPS unit, external"
);
calibration_log_info
(
mavlink_log_pub
,
"Offsets: x: %8.4f, y: %8.4f, z: %8.4f, #%u"
,
(
double
)
sphere_x
[
cur_mag
],
(
double
)
sphere_y
[
cur_mag
],
(
double
)
sphere_z
[
cur_mag
],
cur_mag
);
calibration_log_info
(
mavlink_log_pub
,
"Scale: x: %8.4f, y: %8.4f, z: %8.4f, #%u"
,
(
double
)
diag_x
[
cur_mag
],
(
double
)
diag_y
[
cur_mag
],
(
double
)
diag_z
[
cur_mag
],
cur_mag
);
calibration_log_info
(
mavlink_log_pub
,
"offdiag: x: %8.4f, y: %8.4f, z: %8.4f, #%u"
,
(
double
)
offdiag_x
[
cur_mag
],
(
double
)
offdiag_y
[
cur_mag
],
(
double
)
offdiag_z
[
cur_mag
],
cur_mag
);
result
=
calibrate_return_ok
;
&
sphere_radius
[
cur_mag
],
&
diag_x
[
cur_mag
],
&
diag_y
[
cur_mag
],
&
diag_z
[
cur_mag
],
&
offdiag_x
[
cur_mag
],
&
offdiag_y
[
cur_mag
],
&
offdiag_z
[
cur_mag
]);
result
=
check_calibration_result
(
sphere_x
[
cur_mag
],
sphere_y
[
cur_mag
],
sphere_z
[
cur_mag
],
sphere_radius
[
cur_mag
],
diag_x
[
cur_mag
],
diag_y
[
cur_mag
],
diag_z
[
cur_mag
],
offdiag_x
[
cur_mag
],
offdiag_y
[
cur_mag
],
offdiag_z
[
cur_mag
],
mavlink_log_pub
,
cur_mag
);
if
(
result
==
calibrate_return_error
)
{
break
;
}
}
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment