Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
B
Baitboat
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
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
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
OpenSource
Baitboat
Commits
c45338f0
Commit
c45338f0
authored
10 years ago
by
Randy Mackay
Browse files
Options
Downloads
Patches
Plain Diff
AC_AttControl: div-by-zero check for bf-to-ef conversion
parent
87f0cb61
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
libraries/AC_AttitudeControl/AC_AttitudeControl.cpp
+12
-6
12 additions, 6 deletions
libraries/AC_AttitudeControl/AC_AttitudeControl.cpp
libraries/AC_AttitudeControl/AC_AttitudeControl.h
+4
-3
4 additions, 3 deletions
libraries/AC_AttitudeControl/AC_AttitudeControl.h
with
16 additions
and
9 deletions
libraries/AC_AttitudeControl/AC_AttitudeControl.cpp
+
12
−
6
View file @
c45338f0
...
...
@@ -382,10 +382,11 @@ void AC_AttitudeControl::rate_bf_roll_pitch_yaw(float roll_rate_bf, float pitch_
}
else
{
_acro_angle_switch
=
4500
;
integrate_bf_rate_error_to_angle_errors
();
frame_conversion_bf_to_ef
(
_angle_bf_error
,
angle_ef_error
);
_angle_ef_target
.
x
=
wrap_180_cd_float
(
angle_ef_error
.
x
+
_ahrs
.
roll_sensor
);
_angle_ef_target
.
y
=
wrap_180_cd_float
(
angle_ef_error
.
y
+
_ahrs
.
pitch_sensor
);
_angle_ef_target
.
z
=
wrap_360_cd_float
(
angle_ef_error
.
z
+
_ahrs
.
yaw_sensor
);
if
(
frame_conversion_bf_to_ef
(
_angle_bf_error
,
angle_ef_error
))
{
_angle_ef_target
.
x
=
wrap_180_cd_float
(
angle_ef_error
.
x
+
_ahrs
.
roll_sensor
);
_angle_ef_target
.
y
=
wrap_180_cd_float
(
angle_ef_error
.
y
+
_ahrs
.
pitch_sensor
);
_angle_ef_target
.
z
=
wrap_360_cd_float
(
angle_ef_error
.
z
+
_ahrs
.
yaw_sensor
);
}
if
(
_angle_ef_target
.
y
>
9000.0
f
)
{
_angle_ef_target
.
x
=
wrap_180_cd_float
(
_angle_ef_target
.
x
+
18000.0
f
);
_angle_ef_target
.
y
=
wrap_180_cd_float
(
18000.0
f
-
_angle_ef_target
.
x
);
...
...
@@ -432,12 +433,17 @@ void AC_AttitudeControl::frame_conversion_ef_to_bf(const Vector3f& ef_vector, Ve
}
// frame_conversion_bf_to_ef - converts body frame vector to earth frame vector
void
AC_AttitudeControl
::
frame_conversion_bf_to_ef
(
const
Vector3f
&
bf_vector
,
Vector3f
&
ef_vector
)
bool
AC_AttitudeControl
::
frame_conversion_bf_to_ef
(
const
Vector3f
&
bf_vector
,
Vector3f
&
ef_vector
)
{
// convert earth frame rates to body frame rates
// avoid divide by zero
if
(
_ahrs
.
cos_pitch
()
==
0.0
f
)
{
return
false
;
}
// convert earth frame angle or rates to body frame
ef_vector
.
x
=
bf_vector
.
x
+
_ahrs
.
sin_roll
()
*
(
_ahrs
.
sin_pitch
()
/
_ahrs
.
cos_pitch
())
*
bf_vector
.
y
+
_ahrs
.
cos_roll
()
*
(
_ahrs
.
sin_pitch
()
/
_ahrs
.
cos_pitch
())
*
bf_vector
.
z
;
ef_vector
.
y
=
_ahrs
.
cos_roll
()
*
bf_vector
.
y
-
_ahrs
.
sin_roll
()
*
bf_vector
.
z
;
ef_vector
.
z
=
(
_ahrs
.
sin_roll
()
/
_ahrs
.
cos_pitch
())
*
bf_vector
.
y
+
(
_ahrs
.
cos_roll
()
/
_ahrs
.
cos_pitch
())
*
bf_vector
.
z
;
return
true
;
}
//
...
...
This diff is collapsed.
Click to expand it.
libraries/AC_AttitudeControl/AC_AttitudeControl.h
+
4
−
3
View file @
c45338f0
...
...
@@ -116,11 +116,12 @@ public:
//
// earth-frame <-> body-frame conversion functions
//
// frame_conversion_ef_to_bf - converts earth frame
rate target
s to body frame
rate targets
// frame_conversion_ef_to_bf - converts earth frame
angles or rate
s to body frame
void
frame_conversion_ef_to_bf
(
const
Vector3f
&
ef_vector
,
Vector3f
&
bf_vector
);
// frame_conversion_bf_to_ef - converts body frame rate targets to earth frame rate targets
void
frame_conversion_bf_to_ef
(
const
Vector3f
&
bf_vector
,
Vector3f
&
ef_vector
);
// frame_conversion_bf_to_ef - converts body frame angles or rates to earth frame
// returns false if conversion fails due to gimbal lock
bool
frame_conversion_bf_to_ef
(
const
Vector3f
&
bf_vector
,
Vector3f
&
ef_vector
);
//
// public accessor functions
...
...
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