mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-11-26 04:16:36 +08:00
adapted to new vehicle attitude message
This commit is contained in:
@@ -250,7 +250,9 @@ MulticopterPositionControlMultiplatform::reset_alt_sp()
|
||||
|
||||
//XXX hack until #1741 is in/ported
|
||||
/* reset yaw sp */
|
||||
_att_sp_msg.data().yaw_body = _att->data().yaw;
|
||||
matrix::Quaternion<float> q(&_att->data().q[0]);
|
||||
matrix::Euler<float> euler(q);
|
||||
_att_sp_msg.data().yaw_body = euler(2);
|
||||
|
||||
//XXX: port this once a mavlink like interface is available
|
||||
// mavlink_log_info(&_mavlink_log_pub, "[mpc] reset alt sp: %d", -(int)_pos_sp(2));
|
||||
@@ -582,6 +584,10 @@ void MulticopterPositionControlMultiplatform::handle_vehicle_attitude(const px4
|
||||
static bool was_armed = false;
|
||||
static uint64_t t_prev = 0;
|
||||
|
||||
matrix::Quaternion<float> q(&_att->data().q[0]);
|
||||
matrix::Euler<float> euler(q);
|
||||
matrix::Dcm<float> R(q);
|
||||
|
||||
uint64_t t = get_time_micros();
|
||||
float dt = t_prev != 0 ? (t - t_prev) * 0.000001f : 0.005f;
|
||||
t_prev = t;
|
||||
@@ -641,7 +647,7 @@ void MulticopterPositionControlMultiplatform::handle_vehicle_attitude(const px4
|
||||
|
||||
_att_sp_msg.data().roll_body = 0.0f;
|
||||
_att_sp_msg.data().pitch_body = 0.0f;
|
||||
_att_sp_msg.data().yaw_body = _att->data().yaw;
|
||||
_att_sp_msg.data().yaw_body = euler(2);
|
||||
_att_sp_msg.data().thrust = 0.0f;
|
||||
|
||||
_att_sp_msg.data().timestamp = get_time_micros();
|
||||
@@ -815,11 +821,11 @@ void MulticopterPositionControlMultiplatform::handle_vehicle_attitude(const px4
|
||||
/* thrust compensation for altitude only control mode */
|
||||
float att_comp;
|
||||
|
||||
if (PX4_R(_att->data().R, 2, 2) > TILT_COS_MAX) {
|
||||
att_comp = 1.0f / PX4_R(_att->data().R, 2, 2);
|
||||
if (R(2, 2) > TILT_COS_MAX) {
|
||||
att_comp = 1.0f / R(2, 2);
|
||||
|
||||
} else if (PX4_R(_att->data().R, 2, 2) > 0.0f) {
|
||||
att_comp = ((1.0f / TILT_COS_MAX - 1.0f) / TILT_COS_MAX) * PX4_R(_att->data().R, 2, 2) + 1.0f;
|
||||
} else if (R(2, 2) > 0.0f) {
|
||||
att_comp = ((1.0f / TILT_COS_MAX - 1.0f) / TILT_COS_MAX) * R(2, 2) + 1.0f;
|
||||
saturation_z = true;
|
||||
|
||||
} else {
|
||||
@@ -1005,7 +1011,7 @@ void MulticopterPositionControlMultiplatform::handle_vehicle_attitude(const px4
|
||||
/* reset yaw setpoint to current position if needed */
|
||||
if (reset_yaw_sp) {
|
||||
reset_yaw_sp = false;
|
||||
_att_sp_msg.data().yaw_body = _att->data().yaw;
|
||||
_att_sp_msg.data().yaw_body = euler(2);
|
||||
}
|
||||
|
||||
/* do not move yaw while arming */
|
||||
@@ -1014,13 +1020,13 @@ void MulticopterPositionControlMultiplatform::handle_vehicle_attitude(const px4
|
||||
|
||||
_att_sp_msg.data().yaw_sp_move_rate = _manual_control_sp->data().r * _params.man_yaw_max;
|
||||
_att_sp_msg.data().yaw_body = _wrap_pi(_att_sp_msg.data().yaw_body + _att_sp_msg.data().yaw_sp_move_rate * dt);
|
||||
float yaw_offs = _wrap_pi(_att_sp_msg.data().yaw_body - _att->data().yaw);
|
||||
float yaw_offs = _wrap_pi(_att_sp_msg.data().yaw_body - euler(2));
|
||||
|
||||
if (yaw_offs < - YAW_OFFSET_MAX) {
|
||||
_att_sp_msg.data().yaw_body = _wrap_pi(_att->data().yaw - YAW_OFFSET_MAX);
|
||||
_att_sp_msg.data().yaw_body = _wrap_pi(euler(2) - YAW_OFFSET_MAX);
|
||||
|
||||
} else if (yaw_offs > YAW_OFFSET_MAX) {
|
||||
_att_sp_msg.data().yaw_body = _wrap_pi(_att->data().yaw + YAW_OFFSET_MAX);
|
||||
_att_sp_msg.data().yaw_body = _wrap_pi(euler(2) + YAW_OFFSET_MAX);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user