Add firmware and extension catalogues, configuration transactions, sample review and QML diagnostics. Preserve explicit authority, bounded retries and stop recovery in motor transport.
44 lines
2.1 KiB
Python
44 lines
2.1 KiB
Python
"""Remote throttle matching the admitted FW 5.02 PPM Duty Cycle profile.
|
|
|
|
Percent is an output request, not ground speed or a manufacturer rating.
|
|
Zero always releases; the caller retains lease, neutral and reversal ownership.
|
|
"""
|
|
import math
|
|
|
|
|
|
class DutyOutput:
|
|
def __init__(self, motors, applications, percent):
|
|
if type(percent) not in (int, float) or not 1 <= percent <= 100:
|
|
raise ValueError("Газ должен быть в диапазоне 1–100%.")
|
|
self.fraction = percent / 100
|
|
self.maxima = {}
|
|
positive, negative = [], []
|
|
for identifier, motor in motors.items():
|
|
app = applications[identifier]
|
|
maximum = motor["l_max_duty"]
|
|
if (app["app_ppm_conf.ctrl_type"] != 4 or not math.isfinite(maximum)
|
|
or not 0 < maximum <= 1):
|
|
raise ValueError("Для управления газом требуется профиль PPM Duty Cycle.")
|
|
self.maxima[identifier] = maximum
|
|
for field, target in (("ramp_time_pos", positive), ("ramp_time_neg", negative)):
|
|
value = app["app_ppm_conf." + field]
|
|
if not math.isfinite(value) or not 0 <= value <= 60:
|
|
raise ValueError("Некорректная плавность газа в настройках пульта.")
|
|
target.append(value)
|
|
# One normalised ramp for both tracks, no side outruns the other due
|
|
# to unequal receiver settings. Never faster than either configured ramp.
|
|
self.positive = max(positive)
|
|
self.negative = max(negative)
|
|
|
|
def target(self, identifier, demand):
|
|
return demand * self.fraction * self.maxima[identifier]
|
|
|
|
def advance(self, identifier, previous, target, dt):
|
|
if target == 0:
|
|
return 0.0
|
|
ramp = self.positive if abs(target) > abs(previous) else self.negative
|
|
if ramp <= .01:
|
|
return target
|
|
step = self.maxima[identifier] * max(0, min(.15, dt)) / ramp
|
|
return previous + max(-step, min(step, target - previous))
|