remove SETPOINT_TYPE_IDLE everywhere

along with NAV_CMD_IDLE, set_idle_item, and WaypointType::idle which are
basically the same
This commit is contained in:
Balduin
2026-01-14 13:59:45 +01:00
parent e371c4edd9
commit 503f8d8fc7
18 changed files with 30 additions and 125 deletions
-1
View File
@@ -7,7 +7,6 @@ uint8 SETPOINT_TYPE_VELOCITY=1 # velocity setpoint
uint8 SETPOINT_TYPE_LOITER=2 # loiter setpoint
uint8 SETPOINT_TYPE_TAKEOFF=3 # takeoff setpoint
uint8 SETPOINT_TYPE_LAND=4 # land setpoint, altitude must be ignored, descend until landing
uint8 SETPOINT_TYPE_IDLE=5 # do nothing, switch off motors or keep at idle speed (MC)
uint8 LOITER_TYPE_ORBIT=0 # Circular pattern
uint8 LOITER_TYPE_FIGUREEIGHT=1 # Pattern resembling an 8
@@ -108,13 +108,6 @@ bool FlightTaskAuto::update()
// always reset constraints because they might change depending on the type
_setDefaultConstraints();
// The only time a thrust set-point is sent out is during
// idle. Hence, reset thrust set-point to NAN in case the
// vehicle exits idle.
if (_type_previous == WaypointType::idle) {
_acceleration_setpoint.setNaN();
}
// during mission and reposition, raise the landing gears but only
// if altitude is high enough
if (_highEnoughForLandingGear()) {
@@ -122,13 +115,6 @@ bool FlightTaskAuto::update()
}
switch (_type) {
case WaypointType::idle:
// Send zero thrust setpoint
_position_setpoint.setNaN(); // Don't require any position/velocity setpoints
_velocity_setpoint.setNaN();
_acceleration_setpoint = Vector3f(0.f, 0.f, 100.f); // High downwards acceleration to make sure there's no thrust
break;
case WaypointType::land:
_prepareLandSetpoints();
break;
@@ -64,8 +64,7 @@ enum class WaypointType : int {
velocity = position_setpoint_s::SETPOINT_TYPE_VELOCITY,
loiter = position_setpoint_s::SETPOINT_TYPE_LOITER,
takeoff = position_setpoint_s::SETPOINT_TYPE_TAKEOFF,
land = position_setpoint_s::SETPOINT_TYPE_LAND,
idle = position_setpoint_s::SETPOINT_TYPE_IDLE
land = position_setpoint_s::SETPOINT_TYPE_LAND
};
enum class State {
@@ -129,7 +128,7 @@ protected:
matrix::Vector3f _next_wp{}; /**< The next waypoint after target (local frame). If no next setpoint is available, next is set to target. */
bool _next_was_valid{false};
float _mc_cruise_speed{NAN}; /**< Requested cruise speed. If not valid, default cruise speed is used. */
WaypointType _type{WaypointType::idle}; /**< Type of current target triplet. */
WaypointType _type{WaypointType::position}; /**< Type of current target triplet. */
uORB::SubscriptionData<home_position_s> _sub_home_position{ORB_ID(home_position)};
uORB::SubscriptionData<vehicle_status_s> _sub_vehicle_status{ORB_ID(vehicle_status)};
@@ -148,7 +147,7 @@ protected:
StickYaw _stick_yaw{this};
matrix::Vector3f _land_position;
float _land_heading;
WaypointType _type_previous{WaypointType::idle}; /**< Previous type of current target triplet. */
WaypointType _type_previous{WaypointType::position}; /**< Previous type of current target triplet. */
bool _is_emergency_braking_active{false};
bool _want_takeoff{false};
@@ -387,8 +387,7 @@ FixedWingModeManager::set_control_mode_current(const hrt_abstime &now)
return;
}
} else if ((_control_mode.flag_control_auto_enabled && _control_mode.flag_control_position_enabled)
&& _position_setpoint_current_valid) {
} else if (_control_mode.flag_control_auto_enabled && _control_mode.flag_control_position_enabled && _position_setpoint_current_valid) {
// Enter this mode only if the current waypoint has valid 3D position setpoints.
@@ -577,11 +576,6 @@ FixedWingModeManager::control_auto(const float control_interval, const Vector2d
}
switch (position_sp_type) {
case position_setpoint_s::SETPOINT_TYPE_IDLE: {
control_idle();
break;
}
case position_setpoint_s::SETPOINT_TYPE_POSITION:
control_auto_position(control_interval, curr_pos, ground_speed, pos_sp_prev, current_sp);
break;
@@ -621,24 +615,6 @@ FixedWingModeManager::control_auto(const float control_interval, const Vector2d
}
}
void FixedWingModeManager::control_idle()
{
const hrt_abstime now = hrt_absolute_time();
fixed_wing_lateral_setpoint_s lateral_ctrl_sp {empty_lateral_control_setpoint};
lateral_ctrl_sp.timestamp = now;
lateral_ctrl_sp.lateral_acceleration = 0.0f;
_lateral_ctrl_sp_pub.publish(lateral_ctrl_sp);
fixed_wing_longitudinal_setpoint_s long_contrl_sp {empty_longitudinal_control_setpoint};
long_contrl_sp.timestamp = now;
long_contrl_sp.pitch_direct = 0.f;
long_contrl_sp.throttle_direct = 0.0f;
_longitudinal_ctrl_sp_pub.publish(long_contrl_sp);
_ctrl_configuration_handler.setThrottleMax(0.0f);
_ctrl_configuration_handler.setThrottleMin(0.0f);
}
void
FixedWingModeManager::control_auto_fixed_bank_alt_hold()
{
@@ -243,8 +243,7 @@ bool FeasibilityChecker::checkMissionItemValidity(mission_item_s &mission_item,
}
// check if we find unsupported items and reject mission if so
if (mission_item.nav_cmd != NAV_CMD_IDLE &&
mission_item.nav_cmd != NAV_CMD_WAYPOINT &&
if (mission_item.nav_cmd != NAV_CMD_WAYPOINT &&
mission_item.nav_cmd != NAV_CMD_LOITER_UNLIMITED &&
mission_item.nav_cmd != NAV_CMD_LOITER_TIME_LIMIT &&
mission_item.nav_cmd != NAV_CMD_RETURN_TO_LAUNCH &&
@@ -344,8 +343,7 @@ bool FeasibilityChecker::checkTakeoff(mission_item_s &mission_item)
}
if (!_found_item_with_position) {
_found_item_with_position = (mission_item.nav_cmd != NAV_CMD_IDLE &&
mission_item.nav_cmd != NAV_CMD_DELAY &&
_found_item_with_position = (mission_item.nav_cmd != NAV_CMD_DELAY &&
mission_item.nav_cmd != NAV_CMD_DO_JUMP &&
mission_item.nav_cmd != NAV_CMD_DO_CHANGE_SPEED &&
mission_item.nav_cmd != NAV_CMD_DO_SET_HOME &&
-1
View File
@@ -94,7 +94,6 @@ Land::on_active()
_navigator->get_mission_result()->finished = true;
_navigator->set_mission_result_updated();
_navigator->mode_completed(getNavigatorStateId());
set_idle_item(&_mission_item);
struct position_setpoint_triplet_s *pos_sp_triplet = _navigator->get_position_setpoint_triplet();
mission_item_to_position_setpoint(_mission_item, &pos_sp_triplet->current);
+13 -31
View File
@@ -76,45 +76,27 @@ Loiter::on_active()
void
Loiter::set_loiter_position()
{
if (_navigator->get_vstatus()->arming_state != vehicle_status_s::ARMING_STATE_ARMED &&
_navigator->get_land_detected()->landed) {
position_setpoint_triplet_s *pos_sp_triplet = _navigator->get_position_setpoint_triplet();
// Not setting loiter position if disarmed and landed, instead mark the current
// setpoint as invalid and idle (both, just to be sure).
// Check if we already loiter on a circle and are on the loiter pattern.
bool on_loiter{false};
_navigator->get_position_setpoint_triplet()->current.type = position_setpoint_s::SETPOINT_TYPE_IDLE;
_navigator->set_position_setpoint_triplet_updated();
return;
if (pos_sp_triplet->current.valid && pos_sp_triplet->current.type == position_setpoint_s::SETPOINT_TYPE_LOITER
&& pos_sp_triplet->current.loiter_pattern == position_setpoint_s::LOITER_TYPE_ORBIT) {
const float d_current = get_distance_to_next_waypoint(pos_sp_triplet->current.lat, pos_sp_triplet->current.lon,
_navigator->get_global_position()->lat, _navigator->get_global_position()->lon);
on_loiter = d_current <= (_navigator->get_acceptance_radius() + pos_sp_triplet->current.loiter_radius);
}
position_setpoint_triplet_s *pos_sp_triplet = _navigator->get_position_setpoint_triplet();
if (on_loiter) {
setLoiterItemFromCurrentPositionSetpoint(&_mission_item);
if (_navigator->get_land_detected()->landed) {
_mission_item.nav_cmd = NAV_CMD_IDLE;
} else if (_navigator->get_vstatus()->vehicle_type == vehicle_status_s::VEHICLE_TYPE_ROTARY_WING) {
setLoiterItemFromCurrentPositionWithBraking(&_mission_item);
} else {
// Check if we already loiter on a circle and are on the loiter pattern.
bool on_loiter{false};
if (pos_sp_triplet->current.valid && pos_sp_triplet->current.type == position_setpoint_s::SETPOINT_TYPE_LOITER
&& pos_sp_triplet->current.loiter_pattern == position_setpoint_s::LOITER_TYPE_ORBIT) {
const float d_current = get_distance_to_next_waypoint(pos_sp_triplet->current.lat, pos_sp_triplet->current.lon,
_navigator->get_global_position()->lat, _navigator->get_global_position()->lon);
on_loiter = d_current <= (_navigator->get_acceptance_radius() + pos_sp_triplet->current.loiter_radius);
}
if (on_loiter) {
setLoiterItemFromCurrentPositionSetpoint(&_mission_item);
} else if (_navigator->get_vstatus()->vehicle_type == vehicle_status_s::VEHICLE_TYPE_ROTARY_WING) {
setLoiterItemFromCurrentPositionWithBraking(&_mission_item);
} else {
setLoiterItemFromCurrentPosition(&_mission_item);
}
setLoiterItemFromCurrentPosition(&_mission_item);
}
// convert mission item to current setpoint
+2 -4
View File
@@ -552,10 +552,8 @@ void MissionBase::setEndOfMissionItems()
{
position_setpoint_triplet_s *pos_sp_triplet = _navigator->get_position_setpoint_triplet();
if (_land_detected_sub.get().landed) {
_mission_item.nav_cmd = NAV_CMD_IDLE;
} else {
// Set loiter item only if not landed
if (!_land_detected_sub.get().landed) {
if (pos_sp_triplet->current.valid &&
(pos_sp_triplet->current.type == position_setpoint_s::SETPOINT_TYPE_LOITER ||
pos_sp_triplet->current.type == position_setpoint_s::SETPOINT_TYPE_POSITION)) {
+3 -22
View File
@@ -106,7 +106,6 @@ MissionBlock::is_mission_item_reached_or_completed()
case NAV_CMD_VTOL_LAND:
return _navigator->get_land_detected()->landed;
case NAV_CMD_IDLE: /* fall through */
case NAV_CMD_LOITER_UNLIMITED:
return false;
@@ -650,10 +649,6 @@ MissionBlock::mission_item_to_position_setpoint(const mission_item_s &item, posi
sp->gliding_enabled = (_navigator->get_cruising_throttle() < FLT_EPSILON);
switch (item.nav_cmd) {
case NAV_CMD_IDLE:
sp->type = position_setpoint_s::SETPOINT_TYPE_IDLE;
break;
case NAV_CMD_TAKEOFF:
case NAV_CMD_VTOL_TAKEOFF:
@@ -816,22 +811,6 @@ MissionBlock::set_land_item(struct mission_item_s *item)
item->origin = ORIGIN_ONBOARD;
}
void
MissionBlock::set_idle_item(struct mission_item_s *item)
{
item->nav_cmd = NAV_CMD_IDLE;
item->lat = _navigator->get_home_position()->lat;
item->lon = _navigator->get_home_position()->lon;
item->altitude_is_relative = false;
item->altitude = _navigator->get_home_position()->alt;
item->yaw = NAN;
item->loiter_radius = _navigator->get_default_loiter_rad();
item->acceptance_radius = _navigator->get_acceptance_radius();
item->time_inside = 0.0f;
item->autocontinue = true;
item->origin = ORIGIN_ONBOARD;
}
void
MissionBlock::set_vtol_transition_item(struct mission_item_s *item, const uint8_t new_mode)
{
@@ -1002,7 +981,9 @@ void MissionBlock::updateAltToAvoidTerrainCollisionAndRepublishTriplet(mission_i
if (_navigator->get_nav_min_gnd_dist_param() > FLT_EPSILON && _mission_item.nav_cmd != NAV_CMD_LAND
&& _mission_item.nav_cmd != NAV_CMD_VTOL_LAND && _mission_item.nav_cmd != NAV_CMD_DO_VTOL_TRANSITION
&& _mission_item.nav_cmd != NAV_CMD_IDLE
// && _mission_item.nav_cmd != NAV_CMD_IDLE
// this one was very specifically put here: https://github.com/PX4/PX4-Autopilot/pull/23674
// do we need some other way to encode "mission finisihed"?
&& _navigator->get_local_position()->dist_bottom_valid
&& _navigator->get_local_position()->dist_bottom < _navigator->get_nav_min_gnd_dist_param()
&& _navigator->get_local_position()->vz > FLT_EPSILON
-5
View File
@@ -178,11 +178,6 @@ protected:
*/
void set_land_item(struct mission_item_s *item);
/**
* Set idle mission item
*/
void set_idle_item(struct mission_item_s *item);
/**
* Set vtol transition item
*/
-1
View File
@@ -48,7 +48,6 @@
/* compatible to mavlink MAV_CMD */
enum NAV_CMD {
NAV_CMD_IDLE = 0,
NAV_CMD_WAYPOINT = 16,
NAV_CMD_LOITER_UNLIMITED = 17,
NAV_CMD_LOITER_TIME_LIMIT = 19,
+1 -1
View File
@@ -1200,7 +1200,7 @@ void Navigator::reset_position_setpoint(position_setpoint_s &sp)
sp.cruising_speed = get_cruising_speed();
sp.cruising_throttle = get_cruising_throttle();
sp.valid = false;
sp.type = position_setpoint_s::SETPOINT_TYPE_IDLE;
sp.type = position_setpoint_s::SETPOINT_TYPE_POSITION;
sp.loiter_direction_counter_clockwise = false;
}
-1
View File
@@ -379,7 +379,6 @@ void RtlDirect::set_rtl_item()
}
case RTLState::IDLE: {
set_idle_item(&_mission_item);
_navigator->mode_completed(getNavigatorStateId());
break;
}
+1 -5
View File
@@ -157,11 +157,7 @@ Takeoff::on_active()
position_setpoint_triplet_s *pos_sp_triplet = _navigator->get_position_setpoint_triplet();
// set loiter item so position controllers stop doing takeoff logic
if (_navigator->get_land_detected()->landed) {
_mission_item.nav_cmd = NAV_CMD_IDLE;
} else {
if (!_navigator->get_land_detected()->landed) {
if (pos_sp_triplet->current.valid
&& _navigator->get_vstatus()->vehicle_type == vehicle_status_s::VEHICLE_TYPE_ROTARY_WING) {
setLoiterItemFromCurrentPositionSetpoint(&_mission_item);
@@ -139,8 +139,7 @@ float AckermannAutoMode::arrivalSpeed(const float cruising_speed, const float mi
const int curr_wp_type, const float waypoint_transition_angle, const float max_yaw_rate)
{
if (!PX4_ISFINITE(waypoint_transition_angle)
|| curr_wp_type == position_setpoint_s::SETPOINT_TYPE_LAND
|| curr_wp_type == position_setpoint_s::SETPOINT_TYPE_IDLE) {
|| curr_wp_type == position_setpoint_s::SETPOINT_TYPE_LAND) {
return 0.f; // Stop at the waypoint
} else if (_param_ro_speed_red.get() > FLT_EPSILON) {
@@ -124,7 +124,7 @@ private:
float _waypoint_transition_angle{0.f}; // Angle between the prevWP-currWP and currWP-nextWP line segments [rad]
float _max_yaw_rate{NAN};
float _min_speed{NAN}; // Speed at which the maximum yaw rate limit is enforced given the maximum steer angle and wheel base.
int _curr_wp_type{position_setpoint_s::SETPOINT_TYPE_IDLE};
int _curr_wp_type{position_setpoint_s::SETPOINT_TYPE_POSITION};
DEFINE_PARAMETERS(
(ParamFloat<px4::params::RO_YAW_RATE_LIM>) _param_ro_yaw_rate_limit,
@@ -97,7 +97,7 @@ float DifferentialAutoMode::arrivalSpeed(const float cruising_speed, const float
{
// Upcoming stop
if (!PX4_ISFINITE(waypoint_transition_angle) || waypoint_transition_angle < M_PI_F - trans_drv_trn
|| curr_wp_type == position_setpoint_s::SETPOINT_TYPE_LAND || curr_wp_type == position_setpoint_s::SETPOINT_TYPE_IDLE) {
|| curr_wp_type == position_setpoint_s::SETPOINT_TYPE_LAND) {
return 0.f;
}
@@ -97,8 +97,7 @@ float MecanumAutoMode::arrivalSpeed(const float cruising_speed, const float wayp
const float max_speed, const float speed_red, int curr_wp_type)
{
// Upcoming stop
if (!PX4_ISFINITE(waypoint_transition_angle) || curr_wp_type == position_setpoint_s::SETPOINT_TYPE_LAND
|| curr_wp_type == position_setpoint_s::SETPOINT_TYPE_IDLE) {
if (!PX4_ISFINITE(waypoint_transition_angle) || curr_wp_type == position_setpoint_s::SETPOINT_TYPE_LAND) {
return 0.f;
}