aboutsummaryrefslogtreecommitdiff
path: root/bin
diff options
context:
space:
mode:
authorSelene ToyKeeper2021-08-14 04:53:36 -0600
committerSelene ToyKeeper2021-08-14 04:53:36 -0600
commit91658b2d7e3f6233c6de86377198c7339d842fb1 (patch)
tree3426f28a7fa8d7455a18d255c68cd758d0736c91 /bin
parentcalibrated KR4 jump-start-moon, may be too high on some older hardware (diff)
downloadanduril-91658b2d7e3f6233c6de86377198c7339d842fb1.tar.gz
anduril-91658b2d7e3f6233c6de86377198c7339d842fb1.tar.bz2
anduril-91658b2d7e3f6233c6de86377198c7339d842fb1.zip
clarified the new level_calc calculations a bit, experimented to make sure things are right
Diffstat (limited to '')
-rwxr-xr-xbin/level_calc.py58
1 files changed, 32 insertions, 26 deletions
diff --git a/bin/level_calc.py b/bin/level_calc.py
index acac332..9d72d45 100755
--- a/bin/level_calc.py
+++ b/bin/level_calc.py
@@ -162,46 +162,52 @@ def multi_pwm(answers, channels):
elif goal_lm > channel.prev_lm:
# assume 7135 channels all add together
if channel.type == '7135':
- diff = channel.lm_max - channel.lm_min
+ lm_avail = channel.lm_max - channel.lm_min
# assume FET channel gets higher output on its own
elif channel.type == 'FET':
- diff = channel.lm_max - channel.prev_lm - channel.lm_min
-
- needed = goal_lm - channel.prev_lm - channel.lm_min
-
- ceil = max_pwms[i]
- ratio = needed / diff * (ceil-channel.pwm_min)
- # if there's wiggle room, adjust ceiling to reduce error
- #if dyn_pwm:
- # this_step = max(1, math.floor(ratio))
- # next_step = this_step + 0.5
- # limit = float(this_step) / next_step * ceil
- # limit = max(limit, max_pwm)
- #while (ceil > limit) and ((ratio - math.floor(ratio)) > 0.1):
- # ceil -= 1
- # ratio = needed / diff * (ceil-channel.pwm_min)
- # max_pwms[i] = ceil
- if dyn_pwm and (ceil > max_pwm):
- this_step = max(1, math.floor(ratio))
+ lm_avail = channel.lm_max - channel.prev_lm - channel.lm_min
+
+ lm_needed = goal_lm - channel.prev_lm - channel.lm_min
+
+ pwm_top = max_pwms[i]
+ pwm_avail = pwm_top - channel.pwm_min
+ pwm_needed = pwm_avail * lm_needed / lm_avail
+ if dyn_pwm and (pwm_top > max_pwm):
+ this_step = max(1, math.floor(pwm_needed))
next_step = this_step + 1
- fpart = ratio - math.floor(ratio)
+ fpart = pwm_needed - math.floor(pwm_needed)
correction = (next_step - fpart) / next_step
- ceil = int(ceil * correction)
- ratio = needed / diff * (ceil-channel.pwm_min)
- max_pwms[i] = ceil
+ pwm_top = int(pwm_avail * correction) + channel.pwm_min
+ pwm_avail = pwm_top - channel.pwm_min
+ pwm_needed = pwm_avail * lm_needed / lm_avail
+ max_pwms[i] = pwm_top
# save the result
- pwm = max(0, ratio + channel.pwm_min)
+ pwm = max(0, pwm_needed + channel.pwm_min)
channel.modes.append(pwm)
+ # how close did we get?
+ #ptop = int(round(pwm - channel.pwm_min))
+ #pbot = pwm_top - channel.pwm_min
+ #print('%.3f%% needed, %.3f%% actual' % (
+ # 100.0 * lm_needed / lm_avail,
+ # 100.0 * ptop / pbot,
+ # ))
# This channel isn't active yet, output too low
else:
channel.modes.append(0)
# Show individual levels in detail
+ prev_ratios = [0.0] * len(channels)
for i in range(answers.num_levels):
goal_vis, goal_lm = goals[i]
pwms = []
- for channel in channels:
- pwms.append('%.2f/%i' % (channel.modes[i], max_pwms[i]))
+ for c, channel in enumerate(channels):
+ top = channel.modes[i] - channel.pwm_min
+ bot = max_pwms[i] - channel.pwm_min
+ ratio = 100 * (int(round(top)) / float(bot))
+ pwms.append('%.2f/%i (%.3f%%)' % (top, bot, ratio))
+ if ratio < prev_ratios[c]:
+ pwms.append('WARN')
+ prev_ratios[c] = ratio
print('%i: visually %.2f (%.2f lm): %s' %
(i+1, goal_vis, goal_lm, ', '.join(pwms)))