Skip to content
Open
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
1 change: 1 addition & 0 deletions ArduCopter/Copter.h
Original file line number Diff line number Diff line change
Expand Up @@ -968,6 +968,7 @@ class Copter : public AP_Vehicle {

// radio.cpp
void default_dead_zones();
void save_trim();
void init_rc_in();
void init_rc_out();
void read_radio();
Expand Down
30 changes: 2 additions & 28 deletions ArduCopter/RC_Channel_Copter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ bool RC_Channel_Copter::do_aux_function(const AuxFuncTrigger &trigger)
if ((ch_flag == AuxSwitchPos::HIGH) &&
(copter.flightmode->allows_save_trim()) &&
(copter.channel_throttle->get_control_in() == 0)) {
copter.g2.rc_channels.save_trim();
copter.save_trim();
}
break;

Expand Down Expand Up @@ -721,32 +721,6 @@ void RC_Channel_Copter::do_aux_function_change_force_flying(const AuxSwitchPos c
}
}

// note that this is a method on the RC_Channels object, not the
// individual channel
// save_trim - adds roll and pitch trims from the radio to ahrs
void RC_Channels_Copter::save_trim()
{
float roll_trim_rad = 0.0;
float pitch_trim_rad = 0.0;

#if AP_COPTER_AHRS_AUTO_TRIM_ENABLED
if (auto_trim.running) {
auto_trim.running = false;
} else {
#endif

// get roll and pitch trim adjustment
copter.flightmode->get_pilot_desired_lean_angles_rad(roll_trim_rad, pitch_trim_rad, copter.attitude_control->lean_angle_max_rad(), copter.attitude_control->get_althold_lean_angle_max_rad());

#if AP_COPTER_AHRS_AUTO_TRIM_ENABLED
}
#endif

// save roll and pitch trim
AP::ahrs().add_trim(roll_trim_rad, pitch_trim_rad);
LOGGER_WRITE_EVENT(LogEvent::SAVE_TRIM);
gcs().send_text(MAV_SEVERITY_INFO, "Trim saved");
}

#if AP_COPTER_AHRS_AUTO_TRIM_ENABLED
// start/stop ahrs auto trim
Expand All @@ -768,7 +742,7 @@ void RC_Channels_Copter::do_aux_function_ahrs_auto_trim(const RC_Channel::AuxSwi
case RC_Channel::AuxSwitchPos::LOW:
if (auto_trim.running) {
AP_Notify::flags.save_trim = false;
save_trim();
copter.save_trim();
}
break;
}
Expand Down
1 change: 0 additions & 1 deletion ArduCopter/RC_Channel_Copter.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ class RC_Channels_Copter : public RC_Channels
void auto_trim_run();
void auto_trim_cancel();
#endif // AP_COPTER_AHRS_AUTO_TRIM_ENABLED
void save_trim();

protected:

Expand Down
26 changes: 26 additions & 0 deletions ArduCopter/radio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -218,3 +218,29 @@ int16_t Copter::get_throttle_mid(void)
#endif
return channel_throttle->get_control_mid();
}

// save_trim - adds roll and pitch trims from the radio to AHRS
// called via the SAVE_TRIM aux function switch
void Copter::save_trim()
{
float roll_trim_rad = 0.0f;
float pitch_trim_rad = 0.0f;

#if AP_COPTER_AHRS_AUTO_TRIM_ENABLED
if (g2.rc_channels.auto_trim.running) {
g2.rc_channels.auto_trim.running = false;
} else {
#endif

// get roll and pitch trim from the attitude controller target
flightmode->get_pilot_desired_lean_angles_rad(roll_trim_rad, pitch_trim_rad, attitude_control->lean_angle_max_rad(), attitude_control->get_althold_lean_angle_max_rad());

#if AP_COPTER_AHRS_AUTO_TRIM_ENABLED
}
#endif

// save roll and pitch trim
AP::ahrs().add_trim(roll_trim_rad, pitch_trim_rad);
LOGGER_WRITE_EVENT(LogEvent::SAVE_TRIM);
gcs().send_text(MAV_SEVERITY_INFO, "Trim saved");
}
Loading