update#20
Merged
Merged
Conversation
Reviewer's guide (collapsed on small PRs)Reviewer's GuideAdjusts chassis power limiting logic by introducing a configurable power margin, fixes a bug in solving motor current from target power, and simplifies available power accounting for omni and swerve control paths. Class diagram for updated power control and motor power modelclassDiagram
class MotorPowerModel {
+float CHASSIS_POWER_LIMIT_MARGIN_W
+float calculate_motor_model_power(float current, float rpm, float kt, float k1, float k2)
+float solve_current_for_power(float target_power, float rpm, float kt, float k1, float k2, float original_current)
}
class PowerControl {
-float k3_chassis_
-float sum_error_
-float sum_error_3508_
-float sum_error_6020_
-int motor_count_3508_
-int motor_count_6020_
-float motor_power_3508_*
-float motor_power_6020_*
-float speed_error_3508_*
-float speed_error_6020_*
+void OutputLimitOmni(float max_power)
+void OutputLimitSwerve(float max_power)
}
PowerControl ..> MotorPowerModel : uses
Flow diagram for updated available power calculation in OutputLimitOmni and swerve pathflowchart TD
A[Start power limiting] --> B[Input max_power]
B --> C[Compute available_power = max_power - k3_chassis_ - CHASSIS_POWER_LIMIT_MARGIN_W]
C --> D[Initialize required_power_3508_sum = 0, sum_error_3508 = 0]
D --> E[Loop over 3508 motors]
E --> F[Compute motor_power_3508 at index i via calculate_motor_model_power]
F --> G{motor_power_3508 at index i > 0}
G --> H[Accumulate required_power_3508_sum and sum_error_3508]
G --> I[Do nothing for nonpositive power]
H --> J[Next motor]
I --> J[Next motor]
J --> K[Similar loop for 6020 motors without subtracting negative power]
K --> L[Use available_power and required sums to limit outputs]
L --> M[End power limiting]
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Hey - I've left some high level feedback:
- In
OutputLimitOmni,available_powercan still become negative whileOutputLimitSteerexplicitly clamps it withstd::max(0.0f, ...); consider aligning the behavior between these two paths to avoid inconsistent handling of low power situations. - Replacing the update of
available_powerfor negative motor power inOutputLimitSteer(removing theelse { available_power -= motor_power_XXXX; }blocks) changes the power balance logic; double-check whether you still want negative/regen power to effectively increase available power, and if not, document the new assumption in the power allocation scheme. - The
CHASSIS_POWER_LIMIT_MARGIN_Wmacro is a compile-time constant used in multiple places; consider converting it to a typedconstexpr floatto improve type safety and scoping.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- In `OutputLimitOmni`, `available_power` can still become negative while `OutputLimitSteer` explicitly clamps it with `std::max(0.0f, ...)`; consider aligning the behavior between these two paths to avoid inconsistent handling of low power situations.
- Replacing the update of `available_power` for negative motor power in `OutputLimitSteer` (removing the `else { available_power -= motor_power_XXXX; }` blocks) changes the power balance logic; double-check whether you still want negative/regen power to effectively increase available power, and if not, document the new assumption in the power allocation scheme.
- The `CHASSIS_POWER_LIMIT_MARGIN_W` macro is a compile-time constant used in multiple places; consider converting it to a typed `constexpr float` to improve type safety and scoping.Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
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 by Sourcery
Adjust motor power allocation logic with a configurable chassis power margin and correct quadratic current solver behavior.
Bug Fixes:
Enhancements: