Skip to content

Commit

Permalink
Copter: Add a function to retrieve the LANDED_STATE
Browse files Browse the repository at this point in the history
  • Loading branch information
muramura committed Jun 3, 2024
1 parent eec7876 commit 9cbc234
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 11 deletions.
23 changes: 22 additions & 1 deletion ArduCopter/Copter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -445,7 +445,6 @@ bool Copter::has_ekf_failsafed() const
{
return failsafe.ekf;
}

#endif // AP_SCRIPTING_ENABLED

// returns true if vehicle is landing. Only used by Lua scripts
Expand All @@ -460,6 +459,28 @@ bool Copter::is_taking_off() const
return flightmode->is_taking_off();
}

/**
* Get landed detector states.
*
* @retval 1 landed (on ground)
* @retval 2 in air
* @retval 3 currently taking off
* @retval 4 currently landing
*/
uint8_t Copter::get_landed_state() const
{
if (ap.land_complete) {
return uint8_t(MAV_LANDED_STATE_ON_GROUND);
}
if (flightmode->is_landing()) {
return uint8_t(MAV_LANDED_STATE_LANDING);
}
if (flightmode->is_taking_off()) {
return uint8_t(MAV_LANDED_STATE_TAKEOFF);
}
return uint8_t(MAV_LANDED_STATE_IN_AIR);
}

bool Copter::current_mode_requires_mission() const
{
#if MODE_AUTO_ENABLED == ENABLED
Expand Down
1 change: 1 addition & 0 deletions ArduCopter/Copter.h
Original file line number Diff line number Diff line change
Expand Up @@ -689,6 +689,7 @@ class Copter : public AP_Vehicle {
#endif // AP_SCRIPTING_ENABLED
bool is_landing() const override;
bool is_taking_off() const override;
uint8_t get_landed_state() const override;
void rc_loop();
void throttle_loop();
void update_batt_compass(void);
Expand Down
11 changes: 1 addition & 10 deletions ArduCopter/GCS_Mavlink.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1549,16 +1549,7 @@ uint64_t GCS_MAVLINK_Copter::capabilities() const

MAV_LANDED_STATE GCS_MAVLINK_Copter::landed_state() const
{
if (copter.ap.land_complete) {
return MAV_LANDED_STATE_ON_GROUND;
}
if (copter.flightmode->is_landing()) {
return MAV_LANDED_STATE_LANDING;
}
if (copter.flightmode->is_taking_off()) {
return MAV_LANDED_STATE_TAKEOFF;
}
return MAV_LANDED_STATE_IN_AIR;
return MAV_LANDED_STATE(copter.get_landed_state());
}

void GCS_MAVLINK_Copter::send_wind() const
Expand Down

0 comments on commit 9cbc234

Please sign in to comment.