Skip to content

Commit

Permalink
mc_pos_control: Fix bug causing flyaway when GPS gained after takeoff
Browse files Browse the repository at this point in the history
The change in origin when GPS was gained after takeoff was being used to shift the set point despite the previous origin being invalid.
  • Loading branch information
priseborough committed Sep 19, 2017
1 parent 26f0060 commit 8470d70
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/modules/mc_pos_control/mc_pos_control_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,7 @@ class MulticopterPositionControl : public control::SuperBlock
struct map_projection_reference_s _ref_pos;
float _ref_alt;
hrt_abstime _ref_timestamp;
bool _first_origin_set;
hrt_abstime _last_warn;

math::Vector<3> _thrust_int;
Expand Down Expand Up @@ -452,6 +453,7 @@ MulticopterPositionControl::MulticopterPositionControl() :
_user_intention_z(brake),
_ref_alt(0.0f),
_ref_timestamp(0),
_first_origin_set{false},
_last_warn(0),
_yaw(0.0f),
_yaw_takeoff(0.0f),
Expand Down Expand Up @@ -856,7 +858,7 @@ MulticopterPositionControl::task_main_trampoline(int argc, char *argv[])
void
MulticopterPositionControl::update_ref()
{
if (_local_pos.ref_timestamp != _ref_timestamp) {
if (_local_pos.ref_timestamp != _ref_timestamp && _first_origin_set) {
double lat_sp, lon_sp;
float alt_sp = 0.0f;

Expand All @@ -882,6 +884,13 @@ MulticopterPositionControl::update_ref()
}

_ref_timestamp = _local_pos.ref_timestamp;

} else if (_local_pos.xy_global && _local_pos.z_global) {
// Ignore the origin change for the first time the origin is set.
// This allows for GPS use to commence after takeoff
_first_origin_set = true;
_ref_timestamp = _local_pos.ref_timestamp;

}
}

Expand Down

0 comments on commit 8470d70

Please sign in to comment.