From 7c2b1251d445db6ba6ea00205589b2bf83936c1a Mon Sep 17 00:00:00 2001 From: Roger Littin Date: Sat, 2 Mar 2024 15:08:29 +0000 Subject: [PATCH] Fix issue where the roll is using the wrong path (#129) Fix issue where calculated leeway is invalid if STW is 0 --- calcs/leeway.js | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/calcs/leeway.js b/calcs/leeway.js index 76bf520..3f0c278 100644 --- a/calcs/leeway.js +++ b/calcs/leeway.js @@ -4,7 +4,7 @@ module.exports = function (app, plugin) { group: 'heading', optionKey: 'leeway', title: 'Leeway', - derivedFrom: ['navigation.attitude.roll', 'navigation.speedThroughWater'], + derivedFrom: ['navigation.attitude', 'navigation.speedThroughWater'], properties: { kFactor: { type: 'number', @@ -13,12 +13,11 @@ module.exports = function (app, plugin) { default: 12 } }, - calculator: function (roll, stw) { + calculator: function (attitude, stw) { var kFactor = plugin.properties.heading.kFactor - var rollDegrees = roll / Math.PI * 360 + var rollDegrees = attitude.roll / Math.PI * 360 var stwKnots = stw * 1.94384 - var leewayAngle = - kFactor * rollDegrees / Math.pow(stwKnots, 2) / 360 * Math.PI + var leewayAngle = stwKnots <= 0 ? 0 : kFactor * rollDegrees / Math.pow(stwKnots, 2) / 360 * Math.PI // app.debug('roll: ' + rollDegrees + ' stw: ' + stwKnots + ' knots => leeway: ' + leewayAngle/Math.PI*360) return [{ path: 'performance.leeway', value: leewayAngle }] }