From c7bbdb6b715eb10643043a9f1757d2c05e1f4938 Mon Sep 17 00:00:00 2001 From: David Woodhouse Date: Mon, 31 Mar 2025 09:43:38 +0100 Subject: [PATCH] Make encoder direction a parameter .... and then realise that of course the *board* is the same way round for all of mine (prototype and in-the-wall); it's just that the motor is different. So I didn't need it after all. --- blind.yaml | 10 +++++++--- landing-blind-1.yaml | 17 +++++++++++++++++ landing-blind-3.yaml | 3 ++- 3 files changed, 26 insertions(+), 4 deletions(-) create mode 100644 landing-blind-1.yaml diff --git a/blind.yaml b/blind.yaml index b8285b4..de84fcc 100644 --- a/blind.yaml +++ b/blind.yaml @@ -241,6 +241,9 @@ button: name: Home id: home on_press: + - logger.log: + level: INFO + format: "Blind rehome" - lambda: | id(motor).set_max_speed(${max_speed}/2); id(motor).set_target(id(motor)->current_position - 2.5 * ${encoder_closed_pos} * ${motor_direction}); @@ -391,8 +394,9 @@ sensor: } if (delta < 2 && delta > -2) return {}; + delta *= ${encoder_direction}; id(encoder_tracking_)[0] = curr; - id(encoder_tracking_)[1] -= delta; + id(encoder_tracking_)[1] += delta; if (id(encoder_tracking_)[1] < id(sensored_home_pos)) { ESP_LOGI("home", "Adjusted to %d", id(encoder_tracking_)[1]); id(sensored_home_pos) = id(encoder_tracking_)[1]; @@ -400,10 +404,10 @@ sensor: ESP_LOGD("angle", "Old %d new %d delta %d now %d home %d", id(encoder_tracking_)[0], curr, delta, id(encoder_tracking_)[1] + delta, id(sensored_home_pos)); - if (delta < -100 && id(pd_blinds)->current_operation != COVER_OPERATION_CLOSING) { + if (delta > 100 && id(pd_blinds)->current_operation != COVER_OPERATION_CLOSING) { id(pd_blinds)->current_operation= COVER_OPERATION_CLOSING; ESP_LOGI("cover", "closing"); - } else if (delta > 100 && id(pd_blinds)->current_operation != COVER_OPERATION_OPENING) { + } else if (delta < -100 && id(pd_blinds)->current_operation != COVER_OPERATION_OPENING) { id(pd_blinds)->current_operation = COVER_OPERATION_OPENING; ESP_LOGI("cover", "opening"); } diff --git a/landing-blind-1.yaml b/landing-blind-1.yaml new file mode 100644 index 0000000..65bba3b --- /dev/null +++ b/landing-blind-1.yaml @@ -0,0 +1,17 @@ +substitutions: + name: "landing-blind-1" + encoder_closed_pos: "22500" # full blinds length (in encoder counts) !! CHANGE TO SUIT YOUR SETUP !! + encoder_direction: "-1" # Which way is towards 'closed'? + motor_direction: "-1" # w.r.t. encoder + microsteps: "2" + run_current: "100m" + max_speed: "800" + stallguard_threshold: "60" + pd_voltage: "15" + +packages: + blind: !include blind.yaml + + +logger: + level: DEBUG diff --git a/landing-blind-3.yaml b/landing-blind-3.yaml index 4755082..6a24539 100644 --- a/landing-blind-3.yaml +++ b/landing-blind-3.yaml @@ -2,7 +2,8 @@ substitutions: name: "landing-blind-3" encoder_closed_pos: "230000" # full blinds length (in encoder counts) !! CHANGE TO SUIT YOUR SETUP !! - motor_direction: "1" + encoder_direction: "-1" # Which way is towards 'closed'? + motor_direction: "1" # w.r.t. encoder microsteps: "2" run_current: "100m" max_speed: "800" -- 2.49.0