Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Physical value encoder rounding #142

Merged
merged 2 commits into from
Jan 27, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,18 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

- Empty signal encoders are now allowed
- Signals can now be associated with multiple frames, accessible under `signal.frames`
- Physical values are now rounded to the nearest integer, rather than down

### Migration guide for 0.26.0

- Newly written should be using `signal.frames` to determine the owners of a signal, for
compatibility reasons `signal.frame` is still set, but only when a signal is associated with one
frame
- Physical values might be rounded the wrong way depending on the user's intention. This type of
rounding should generally work better in values ranging from `0-X`, for example `49.9` is no longer
rounded down to `49`. If this is undesired the user can in most cases offset the input by `0.5` and
it should work as previously as `-0.5` rounds to `0`, check
[Python's round function](https://docs.python.org/3/library/functions.html#round) for more.

## [0.25.0] - 2024-04-28

Expand Down
2 changes: 1 addition & 1 deletion ldfparser/encoding.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def encode(self, value: Union[str, int, float], signal: 'LinSignal') -> int:

raw = self.offset
if self.scale != 0:
raw = int((num - self.offset) / self.scale)
raw = round((num - self.offset) / self.scale)

if raw < self.phy_min or raw > self.phy_max:
raise ValueError(f"value: {raw} out of range ({self.phy_min}, {self.phy_max})")
Expand Down
Loading