Skip to content

Cleanup and improve sim battery#32124

Closed
hunt0r wants to merge 11 commits intoArduPilot:masterfrom
hunt0r:issue10050-cleanup-and-improve-sim-battery
Closed

Cleanup and improve sim battery#32124
hunt0r wants to merge 11 commits intoArduPilot:masterfrom
hunt0r:issue10050-cleanup-and-improve-sim-battery

Conversation

@hunt0r
Copy link
Copy Markdown
Contributor

@hunt0r hunt0r commented Feb 6, 2026

Description

This PR prepares for every simulated vehicle to implement battery consumption (#10050).

It causes minimal (no?) changes in observed behavior. A follow-up PR will switch vehicles to actually using these improvements. (If you're interested, preview that PR here.)

Summary of significant changes:

  • Reword the SIM_BATT_VOLTAGE and SIM_BATT_CAP_AH parameter descriptions for clarity & completeness. These define the user-facing behavior.
  • Improve SITL::Battery class to support that behavior.
  • Disentangle SITL::Battery from SITL::Frame.

Testing (your PR may be summarily closed without these)

Side-by-side of EvaluateBatteryModel shows no changes (figures below).
Simple MultiCopter (--model x) in SITL: arm, takeoff, hover, land.

  • Tested via example
  • Tested in SITL
  • Tested on hardware
  • Autotest included
  • Not AI slop
  • logs attached
  • logs available on request

Recommendations

Reviewers: Please start with the descriptions of SIM_BATT_VOLTAGE and SIM_BATT_CAP_AH parameters. In case I interpreted these incorrectly, we must sort that first! (They're in the last commit.)

After that, I recommend skimming commit-by-commit to understand the individual steps being taken.

Testing images from example

Observe that before-and-after are the same.

After this PR:
image

Reference image (from here in repo):
image

Comment thread libraries/SITL/SITL.cpp Outdated
Comment thread libraries/SITL/SITL.cpp Outdated
Comment thread libraries/SITL/SITL.cpp Outdated

Aircraft::Aircraft(const char *frame_str) :
frame(frame_str)
Aircraft::Aircraft(const char *unused_frame_str)
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I looked at removing this, but it looks like ~20 children also have it because this does. 🙁

I'm happy to do that in a separate cleanup PR, but it would distract too much from the focus of this one.

Comment on lines +231 to 233
// OPTIONAL battery model
// ("OPTIONAL" because a child can ignore it and directly set/get battery_* members.)
Battery battery;
Copy link
Copy Markdown
Contributor Author

@hunt0r hunt0r Feb 6, 2026

Choose a reason for hiding this comment

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

I don't love how every Aircraft has a SITL::Battery but many ignore it. That's a slightly smelly design. But its consistent with the current state of the code. Hence me merely adding a comment here to alert folks about that.

I welcome a spin-off discussion about the future of simulated batteries. I'd prefer that every aircraft (every instantiated child of SITL::Aircraft) either have a SITL::Battery and use it, or do something custom and not have a SITL::Battery inside at all.

As an example, an alternate design would be for "the sim" to own "the simulated battery" as a stand-alone object. While that's nonphysical, its consistent with SITL::Sim containing stuff like a SITL::Sprayer, SITL::Parachute, SITL::Buzzer, etc. which I presume would be physically carried by the aircraft.

@hunt0r
Copy link
Copy Markdown
Contributor Author

hunt0r commented Feb 6, 2026

TIL that ./waf all does not in fact build everything. I will fix the failure...

(In case anyone is interested, there are targets which are only valid for --board=linux.)

Update: Fixed.

@peterbarker peterbarker self-requested a review February 6, 2026 21:57
@hunt0r hunt0r force-pushed the issue10050-cleanup-and-improve-sim-battery branch 2 times, most recently from 003f6ac to 9b5d9d7 Compare February 14, 2026 21:11
@IamPete1
Copy link
Copy Markdown
Member

This is a surprisingly big change, the commits also need a squash. Rather than a larger rework it would be easyer to review if you could make the minimum change to get the new functionality.

@hunt0r
Copy link
Copy Markdown
Contributor Author

hunt0r commented Feb 23, 2026

I'm not yet understanding the feedback, can you provide more detail?

the commits also need a squash.

Sure! I am happy to squash them together after the content is approved. (I assumed it is helpful to parse the changes step-by-step, but of course if a reviewer prefers not, just review the final outcome.)

Rather than a larger rework it would be easyer to review if you could make the minimum change to get the new functionality.

What "new functionality" are you referring to?

This is a surprisingly big change

Which step(s) should not be done?

Comment thread libraries/AP_HAL_SITL/SITL_State.cpp
@hunt0r
Copy link
Copy Markdown
Contributor Author

hunt0r commented Mar 2, 2026

Rebasing on master to see if the tests now pass. (At least the most significant-looking one did for us locally yesterday...)

@hunt0r hunt0r force-pushed the issue10050-cleanup-and-improve-sim-battery branch from 9b5d9d7 to f1f12b1 Compare March 2, 2026 18:57
@hunt0r
Copy link
Copy Markdown
Contributor Author

hunt0r commented Mar 3, 2026

I have repro'ed the failure locally. Converting to draft while I fix it.

@hunt0r hunt0r marked this pull request as draft March 3, 2026 20:55
@hunt0r hunt0r force-pushed the issue10050-cleanup-and-improve-sim-battery branch from f1f12b1 to adba694 Compare March 24, 2026 19:28
@hunt0r
Copy link
Copy Markdown
Contributor Author

hunt0r commented Mar 31, 2026

Closing this, because it's contribution is being landed incrementally via various PRs such as #32561, #32538, and #32637

@hunt0r hunt0r closed this Mar 31, 2026
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