v 1.2
This commit is contained in:
@@ -47,6 +47,8 @@ class ForceConverter:
|
||||
enabled: bool = True
|
||||
extrapolate: bool = True
|
||||
clamp_output_min: float | None = 0.0
|
||||
input_mode: str = "magnitude"
|
||||
signed: bool = False
|
||||
|
||||
@classmethod
|
||||
def from_config(cls, calibration, config_name):
|
||||
@@ -71,6 +73,8 @@ class ForceConverter:
|
||||
enabled=True,
|
||||
extrapolate=bool(calibration.get("extrapolate", True)),
|
||||
clamp_output_min=calibration.get("clamp_output_min", 0.0),
|
||||
input_mode=str(calibration.get("input", "magnitude")).lower(),
|
||||
signed=bool(calibration.get("signed", False)),
|
||||
)
|
||||
|
||||
def convert(self, raw):
|
||||
@@ -104,8 +108,14 @@ class ForceConverter:
|
||||
value = n0 + ratio * (n1 - n0)
|
||||
return self._clamp(value)
|
||||
|
||||
def convert_component(self, raw):
|
||||
if not self.signed:
|
||||
return self.convert(raw)
|
||||
raw = float(raw)
|
||||
sign = -1.0 if raw < 0.0 else 1.0
|
||||
return sign * self.convert(abs(raw))
|
||||
|
||||
def _clamp(self, value):
|
||||
if self.clamp_output_min is not None:
|
||||
value = max(float(self.clamp_output_min), value)
|
||||
return value
|
||||
|
||||
|
||||
Reference in New Issue
Block a user