Skip to content

fix: accept negative numbers as positional arguments in examples - #9

Merged
X-F-R merged 1 commit into
mainfrom
fix/negative-number-arguments
Oct 9, 2026
Merged

X-F-R merged 1 commit into
mainfrom
fix/negative-number-arguments

Conversation

@X-F-R

@X-F-R X-F-R commented Oct 9, 2026

Copy link
Copy Markdown
Contributor

Summary

The example argument parser (examples/_common.cpp) treated every token
starting with - as an unknown switch and exited with status 2. The
documented usage in examples/02_movej.cpp —
./02_movej --go 0.1 0 -0.1 0 0 0 0 — therefore could not run at all,
and a negative value could not be passed to an example-private switch
(--dist -0.04).

Changes

  • examples/_common.cpp: a token that parses as a complete number is now
    accepted as a positional argument and as the value of a private switch.
    Non-numeric -x tokens are still rejected as unknown switches.
  • tests/test_example_args.cpp: new suite covering negative positional
    values, -5 / -.5 / -1e-3 forms, a negative private-switch value,
    the unchanged positive forms, --help, and the exit(2) error path
    (forked).
  • CMakeLists.txt: compile examples/_common.cpp into
    test_example_args so the suite does not depend on
    LITEARM_BUILD_EXAMPLES.

Testing

Offline: ./build.sh — 28/28 pass (test_protocol_sync SKIP: no
firmware tree), including the new test_example_args (6 cases).

Real machine (LiteArm 7J, firmware Litearm1.10.0-7J, USB 1d50:606f).

Before this change:

  • ./run_example.sh 02_movej --go 0 0 -0.25 0 0 0 0 →
    未知开关: -0.25 (用 --help 看用法), exit 2 (never connects)
  • ./run_example.sh 07_vel_jitter_trace --go --dist -0.01 → same exit 2

After this change:

  • ./run_example.sh 02_movej --go 0 0 -0.25 0 0 0 0 →
    movej 到位 q = [-0.001, 0.001, -0.249, -0.001, -0.001, 0.000, -0.001]
  • ./run_example.sh 07_vel_jitter_trace --go --dir 1 --dist -0.01 →
    规划: ok=1 n_wp=5 settled=1, 收尾 TCP [0.0004, -0.0096, 0.7829, ...],
    both trace CSVs written (0 dropped frames on the 100 Hz channel)

Issues

None.

The example argument parser treated every token starting with "-" as an unknown switch and exited with status 2, so the documented usage ./02_movej --go 0.1 0 -0.1 0 0 0 0 did not work; negative values were also rejected as the value of an example-private switch (--dist -0.04).

Tokens that parse as a complete number are now accepted as positional arguments and as private-switch values. Non-numeric tokens are still rejected as unknown switches.

Add tests/test_example_args.cpp and compile examples/_common.cpp into that test target so the suite does not depend on LITEARM_BUILD_EXAMPLES.
@X-F-R
X-F-R merged commit 78f6917 into main Oct 9, 2026
1 check passed
@X-F-R
X-F-R deleted the fix/negative-number-arguments branch October 9, 2026 08:44
@github-actions

github-actions Bot commented Oct 9, 2026

Copy link
Copy Markdown

🎉 This PR is included in version 0.1.2 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

@github-actions github-actions Bot added the released Shipped in a release label Oct 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

released Shipped in a release

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant