Skip to content

Commit 80af13e

Browse files
committed
keep in sync with master
follow changes in master Fixing of errors caused by #19495 autogyro takeoff updats Fix build of Autogyro take off Add motor rampup state, killswitch handling update throttle Keep upstream
1 parent 158981d commit 80af13e

File tree

4 files changed

+137
-27
lines changed

4 files changed

+137
-27
lines changed

src/modules/fw_pos_control_l1/autogyro_takeoff/AutogyroTakeoff.cpp

Lines changed: 95 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -80,19 +80,28 @@ void AutogyroTakeoff::update(const hrt_abstime &now, float airspeed, float rotor
8080
_climbout = true;
8181
takeoff_status_s takeoff_status = {};
8282

83+
actuator_armed_s actuator_armed;
84+
_actuator_armed_sub.update(&actuator_armed);
85+
86+
if (actuator_armed.manual_lockdown && _state <= AutogyroTakeoffState::PRE_TAKEOFF_RAMPUP) {
87+
_state = AutogyroTakeoffState::TAKEOFF_ERROR;
88+
}
89+
8390
switch (_state) {
8491
/*
8592
Hangling error states of takeoff mode. Should lead in allerting operator and/or
8693
abrod takeoff process
8794
8895
IN: error state
8996
*/
90-
case AutogyroTakeoffState::TAKEOFF_ERROR:
91-
PX4_INFO("ERR STATE");
92-
mavlink_log_info(mavlink_log_pub, "#Takeoff: Error state");
97+
case AutogyroTakeoffState::TAKEOFF_ERROR: {
98+
if (_state != _state_last) {
99+
PX4_INFO("ERR STATE");
100+
mavlink_log_info(mavlink_log_pub, "#Takeoff: Error state");
101+
}
102+
}
93103
break;
94104

95-
96105
/*
97106
Initial state of regulator, wait for manual prerotate of rotor.
98107
@@ -118,7 +127,8 @@ void AutogyroTakeoff::update(const hrt_abstime &now, float airspeed, float rotor
118127
_time_in_state = now;
119128
}
120129

121-
mavlink_log_info(mavlink_log_pub, "#Takeoff: minimal RPM for prerotator reached");
130+
mavlink_log_info(mavlink_log_pub, "Takeoff: minimal RPM for prerotator reached");
131+
//PX4_INFO("Takeoff: minimal RPM for prerotator reached");
122132
}
123133

124134
break;
@@ -140,13 +150,14 @@ void AutogyroTakeoff::update(const hrt_abstime &now, float airspeed, float rotor
140150
_time_in_state = now;
141151
play_next_tone();
142152
mavlink_log_info(mavlink_log_pub, "Takeoff, prerotator RPM reached");
153+
//PX4_INFO("Takeoff: prerotator RPM reached");
143154
}
144155

145156
break;
146157

147158
/*
148-
All required takeoff conditions are satisfied. Now it is prepared to start.
149-
Try to start main motor. Slowly rump up and check it.
159+
All required takeoff conditions are satisfied. Now it is prepared to
160+
try to start main motor.
150161
151162
IN: rotor prepared;
152163
OUT: rotor prepared; minimal airspeed; motor max power,
@@ -156,31 +167,75 @@ void AutogyroTakeoff::update(const hrt_abstime &now, float airspeed, float rotor
156167

157168
if (rotor_rpm < _param_ag_rotor_flight_rpm.get()) {
158169
ready_for_release = false;
159-
170+
//PX4_INFO("Takeofff, waiting for flight rpm.");
160171
// Some histesis needs to be applied for the start interrupt procedure.
161172
// Currently, this does not allow the start to be interrupted.
162173
//_state = AutogyroTakeoffState::PRE_TAKEOFF_PREROTATE;
163-
_time_in_state = now;
174+
//_time_in_state = now;
164175
}
165176

166177
// check minimal airspeed
167178
if (airspeed < (_param_fw_airspd_min.get() * _param_rwto_airspd_scl.get())) {
168179
ready_for_release = false;
180+
//PX4_INFO("Takeofff, waiting for min airspeed.");
169181
}
170182

171183
if (ready_for_release) {
172184
_init_yaw = get_bearing_to_next_waypoint(_initial_wp(0), _initial_wp(1), current_lat, current_lon);
173185

174-
_state = AutogyroTakeoffState::TAKEOFF_RELEASE;
186+
_state = AutogyroTakeoffState::PRE_TAKEOFF_RAMPUP;
175187
_time_in_state = now;
176-
mavlink_log_info(mavlink_log_pub, "Takeoff, Please release.");
177-
188+
mavlink_log_info(mavlink_log_pub, "Ready to start motor");
189+
//PX4_INFO("Takeoff, Please release.");
178190
play_next_tone();
179191
}
180192

181193
}
182194
break;
183195

196+
/*
197+
Slowly rampup motor. Keep trying to check other flight parameters.
198+
If I can still fly
199+
*/
200+
case AutogyroTakeoffState::PRE_TAKEOFF_RAMPUP: {
201+
bool ready_for_release = true;
202+
203+
if (rotor_rpm < _param_ag_rotor_flight_rpm.get()) {
204+
ready_for_release = false;
205+
//PX4_INFO("Takeofff, waiting for flight rpm.");
206+
// Some histesis needs to be applied for the start interrupt procedure.
207+
// Currently, this does not allow the start to be interrupted.
208+
//_state = AutogyroTakeoffState::PRE_TAKEOFF_PREROTATE;
209+
//_time_in_state = now;
210+
}
211+
212+
// check minimal airspeed
213+
if (airspeed < (_param_fw_airspd_min.get() * _param_rwto_airspd_scl.get())) {
214+
ready_for_release = false;
215+
//PX4_INFO("Takeofff, waiting for min airspeed.");
216+
}
217+
218+
// ramup time elapsed
219+
if (hrt_elapsed_time(&_time_in_state) < (_param_rwto_ramp_time.get() * 1_s * 1.5)) {
220+
ready_for_release = false;
221+
}
222+
223+
// Check if motor/esc power (properller RPM) is suffiscient
224+
// TODO
225+
if (false) {
226+
ready_for_release = false;
227+
}
228+
229+
if (ready_for_release) {
230+
231+
_state = AutogyroTakeoffState::TAKEOFF_RELEASE;
232+
_time_in_state = now;
233+
PX4_INFO("Takeoff, Please release.");
234+
play_next_tone();
235+
}
236+
}
237+
break;
238+
184239
/*
185240
Command for release. Sound signal for release from hand or release from
186241
some takeoff platform with mavlink command. This step ends on release ACK.
@@ -198,8 +253,9 @@ void AutogyroTakeoff::update(const hrt_abstime &now, float airspeed, float rotor
198253
play_release_tone();
199254
}
200255

201-
if (alt_agl > _param_rwto_nav_alt.get()) {
256+
if (alt_agl > _param_ag_nav_alt.get()) {
202257
mavlink_log_info(mavlink_log_pub, "Climbout");
258+
PX4_INFO("Takeoff: Climbout.");
203259
_state = AutogyroTakeoffState::TAKEOFF_CLIMBOUT;
204260
play_next_tone();
205261
_time_in_state = now;
@@ -224,6 +280,7 @@ void AutogyroTakeoff::update(const hrt_abstime &now, float airspeed, float rotor
224280
_climbout = false;
225281
_state = AutogyroTakeoffState::FLY;
226282
_time_in_state = now;
283+
PX4_INFO("Takeoff:FLY.");
227284
}
228285

229286
//_climbout = false;
@@ -278,6 +335,7 @@ float AutogyroTakeoff::getRequestedAirspeed()
278335
case AutogyroTakeoffState::PRE_TAKEOFF_PREROTATE_START:
279336
case AutogyroTakeoffState::PRE_TAKEOFF_PREROTATE:
280337
case AutogyroTakeoffState::PRE_TAKEOFF_DONE:
338+
case AutogyroTakeoffState::PRE_TAKEOFF_RAMPUP:
281339
return _param_fw_airspd_min.get() * _param_rwto_airspd_scl.get();
282340

283341
default:
@@ -305,12 +363,14 @@ float AutogyroTakeoff::getPitch(float tecsPitch)
305363
switch (_state) {
306364

307365
case AutogyroTakeoffState::TAKEOFF_ERROR:
308-
case AutogyroTakeoffState::PRE_TAKEOFF_PREROTATE_START: // 0 Null pitch
309366
return 0;
310367

368+
case AutogyroTakeoffState::PRE_TAKEOFF_PREROTATE_START: // 0 Null pitch
311369
case AutogyroTakeoffState::PRE_TAKEOFF_PREROTATE: // 1 maximal pitch
312370
case AutogyroTakeoffState::PRE_TAKEOFF_DONE: // 2
313-
return math::radians(_param_rwto_max_pitch.get());
371+
case AutogyroTakeoffState::PRE_TAKEOFF_RAMPUP:
372+
//return math::radians(_param_rwto_max_pitch.get());
373+
return math::radians(_param_rwto_psp.get());
314374

315375
// FLy
316376
default:
@@ -331,8 +391,8 @@ float AutogyroTakeoff::getRoll(float navigatorRoll)
331391
// allow some limited roll during RELEASE and CLIMBOUT
332392
else if (_state < AutogyroTakeoffState::FLY) {
333393
return math::constrain(navigatorRoll,
334-
math::radians(-_param_rwto_max_roll.get()),
335-
math::radians(_param_rwto_max_roll.get()));
394+
math::radians(-_param_ag_tko_max_roll.get()),
395+
math::radians(_param_ag_tko_max_roll.get()));
336396
}
337397

338398
return navigatorRoll;
@@ -367,6 +427,8 @@ float AutogyroTakeoff::getThrottle(const hrt_abstime &now, float tecsThrottle)
367427

368428
float idle = (double)_param_fw_thr_idle.get();
369429

430+
//PX4_INFO("GET THROTTLE %f, state: %f, time: %f", (double)idle, (double)_state, (double)(now - _time_in_state));
431+
370432
switch (_state) {
371433

372434
case AutogyroTakeoffState::TAKEOFF_ERROR:
@@ -377,15 +439,15 @@ float AutogyroTakeoff::getThrottle(const hrt_abstime &now, float tecsThrottle)
377439
case AutogyroTakeoffState::PRE_TAKEOFF_DONE: {
378440
if (_param_ag_prerotator_type.get() == AutogyroTakeoffType::WOPREROT_RUNWAY) {
379441
float throttle = ((now - _time_in_state) / (_param_rwto_ramp_time.get() * 1_s)) * _param_rwto_max_thr.get();
442+
//PX4_INFO("Thortle: %f",(double)throttle);
380443
return math::min(throttle, _param_rwto_max_thr.get());
381444

382445
} else {
383446
return idle;
384447
}
385448
}
386449

387-
388-
case AutogyroTakeoffState::TAKEOFF_RELEASE: {
450+
case AutogyroTakeoffState::PRE_TAKEOFF_RAMPUP: {
389451
float throttle = idle;
390452

391453
if (_param_ag_prerotator_type.get() == AutogyroTakeoffType::WOPREROT_RUNWAY) {
@@ -396,6 +458,20 @@ float AutogyroTakeoff::getThrottle(const hrt_abstime &now, float tecsThrottle)
396458
throttle = math::min(throttle, _param_rwto_max_thr.get());
397459
}
398460

461+
return throttle;
462+
}
463+
464+
465+
case AutogyroTakeoffState::TAKEOFF_RELEASE: {
466+
float throttle = idle;
467+
468+
if (_param_ag_prerotator_type.get() == AutogyroTakeoffType::WOPREROT_RUNWAY) {
469+
throttle = _param_rwto_max_thr.get();
470+
471+
} else if (_param_ag_prerotator_type.get() == AutogyroTakeoffType::WOPREROT_PLATFORM) {
472+
throttle = _param_rwto_max_thr.get();
473+
}
474+
399475
return math::min(throttle, _param_rwto_max_thr.get());
400476
}
401477

src/modules/fw_pos_control_l1/autogyro_takeoff/AutogyroTakeoff.h

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,12 @@
5050
#include <mathlib/mathlib.h>
5151
#include <matrix/math.hpp>
5252

53+
#include <uORB/Subscription.hpp>
5354
#include <uORB/Publication.hpp>
5455
#include <uORB/topics/takeoff_status.h>
5556
#include <uORB/topics/debug_value.h>
5657
#include <uORB/topics/tune_control.h>
58+
#include <uORB/topics/actuator_armed.h>
5759

5860
namespace autogyrotakeoff
5961
{
@@ -63,9 +65,10 @@ enum AutogyroTakeoffState {
6365
TAKEOFF_ERROR = -1,
6466
PRE_TAKEOFF_PREROTATE_START = 0, /**< Wait for manual rotor prerotation or for some other trigger */
6567
PRE_TAKEOFF_PREROTATE = 1, /**< Start prerotation of rotor controlled from AP or prerotation with some movement */
66-
PRE_TAKEOFF_DONE = 2, /**< autogyro conditions are OK for takeoff, rampup motor */
67-
TAKEOFF_RELEASE = 3, /**< command for release */
68-
TAKEOFF_CLIMBOUT = 4, /**< Climbout for minimal altitude */
68+
PRE_TAKEOFF_DONE = 2, /**< autogyro conditions are OK for takeoff*/
69+
PRE_TAKEOFF_RAMPUP = 3, /**< Get ready to takeoff, rampup motor */
70+
TAKEOFF_RELEASE = 4, /**< command for release */
71+
TAKEOFF_CLIMBOUT = 5, /**< Climbout for minimal altitude */
6972
FLY /**< fly to next waypoint */
7073
};
7174

@@ -115,6 +118,7 @@ class __EXPORT AutogyroTakeoff : public ModuleParams
115118

116119
void reset();
117120

121+
uORB::Subscription _actuator_armed_sub{ORB_ID(actuator_armed)};
118122

119123
void play_next_tone();
120124
void play_release_tone();
@@ -147,11 +151,9 @@ class __EXPORT AutogyroTakeoff : public ModuleParams
147151
(ParamBool<px4::params::AG_TKOFF>) _param_ag_tkoff,
148152
(ParamBool<px4::params::RWTO_TKOFF>) _param_rwto_tkoff,
149153
(ParamInt<px4::params::RWTO_HDG>) _param_rwto_hdg,
150-
(ParamFloat<px4::params::RWTO_NAV_ALT>) _param_rwto_nav_alt,
151154
(ParamFloat<px4::params::RWTO_MAX_THR>) _param_rwto_max_thr,
152155
(ParamFloat<px4::params::RWTO_PSP>) _param_rwto_psp,
153156
(ParamFloat<px4::params::RWTO_MAX_PITCH>) _param_rwto_max_pitch,
154-
(ParamFloat<px4::params::RWTO_MAX_ROLL>) _param_rwto_max_roll,
155157
(ParamFloat<px4::params::RWTO_AIRSPD_SCL>) _param_rwto_airspd_scl,
156158
(ParamFloat<px4::params::RWTO_RAMP_TIME>) _param_rwto_ramp_time,
157159

@@ -164,7 +166,10 @@ class __EXPORT AutogyroTakeoff : public ModuleParams
164166
(ParamFloat<px4::params::AG_PROT_MIN_RPM>) _param_ag_prerotator_minimal_rpm,
165167
(ParamFloat<px4::params::AG_PROT_TRG_RPM>) _param_ag_prerotator_target_rpm,
166168
(ParamFloat<px4::params::AG_ROTOR_RPM>) _param_ag_rotor_flight_rpm,
167-
(ParamInt<px4::params::AG_PROT_TYPE>) _param_ag_prerotator_type
169+
(ParamInt<px4::params::AG_PROT_TYPE>) _param_ag_prerotator_type,
170+
171+
(ParamFloat<px4::params::AG_NAV_ALT>) _param_ag_nav_alt,
172+
(ParamFloat<px4::params::AG_TKO_MAX_ROLL>) _param_ag_tko_max_roll
168173

169174

170175
)

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);

src/modules/logger/logged_topics.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@ void LoggedTopics::add_default_topics()
5050
add_optional_topic("actuator_controls_status_0", 300);
5151
add_topic("airspeed", 1000);
5252
add_optional_topic("airspeed_validated", 200);
53-
add_optional_topic("autogyro_takeoff_status", 100);
5453
add_optional_topic("autotune_attitude_control_status", 100);
5554
add_optional_topic("camera_capture");
5655
add_optional_topic("camera_trigger");
@@ -105,7 +104,7 @@ void LoggedTopics::add_default_topics()
105104
add_topic("sensors_status_imu", 200);
106105
add_optional_topic("spoilers_setpoint", 1000);
107106
add_topic("system_power", 500);
108-
add_optional_topic("takeoff_status", 1000);
107+
add_topic("takeoff_status");
109108
add_optional_topic("tecs_status", 200);
110109
add_optional_topic("tiltrotor_extra_controls", 100);
111110
add_topic("trajectory_setpoint", 200);

0 commit comments

Comments
 (0)