Skip to content

Commit

Permalink
Use VehicleCommand heading for VTOL transition
Browse files Browse the repository at this point in the history
  • Loading branch information
JacopoPan authored Oct 2, 2024
1 parent 19441a1 commit 327c88e
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 2 deletions.
6 changes: 6 additions & 0 deletions src/modules/navigator/navigator_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -651,6 +651,12 @@ void Navigator::run()

_vtol_takeoff.setTransitionAltitudeAbsolute(cmd.param7);

float epsilon = 1e-6f;
if (std::fabs(cmd.param2 - 3.0f) < epsilon) { // Specified transition direction
PX4_WARN("[Navigator::run] setTransitionDirecton from cmd.param4");
_vtol_takeoff.setTransitionDirection(cmd.param4);
}

// after the transition the vehicle will establish on a loiter at this position
_vtol_takeoff.setLoiterLocation(matrix::Vector2d(cmd.param5, cmd.param6));

Expand Down
9 changes: 7 additions & 2 deletions src/modules/navigator/vtol_takeoff.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,13 @@ VtolTakeoff::on_active()
position_setpoint_triplet_s *pos_sp_triplet = _navigator->get_position_setpoint_triplet();

_mission_item.nav_cmd = NAV_CMD_WAYPOINT;
_mission_item.yaw = wrap_pi(get_bearing_to_next_waypoint(_mission_item.lat,
_mission_item.lon, _loiter_location(0), _loiter_location(1)));
if (std::isnan(_transition_direction_deg)) {
_mission_item.yaw = wrap_pi(get_bearing_to_next_waypoint(_navigator->get_home_position()->lat,
_navigator->get_home_position()->lon, _loiter_location(0), _loiter_location(1)));
} else {
PX4_WARN("[VtolTakeoff] Transition direction from Command");
_mission_item.yaw = wrap_pi(math::radians(_transition_direction_deg));
}
_mission_item.force_heading = true;
mission_item_to_position_setpoint(_mission_item, &pos_sp_triplet->current);
pos_sp_triplet->current.cruising_speed = -1.f;
Expand Down
2 changes: 2 additions & 0 deletions src/modules/navigator/vtol_takeoff.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ class VtolTakeoff : public MissionBlock, public ModuleParams
void on_active() override;

void setTransitionAltitudeAbsolute(const float alt_amsl) {_transition_alt_amsl = alt_amsl; }
void setTransitionDirection(const float tran_bear) {_transition_direction_deg = tran_bear; }

void setLoiterLocation(matrix::Vector2d loiter_location) { _loiter_location = loiter_location; }
void setLoiterHeight(const float height_m) { _loiter_height = height_m; }
Expand All @@ -72,6 +73,7 @@ class VtolTakeoff : public MissionBlock, public ModuleParams
float _transition_alt_amsl{0.f}; // absolute altitude at which vehicle will transition to forward flight
matrix::Vector2d _loiter_location;
float _loiter_height{0};
float _transition_direction_deg{NAN};

DEFINE_PARAMETERS(
(ParamFloat<px4::params::VTO_LOITER_ALT>) _param_loiter_alt
Expand Down

0 comments on commit 327c88e

Please sign in to comment.