SITL: Fix the --param (aka -P) cli option#32158
SITL: Fix the --param (aka -P) cli option#32158hunt0r wants to merge 6 commits intoArduPilot:masterfrom
-P) cli option#32158Conversation
peterbarker
left a comment
There was a problem hiding this comment.
There's no testing infrastructure or this.
Test with a maximum-name parameter
Fail if there are any characters in the value we don't understand (which is checking the other bit out of strtof, I think?)
Not a problem to have 20 parameters settable with this mechanism.
Continue to avoid std::string
Do your testing while also running with --valgrind, just in case.
Thanks for working on this!
|
|
||
| char *for_parsing = strdup(to_be_set); | ||
| if (for_parsing == nullptr) { | ||
| AP_HAL::panic("strdup failed (insufficient memory)"); |
There was a problem hiding this comment.
This is a wildly different call than exit.
Why are you not being consistent with other errors in here?
There was a problem hiding this comment.
I was following (or attempting to follow) what I see in SITL_State::_parse_command_line().
But, as is probably obvious, I don't understand when/why to use panic() in SITL.
There was a problem hiding this comment.
I changed it to exit: 94c2b9e
But of course if consistency with _parse_command_line() is better, I can easily drop my recent commit, just say the word.
Added to description: I used
Changed: efde652.
Changed: 96ff06f.
Done, and added to PR description. |
|
This isn't working for a lot of parameters; the current spot where things are being set is before the simulation has set the paramete rvalue from the default parameters. e.g. I was using Please create an autotest which uses Need to work out whether this should set the parameter value - or the default parameter value. |
I agree (have repro'ed). Thanks for catching!
Will do.
Should we generalize that to include the desired interactions of |
94c2b9e to
3fec7c1
Compare
|
Per dev call 2026-02-23, we are considering instead simply deleting this |
|
Change of direction: will delete this feature instead. |

This addresses issue #6114 .
Solution summary: split cli handling into a "parse" phase which verifies and saves the info, and a "set" phase which is called after the params exist with default values to set them to the
-P-provided values.Test summary: Reviewers please request other specific tests in case the original coverage is not sufficient.
Also, do we have any suitable automatic testing infra for cli-parsing like this?Per reviewer: no.
Design review
While the solution is straightforward, and the testing examples are helpful, reviewers should start with these design-level questions:
Is a compile-constant max on the number of cli params a desired design? If yes, what value is desired? (Currently at 4, which made testing simpler, trivial to increase it to any desired value.)Reviewer: Use 20.AP::sitl()is nullptr? (If yes, I think that's an easy fix.)-P NAME1=VAL1,NAME2=VAL2vs-P NAME1=VAL1 -P NAME2=VAL2. Do we want to permit only one, or both? If both, do we want the usage to describe both? (Right now both are permitted, usage only describes one.)-Pto interact with other possibilities for setting parameter values? (e.g.--wipe,--defaults--model) The same question holds for the values which get auto-saved to a file and auto-loaded next time. (I propose we postpone this discussion, land the PR, and just let the interaction(s) emerge. With clean/clear code, adjusting them in the future is not hard.)-P --model=foothinks the param name is "--model", which fortunately fails to be found.) Do we need specific detection/prevention of this? (I propose that we don't, because it will fail naturally.)sim_vehicle.pyhas a-P, but it does not use this (now fixed) capability. Should it? (I propose we postpone this discussion to unblock the PR. We can make that a 'next step' in the issue, if desired.)Do we want to continue avoiding niceReviewer: yes.std::stringin SITL? (OFC this PR does, if for no stronger reason than preserving stylistic consistency.)Testing
All testing performed under valgrind, no leaks.
Happy-path test summary:
-P MNT1_TYPE=8, confirmed expected value viaparam show MNT1_TYPEin MAVLink.-P MNT1_TYPE=8,MNT1_ROLL_MIN=-88.8,MNT1_ROLL_MAX=99, confirmed expected values viaparam show MNT1*in MAVLink.-P ""continues with no parameters changed. (Same as omitting-P ...altogether.)Error-catching test summary:
-P " "errors withSpecify param+val via: NAME=VALUE (No '=' found in )-P --model +errors withSpecify param+val via: NAME=VALUE (No '=' found in --model)-P MNT1_TYPE:8errors withSpecify param+val via: NAME=VALUE (No '=' found in MNT1_TYPE:8)-P MNT1_TYPE==8errors withUnable to convert to float: =8-P MXT1_TYPE=8errors withUnknown parameter: MXT1_TYPE-P MNT1_TYPE=abcderrors withUnable to convert to float: abcd-P MNT1_TYPE=8abcderrors withUnable to convert to float: 8abcd(Relevant because behavior for this case changed during review process.)For testing purposes, I lowered the MAX from 20 to 4, recompiled, and did this additional test:
-P MNT1_TYPE=8,MNT1_ROLL_MIN=-88.8,MNT1_ROLL_MAX=99,MNT1_PITCH_MIN=-44,MNT1_PITCH_MAX=44errors with-P only supports 4 values. To proceed, recompile with increased maximum.Corner case summary:
-P MNT1_TYPE=8,,,,,,,,MNT1_ROLL_MIN=-88.8,works to set those 2 params.-P FLTMODE_GCSBLOCK=19works to set that 16-char param.Testing details: I used
--wipeinfront of every-Pto ensure its behavior was being observed, not previously saved values. From theardupilot/ArduCopterfolder, my commands were like/Users/hunt0r/ardupilot/build/sitl/bin/arducopter --wipe -P [...] --model + --slave 0 --sim-address=127.0.0.1 -I0and the MAVProxy command I used to verify was
~/MAVProxy/MAVProxy/mavproxy.py --console --out 127.0.0.1:14550 --master tcp:127.0.0.1:5760 --sitl 127.0.0.1:5501.The valgrind specifics were:
valgrind --leak-check=full --show-leak-kinds=all --track-origins=yes --num-callers=20 [...].I saw 0 direct, indirect, and possibly. (Nonzero 'still-reachable', but that seems typical.)