Conversation
完善最大功率选择和添加电机数目
Reviewer's GuideRefactors the PowerControl module and its RLS helper to use Eigen instead of a custom matrix library, introduces error-aware power distribution logic for omni and helm chassis, relaxes/changes some power model parameters and current-solving logic, and replaces the STM32-based CI build with a generic Linux/libxr-based build pipeline. Sequence diagram for chassis power control loop using PowerControlsequenceDiagram
participant ChassisController
participant PowerControl
participant SuperPower
participant RLS as RLS_2
ChassisController->>PowerControl: SetMotorData3508(currents_3508, speeds_3508, speed_errors_3508)
ChassisController->>PowerControl: SetMotorData6020(currents_6020, speeds_6020, speed_errors_6020)
ChassisController->>PowerControl: CalculatePowerControlParam()
PowerControl->>SuperPower: GetChassisPower()
SuperPower-->>PowerControl: measured_power
PowerControl->>SuperPower: IsOnline()
SuperPower-->>PowerControl: online_flag
PowerControl->>RLS: Update(samples_3508_, residual)
RLS-->>PowerControl: params_3508_
PowerControl->>PowerControl: update k1_3508_, k2_3508_
ChassisController->>PowerControl: OutputLimit(max_power)
alt is_helm_ == false
PowerControl->>PowerControl: OutputLimitOmni(max_power)
else is_helm_ == true
PowerControl->>PowerControl: OutputLimitHelm(max_power)
end
ChassisController->>PowerControl: GetPowerControlData()
PowerControl-->>ChassisController: PowerControlData (new currents, is_power_limited)
Updated class diagram for PowerControl and RLSclassDiagram
class LibXR_Application {
}
class SuperPower {
+float GetChassisPower()
+float GetCapEnergy()
+bool IsOnline()
}
class RLS_2 {
<<template<2>>
+uint32_t dimension_
+float lambda_
+float delta_
+Eigen_Matrix_float_2_2 transmatrix_
+ParamVector gainvector_
+ParamVector paramsvector_
+ParamVector defaultparamsvector_
+RLS_2(float delta_, float lambda_)
+void Reset()
+const ParamVector& Update(const ParamVector& sample_vector, float actual_output)
+void SetParamVector(const ParamVector& updated_params)
}
class PowerControl {
+static int MAX_MOTOR_COUNT
-LibXR_Mutex mutex_
-SuperPower* superpower_
-bool is_helm_
-RLS_2 rls_
-PowerControlData powercontrol_data_
-float k3_chassis_
-float error_confidence_
-float sum_error_
-float speed_error_3508_[MAX_MOTOR_COUNT]
-float speed_error_6020_[MAX_MOTOR_COUNT]
-int motor_count_3508_
-int motor_count_6020_
-float kt_3508_
-float k1_3508_
-float k2_3508_
-Eigen_Matrix_float_2_1 samples_3508_
-Eigen_Matrix_float_2_1 params_3508_
-float output_current_3508_[MAX_MOTOR_COUNT]
-float rotorspeed_rpm_3508_[MAX_MOTOR_COUNT]
-float motor_power_3508_[MAX_MOTOR_COUNT]
-float kt_6020_
-float k1_6020_
-float k2_6020_
-float output_current_6020_[MAX_MOTOR_COUNT]
-float rotorspeed_rpm_6020_[MAX_MOTOR_COUNT]
-float motor_power_6020_[MAX_MOTOR_COUNT]
-float measured_power_
+PowerControl(LibXR_HardwareContainer& hw, LibXR_ApplicationManager& app, SuperPower* superpower, bool is_helm, float chassis_static_power_loss, int motor_count_3508, int motor_count_6020)
+void SetMotorData3508(float* output_current, float* rotorspeed_rpm, float* speed_error)
+void SetMotorData6020(float* output_current, float* rotorspeed_rpm, float* speed_error)
+void CalculatePowerControlParam()
+void OutputLimit(float max_power)
+PowerControlData GetPowerControlData()
+float GetMeasuredPower() const
+float GetCapEnergy()
+bool IsOnline()
+void OnMonitor()
-void OutputLimitOmni(float max_power)
-void OutputLimitHelm(float max_power)
}
class PowerControlData {
+float new_output_current_3508[POWER_CONTROL_MAX_MOTOR_COUNT]
+float new_output_current_6020[POWER_CONTROL_MAX_MOTOR_COUNT]
+bool is_power_limited
}
LibXR_Application <|-- PowerControl
PowerControl --> SuperPower : uses
PowerControl --> RLS_2 : uses
PowerControl --> PowerControlData : aggregates
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:
- The new implementation of
solve_current_for_powerremoves the negative-delta/small-aguard but still callssqrtf(delta)unconditionally and divides by2*a, which can lead to NaNs or division-by-zero whendelta < 0ork1 ≈ 0; consider restoring/adjusting these checks and settingfinal_currentconsistently (thedelta < 1e-9branch currently computesx3but never uses it). - In
OutputLimitOmni/OutputLimitHelm, constants like the extra power margin3.0fand the thresholdsERROR_POWERDISTRIBUTION_SET/POP_POWERDISTRIBUTIONare hard-coded; consider making themconstexprconfiguration parameters or clearly named class members so their intent and tunability are explicit.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- The new implementation of `solve_current_for_power` removes the negative-`delta`/small-`a` guard but still calls `sqrtf(delta)` unconditionally and divides by `2*a`, which can lead to NaNs or division-by-zero when `delta < 0` or `k1 ≈ 0`; consider restoring/adjusting these checks and setting `final_current` consistently (the `delta < 1e-9` branch currently computes `x3` but never uses it).
- In `OutputLimitOmni`/`OutputLimitHelm`, constants like the extra power margin `3.0f` and the thresholds `ERROR_POWERDISTRIBUTION_SET`/`POP_POWERDISTRIBUTION` are hard-coded; consider making them `constexpr` configuration parameters or clearly named class members so their intent and tunability are explicit.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
Refine the chassis power control module with Eigen-based math utilities, enhanced power distribution logic, and updated CI to build and test the module via the generic libxr-based Linux workflow.
New Features:
Enhancements:
Build:
CI: