Skip to content

Commit 96abd65

Browse files
peterbarkerclaude
authored andcommitted
AP_Mount: Viewpro converts angles to output using radians directly
Add AP_MOUNT_VIEWPRO_RAD_TO_OUTPUT and use it for the target pitch/yaw angles and for the vehicle attitude sent in the M_AHRS packet, taking the values from the AHRS in radians rather than degrees. This removes the intermediate radians-to-degrees conversions and the now-unused AP_MOUNT_VIEWPRO_DEG_TO_OUTPUT scalar. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
1 parent cee8714 commit 96abd65

1 file changed

Lines changed: 10 additions & 10 deletions

File tree

libraries/AP_Mount/AP_Mount_Viewpro.cpp

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ extern const AP_HAL::HAL& hal;
2323
#define AP_MOUNT_VIEWPRO_EO_ZOOM_SPEED 0x07 // hard-coded zoom speed (fast)
2424
#define AP_MOUNT_VIEWPRO_IR_ZOOM_SPEED 1
2525
#define AP_MOUNT_VIEWPRO_ZOOM_MAX 10 // hard-coded absolute zoom times max
26-
#define AP_MOUNT_VIEWPRO_DEG_TO_OUTPUT (65536.0 / 360.0) // scalar to convert degrees to the viewpro angle scaling
26+
#define AP_MOUNT_VIEWPRO_RAD_TO_OUTPUT (65536.0 / M_2PI) // scalar to convert radians to the viewpro angle scaling
2727
#define AP_MOUNT_VIEWPRO_OUTPUT_TO_DEG (360.0 / 65536.0) // scalar to convert viewpro angle scaling to degrees
2828

2929
#define AP_MOUNT_VIEWPRO_DEBUG 0
@@ -492,8 +492,8 @@ void AP_Mount_Viewpro::send_target_angles(const MountAngleTarget &angle_rad)
492492
}
493493

494494
// scale pitch and yaw to values gimbal understands
495-
const int16_t pitch_angle_output = -degrees(pitch_rad) * AP_MOUNT_VIEWPRO_DEG_TO_OUTPUT;
496-
const int16_t yaw_angle_output = degrees(yaw_bf_rad) * AP_MOUNT_VIEWPRO_DEG_TO_OUTPUT;
495+
const int16_t pitch_angle_output = -pitch_rad * AP_MOUNT_VIEWPRO_RAD_TO_OUTPUT;
496+
const int16_t yaw_angle_output = yaw_bf_rad * AP_MOUNT_VIEWPRO_RAD_TO_OUTPUT;
497497

498498
// fill in packet
499499
const A1Packet a1_packet {
@@ -626,28 +626,28 @@ bool AP_Mount_Viewpro::send_m_ahrs()
626626
// get vehicle velocity in m/s in NED Frame
627627
Vector3f vel_NED;
628628
IGNORE_RETURN(AP::ahrs().get_velocity_NED(vel_NED));
629-
float vel_yaw_deg = wrap_360(degrees(vel_NED.xy().angle()));
629+
const float vel_yaw_rad = wrap_2PI(vel_NED.xy().angle());
630630

631631
// get GPS vdop
632632
uint16_t gps_vdop = AP::gps().get_vdop();
633633

634-
// get vehicle yaw in the range 0 to 360
635-
const uint16_t veh_yaw_deg = AP::ahrs().get_yaw_deg();
634+
// get vehicle yaw in the range 0 to 2*pi
635+
const float veh_yaw_rad = wrap_2PI(AP::ahrs().get_yaw_rad());
636636

637637
// fill in packet
638638
const M_AHRSPacket mahrs_packet {
639639
.content = {
640640
frame_id: FrameId::M_AHRS,
641641
data_type: 0x07, // Bit0: Attitude, Bit1: GPS, Bit2 Gyro
642642
unused2to8 : {0, 0, 0, 0, 0, 0, 0},
643-
roll_be: htobe16(AP::ahrs().get_roll_deg() * AP_MOUNT_VIEWPRO_DEG_TO_OUTPUT), // vehicle roll angle. 1bit=360deg/65536
644-
pitch_be: htobe16(-AP::ahrs().get_pitch_deg() * AP_MOUNT_VIEWPRO_DEG_TO_OUTPUT), // vehicle pitch angle. 1bit=360deg/65536
645-
yaw_be: htobe16(veh_yaw_deg * AP_MOUNT_VIEWPRO_DEG_TO_OUTPUT), // vehicle yaw angle. 1bit=360deg/65536
643+
roll_be: htobe16(AP::ahrs().get_roll_rad() * AP_MOUNT_VIEWPRO_RAD_TO_OUTPUT), // vehicle roll angle. 1bit=360deg/65536
644+
pitch_be: htobe16(-AP::ahrs().get_pitch_rad() * AP_MOUNT_VIEWPRO_RAD_TO_OUTPUT), // vehicle pitch angle. 1bit=360deg/65536
645+
yaw_be: htobe16(veh_yaw_rad * AP_MOUNT_VIEWPRO_RAD_TO_OUTPUT), // vehicle yaw angle. 1bit=360deg/65536
646646
date_be: htobe16(date), // bit0~6:year, bit7~10:month, bit11~15:day
647647
seconds_utc: {uint8_t((second_hundredths & 0xFF0000ULL) >> 16), // seconds * 100 MSB. 1bit = 0.01sec
648648
uint8_t((second_hundredths & 0xFF00ULL) >> 8), // seconds * 100 next MSB. 1bit = 0.01sec
649649
uint8_t(second_hundredths & 0xFFULL)}, // seconds * 100 LSB. 1bit = 0.01sec
650-
gps_yaw_be: htobe16(vel_yaw_deg * AP_MOUNT_VIEWPRO_DEG_TO_OUTPUT), // GPS yaw
650+
gps_yaw_be: htobe16(vel_yaw_rad * AP_MOUNT_VIEWPRO_RAD_TO_OUTPUT), // GPS yaw
651651
position_mark_bitmask: 0x0F, // bit0:new position, bit1:clock fix calced, bit2:horiz calced, bit3:alt calced
652652
latitude_be: htobe32(loc.lat), // latitude. 1bit = 10e-7
653653
longitude_be: htobe32(loc.lng), // longitude. 1bit = 10e-7

0 commit comments

Comments
 (0)