Skip to content

The battery pack belongs to the vehicle, not to a constant - #12

Merged
yalexx merged 1 commit into
mainfrom
feature/configurable-battery-pack
Aug 1, 2026
Merged

The battery pack belongs to the vehicle, not to a constant#12
yalexx merged 1 commit into
mainfrom
feature/configurable-battery-pack

Conversation

@yalexx

@yalexx yalexx commented Aug 1, 2026

Copy link
Copy Markdown
Contributor

A --model json SITL takes its battery from the simulator: ArduPilot's JSON backend reads voltage and current out of the physics frame every tick, so the autopilot's own SIM_BATT_* parameters have no effect on what it believes about its pack.

skysim was therefore the only thing deciding endurance, and it decided the same thing for every vehicle in every world — a 3S 3.3 Ah hobby pack, 12.6 V full, compiled in.

That is roughly a fifth of the aircraft the SkyHub fleet stands in for, and it was invisible from the caller's side: the gateway set SIM_BATT_CAP_AH to 27 Ah, read it back as 27 Ah, and watched the vehicle reach its reserve in six minutes. Three full survey runs were measured against the wrong aircraft before anyone thought to look at the pack voltage — 12.59 V on what was supposed to be a 25.2 V battery.

What changes

The pack moves onto SpawnRequest as a BatteryPack (capacity, full/empty voltage, idle and draw current), so a caller can describe the aircraft it is simulating, and a world can hold a mixed fleet.

Defaults are the old constants, so a spawn that says nothing about its battery behaves exactly as before.

A pack whose empty voltage is not below its full voltage is corrected rather than accepted — inverted sag would make a draining battery report a rising charge, which is worse than refusing the request.

battery/reset now restores that vehicle's own full voltage rather than a compiled-in one.

A note on the field name

hover_a is not the current at hover; it multiplies the square of normalised throttle. Reading it as amps-at-hover is about a factor-of-ten error, and calibrating against an assumed cruise demand rather than a measured one has now gone wrong twice downstream. Worth renaming at some point.

Testing

All 11 test binaries pass. test_api covers the defaults, a fully-specified pack reaching the tick thread, and the inverted-voltage correction.

🤖 Generated with Claude Code

A `--model json` SITL takes its battery from the simulator: ArduPilot's JSON backend
reads voltage and current out of the physics frame every tick, so the autopilot's own
SIM_BATT_* parameters have no effect on what it believes about its pack. skysim was
therefore the only thing deciding endurance, and it decided the same thing for every
vehicle in every world — a 3S 3.3 Ah hobby pack, 12.6 V full, compiled in.

That is roughly a fifth of the aircraft the SkyHub fleet actually stands in for, and it
was invisible from the gateway side, which set SIM_BATT_CAP_AH to 27 Ah, read it back as
27 Ah, and watched the vehicle reach its reserve in six minutes.

The pack moves onto SpawnRequest, so a caller can describe the aircraft it is simulating,
and defaults to the old constants so a spawn that says nothing behaves exactly as before.
A pack whose empty voltage is not below its full voltage is corrected rather than
accepted: inverted sag would make a draining battery report a rising charge.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Aug 1, 2026

Copy link
Copy Markdown

Warning

Review limit reached

You’ve reached a temporary PR review limit under our Fair Usage Limits Policy.

Your recent review volume is higher than typical usage, so adaptive limits are currently applied.

Next review available in: 59 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 94e6fc87-44fe-4b04-8994-dbe440a63c8d

📥 Commits

Reviewing files that changed from the base of the PR and between 8251bc2 and 89a9f15.

📒 Files selected for processing (4)
  • src/api/control_server.cpp
  • src/main.cpp
  • src/vehicle/manager.h
  • tests/test_api.cpp

Comment @coderabbitai help to get the list of available commands.

@yalexx

yalexx commented Aug 1, 2026

Copy link
Copy Markdown
Contributor Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Aug 1, 2026

Copy link
Copy Markdown
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@yalexx

yalexx commented Aug 1, 2026

Copy link
Copy Markdown
Contributor Author

@coderabbitai full review

@coderabbitai

coderabbitai Bot commented Aug 1, 2026

Copy link
Copy Markdown
✅ Action performed

Full review finished.


Your included review limit is currently reached under our Fair Usage Limits Policy. Your recent PR review activity is in the 95th percentile or higher among CodeRabbit users, so adaptive limits apply. This review may still proceed through usage-based billing if eligible. Your next included review will be available in 48 minutes.

@yalexx

yalexx commented Aug 1, 2026

Copy link
Copy Markdown
Contributor Author

@coderabbitai full review

@coderabbitai

coderabbitai Bot commented Aug 1, 2026

Copy link
Copy Markdown
✅ Action performed

Full review finished.

@yalexx
yalexx merged commit 5647e94 into main Aug 1, 2026
7 checks passed
@yalexx
yalexx deleted the feature/configurable-battery-pack branch August 1, 2026 22:12
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.

1 participant