Skip to content

Commit

Permalink
MC Auto: add fixed yaw mode
Browse files Browse the repository at this point in the history
  • Loading branch information
muramura authored Apr 25, 2024
1 parent 98b23e4 commit ba448fb
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 7 deletions.
20 changes: 13 additions & 7 deletions src/modules/flight_mode_manager/tasks/Auto/FlightTaskAuto.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,8 @@ bool FlightTaskAuto::update()
waypoints[2] = _position_setpoint;
}

const bool should_wait_for_yaw_align = _param_mpc_yaw_mode.get() == 4 && !_yaw_sp_aligned;
const bool should_wait_for_yaw_align = _param_mpc_yaw_mode.get() == int32_t(yaw_mode::towards_waypoint_yaw_first)
&& !_yaw_sp_aligned;
const bool force_zero_velocity_setpoint = should_wait_for_yaw_align || _is_emergency_braking_active;
_updateTrajConstraints();
PositionSmoothing::PositionSmoothingSetpoints smoothed_setpoints;
Expand Down Expand Up @@ -532,32 +533,37 @@ void FlightTaskAuto::_set_heading_from_mode()

Vector2f v; // Vector that points towards desired location

switch (_param_mpc_yaw_mode.get()) {
switch (yaw_mode(_param_mpc_yaw_mode.get())) {

case 0: // Heading points towards the current waypoint.
case 4: // Same as 0 but yaw first and then go
case yaw_mode::towards_waypoint: // Heading points towards the current waypoint.
case yaw_mode::towards_waypoint_yaw_first: // Same as 0 but yaw first and then go
v = Vector2f(_target) - Vector2f(_position);
break;

case 1: // Heading points towards home.
case yaw_mode::towards_home: // Heading points towards home.
if (_sub_home_position.get().valid_lpos) {
v = Vector2f(&_sub_home_position.get().x) - Vector2f(_position);
}

break;

case 2: // Heading point away from home.
case yaw_mode::away_from_home: // Heading point away from home.
if (_sub_home_position.get().valid_lpos) {
v = Vector2f(_position) - Vector2f(&_sub_home_position.get().x);
}

break;

case 3: // Along trajectory.
case yaw_mode::along_trajectory: // Along trajectory.
// The heading depends on the kind of setpoint generation. This needs to be implemented
// in the subclasses where the velocity setpoints are generated.
v.setAll(NAN);
break;

case yaw_mode::yaw_fixed: // Yaw fixed.
// Yaw is operated via manual control or MAVLINK messages.
break;

}

if (v.isAllFinite()) {
Expand Down
9 changes: 9 additions & 0 deletions src/modules/flight_mode_manager/tasks/Auto/FlightTaskAuto.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,15 @@ enum class State {
none /**< Vehicle is in normal tracking mode from triplet previous to triplet target */
};

enum class yaw_mode : int32_t {
towards_waypoint = 0,
towards_home = 1,
away_from_home = 2,
along_trajectory = 3,
towards_waypoint_yaw_first = 4,
yaw_fixed = 5,
};

class FlightTaskAuto : public FlightTask
{
public:
Expand Down
1 change: 1 addition & 0 deletions src/modules/mc_pos_control/multicopter_autonomous_params.c
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@ PARAM_DEFINE_FLOAT(MPC_YAWRAUTO_ACC, 60.f);
* @value 2 away from home
* @value 3 along trajectory
* @value 4 towards waypoint (yaw first)
* @value 5 yaw fixed
* @group Mission
*/
PARAM_DEFINE_INT32(MPC_YAW_MODE, 0);

0 comments on commit ba448fb

Please sign in to comment.