From 0f028e8d52b38386e74ec3468d196f26f750275a Mon Sep 17 00:00:00 2001 From: Nikolai Sukhanov Date: Wed, 13 Mar 2024 00:01:24 +0400 Subject: [PATCH] feat: reduce servo calibration result to mitigate motor straining at the ends of the range --- modules/shared/misc/src/lib/i-app-config.ts | 5 ++++- .../lib/hub-facades/hub-servo-calibration-facade.service.ts | 5 +++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/modules/shared/misc/src/lib/i-app-config.ts b/modules/shared/misc/src/lib/i-app-config.ts index 03bd460c..180dc495 100644 --- a/modules/shared/misc/src/lib/i-app-config.ts +++ b/modules/shared/misc/src/lib/i-app-config.ts @@ -18,6 +18,8 @@ export interface IAppConfig { readonly autoCalibrationRuns: number; readonly aposCenterMin: number; readonly aposCenterMax: number; + // 0.05 means 5% reduction. Used to reduce straining on the servo motor at the ends of the range. + readonly calibrationRangeResultReductionFactor: number; }; } @@ -38,7 +40,8 @@ export const APP_CONFIG = new InjectionToken('APP_CONFIG', { manualCalibrationRuns: 2, autoCalibrationRuns: 1, aposCenterMin: -MOTOR_LIMITS.maxServoDegreesRange / 2, - aposCenterMax: MOTOR_LIMITS.maxServoDegreesRange / 2 + aposCenterMax: MOTOR_LIMITS.maxServoDegreesRange / 2, + calibrationRangeResultReductionFactor: 0.05 } }), providedIn: 'root' diff --git a/modules/store/src/lib/hub-facades/hub-servo-calibration-facade.service.ts b/modules/store/src/lib/hub-facades/hub-servo-calibration-facade.service.ts index 89269f68..af59a149 100644 --- a/modules/store/src/lib/hub-facades/hub-servo-calibration-facade.service.ts +++ b/modules/store/src/lib/hub-facades/hub-servo-calibration-facade.service.ts @@ -276,11 +276,12 @@ export class HubServoCalibrationFacadeService { const cwDistanceFromStartPosition = cwProbeResult - startRelativePosition; const arcCenterPosition = Math.round((ccwProbeResult + cwProbeResult) / 2); - const servoRange = Math.round(Math.abs(ccwDistanceFromStartPosition + cwDistanceFromStartPosition)); + const rawServoRange = Math.round(Math.abs(ccwDistanceFromStartPosition + cwDistanceFromStartPosition)); + const servoRange = rawServoRange * Math.max(0, 1 - this.appConfig.servo.calibrationRangeResultReductionFactor); const arcCenterAbsolutePosition = Math.round(transformRelativeDegToAbsoluteDeg(arcCenterPosition + encoderOffset)); return { - servoRange: servoRange, + servoRange, arcCenterPosition, arcCenterAbsolutePosition };