Skip to content

Commit

Permalink
Plane: Logs NaN on ATT.DesPitch when not used
Browse files Browse the repository at this point in the history
  • Loading branch information
Georacer committed Jan 14, 2025
1 parent 72a3e2e commit dff1ad7
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 2 deletions.
3 changes: 3 additions & 0 deletions ArduPlane/Log.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ void Plane::Log_Write_Attitude(void)
demanded_pitch_cd * 0.01f,
0 //Plane does not have the concept of navyaw. This is a placeholder.
};
if (!flag_demanded_pitch_used) {
targets.y = NAN;
}

#if HAL_QUADPLANE_ENABLED
if (quadplane.show_vtol_view()) {
Expand Down
4 changes: 2 additions & 2 deletions ArduPlane/Plane.h
Original file line number Diff line number Diff line change
Expand Up @@ -671,8 +671,8 @@ class Plane : public AP_Vehicle {
// The instantaneous navigator-commanded pitch angle. Hundredths of a degree
int32_t nav_pitch_cd;

// The instantaneous desired pitch angle. Hundredths of a degree.
int32_t demanded_pitch_cd;
int32_t demanded_pitch_cd; // The instantaneous desired pitch angle. Hundredths of a degree.
bool flag_demanded_pitch_used; // For logging purposes, declares if active pitch control is happening.

// the aerodynamic load factor. This is calculated from the demanded
// roll before the roll is clipped, using 1/sqrt(cos(nav_roll))
Expand Down
3 changes: 3 additions & 0 deletions ArduPlane/mode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,9 @@ bool Mode::enter()
plane.auto_state.highest_airspeed = 0;
plane.auto_state.initial_pitch_cd = ahrs.pitch_sensor;

// Declare that pitch is actively controlled, unless children ovewrite.
plane.flag_demanded_pitch_used = true;

// disable taildrag takeoff on mode change
plane.auto_state.fbwa_tdrag_takeoff_mode = false;

Expand Down
2 changes: 2 additions & 0 deletions ArduPlane/mode.h
Original file line number Diff line number Diff line change
Expand Up @@ -439,6 +439,8 @@ class ModeManual : public Mode
const char *name4() const override { return "MANU"; }

// methods that affect movement of the vehicle in this mode
bool _enter() override;

void update() override;

void run() override;
Expand Down
1 change: 1 addition & 0 deletions ArduPlane/mode_acro.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ bool ModeAcro::_enter()
{
acro_state.locked_roll = false;
acro_state.locked_pitch = false;
plane.flag_demanded_pitch_used = false; // ACRO does not control pitch through demanded_pitch_cd.
IGNORE_RETURN(ahrs.get_quaternion(acro_state.q));
return true;
}
Expand Down
6 changes: 6 additions & 0 deletions ArduPlane/mode_manual.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
#include "mode.h"
#include "Plane.h"

bool ModeManual::_enter()
{
plane.flag_demanded_pitch_used = false;
return true;
}

void ModeManual::update()
{
SRV_Channels::set_output_scaled(SRV_Channel::k_aileron, plane.roll_in_expo(false));
Expand Down
2 changes: 2 additions & 0 deletions ArduPlane/mode_training.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,10 @@ void ModeTraining::run()

if (plane.training_manual_pitch) {
SRV_Channels::set_output_scaled(SRV_Channel::k_elevator, pexpo);
plane.flag_demanded_pitch_used = false;
} else {
plane.stabilize_pitch();
plane.flag_demanded_pitch_used = true;
if ((plane.nav_pitch_cd > 0 && pexpo < SRV_Channels::get_output_scaled(SRV_Channel::k_elevator)) ||
(plane.nav_pitch_cd < 0 && pexpo > SRV_Channels::get_output_scaled(SRV_Channel::k_elevator))) {
// allow user to get back to level
Expand Down

0 comments on commit dff1ad7

Please sign in to comment.