Skip to content

Commit d733326

Browse files
committed
AP_LandingGear: stop dup retract messages,clean up code
1 parent f15d35d commit d733326

File tree

1 file changed

+24
-28
lines changed

1 file changed

+24
-28
lines changed

libraries/AP_LandingGear/AP_LandingGear.cpp

+24-28
Original file line numberDiff line numberDiff line change
@@ -163,19 +163,17 @@ void AP_LandingGear::deploy()
163163
return;
164164
}
165165

166-
// set servo PWM to deployed position
167-
SRV_Channels::set_output_limit(SRV_Channel::k_landing_gear_control, SRV_Channel::Limit::MAX);
168-
169-
// send message only if output has been configured
166+
// set servo and send message only if output has been configured and not already deployed
170167
if (!_deployed &&
171168
SRV_Channels::function_assigned(SRV_Channel::k_landing_gear_control)) {
172169
GCS_SEND_TEXT(MAV_SEVERITY_INFO, "LandingGear: DEPLOY");
170+
// set deployed flag
171+
_deployed = true;
172+
_have_changed = true;
173+
LOGGER_WRITE_EVENT(LogEvent::LANDING_GEAR_DEPLOYED);
174+
// set servo PWM to deployed position
175+
SRV_Channels::set_output_limit(SRV_Channel::k_landing_gear_control, SRV_Channel::Limit::MAX);
173176
}
174-
175-
// set deployed flag
176-
_deployed = true;
177-
_have_changed = true;
178-
LOGGER_WRITE_EVENT(LogEvent::LANDING_GEAR_DEPLOYED);
179177
}
180178

181179
/// retract - retract landing gear
@@ -184,18 +182,17 @@ void AP_LandingGear::retract()
184182
if (!_enable) {
185183
return;
186184
}
187-
188-
// set servo PWM to retracted position
189-
SRV_Channels::set_output_limit(SRV_Channel::k_landing_gear_control, SRV_Channel::Limit::MIN);
190-
191-
// reset deployed flag
192-
_deployed = false;
193-
_have_changed = true;
194-
LOGGER_WRITE_EVENT(LogEvent::LANDING_GEAR_RETRACTED);
195-
196-
// send message only if output has been configured
197-
if (SRV_Channels::function_assigned(SRV_Channel::k_landing_gear_control)) {
185+
186+
// set servo and send message only if output has been configured and already deployed
187+
if ((_deployed || !_have_changed ) &&
188+
SRV_Channels::function_assigned(SRV_Channel::k_landing_gear_control)) {
198189
GCS_SEND_TEXT(MAV_SEVERITY_INFO, "LandingGear: RETRACT");
190+
// reset deployed flag
191+
_deployed = false;
192+
_have_changed = true;
193+
LOGGER_WRITE_EVENT(LogEvent::LANDING_GEAR_RETRACTED);
194+
// set servo PWM to retracted position
195+
SRV_Channels::set_output_limit(SRV_Channel::k_landing_gear_control, SRV_Channel::Limit::MIN);
199196
}
200197
}
201198

@@ -286,18 +283,17 @@ void AP_LandingGear::update(float height_above_ground_m)
286283

287284
if (hal.util->get_soft_armed()) {
288285
// only do height based triggering when armed
289-
if ((!_deployed || !_have_changed) &&
286+
if (!_deployed &&
290287
_deploy_alt > 0 &&
291288
alt_m <= _deploy_alt &&
292289
_last_height_above_ground > _deploy_alt) {
293290
deploy();
294-
}
295-
if ((_deployed || !_have_changed) &&
296-
_retract_alt > 0 &&
297-
_retract_alt >= _deploy_alt &&
298-
alt_m >= _retract_alt &&
299-
_last_height_above_ground < _retract_alt) {
300-
retract();
291+
} else if ((_deployed || !_have_changed)&&
292+
_retract_alt > 0 &&
293+
_retract_alt >= _deploy_alt &&
294+
alt_m >= _retract_alt &&
295+
_last_height_above_ground < _retract_alt) {
296+
retract();
301297
}
302298
}
303299

0 commit comments

Comments
 (0)