Skip to content

Commit f70224e

Browse files
committed
Fix build of Autogyro take off
1 parent ef98f3a commit f70224e

File tree

5 files changed

+85
-47
lines changed

5 files changed

+85
-47
lines changed

src/modules/fw_pos_control_l1/FixedwingPositionControl.cpp

Lines changed: 34 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -733,31 +733,17 @@ FixedwingPositionControl::getManualHeightRateSetpoint()
733733
return height_rate_setpoint;
734734
}
735735

736+
//TADY/////////////////////////////////////////////////////////////////////////////////////////////////TADY
736737
void
737738
FixedwingPositionControl::updateManualTakeoffStatus()
738739
{
739-
740-
// a VTOL does not need special takeoff handling
741-
if (_vehicle_status.is_vtol) {
742-
return false;
743-
}
744-
745-
if (_autogyro_takeoff.autogyroTakeoffEnabled()) {
746-
return (!_autogyro_takeoff.isInitialized() || _autogyro_takeoff.climbout());
747-
}
748-
749740
if (!_completed_manual_takeoff) {
750741
const bool at_controllable_airspeed = _airspeed > _param_fw_airspd_min.get()
751742
|| !_airspeed_valid;
752743
const bool is_hovering = _vehicle_status.vehicle_type == vehicle_status_s::VEHICLE_TYPE_ROTARY_WING
753744
&& _control_mode.flag_armed;
754745
_completed_manual_takeoff = (!_landed && at_controllable_airspeed) || is_hovering;
755746
}
756-
757-
// in air for < 10s
758-
return (hrt_elapsed_time(&_time_went_in_air) < 10_s)
759-
&& (_current_altitude <= _takeoff_ground_alt + _param_fw_clmbout_diff.get());
760-
761747
}
762748

763749
void
@@ -1435,25 +1421,39 @@ FixedwingPositionControl::control_auto_takeoff(const hrt_abstime &now, const flo
14351421
_autogyro_takeoff.update(now, _airspeed, _rotor_rpm, _current_altitude - _takeoff_ground_alt,
14361422
_current_latitude, _current_longitude, &_mavlink_log_pub);
14371423

1438-
float target_airspeed = get_auto_airspeed_setpoint(control_interval,
1439-
_runway_takeoff.getMinAirspeedScaling() * _param_fw_airspd_min.get(), ground_speed);
1440-
/*
1441-
* Update navigation: _autogyro_takeoff returns the start WP according to mode and phase.
1442-
* If we use the navigator heading or not is decided later.
1443-
*/
1444-
Vector2f prev_wp_local = _global_local_proj_ref.project(_runway_takeoff.getStartWP()(0),
1445-
_runway_takeoff.getStartWP()(1));
1424+
const float takeoff_airspeed = _runway_takeoff.getMinAirspeedScaling() * _param_fw_airspd_min.get();
1425+
float adjusted_min_airspeed = _param_fw_airspd_min.get();
1426+
1427+
if (takeoff_airspeed < _param_fw_airspd_min.get()) {
1428+
// adjust underspeed detection bounds for takeoff airspeed
1429+
_tecs.set_equivalent_airspeed_min(takeoff_airspeed);
1430+
adjusted_min_airspeed = takeoff_airspeed;
1431+
}
1432+
1433+
float target_airspeed = get_auto_airspeed_setpoint(control_interval, takeoff_airspeed, adjusted_min_airspeed,
1434+
ground_speed);
1435+
1436+
1437+
const Vector2f start_pos_local = _global_local_proj_ref.project(_runway_takeoff.getStartPosition()(0),
1438+
_runway_takeoff.getStartPosition()(1));
1439+
const Vector2f takeoff_waypoint_local = _global_local_proj_ref.project(pos_sp_curr.lat, pos_sp_curr.lon);
1440+
1441+
// the bearing from runway start to the takeoff waypoint is followed until the clearance altitude is exceeded
1442+
const Vector2f takeoff_bearing_vector = calculateTakeoffBearingVector(start_pos_local, takeoff_waypoint_local);
1443+
14461444

14471445
if (_param_fw_use_npfg.get()) {
14481446
_npfg.setAirspeedNom(target_airspeed * _eas2tas);
14491447
_npfg.setAirspeedMax(_param_fw_airspd_max.get() * _eas2tas);
1450-
_npfg.navigateWaypoints(prev_wp_local, curr_wp_local, curr_pos_local, ground_speed, _wind_vel);
1448+
_npfg.navigatePathTangent(local_2D_position, start_pos_local, takeoff_bearing_vector, ground_speed,
1449+
_wind_vel, 0.0f);
14511450

14521451
_att_sp.roll_body = _autogyro_takeoff.getRoll(_npfg.getRollSetpoint());
14531452
target_airspeed = _npfg.getAirspeedRef() / _eas2tas;
14541453

14551454
} else {
1456-
_l1_control.navigate_waypoints(prev_wp_local, curr_wp_local, curr_pos_local, ground_speed);
1455+
const Vector2f virtual_waypoint = start_pos_local + takeoff_bearing_vector * HDG_HOLD_DIST_NEXT;
1456+
_l1_control.navigate_waypoints(start_pos_local, virtual_waypoint, local_2D_position, ground_speed);
14571457
_att_sp.roll_body = _autogyro_takeoff.getRoll(_l1_control.get_roll_setpoint());
14581458
}
14591459

@@ -1468,7 +1468,6 @@ FixedwingPositionControl::control_auto_takeoff(const hrt_abstime &now, const flo
14681468
radians(takeoff_pitch_max_deg),
14691469
_param_fw_thr_min.get(),
14701470
_param_fw_thr_max.get(), // XXX should we also set autogyro_takeoff_throttle here?
1471-
_param_fw_thr_cruise.get(),
14721471
_autogyro_takeoff.climbout(),
14731472
radians(_autogyro_takeoff.getMinPitch(_takeoff_pitch_min.get(), _param_fw_p_lim_min.get())),
14741473
tecs_status_s::TECS_MODE_TAKEOFF);
@@ -1481,7 +1480,10 @@ FixedwingPositionControl::control_auto_takeoff(const hrt_abstime &now, const flo
14811480
_att_sp.roll_reset_integral = _autogyro_takeoff.resetIntegrators();
14821481
_att_sp.pitch_reset_integral = _autogyro_takeoff.resetIntegrators();
14831482

1484-
} else if (_runway_takeoff.runwayTakeoffEnabled()) {
1483+
}
1484+
1485+
/////////////////////////////////////////////////////////////RUNWAY
1486+
else if (_runway_takeoff.runwayTakeoffEnabled()) {
14851487
if (!_runway_takeoff.isInitialized()) {
14861488
_runway_takeoff.init(now, _yaw, global_position);
14871489

@@ -1599,7 +1601,10 @@ FixedwingPositionControl::control_auto_takeoff(const hrt_abstime &now, const flo
15991601
_att_sp.apply_flaps = vehicle_attitude_setpoint_s::FLAPS_TAKEOFF;
16001602
_att_sp.apply_spoilers = vehicle_attitude_setpoint_s::SPOILERS_OFF;
16011603

1602-
} else {
1604+
}
1605+
1606+
///////////LOUNCH
1607+
else {
16031608
/* Perform launch detection */
16041609
if (!_skipping_takeoff_detection && _launchDetector.launchDetectionEnabled() &&
16051610
_launch_detection_state != LAUNCHDETECTION_RES_DETECTED_ENABLEMOTORS) {
@@ -1742,7 +1747,7 @@ FixedwingPositionControl::control_auto_takeoff(const hrt_abstime &now, const flo
17421747
_att_sp.thrust_body[0] = _runway_takeoff.getThrottle(now, get_tecs_thrust());
17431748

17441749
} else if (_autogyro_takeoff.autogyroTakeoffEnabled()) {
1745-
PX4_INFO("Spoustim GETTHROTTLE");
1750+
//PX4_INFO("Spoustim GETTHROTTLE");
17461751
_att_sp.thrust_body[0] = _autogyro_takeoff.getThrottle(now, get_tecs_thrust());
17471752

17481753
} else {

src/modules/fw_pos_control_l1/FixedwingPositionControl.hpp

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,7 @@ class FixedwingPositionControl final : public ModuleBase<FixedwingPositionContro
259259
double _current_longitude{0};
260260
float _current_altitude{0.f};
261261

262+
float _roll{0.0f};
262263
float _pitch{0.0f};
263264
float _yaw{0.0f};
264265
float _yawrate{0.0f};
@@ -337,13 +338,11 @@ class FixedwingPositionControl final : public ModuleBase<FixedwingPositionContro
337338
// orbit to altitude only when the aircraft has entered the final *straight approach.
338339
hrt_abstime _time_started_landing{0};
339340

340-
<<<<<<< HEAD
341341
// [m] lateral touchdown position offset manually commanded during landing
342342
float _lateral_touchdown_position_offset{0.0f};
343-
=======
344-
RunwayTakeoff _runway_takeoff;
343+
345344
AutogyroTakeoff _autogyro_takeoff;
346-
>>>>>>> Autogyro takeoff, squash and clean
345+
347346

348347
// [m] relative vector from land point to approach entrance (NE)
349348
Vector2f _landing_approach_entrance_offset_vector{};
@@ -394,10 +393,7 @@ class FixedwingPositionControl final : public ModuleBase<FixedwingPositionContro
394393

395394
float _groundspeed_undershoot{0.0f}; ///< ground speed error to min. speed in m/s
396395

397-
float _roll{0.0f};
398-
float _pitch{0.0f};
399-
float _yaw{0.0f};
400-
float _yawrate{0.0f};
396+
401397

402398
// TECS
403399
// total energy control system - airspeed / altitude control

src/modules/fw_pos_control_l1/autogyro_takeoff/AutogyroTakeoff.cpp

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,8 @@ void AutogyroTakeoff::update(const hrt_abstime &now, float airspeed, float rotor
118118
_time_in_state = now;
119119
}
120120

121-
mavlink_log_info(mavlink_log_pub, "#Takeoff: minimal RPM for prerotator reached");
121+
mavlink_log_info(mavlink_log_pub, "Takeoff: minimal RPM for prerotator reached");
122+
//PX4_INFO("Takeoff: minimal RPM for prerotator reached");
122123
}
123124

124125
break;
@@ -140,6 +141,7 @@ void AutogyroTakeoff::update(const hrt_abstime &now, float airspeed, float rotor
140141
_time_in_state = now;
141142
play_next_tone();
142143
mavlink_log_info(mavlink_log_pub, "Takeoff, prerotator RPM reached");
144+
//PX4_INFO("Takeoff: prerotator RPM reached");
143145
}
144146

145147
break;
@@ -156,7 +158,7 @@ void AutogyroTakeoff::update(const hrt_abstime &now, float airspeed, float rotor
156158

157159
if (rotor_rpm < _param_ag_rotor_flight_rpm.get()) {
158160
ready_for_release = false;
159-
161+
//PX4_INFO("Takeofff, waiting for flight rpm.");
160162
// Some histesis needs to be applied for the start interrupt procedure.
161163
// Currently, this does not allow the start to be interrupted.
162164
//_state = AutogyroTakeoffState::PRE_TAKEOFF_PREROTATE;
@@ -166,6 +168,7 @@ void AutogyroTakeoff::update(const hrt_abstime &now, float airspeed, float rotor
166168
// check minimal airspeed
167169
if (airspeed < (_param_fw_airspd_min.get() * _param_rwto_airspd_scl.get())) {
168170
ready_for_release = false;
171+
//PX4_INFO("Takeofff, waiting for min airspeed.");
169172
}
170173

171174
if (ready_for_release) {
@@ -174,7 +177,7 @@ void AutogyroTakeoff::update(const hrt_abstime &now, float airspeed, float rotor
174177
_state = AutogyroTakeoffState::TAKEOFF_RELEASE;
175178
_time_in_state = now;
176179
mavlink_log_info(mavlink_log_pub, "Takeoff, Please release.");
177-
180+
//PX4_INFO("Takeoff, Please release.");
178181
play_next_tone();
179182
}
180183

@@ -198,8 +201,9 @@ void AutogyroTakeoff::update(const hrt_abstime &now, float airspeed, float rotor
198201
play_release_tone();
199202
}
200203

201-
if (alt_agl > _param_rwto_nav_alt.get()) {
204+
if (alt_agl > _param_ag_nav_alt.get()) {
202205
mavlink_log_info(mavlink_log_pub, "Climbout");
206+
PX4_INFO("Takeoff: Climbout.");
203207
_state = AutogyroTakeoffState::TAKEOFF_CLIMBOUT;
204208
play_next_tone();
205209
_time_in_state = now;
@@ -224,6 +228,7 @@ void AutogyroTakeoff::update(const hrt_abstime &now, float airspeed, float rotor
224228
_climbout = false;
225229
_state = AutogyroTakeoffState::FLY;
226230
_time_in_state = now;
231+
PX4_INFO("Takeoff:FLY.");
227232
}
228233

229234
//_climbout = false;
@@ -332,8 +337,8 @@ float AutogyroTakeoff::getRoll(float navigatorRoll)
332337
// allow some limited roll during RELEASE and CLIMBOUT
333338
else if (_state < AutogyroTakeoffState::FLY) {
334339
return math::constrain(navigatorRoll,
335-
math::radians(-_param_rwto_max_roll.get()),
336-
math::radians(_param_rwto_max_roll.get()));
340+
math::radians(-_param_ag_tko_max_roll.get()),
341+
math::radians(_param_ag_tko_max_roll.get()));
337342
}
338343

339344
return navigatorRoll;
@@ -368,7 +373,7 @@ float AutogyroTakeoff::getThrottle(const hrt_abstime &now, float tecsThrottle)
368373

369374
float idle = (double)_param_fw_thr_idle.get();
370375

371-
PX4_INFO("GET THROTTLE %f, state: %f, time: %f", (double)idle, (double)_state, (double)(now - _time_in_state));
376+
//PX4_INFO("GET THROTTLE %f, state: %f, time: %f", (double)idle, (double)_state, (double)(now - _time_in_state));
372377

373378
switch (_state) {
374379

@@ -380,6 +385,7 @@ float AutogyroTakeoff::getThrottle(const hrt_abstime &now, float tecsThrottle)
380385
case AutogyroTakeoffState::PRE_TAKEOFF_DONE: {
381386
if (_param_ag_prerotator_type.get() == AutogyroTakeoffType::WOPREROT_RUNWAY) {
382387
float throttle = ((now - _time_in_state) / (_param_rwto_ramp_time.get() * 1_s)) * _param_rwto_max_thr.get();
388+
//PX4_INFO("Thortle: %f",(double)throttle);
383389
return math::min(throttle, _param_rwto_max_thr.get());
384390

385391
} else {

src/modules/fw_pos_control_l1/autogyro_takeoff/AutogyroTakeoff.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -147,11 +147,9 @@ class __EXPORT AutogyroTakeoff : public ModuleParams
147147
(ParamBool<px4::params::AG_TKOFF>) _param_ag_tkoff,
148148
(ParamBool<px4::params::RWTO_TKOFF>) _param_rwto_tkoff,
149149
(ParamInt<px4::params::RWTO_HDG>) _param_rwto_hdg,
150-
(ParamFloat<px4::params::RWTO_NAV_ALT>) _param_rwto_nav_alt,
151150
(ParamFloat<px4::params::RWTO_MAX_THR>) _param_rwto_max_thr,
152151
(ParamFloat<px4::params::RWTO_PSP>) _param_rwto_psp,
153152
(ParamFloat<px4::params::RWTO_MAX_PITCH>) _param_rwto_max_pitch,
154-
(ParamFloat<px4::params::RWTO_MAX_ROLL>) _param_rwto_max_roll,
155153
(ParamFloat<px4::params::RWTO_AIRSPD_SCL>) _param_rwto_airspd_scl,
156154
(ParamFloat<px4::params::RWTO_RAMP_TIME>) _param_rwto_ramp_time,
157155

@@ -164,7 +162,10 @@ class __EXPORT AutogyroTakeoff : public ModuleParams
164162
(ParamFloat<px4::params::AG_PROT_MIN_RPM>) _param_ag_prerotator_minimal_rpm,
165163
(ParamFloat<px4::params::AG_PROT_TRG_RPM>) _param_ag_prerotator_target_rpm,
166164
(ParamFloat<px4::params::AG_ROTOR_RPM>) _param_ag_rotor_flight_rpm,
167-
(ParamInt<px4::params::AG_PROT_TYPE>) _param_ag_prerotator_type
165+
(ParamInt<px4::params::AG_PROT_TYPE>) _param_ag_prerotator_type,
166+
167+
(ParamFloat<px4::params::AG_NAV_ALT>) _param_ag_nav_alt,
168+
(ParamFloat<px4::params::AG_TKO_MAX_ROLL>) _param_ag_tko_max_roll
168169

169170

170171
)

src/modules/fw_pos_control_l1/autogyro_takeoff/autogyro_takeoff_parameters.c

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,3 +99,33 @@ PARAM_DEFINE_FLOAT(AG_ROTOR_RPM, 1000.0);
9999
* @value 10 Not implemented: SITL in flightgear
100100
*/
101101
PARAM_DEFINE_INT32(AG_PROT_TYPE, 0);
102+
103+
104+
/**
105+
* Altitude AGL at which we have enough ground clearance to allow some roll.
106+
*
107+
*
108+
* @unit m
109+
* @min 0.0
110+
* @max 100.0
111+
* @decimal 1
112+
* @increment 1
113+
* @group Autogyro
114+
*/
115+
PARAM_DEFINE_FLOAT(AG_NAV_ALT, 5.0);
116+
117+
/**
118+
* Max roll during climbout.
119+
*
120+
* Roll is limited during climbout to ensure enough lift and prevents aggressive
121+
* navigation before we're on a safe height.
122+
*
123+
* @unit deg
124+
* @min 0.0
125+
* @max 60.0
126+
* @decimal 1
127+
* @increment 0.5
128+
* @group Autogyro
129+
*/
130+
131+
PARAM_DEFINE_FLOAT(AG_TKO_MAX_ROLL, 25.0);

0 commit comments

Comments
 (0)