From 971a888fe1422869f00c87e3f77a3c850e9a784c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torbj=C3=B8rn=20Ludvigsen?= Date: Mon, 1 Dec 2025 15:46:31 +0100 Subject: [PATCH] Introduces buildup_factor and uses distances that are relative to the origin. The buildup compensation is not applied yet, it's just prepared for. --- klippy/chelper/__init__.py | 2 +- klippy/chelper/kin_winch.c | 5 ++++- klippy/kinematics/winch.py | 4 +++- 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/klippy/chelper/__init__.py b/klippy/chelper/__init__.py index b99149433..c0d911a99 100644 --- a/klippy/chelper/__init__.py +++ b/klippy/chelper/__init__.py @@ -154,7 +154,7 @@ defs_kin_winch = """ struct winch_flex *winch_flex_alloc(void); void winch_flex_free(struct winch_flex *wf); void winch_flex_configure(struct winch_flex *wf, int num_anchors, - const double *anchors, double mover_weight, double spring_constant, + const double *anchors, double buildup_factor, double mover_weight, double spring_constant, const double *min_force, const double *max_force, const double *guy_wires, int flex_compensation_algorithm, int ignore_gravity, int ignore_pretension, diff --git a/klippy/chelper/kin_winch.c b/klippy/chelper/kin_winch.c index 43acc132c..057b1b17d 100644 --- a/klippy/chelper/kin_winch.c +++ b/klippy/chelper/kin_winch.c @@ -32,6 +32,7 @@ struct winch_flex { int num_anchors; int enabled; int flex_compensation_algorithm; + double buildup_factor; double mover_weight; double spring_constant; double min_force[WINCH_MAX_ANCHORS]; @@ -615,7 +616,7 @@ calc_position_common(struct winch_stepper *ws, struct move *m, double move_time) double distances[WINCH_MAX_ANCHORS]; double flex[WINCH_MAX_ANCHORS]; compute_flex(wf, pos.x, pos.y, pos.z, distances, flex); - return dist + flex[ws->index]; + return dist - wf->distances_origin[ws->index] + flex[ws->index]; } static double @@ -661,6 +662,7 @@ void __visible winch_flex_configure(struct winch_flex *wf, int num_anchors, const double *anchors, + double buildup_factor, double mover_weight, double spring_constant, const double *min_force, @@ -678,6 +680,7 @@ winch_flex_configure(struct winch_flex *wf, if (num_anchors > WINCH_MAX_ANCHORS) num_anchors = WINCH_MAX_ANCHORS; wf->num_anchors = num_anchors; + wf->buildup_factor = buildup_factor; wf->mover_weight = mover_weight; wf->spring_constant = spring_constant; wf->flex_compensation_algorithm = flex_compensation_algorithm; diff --git a/klippy/kinematics/winch.py b/klippy/kinematics/winch.py index 2f0934092..45c6be831 100644 --- a/klippy/kinematics/winch.py +++ b/klippy/kinematics/winch.py @@ -31,6 +31,7 @@ class WinchFlexHelper: self.set_active(self.enabled) def _read_config(self, config): + self.buildup_factor = config.getfloat('winch_buildup_factor', 0., minval=0.) self.mover_weight = config.getfloat('winch_mover_weight', 0., minval=0.) self.spring_constant = config.getfloat('winch_spring_constant', 0., minval=0.) if self.num: @@ -50,6 +51,7 @@ class WinchFlexHelper: self.min_force = [] self.max_force = [] self.guy_wires = [] + self.mechanical_advantage = [] algo_choices = list(self.ALGORITHMS.keys()) self.flex_compensation_algorithm_name = config.getchoice( 'flex_compensation_algorithm', algo_choices, default='qp') @@ -64,7 +66,7 @@ class WinchFlexHelper: max_c = self.ffi_main.new("double[]", self.max_force) guy_ptr = self.ffi_main.new("double[]", self.guy_wires) self.ffi_lib.winch_flex_configure( - self.ptr, self.num, anchors_c, self.mover_weight, + self.ptr, self.num, anchors_c, self.buildup_factor, self.mover_weight, self.spring_constant, min_c, max_c, guy_ptr, self.flex_compensation_algorithm, self.ignore_gravity, self.ignore_pretension, self.mechanical_advantage)