Skip to content

Commit

Permalink
continuous improvement (#19897)
Browse files Browse the repository at this point in the history
- servo fix on movement during operation. position did not behave as expected if position change before stop
- enhanced minimum change on stepper shutter depending on motordelay
  • Loading branch information
stefanbode authored Nov 1, 2023
1 parent ba4d031 commit 2e95f45
Showing 1 changed file with 11 additions and 15 deletions.
26 changes: 11 additions & 15 deletions tasmota/tasmota_xdrv_driver/xdrv_27_esp32_shutter.ino
Original file line number Diff line number Diff line change
Expand Up @@ -674,17 +674,21 @@ void ShutterInit(void)
Shutter[i].tilt_target_pos = Shutter[i].tilt_real_pos = ShutterSettings.shutter_tilt_pos[i];
Shutter[i].tilt_velocity = Shutter[i].tilt_config[2] > 0 ? ((Shutter[i].tilt_config[1] - Shutter[i].tilt_config[0]) / Shutter[i].tilt_config[2]) + 1 : 1;
Shutter[i].close_velocity_max = ShutterGlobal.open_velocity_max*Shutter[i].open_time / Shutter[i].close_time;
Shutter[i].min_TiltChange = 2 * Shutter[i].tilt_velocity;

//servo can make any movement without time restriction
Shutter[i].min_realPositionChange = 0;
if (ShutterGlobal.position_mode != SHT_PWM_VALUE) {
Shutter[i].min_realPositionChange = 2 * tmax(ShutterGlobal.open_velocity_max, Shutter[i].close_velocity_max);
Shutter[i].min_realPositionChange = 2 * tmax(ShutterGlobal.open_velocity_max, Shutter[i].close_velocity_max);
switch (ShutterGlobal.position_mode) {
case SHT_PWM_VALUE:
Shutter[i].min_realPositionChange = 0;
break;
case SHT_COUNTER:
Shutter[i].min_realPositionChange = SHT_DIV_ROUND(Shutter[i].min_realPositionChange, Shutter[i].motordelay);
break;
}

Shutter[i].min_TiltChange = 2 * Shutter[i].tilt_velocity;

AddLog(LOG_LEVEL_DEBUG, PSTR("SHT: Shtr%d min realpos_chg: %d, min tilt_chg %d"), i+1, Shutter[i].min_realPositionChange, Shutter[i].min_TiltChange);
AddLog(LOG_LEVEL_DEBUG_MORE, PSTR("SHT: Shtr%d Openvel %d, Closevel: %d"), i+1, ShutterGlobal.open_velocity_max, Shutter[i].close_velocity_max);
AddLog(LOG_LEVEL_DEBUG, PSTR("SHT: Shtr%d Openvel %d, Closevel: %d"), i+1, ShutterGlobal.open_velocity_max, Shutter[i].close_velocity_max);
AddLog(LOG_LEVEL_DEBUG, PSTR("SHT: Shtr%d Init. Pos %d, Inv %d, Locked %d, Endstop enab %d, webButt inv %d, Motordel: %d"),
i+1, Shutter[i].real_position,
(ShutterSettings.shutter_options[i] & 1) ? 1 : 0, (ShutterSettings.shutter_options[i] & 2) ? 1 : 0, (ShutterSettings.shutter_options[i] & 4) ? 1 : 0, (ShutterSettings.shutter_options[i] & 8) ? 1 : 0, Shutter[i].motordelay);
Expand Down Expand Up @@ -810,10 +814,7 @@ void ShutterPowerOff(uint8_t i)
// Store current PWM value to ensure proper position after reboot.
switch (ShutterGlobal.position_mode) {
case SHT_PWM_VALUE:
Shutter[i].pwm_value = SHT_DIV_ROUND((ShutterSettings.shutter_pwmrange[1][i]-ShutterSettings.shutter_pwmrange[0][i]) * Shutter[i].target_position , Shutter[i].open_max)+ShutterSettings.shutter_pwmrange[0][i];
//analogWrite(Pin(GPIO_PWM1, i), Shutter[i].pwm_value);
TasmotaGlobal.pwm_value[i] = Shutter[i].pwm_value;
AddLog(LOG_LEVEL_DEBUG, PSTR("SHT: PWM final %d"),Shutter[i].pwm_value);
pwm_apply = true;
char scmnd[20];
#ifdef SHUTTER_CLEAR_PWM_ONSTOP
Expand Down Expand Up @@ -990,12 +991,7 @@ void ShutterRtc50mS(void)
case SHT_PWM_VALUE:
ShutterUpdateVelocity(i);
Shutter[i].real_position += Shutter[i].direction > 0 ? Shutter[i].pwm_velocity : (Shutter[i].direction < 0 ? -Shutter[i].pwm_velocity : 0);
// avoid overshoot on servo if changes are very small
if ((Shutter[i].direction > 0 && Shutter[i].real_position > Shutter[i].target_position)
|| (Shutter[i].direction < 0 && Shutter[i].real_position < Shutter[i].target_position)) {
Shutter[i].real_position = Shutter[i].target_position;
}
Shutter[i].pwm_value = SHT_DIV_ROUND((ShutterSettings.shutter_pwmrange[1][i]-ShutterSettings.shutter_pwmrange[0][i]) * Shutter[i].real_position , Shutter[i].open_max)+ShutterSettings.shutter_pwmrange[0][i];
Shutter[i].pwm_value = SHT_DIV_ROUND((ShutterSettings.shutter_pwmrange[1][i] - ShutterSettings.shutter_pwmrange[0][i]) * Shutter[i].real_position , Shutter[i].open_max) + ShutterSettings.shutter_pwmrange[0][i];
TasmotaGlobal.pwm_value[i] = Shutter[i].pwm_value;
pwm_apply = true;
break;
Expand Down

0 comments on commit 2e95f45

Please sign in to comment.