Repository navigation
fix: accept negative numbers as positional arguments in examples - #9
Merged
Merged
Conversation
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.
|
🎉 This PR is included in version 0.1.2 🎉 The release is available on GitHub release Your semantic-release bot 📦🚀 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
The example argument parser (
examples/_common.cpp) treated every tokenstarting with
-as an unknown switch and exited with status 2. Thedocumented 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 nowaccepted as a positional argument and as the value of a private switch.
Non-numeric
-xtokens are still rejected as unknown switches.tests/test_example_args.cpp: new suite covering negative positionalvalues,
-5/-.5/-1e-3forms, a negative private-switch value,the unchanged positive forms,
--help, and the exit(2) error path(forked).
CMakeLists.txt: compileexamples/_common.cppintotest_example_argsso the suite does not depend onLITEARM_BUILD_EXAMPLES.Testing
Offline:
./build.sh— 28/28 pass (test_protocol_syncSKIP: nofirmware 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 2After 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.