No longer modify control vector in-place, add mju_clip.

- Never modify `d->ctrl`:
  - `ctrl` values which are outside their respective `ctrlrange` are clamped internally, but `d->ctrl` itself is unmodified.
  - Similarly, if `mjWARN_BADCTRL` is raised (NaNs or huge values), `ctrl` is cleared internally, but `d->ctrl` itself is unmodified.
- `mjWARN_BADCTRL` is no longer raised for `d->ctrl` values that are larger in absolute value than `mjMAXVAL`, if clamping makes them smaller than that.
- Added `mju_clip()` utility function.
- Added missing warning string for `case mjWARN_BADCTRL`.

PiperOrigin-RevId: 459025950
Change-Id: Ifbf974f9c02c3d70afdaa3114018fc81dfd746d3
This commit is contained in:
Yuval Tassa
2022-07-05 01:38:01 -07:00
committed by Copybara-Service
parent 09a5efc09e
commit 6d01627c0b
7 changed files with 158 additions and 43 deletions
+20
View File
@@ -6573,6 +6573,26 @@ FUNCTIONS: Mapping[str, FunctionDecl] = dict([
),
doc='Return max(a,b) with single evaluation of a and b.',
)),
('mju_clip',
FunctionDecl(
name='mju_clip',
return_type=ValueType(name='mjtNum'),
parameters=(
FunctionParameterDecl(
name='x',
type=ValueType(name='mjtNum'),
),
FunctionParameterDecl(
name='min',
type=ValueType(name='mjtNum'),
),
FunctionParameterDecl(
name='max',
type=ValueType(name='mjtNum'),
),
),
doc='Clip x to the range [min, max].',
)),
('mju_sign',
FunctionDecl(
name='mju_sign',