Skip to content

Commit 7a586d2

Browse files
mrivibresch
authored andcommitted
ObstacleAvoidance: hysteresis on failsafe
1 parent 79d4c09 commit 7a586d2

File tree

2 files changed

+19
-7
lines changed

2 files changed

+19
-7
lines changed

src/lib/FlightTasks/tasks/Utility/ObstacleAvoidance.cpp

+16-7
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ using namespace time_literals;
4242

4343
/** Timeout in us for trajectory data to get considered invalid */
4444
static constexpr uint64_t TRAJECTORY_STREAM_TIMEOUT_US = 500_ms;
45+
/** If Flighttask fails, keep 0.5 seconds the current setpoint before going into failsafe land */
46+
static constexpr uint64_t TIME_BEFORE_FAILSAFE = 500_ms;
4547

4648
const vehicle_trajectory_waypoint_s empty_trajectory_waypoint = {0, 0, {0, 0, 0, 0, 0, 0, 0},
4749
{ {0, {NAN, NAN, NAN}, {NAN, NAN, NAN}, {NAN, NAN, NAN}, NAN, NAN, false, {0, 0, 0}},
@@ -57,6 +59,8 @@ ObstacleAvoidance::ObstacleAvoidance(ModuleParams *parent) :
5759
{
5860
_desired_waypoint = empty_trajectory_waypoint;
5961
_failsafe_position.setNaN();
62+
_avoidance_point_not_valid_hysteresis.set_hysteresis_time_from(false, TIME_BEFORE_FAILSAFE);
63+
6064
}
6165

6266
ObstacleAvoidance::~ObstacleAvoidance()
@@ -99,7 +103,9 @@ void ObstacleAvoidance::injectAvoidanceSetpoints(Vector3f &pos_sp, Vector3f &vel
99103
const bool avoidance_point_valid =
100104
_sub_vehicle_trajectory_waypoint->get().waypoints[vehicle_trajectory_waypoint_s::POINT_0].point_valid == true;
101105

102-
if (avoidance_data_timeout || !avoidance_point_valid) {
106+
_avoidance_point_not_valid_hysteresis.set_state_and_update(!avoidance_point_valid, hrt_absolute_time());
107+
108+
if (avoidance_data_timeout || _avoidance_point_not_valid_hysteresis.get_state()) {
103109
PX4_WARN("Obstacle Avoidance system failed, loitering");
104110
_publishVehicleCmdDoLoiter();
105111

@@ -119,14 +125,17 @@ void ObstacleAvoidance::injectAvoidanceSetpoints(Vector3f &pos_sp, Vector3f &vel
119125
_failsafe_position.setNaN();
120126
}
121127

122-
pos_sp = _sub_vehicle_trajectory_waypoint->get().waypoints[vehicle_trajectory_waypoint_s::POINT_0].position;
123-
vel_sp = _sub_vehicle_trajectory_waypoint->get().waypoints[vehicle_trajectory_waypoint_s::POINT_0].velocity;
128+
if (avoidance_point_valid) {
129+
pos_sp = _sub_vehicle_trajectory_waypoint->get().waypoints[vehicle_trajectory_waypoint_s::POINT_0].position;
130+
vel_sp = _sub_vehicle_trajectory_waypoint->get().waypoints[vehicle_trajectory_waypoint_s::POINT_0].velocity;
124131

125-
if (!_ext_yaw_active) {
126-
// inject yaw setpoints only if weathervane isn't active
127-
yaw_sp = _sub_vehicle_trajectory_waypoint->get().waypoints[vehicle_trajectory_waypoint_s::POINT_0].yaw;
128-
yaw_speed_sp = _sub_vehicle_trajectory_waypoint->get().waypoints[vehicle_trajectory_waypoint_s::POINT_0].yaw_speed;
132+
if (!_ext_yaw_active) {
133+
// inject yaw setpoints only if weathervane isn't active
134+
yaw_sp = _sub_vehicle_trajectory_waypoint->get().waypoints[vehicle_trajectory_waypoint_s::POINT_0].yaw;
135+
yaw_speed_sp = _sub_vehicle_trajectory_waypoint->get().waypoints[vehicle_trajectory_waypoint_s::POINT_0].yaw_speed;
136+
}
129137
}
138+
130139
}
131140

132141
void ObstacleAvoidance::updateAvoidanceDesiredWaypoints(const Vector3f &curr_wp, const float curr_yaw,

src/lib/FlightTasks/tasks/Utility/ObstacleAvoidance.hpp

+3
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@
5252
#include <uORB/topics/vehicle_trajectory_waypoint.h>
5353
#include <uORB/topics/position_setpoint.h>
5454

55+
#include <lib/hysteresis/hysteresis.h>
5556

5657
#include <matrix/matrix/math.hpp>
5758

@@ -121,6 +122,8 @@ class ObstacleAvoidance : public ModuleParams
121122
matrix::Vector3f _position = {}; /**< current vehicle position */
122123
matrix::Vector3f _failsafe_position = {}; /**< vehicle position when entered in failsafe */
123124

125+
systemlib::Hysteresis _avoidance_point_not_valid_hysteresis{false}; /**< becomes true if the companion doesn't start sending valid setpoints */
126+
124127
bool _ext_yaw_active = false; /**< true, if external yaw handling is active */
125128

126129
/**

0 commit comments

Comments
 (0)