@@ -163,19 +163,17 @@ void AP_LandingGear::deploy()
163
163
return ;
164
164
}
165
165
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
170
167
if (!_deployed &&
171
168
SRV_Channels::function_assigned (SRV_Channel::k_landing_gear_control)) {
172
169
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);
173
176
}
174
-
175
- // set deployed flag
176
- _deployed = true ;
177
- _have_changed = true ;
178
- LOGGER_WRITE_EVENT (LogEvent::LANDING_GEAR_DEPLOYED);
179
177
}
180
178
181
179
// / retract - retract landing gear
@@ -184,18 +182,17 @@ void AP_LandingGear::retract()
184
182
if (!_enable) {
185
183
return ;
186
184
}
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)) {
198
189
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);
199
196
}
200
197
}
201
198
@@ -286,18 +283,17 @@ void AP_LandingGear::update(float height_above_ground_m)
286
283
287
284
if (hal.util ->get_soft_armed ()) {
288
285
// only do height based triggering when armed
289
- if (( !_deployed || !_have_changed) &&
286
+ if (!_deployed &&
290
287
_deploy_alt > 0 &&
291
288
alt_m <= _deploy_alt &&
292
289
_last_height_above_ground > _deploy_alt) {
293
290
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 ();
301
297
}
302
298
}
303
299
0 commit comments