Skip to content

Commit

Permalink
MC pos control: Fix attitude and thrust SP generation
Browse files Browse the repository at this point in the history
  • Loading branch information
LorenzMeier committed Dec 18, 2015
1 parent d2e4566 commit 35df66c
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions src/modules/mc_pos_control/mc_pos_control_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1652,8 +1652,6 @@ MulticopterPositionControl::task_main()
_vel_sp_prev = _vel;
}

math::Matrix<3, 3> R_sp;

/* generate attitude setpoint from manual controls */
if (_control_mode.flag_control_manual_enabled && _control_mode.flag_control_attitude_enabled) {

Expand Down Expand Up @@ -1694,10 +1692,20 @@ MulticopterPositionControl::task_main()
}
}

math::Matrix<3, 3> R_sp;

/* construct attitude setpoint rotation matrix */
R_sp.from_euler(_att_sp.roll_body, _att_sp.pitch_body, _att_sp.yaw_body);
memcpy(&_att_sp.R_body[0], R_sp.data, sizeof(_att_sp.R_body));

/* reset the acceleration set point for all non-attitude flight modes */
if (!(_control_mode.flag_control_offboard_enabled &&
!(_control_mode.flag_control_position_enabled ||
_control_mode.flag_control_velocity_enabled))) {

_thrust_sp_prev = R_sp * math::Vector<3>(0, 0, -_att_sp.thrust);
}

/* copy quaternion setpoint to attitude setpoint topic */
math::Quaternion q_sp;
q_sp.from_dcm(R_sp);
Expand All @@ -1721,8 +1729,6 @@ MulticopterPositionControl::task_main()
!(_control_mode.flag_control_position_enabled ||
_control_mode.flag_control_velocity_enabled))) {

_thrust_sp_prev = R_sp * math::Vector<3>(0, 0, -_att_sp.thrust);

if (_att_sp_pub != nullptr) {
orb_publish(_attitude_setpoint_id, _att_sp_pub, &_att_sp);

Expand Down

0 comments on commit 35df66c

Please sign in to comment.