gcormier / megadesk

Open-source IKEA Bekant controller board
GNU General Public License v3.0
724 stars 53 forks source link

potential to move beyond DANGER_MAX_HEIGHT/DANGER_MIN_HEIGHT? #68

Closed philwmcdonald closed 3 years ago

philwmcdonald commented 3 years ago

with the recalibration procedure the safety margin was removed. I'm wondering if this is still safe:

if (targetHeight > currentHeight && abs(targetHeight - currentHeight) > HYSTERESIS && currentHeight < maxHeight)
    motorUp(true);
  else if (targetHeight < currentHeight && abs(targetHeight - currentHeight) > HYSTERESIS && currentHeight > minHeight)
    motorDown(true);

or if that should be changed to (use targetHeight instead of currentHeight):

if (targetHeight > currentHeight && abs(targetHeight - currentHeight) > HYSTERESIS && targetHeight < maxHeight)
    motorUp(true);
  else if (targetHeight < currentHeight && abs(targetHeight - currentHeight) > HYSTERESIS && targetHeight > minHeight)
    motorDown(true);

This wouldn't effect recalibration, as that this snippet isn't executed during recal.

gcormier commented 3 years ago

Hmm good question. I think we should be OK as we still have HYSTERISIS which is set at 137 that is added/removed from the boundaries. It doesn't necessarily match the coast length for the deceleration which I haven't been able to measure.

I can plug in the logic analyzer again and see what the reported motor heights are for both controllers at their limits to see if we need to adjust.

philwmcdonald commented 3 years ago

I monitored serial which helpfully provides telemetry during the coast stage (after memoryMove is off). I measure movement of 120 & 123 going downwards and 111 & 111 going up. Both are less than hysteresis of 137. but typically each time through the loop we see a movement of 24 or even 27, currentHeight may already be 20+ beyond min/max.

I set max and a slot at the same height. then tried both memory recall and up-button-hold to see if I could exceed the max I set. memory recall never exceeded the max, but I could with the up-button. and exceeded the max by the exact coast distance I measured above.

With the same experiment with a min limit. I consistently exceeded the min by no more than 117.

As I haven't been able to exceed the soft limits by more than hysteresis I conclude this isn't a real problem. And the code is good as is.