Skip to content

Commit

Permalink
feat: reduce servo calibration result to mitigate motor straining at …
Browse files Browse the repository at this point in the history
…the ends of the range
  • Loading branch information
nvsukhanov committed Mar 12, 2024
1 parent a7b289b commit 66fed42
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
5 changes: 4 additions & 1 deletion modules/shared/misc/src/lib/i-app-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
}

Expand All @@ -38,7 +40,8 @@ export const APP_CONFIG = new InjectionToken<IAppConfig>('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'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
};
Expand Down

0 comments on commit 66fed42

Please sign in to comment.