Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use enumerations in CompassCalibrator #27502

Merged
merged 2 commits into from
Jul 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 18 additions & 6 deletions libraries/AP_Compass/CompassCalibrator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -138,9 +138,21 @@ void CompassCalibrator::new_sample(const Vector3f& sample)

bool CompassCalibrator::failed() {
WITH_SEMAPHORE(state_sem);
return (cal_state.status == Status::FAILED ||
cal_state.status == Status::BAD_ORIENTATION ||
cal_state.status == Status::BAD_RADIUS);
switch (cal_state.status) {
case Status::FAILED:
case Status::BAD_ORIENTATION:
case Status::BAD_RADIUS:
return true;
case Status::SUCCESS:
case Status::NOT_STARTED:
case Status::WAITING_TO_START:
case Status::RUNNING_STEP_ONE:
case Status::RUNNING_STEP_TWO:
return false;
}

// compiler guarantees we don't get here
return true;
}


Expand Down Expand Up @@ -461,10 +473,10 @@ bool CompassCalibrator::set_status(CompassCalibrator::Status status)

_status = status;
return true;

default:
return false;
};

// compiler guarantees we don't get here
return false;
}

bool CompassCalibrator::fit_acceptable() const
Expand Down
3 changes: 2 additions & 1 deletion libraries/AP_Compass/CompassCalibrator.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ class CompassCalibrator {
// update the state machine and calculate offsets, diagonals and offdiagonals
void update();

// compass calibration states
// compass calibration states - these correspond to the mavlink
// MAG_CAL_STATUS enumeration
enum class Status {
NOT_STARTED = 0,
WAITING_TO_START = 1,
Expand Down
Loading