Skip to content

Conversation

@ohyaiamhere
Copy link
Contributor

@ohyaiamhere ohyaiamhere commented Oct 31, 2025

To solve the old issue #6114 , the file sim_vehicle.py was modified to also take -P as a parameter to pass one parameter and its value to SITL.

It does this by creating a new.parm file in the build folder, and using the same logical flow as the add_param_file option, to append it to the parameter files list. The parameter, tested with single vehicle SITL, is succcessfully passed into the simulation. This is similar to what has been suggested at the end of pull request #6040

Example commands:

sim_vehicle.py -v Plane -P SIM_SPEEDUP=8 -D -G -B _set_param_default

sim_vehicle.py -v Plane -P SIM_RC_FAIL=1 -D -G -B _set_param_default

The command must not have any spaces in the param or around the = sign, else it throws an error.

@ohyaiamhere ohyaiamhere marked this pull request as draft October 31, 2025 14:30
@ohyaiamhere ohyaiamhere force-pushed the pCommand branch 3 times, most recently from 59407ed to 053f077 Compare October 31, 2025 14:50
@ohyaiamhere ohyaiamhere marked this pull request as ready for review October 31, 2025 14:50
Copy link
Contributor

@peterbarker peterbarker left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't work:

pbarker@crun:~/rc/ardupilot((HEAD detached at ohyaiamhere/pCommand))$ ./Tools/autotest/sim_vehicle.py -v Plane --gdb --debug -P LOG_DISARMED=16 -P LOG_REPLAY=17,LOG_MAX_FILES=78^C
pbarker@crun:~/rc/ardupilot((HEAD detached at ohyaiamhere/pCommand))$ cat build/new.parm 
LOG_REPLAY 17,LOG_MAX_FILES 78pbarker@crun:~/rc/ardupilot((HEAD detached at ohyaiamhere/pCommand))$ 

Please split on commas to allow a csl.... need a newline for neatness in that file.

A small autotest which customises the SITL command-line as I have there and makes sure that the values come up correctly will make sure this behaviour doesn't break (again).

Thanks for working on this, will be useful.

@ohyaiamhere
Copy link
Contributor Author

This doesn't work:

pbarker@crun:~/rc/ardupilot((HEAD detached at ohyaiamhere/pCommand))$ ./Tools/autotest/sim_vehicle.py -v Plane --gdb --debug -P LOG_DISARMED=16 -P LOG_REPLAY=17,LOG_MAX_FILES=78^C
pbarker@crun:~/rc/ardupilot((HEAD detached at ohyaiamhere/pCommand))$ cat build/new.parm 
LOG_REPLAY 17,LOG_MAX_FILES 78pbarker@crun:~/rc/ardupilot((HEAD detached at ohyaiamhere/pCommand))$ 

Please split on commas to allow a csl.... need a newline for neatness in that file.

A small autotest which customises the SITL command-line as I have there and makes sure that the values come up correctly will make sure this behaviour doesn't break (again).

Thanks for working on this, will be useful.

Happy to help.

I had an idea for implementing this. Essentially, a loop where the new params get appended to the file instead of being written all in one go. I will try to see if I can get it to work next week.

@khancyr
Copy link
Contributor

khancyr commented Nov 3, 2025

Hello,

That doesn't address that issue as this just add -P on sim_vehicle.py which isn't sitl .
It could be a good idea thus. So the implementation should be just creating a new param file and append it to the list to load as default.

as we are in python, we could probably use a tmpfile feature to not polute the workspace and garantee to not load those parameter if they aren't passed on cmdline !

@ohyaiamhere ohyaiamhere force-pushed the pCommand branch 3 times, most recently from f3c22d3 to 37ee17c Compare November 3, 2025 11:04
@ohyaiamhere ohyaiamhere force-pushed the pCommand branch 3 times, most recently from e540b37 to 53d8c20 Compare November 4, 2025 08:57
@ohyaiamhere
Copy link
Contributor Author

Hello,

That doesn't address that issue as this just add -P on sim_vehicle.py which isn't sitl . It could be a good idea thus. So the implementation should be just creating a new param file and append it to the list to load as default.

as we are in python, we could probably use a tmpfile feature to not polute the workspace and garantee to not load those parameter if they aren't passed on cmdline !

Hello Pierre,

A temporary file was tried for this purpose, as used for opt.gdb and other applications. This recommended change has been implemented and tested for the command below:

./Tools/autotest/sim_vehicle.py -v Plane --gdb --debug -P LOG_DISARMED=16 -P LOG_REPLAY=17,LOG_MAX_FILES=78,SIM_SPEEDUP=5

Where the value of SIM_SPEEDUP would be varied and the parameter checked using a Mavlink GCS (like QGC), to see that the value is as expected.

if opts.param:
param = str(opts.param)
param_file = tempfile.NamedTemporaryFile(mode='w', delete=False)
atexit.register(os.unlink, param_file.name)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

probably not need as those files will be cleaned up on /tmp and the creation guarantee they won't be reused

Copy link
Contributor Author

@ohyaiamhere ohyaiamhere Nov 4, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pardon me, I don't follow which line is verbose. The delete parameter has been set to false (line 818), and at exit, this file can be deleted by the line 819 (atexit called at line 1446). File creating and deletion flow created to be similar to other temporary files in the script.

Is there something here that we can perhaps do without?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants