-
Notifications
You must be signed in to change notification settings - Fork 17.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
AC_AttitudeControl: introduce ANG log message for high resolution att…
…itude logging Move RATE message to AC_AttitudeControl_Logging.cpp
- Loading branch information
Showing
4 changed files
with
112 additions
and
52 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
82 changes: 82 additions & 0 deletions
82
libraries/AC_AttitudeControl/AC_AttitudeControl_Logging.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
#include <AP_Logger/AP_Logger_config.h> | ||
|
||
#if HAL_LOGGING_ENABLED | ||
|
||
#include "AC_AttitudeControl.h" | ||
#include "AC_PosControl.h" | ||
#include <AP_Logger/AP_Logger.h> | ||
#include <AP_Scheduler/AP_Scheduler.h> | ||
#include "LogStructure.h" | ||
|
||
// Write an ANG packet | ||
void AC_AttitudeControl::Write_Attitude() const | ||
{ | ||
Vector3f targets = get_att_target_euler_rad() * RAD_TO_DEG; | ||
// Retrieve quaternion body attitude | ||
Quaternion attitude_body; | ||
_ahrs.get_quat_body_to_ned(attitude_body); | ||
// calculate the attitude body euler angles | ||
Vector3f attitude_body_angles; | ||
attitude_body.to_euler(attitude_body_angles); | ||
attitude_body_angles *= RAD_TO_DEG; | ||
|
||
const struct log_ANG pkt{ | ||
LOG_PACKET_HEADER_INIT(LOG_ANG_MSG), | ||
time_us : AP::scheduler().get_loop_start_time_us(), | ||
control_roll : targets.x, | ||
roll : attitude_body_angles.x, | ||
control_pitch : targets.y, | ||
pitch : attitude_body_angles.y, | ||
control_yaw : wrap_360(targets.z), | ||
yaw : wrap_360(attitude_body_angles.z), | ||
sensor_dt : AP::scheduler().get_last_loop_time_s() | ||
}; | ||
AP::logger().WriteBlock(&pkt, sizeof(pkt)); | ||
} | ||
|
||
// Write a rate packet | ||
void AC_AttitudeControl::Write_Rate(const AC_PosControl &pos_control) const | ||
{ | ||
const Vector3f &rate_targets = rate_bf_targets(); | ||
const Vector3f &accel_target = pos_control.get_accel_target_cmss(); | ||
const Vector3f &gyro_rate = _rate_gyro; | ||
const struct log_Rate pkt_rate{ | ||
LOG_PACKET_HEADER_INIT(LOG_RATE_MSG), | ||
time_us : _rate_gyro_time_us, | ||
control_roll : degrees(rate_targets.x), | ||
roll : degrees(gyro_rate.x), | ||
roll_out : _motors.get_roll()+_motors.get_roll_ff(), | ||
control_pitch : degrees(rate_targets.y), | ||
pitch : degrees(gyro_rate.y), | ||
pitch_out : _motors.get_pitch()+_motors.get_pitch_ff(), | ||
control_yaw : degrees(rate_targets.z), | ||
yaw : degrees(gyro_rate.z), | ||
yaw_out : _motors.get_yaw()+_motors.get_yaw_ff(), | ||
control_accel : (float)accel_target.z, | ||
accel : (float)(-(_ahrs.get_accel_ef().z + GRAVITY_MSS) * 100.0f), | ||
accel_out : _motors.get_throttle(), | ||
throttle_slew : _motors.get_throttle_slew_rate() | ||
}; | ||
AP::logger().WriteBlock(&pkt_rate, sizeof(pkt_rate)); | ||
|
||
/* | ||
log P/PD gain scale if not == 1.0 | ||
*/ | ||
const Vector3f &scale = get_last_angle_P_scale(); | ||
const Vector3f &pd_scale = _pd_scale_used; | ||
if (scale != AC_AttitudeControl::VECTORF_111 || pd_scale != AC_AttitudeControl::VECTORF_111) { | ||
const struct log_ATSC pkt_ATSC { | ||
LOG_PACKET_HEADER_INIT(LOG_ATSC_MSG), | ||
time_us : _rate_gyro_time_us, | ||
scaleP_x : scale.x, | ||
scaleP_y : scale.y, | ||
scaleP_z : scale.z, | ||
scalePD_x : pd_scale.x, | ||
scalePD_y : pd_scale.y, | ||
scalePD_z : pd_scale.z, | ||
}; | ||
AP::logger().WriteBlock(&pkt_ATSC, sizeof(pkt_ATSC)); | ||
} | ||
} | ||
|
||
#endif // HAL_LOGGING_ENABLED |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters