From 5919fd2e10cec07fd93e8fa4400bccf92f154aaa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torbj=C3=B8rn=20Ludvigsen?= Date: Sun, 12 Oct 2025 14:42:59 +0200 Subject: [PATCH] Winch flex compensation: Prints optimal pretension at the origin --- klippy/chelper/kin_winch.c | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/klippy/chelper/kin_winch.c b/klippy/chelper/kin_winch.c index 83a77eb49..b35baebd0 100644 --- a/klippy/chelper/kin_winch.c +++ b/klippy/chelper/kin_winch.c @@ -11,6 +11,7 @@ #include // malloc #include // memset #include "compiler.h" // __visible +#include "pyhelper.h" // errorf #include "itersolve.h" // struct stepper_kinematics #include "trapq.h" // move_get_coord @@ -425,14 +426,28 @@ recalc_origin(struct winch_flex *wf) else return; + double pretension[WINCH_MAX_ANCHORS] = {0.}; for (int i = 0; i < num; ++i) { double spring_length = wf->distances_origin[i] + wf->guy_wires[i]; if (spring_length < EPSILON) spring_length = EPSILON; double spring_k = wf->spring_constant / spring_length; - double relaxed = wf->distances_origin[i] - forces[i] / spring_k; + double tension = forces[i] / spring_k; + pretension[i] = tension; + double relaxed = wf->distances_origin[i] - tension; wf->relaxed_origin[i] = relaxed; } + if (wf->flex_enabled && num > 0) { + char msg[256]; + int len = snprintf(msg, sizeof(msg), "winch pretension at origin:"); + for (int i = 0; i < num && len > 0 && len < (int)sizeof(msg); ++i) { + len += snprintf(msg + len, sizeof(msg) - len, + " %d:%.6f", i, pretension[i]); + if (len >= (int)sizeof(msg)) + break; + } + errorf("%s", msg); + } } void __visible