From 7ffb0bc5008ebf75ec2b9fe932f2a5ee43e8acb0 Mon Sep 17 00:00:00 2001 From: Marcelo Bezerra <23555060+mmosca@users.noreply.github.com> Date: Sat, 22 Jun 2024 14:03:06 +0200 Subject: [PATCH] Fix center when no valid headtracker data is available --- src/main/io/gimbal_serial.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/main/io/gimbal_serial.c b/src/main/io/gimbal_serial.c index 311d790a9..4eec29039 100644 --- a/src/main/io/gimbal_serial.c +++ b/src/main/io/gimbal_serial.c @@ -60,6 +60,7 @@ static volatile uint8_t txBuffer[GIMBAL_SERIAL_BUFFER_SIZE]; #if defined(USE_HEADTRACKER) && defined(USE_HEADTRACKER_SERIAL) static gimbalSerialHtrkState_t headTrackerState = { .payloadSize = 0, + .attitude = {}, .state = WAITING_HDR1, }; #endif @@ -189,7 +190,10 @@ void gimbalSerialProcess(gimbalDevice_t *gimbalDevice, timeUs_t currentTime) gimbalHtkAttitudePkt_t attitude = { .sync = {HTKATTITUDE_SYNC0, HTKATTITUDE_SYNC1}, - .mode = GIMBAL_MODE_DEFAULT + .mode = GIMBAL_MODE_DEFAULT, + .pan = 0, + .tilt = 0, + .roll = 0 }; const gimbalConfig_t *cfg = gimbalConfig(); @@ -238,9 +242,9 @@ void gimbalSerialProcess(gimbalDevice_t *gimbalDevice, timeUs_t currentTime) DEBUG_SET(DEBUG_HEADTRACKING, 4, 1); } else { - attitude.pan = constrain(gimbal_scale12(PWM_RANGE_MIN, PWM_RANGE_MAX, PWM_RANGE_MIDDLE + cfg->panTrim), PWM_RANGE_MIN, PWM_RANGE_MAX); - attitude.tilt = constrain(gimbal_scale12(PWM_RANGE_MIN, PWM_RANGE_MAX, PWM_RANGE_MIDDLE + cfg->tiltTrim), PWM_RANGE_MIN, PWM_RANGE_MAX); - attitude.roll = constrain(gimbal_scale12(PWM_RANGE_MIN, PWM_RANGE_MAX, PWM_RANGE_MIDDLE + cfg->rollTrim), PWM_RANGE_MIN, PWM_RANGE_MAX); + attitude.pan = constrain(gimbal_scale12(PWM_RANGE_MIN, PWM_RANGE_MAX, PWM_RANGE_MIDDLE + cfg->panTrim), HEADTRACKER_RANGE_MIN, HEADTRACKER_RANGE_MAX); + attitude.tilt = constrain(gimbal_scale12(PWM_RANGE_MIN, PWM_RANGE_MAX, PWM_RANGE_MIDDLE + cfg->tiltTrim), HEADTRACKER_RANGE_MIN, HEADTRACKER_RANGE_MAX); + attitude.roll = constrain(gimbal_scale12(PWM_RANGE_MIN, PWM_RANGE_MAX, PWM_RANGE_MIDDLE + cfg->rollTrim), HEADTRACKER_RANGE_MIN, HEADTRACKER_RANGE_MAX); DEBUG_SET(DEBUG_HEADTRACKING, 4, -1); } } else { -- 2.11.4.GIT