diff --git a/src/js/tabs/pid_tuning.js b/src/js/tabs/pid_tuning.js index ae1185ee323..2381cf2fa37 100644 --- a/src/js/tabs/pid_tuning.js +++ b/src/js/tabs/pid_tuning.js @@ -1722,10 +1722,10 @@ pid_tuning.initialize = function (callback) { // y = (1-t)^2 * p0 + 2 * (1-t)*t*p1 + t^2 * p2 // y = (p2+p0-2p1)x^2 + 2(p1 - p0)x + p0 // 0 = (p2+p0-2p1)x^2 + 2(p1 - p0)x + (p0 - y) - const a = startY+endY-2*cpY - const b = 2*(cpY - startY) - const c = startY - y - return a==0? -c/b : (-b + Math.sqrt(Math.pow(b, 2) - 4 * a * c)) / (2 * a) + const a = startY+endY-2*cpY; + const b = 2*(cpY - startY); + const c = startY - y; + return a==0? -c/b : (-b + Math.sqrt(Math.pow(b, 2) - 4 * a * c)) / (2 * a); } /* --- */ @@ -1781,25 +1781,23 @@ pid_tuning.initialize = function (callback) { context.beginPath(); context.moveTo(0, canvasHeight); if (throttleLimitType === THROTTLE_LIMIT_TYPES.CLIP){ + const clippos = throttleLimitPercent <= midy ? getPosfromYBezier(throttleLimitPercent,canvasHeight,midyl, midy) : getPosfromYBezier(throttleLimitPercent,midy, midyl, 0); if (throttleLimitPercent <= midyl){ //first half - lowerctrl = getQuadraticCurvePoint(0, canvasHeight, midxl, midyl, midx, midy, clippos/2); - curveclip = getQuadraticCurvePoint(0, canvasHeight, midxl, midyl, midx, midy, clippos); - context.quadraticCurveTo(lowerctrl.x, lowerctrl.y, curveclip.x, curveclip.y); - context.moveTo(curveclip.x, curveclip.y); - context.lineTo(canvasWidth, curveclip.y); + let lowerctrl = getQuadraticCurvePoint(0, canvasHeight, midxl, midyl, midx, midy, clippos/2); + let curveclip = getQuadraticCurvePoint(0, canvasHeight, midxl, midyl, midx, midy, clippos); } else { context.quadraticCurveTo(midxl, midyl, midx, midy); context.moveTo(midx, midy); - lowerctrl = getQuadraticCurvePoint(midx, midy, midxr, midyr, canvasWidth, 0, clippos/2); - curveclip = getQuadraticCurvePoint(midx, midy, midxr, midyr, canvasWidth, 0, clippos); - context.quadraticCurveTo(lowerctrl.x, lowerctrl.y, curveclip.x, curveclip.y); - context.moveTo(curveclip.x, curveclip.y); - context.lineTo(canvasWidth, curveclip.y); + let lowerctrl = getQuadraticCurvePoint(midx, midy, midxr, midyr, canvasWidth, 0, clippos/2); + let curveclip = getQuadraticCurvePoint(midx, midy, midxr, midyr, canvasWidth, 0, clippos); } + context.quadraticCurveTo(lowerctrl.x, lowerctrl.y, curveclip.x, curveclip.y); + context.moveTo(curveclip.x, curveclip.y); + context.lineTo(canvasWidth, curveclip.y); } context.quadraticCurveTo(midxl, midyl, midx, midy); context.moveTo(midx, midy);