Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 7c7d980

Browse files
MaEtUgRLorenzMeier
authored andcommitted
FlightTasks: fix takeoff trigger for offboard
1 parent e73218d commit 7c7d980

File tree

6 files changed

+42
-31
lines changed

6 files changed

+42
-31
lines changed

src/lib/FlightTasks/tasks/Auto/FlightTaskAuto.cpp

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -129,17 +129,6 @@ void FlightTaskAuto::_limitYawRate()
129129
}
130130
}
131131

132-
bool FlightTaskAuto::_checkTakeoff() {
133-
// position setpoint above the minimum altitude
134-
float min_altitude = 0.2f;
135-
const float min_distance_to_ground = _sub_vehicle_local_position->get().hagl_min;
136-
if (PX4_ISFINITE(min_distance_to_ground)) {
137-
min_altitude = min_distance_to_ground + 0.05f;
138-
}
139-
140-
return PX4_ISFINITE(_position_setpoint(2)) && _position_setpoint(2) < (_position(2) - min_altitude);
141-
}
142-
143132
bool FlightTaskAuto::_evaluateTriplets()
144133
{
145134
// TODO: fix the issues mentioned below

src/lib/FlightTasks/tasks/Auto/FlightTaskAuto.hpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,6 @@ class FlightTaskAuto : public FlightTask
9191
matrix::Vector2f _getTargetVelocityXY(); /**< only used for follow-me and only here because of legacy reason.*/
9292
void _updateInternalWaypoints(); /**< Depending on state of vehicle, the internal waypoints might differ from target (for instance if offtrack). */
9393
bool _compute_heading_from_2D_vector(float &heading, matrix::Vector2f v); /**< Computes and sets heading a 2D vector */
94-
virtual bool _checkTakeoff(); /**< determines when to trigger a takeoff (ignored in flight) */
9594

9695
matrix::Vector3f _prev_prev_wp{}; /**< Pre-previous waypoint (local frame). This will be used for smoothing trajectories -> not used yet. */
9796
matrix::Vector3f _prev_wp{}; /**< Previous waypoint (local frame). If no previous triplet is available, the prev_wp is set to current position. */

src/lib/FlightTasks/tasks/FlightTask/FlightTask.cpp

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ constexpr uint64_t FlightTask::_timeout;
66
// First index of empty_setpoint corresponds to time-stamp and requires a finite number.
77
const vehicle_local_position_setpoint_s FlightTask::empty_setpoint = {0, NAN, NAN, NAN, NAN, NAN, NAN, NAN, NAN, NAN, NAN, NAN, NAN, NAN, NAN, {NAN, NAN, NAN}};
88

9-
const vehicle_constraints_s FlightTask::empty_constraints = {0, NAN, NAN, NAN, NAN, NAN, NAN, NAN, {}};
9+
const vehicle_constraints_s FlightTask::empty_constraints = {0, NAN, NAN, NAN, NAN, NAN, NAN, NAN, false, {}};
1010
const landing_gear_s FlightTask::empty_landing_gear_default_keep = {0, landing_gear_s::GEAR_KEEP, {}};
1111

1212
bool FlightTask::initializeSubscriptions(SubscriptionArray &subscription_array)
@@ -145,3 +145,30 @@ void FlightTask::_setDefaultConstraints()
145145
_constraints.max_distance_to_ground = NAN;
146146
_constraints.want_takeoff = false;
147147
}
148+
149+
bool FlightTask::_checkTakeoff()
150+
{
151+
// position setpoint above the minimum altitude
152+
bool position_triggered_takeoff = false;
153+
154+
if (PX4_ISFINITE(_position_setpoint(2))) {
155+
//minimal altitude either 20cm or what is necessary for correct estimation e.g. optical flow
156+
float min_altitude = 0.2f;
157+
const float min_distance_to_ground = _sub_vehicle_local_position->get().hagl_min;
158+
159+
if (PX4_ISFINITE(min_distance_to_ground)) {
160+
min_altitude = min_distance_to_ground + 0.05f;
161+
}
162+
163+
position_triggered_takeoff = _position_setpoint(2) < (_position(2) - min_altitude);
164+
}
165+
166+
// upwards velocity setpoint
167+
bool velocity_triggered_takeoff = false;
168+
169+
if (PX4_ISFINITE(_velocity_setpoint(2))) {
170+
velocity_triggered_takeoff = _velocity_setpoint(2) < -0.3f;
171+
}
172+
173+
return position_triggered_takeoff || velocity_triggered_takeoff;
174+
}

src/lib/FlightTasks/tasks/FlightTask/FlightTask.hpp

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -185,21 +185,18 @@ class FlightTask : public ModuleParams
185185
uORB::Subscription<vehicle_attitude_s> *_sub_attitude{nullptr};
186186
uint8_t _heading_reset_counter{0}; /**< estimator heading reset */
187187

188-
/**
189-
* Reset all setpoints to NAN
190-
*/
188+
/** Reset all setpoints to NAN */
191189
void _resetSetpoints();
192190

193-
/**
194-
* Check and update local position
195-
*/
191+
/** Check and update local position */
196192
void _evaluateVehicleLocalPosition();
197193

198-
/**
199-
* Set constraints to default values
200-
*/
194+
/** Set constraints to default values */
201195
virtual void _setDefaultConstraints();
202196

197+
/** determines when to trigger a takeoff (ignored in flight) */
198+
virtual bool _checkTakeoff();
199+
203200
/* Time abstraction */
204201
static constexpr uint64_t _timeout = 500000; /**< maximal time in us before a loop or data times out */
205202
float _time = 0; /**< passed time in seconds since the task was activated */

src/lib/FlightTasks/tasks/ManualAltitude/FlightTaskManualAltitude.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ class FlightTaskManualAltitude : public FlightTaskManual
5656
void _updateHeadingSetpoints(); /**< sets yaw or yaw speed */
5757
virtual void _updateSetpoints(); /**< updates all setpoints */
5858
virtual void _scaleSticks(); /**< scales sticks to velocity in z */
59-
virtual bool _checkTakeoff(); /**< determines when to trigger a takeoff (ignored in flight) */
59+
bool _checkTakeoff() override;
6060

6161
/**
6262
* rotates vector into local frame

src/lib/FlightTasks/tasks/Offboard/FlightTaskOffboard.cpp

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -75,17 +75,16 @@ bool FlightTaskOffboard::activate()
7575

7676
bool FlightTaskOffboard::update()
7777
{
78+
// reset setpoint for every loop
79+
_resetSetpoints();
80+
7881
if (!_sub_triplet_setpoint->get().current.valid) {
79-
_resetSetpoints();
82+
_setDefaultConstraints();
8083
_position_setpoint = _position;
8184
return false;
8285
}
8386

84-
// reset setpoint for every loop
85-
_resetSetpoints();
86-
8787
// Yaw / Yaw-speed
88-
8988
if (_sub_triplet_setpoint->get().current.yaw_valid) {
9089
// yaw control required
9190
_yaw_setpoint = _sub_triplet_setpoint->get().current.yaw;
@@ -169,7 +168,6 @@ bool FlightTaskOffboard::update()
169168
// 2. position setpoint + velocity setpoint (velocity used as feedforward)
170169
// 3. velocity setpoint
171170
// 4. acceleration setpoint -> this will be mapped to normalized thrust setpoint because acceleration is not supported
172-
173171
const bool position_ctrl_xy = _sub_triplet_setpoint->get().current.position_valid
174172
&& _sub_vehicle_local_position->get().xy_valid;
175173
const bool position_ctrl_z = _sub_triplet_setpoint->get().current.alt_valid
@@ -225,7 +223,6 @@ bool FlightTaskOffboard::update()
225223
}
226224

227225
// Z-direction
228-
229226
if (feedforward_ctrl_z) {
230227
_position_setpoint(2) = _sub_triplet_setpoint->get().current.z;
231228
_velocity_setpoint(2) = _sub_triplet_setpoint->get().current.vz;
@@ -239,12 +236,14 @@ bool FlightTaskOffboard::update()
239236

240237
// Acceleration
241238
// Note: this is not supported yet and will be mapped to normalized thrust directly.
242-
243239
if (_sub_triplet_setpoint->get().current.acceleration_valid) {
244240
_thrust_setpoint(0) = _sub_triplet_setpoint->get().current.a_x;
245241
_thrust_setpoint(1) = _sub_triplet_setpoint->get().current.a_y;
246242
_thrust_setpoint(2) = _sub_triplet_setpoint->get().current.a_z;
247243
}
248244

245+
// use default conditions of upwards position or velocity to take off
246+
_constraints.want_takeoff = _checkTakeoff();
247+
249248
return true;
250249
}

0 commit comments

Comments
 (0)