-
Notifications
You must be signed in to change notification settings - Fork 6
Spring 2025 Improvements #115
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -11,17 +11,34 @@ | |
| namespace voss::controller { | ||
|
|
||
| class BoomerangController : public AbstractController { | ||
| public: | ||
| enum class ThruBehavior { // affects calculation of lin_speed on thru movements | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. warning: enum 'ThruBehavior' uses a larger base type ('int', size: 4 bytes) than necessary for its value set, consider using 'std::uint8_t' (1 byte) as the base type to reduce its size [performance-enum-size] enum class ThruBehavior { // affects calculation of lin_speed on thru movements
^ |
||
| MIN_VEL, // use linear PID, but enforce a minimum velocity | ||
| FULL_SPEED // no PID, go full speed | ||
| }; | ||
| enum class CosineScaling { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. warning: enum 'CosineScaling' uses a larger base type ('int', size: 4 bytes) than necessary for its value set, consider using 'std::uint8_t' (1 byte) as the base type to reduce its size [performance-enum-size] enum class CosineScaling {
^ |
||
| MIN_ERR, // only do cosine scaling within the minimum err | ||
| ALL_THE_TIME // do cosine scaling all the time | ||
| }; | ||
| enum class MinErrBehavior { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. warning: enum 'MinErrBehavior' uses a larger base type ('int', size: 4 bytes) than necessary for its value set, consider using 'std::uint8_t' (1 byte) as the base type to reduce its size [performance-enum-size] enum class MinErrBehavior {
^ |
||
| TARGET_HEADING, // directly switch from turning towards carrot point to turning towards target heading | ||
| SCALE_TARGET_HEADING, // scale between turning towards carrot point to turning towards target point | ||
| }; | ||
| protected: | ||
| std::shared_ptr<BoomerangController> p; | ||
| double lead_pct; | ||
| Pose carrotPoint; | ||
|
|
||
| utils::PID linear_pid, angular_pid; | ||
| double min_error; | ||
| bool can_reverse; | ||
|
|
||
| double min_vel; | ||
|
|
||
| ThruBehavior thru_behavior = ThruBehavior::FULL_SPEED; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. warning: member variable 'thru_behavior' has protected visibility [cppcoreguidelines-non-private-member-variables-in-classes] ThruBehavior thru_behavior = ThruBehavior::FULL_SPEED;
^ |
||
| CosineScaling cosine_scaling = CosineScaling::ALL_THE_TIME; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. warning: member variable 'cosine_scaling' has protected visibility [cppcoreguidelines-non-private-member-variables-in-classes] CosineScaling cosine_scaling = CosineScaling::ALL_THE_TIME;
^ |
||
| MinErrBehavior min_err_behavior = MinErrBehavior::SCALE_TARGET_HEADING; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. warning: member variable 'min_err_behavior' has protected visibility [cppcoreguidelines-non-private-member-variables-in-classes] MinErrBehavior min_err_behavior = MinErrBehavior::SCALE_TARGET_HEADING;
^ |
||
| bool enable_overturn = false; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. warning: member variable 'enable_overturn' has protected visibility [cppcoreguidelines-non-private-member-variables-in-classes] bool enable_overturn = false;
^ |
||
|
|
||
| public: | ||
| BoomerangController(std::shared_ptr<localizer::AbstractLocalizer> l); | ||
|
|
||
|
|
@@ -42,6 +59,11 @@ class BoomerangController : public AbstractController { | |
| std::shared_ptr<BoomerangController> modify_min_error(double error); | ||
| std::shared_ptr<BoomerangController> modify_lead_pct(double lead_pct); | ||
|
|
||
| void set_thru_behavior(ThruBehavior thru_behavior); | ||
| void set_cosine_scaling(CosineScaling cosine_scaling); | ||
| void set_min_err_behavior(MinErrBehavior min_err_behavior); | ||
| void set_overturn(bool overturn); | ||
|
|
||
| friend class BoomerangControllerBuilder; | ||
| }; | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7,16 +7,36 @@ | |
| namespace voss::controller { | ||
|
|
||
| class PIDController : public AbstractController { | ||
| public: | ||
| enum class ThruBehavior { // affects calculation of lin_speed on thru movements | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. warning: enum 'ThruBehavior' uses a larger base type ('int', size: 4 bytes) than necessary for its value set, consider using 'std::uint8_t' (1 byte) as the base type to reduce its size [performance-enum-size] enum class ThruBehavior { // affects calculation of lin_speed on thru movements
^ |
||
| MIN_VEL, // use linear PID, but enforce a minimum velocity | ||
| FULL_SPEED // no PID, go full speed | ||
| }; | ||
| enum class CosineScaling { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. warning: enum 'CosineScaling' uses a larger base type ('int', size: 4 bytes) than necessary for its value set, consider using 'std::uint8_t' (1 byte) as the base type to reduce its size [performance-enum-size] enum class CosineScaling {
^ |
||
| MIN_ERR, // only do cosine scaling within the minimum err | ||
| ALL_THE_TIME // do cosine scaling all the time | ||
| }; | ||
| enum class MinErrBehavior { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. warning: enum 'MinErrBehavior' uses a larger base type ('int', size: 4 bytes) than necessary for its value set, consider using 'std::uint8_t' (1 byte) as the base type to reduce its size [performance-enum-size] enum class MinErrBehavior {
^ |
||
| NO_ANG_PID, // no angular PID, set ang_speed to 0 | ||
| SCALE_ANG_PID, // scale output of angular pid so it reaches 0 at half of min_err | ||
| MAINTAIN_HEADING // maintain heading of when it entered min_err | ||
| }; | ||
| protected: | ||
| std::shared_ptr<PIDController> p; | ||
|
|
||
| utils::PID linear_pid, angular_pid; | ||
| double min_error; | ||
| bool can_reverse; | ||
| double min_err_heading; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. warning: member variable 'min_err_heading' has protected visibility [cppcoreguidelines-non-private-member-variables-in-classes] double min_err_heading;
^ |
||
|
|
||
| double min_vel; | ||
| bool turn_overshoot; | ||
|
|
||
| ThruBehavior thru_behavior = ThruBehavior::FULL_SPEED; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. warning: member variable 'thru_behavior' has protected visibility [cppcoreguidelines-non-private-member-variables-in-classes] ThruBehavior thru_behavior = ThruBehavior::FULL_SPEED;
^ |
||
| CosineScaling cosine_scaling = CosineScaling::MIN_ERR; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. warning: member variable 'cosine_scaling' has protected visibility [cppcoreguidelines-non-private-member-variables-in-classes] CosineScaling cosine_scaling = CosineScaling::MIN_ERR;
^ |
||
| MinErrBehavior min_err_behavior = MinErrBehavior::MAINTAIN_HEADING; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. warning: member variable 'min_err_behavior' has protected visibility [cppcoreguidelines-non-private-member-variables-in-classes] MinErrBehavior min_err_behavior = MinErrBehavior::MAINTAIN_HEADING;
^ |
||
| bool enable_overturn = false; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. warning: member variable 'enable_overturn' has protected visibility [cppcoreguidelines-non-private-member-variables-in-classes] bool enable_overturn = false;
^ |
||
|
|
||
| public: | ||
| PIDController(std::shared_ptr<localizer::AbstractLocalizer> l); | ||
|
|
||
|
|
@@ -36,6 +56,11 @@ class PIDController : public AbstractController { | |
| modify_angular_constants(double kP, double kI, double kD); | ||
| std::shared_ptr<PIDController> modify_min_error(double min_error); | ||
|
|
||
| void set_thru_behavior(ThruBehavior thru_behavior); | ||
| void set_cosine_scaling(CosineScaling cosine_scaling); | ||
| void set_min_err_behavior(MinErrBehavior min_err_behavior); | ||
| void set_overturn(bool overturn); | ||
|
|
||
| friend class PIDControllerBuilder; | ||
| friend class BoomerangControllerBuilder; | ||
| }; | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -12,6 +12,8 @@ class TrackingWheelLocalizer : public AbstractLocalizer { | |
| protected: | ||
| std::atomic<double> prev_left_pos, prev_right_pos, prev_middle_pos; | ||
| AtomicPose prev_pose; | ||
| AtomicPose real_pose; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. warning: member variable 'real_pose' has protected visibility [cppcoreguidelines-non-private-member-variables-in-classes] AtomicPose real_pose;
^ |
||
| Pose local_offset = {0, 0, 0}; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. warning: member variable 'local_offset' has protected visibility [cppcoreguidelines-non-private-member-variables-in-classes] Pose local_offset = {0, 0, 0};
^There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. warning: no header providing "voss::Pose" is directly included [misc-include-cleaner] Pose local_offset = {0, 0, 0};
^ |
||
|
|
||
| std::atomic<double> left_right_dist, middle_dist; | ||
| std::unique_ptr<AbstractTrackingWheel> left_tracking_wheel, | ||
|
|
@@ -28,6 +30,7 @@ class TrackingWheelLocalizer : public AbstractLocalizer { | |
| void calibrate() override; | ||
| void set_pose(Pose pose) override; | ||
| void set_pose(double x, double y, double theta) override; | ||
| void set_local_offset(Pose local_offset); | ||
|
|
||
| friend class TrackingWheelLocalizerBuilder; | ||
| }; | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| #pragma once | ||
|
|
||
| namespace voss { | ||
|
|
||
| void enable_debug(); | ||
| void disable_debug(); | ||
| bool get_debug(); | ||
|
|
||
| } |
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -3,6 +3,7 @@ | |||||||||
| #include "PIDController.hpp" | ||||||||||
| #include "VOSS/chassis/ChassisCommand.hpp" | ||||||||||
| #include "VOSS/utils/angle.hpp" | ||||||||||
| #include "VOSS/utils/debug.hpp" | ||||||||||
| #include <cmath> | ||||||||||
|
|
||||||||||
| namespace voss::controller { | ||||||||||
|
|
@@ -23,18 +24,23 @@ BoomerangController::get_command(bool reverse, bool thru, | |||||||||
| Point current_pos = this->l->get_position(); | ||||||||||
|
|
||||||||||
| int dir = reverse ? -1 : 1; | ||||||||||
| Pose trueTarget; | ||||||||||
| double dx = target.x - current_pos.x; | ||||||||||
| double dy = target.y - current_pos.y; | ||||||||||
|
|
||||||||||
| double distance_error = sqrt(dx * dx + dy * dy); | ||||||||||
| double at = target.theta.value(); | ||||||||||
| double target_angle = target.theta.value(); | ||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. warning: variable 'target_angle' is not initialized [cppcoreguidelines-init-variables]
Suggested change
|
||||||||||
|
|
||||||||||
| this->carrotPoint = {this->target.x - distance_error * cos(at) * lead_pct, | ||||||||||
| this->target.y - distance_error * sin(at) * lead_pct, | ||||||||||
| target.theta}; | ||||||||||
| dx = carrotPoint.x - current_pos.x; | ||||||||||
| dy = carrotPoint.y - current_pos.y; | ||||||||||
| Point carrot_point; | ||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. warning: uninitialized record type: 'carrot_point' [cppcoreguidelines-pro-type-member-init]
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. warning: variable 'carrot_point' of type 'Point' can be declared 'const' [misc-const-correctness]
Suggested change
|
||||||||||
| if (!reverse) { | ||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. warning: if with identical then and else branches [bugprone-branch-clone] if (!reverse) {
^Additional contextsrc/VOSS/controller/BoomerangController.cpp:36: else branch starts here } else {
^ |
||||||||||
| carrot_point = {target.x - distance_error * cos(target_angle) * lead_pct, | ||||||||||
| target.y - distance_error * sin(target_angle) * lead_pct}; | ||||||||||
| } else { | ||||||||||
| carrot_point = {target.x + distance_error * cos(target_angle) * lead_pct, | ||||||||||
| target.y + distance_error * sin(target_angle) * lead_pct}; | ||||||||||
| } | ||||||||||
|
|
||||||||||
| dx = carrot_point.x - current_pos.x; | ||||||||||
| dy = carrot_point.y - current_pos.y; | ||||||||||
| double current_angle = this->l->get_orientation_rad(); | ||||||||||
|
|
||||||||||
| double angle_error; | ||||||||||
|
|
@@ -48,42 +54,57 @@ BoomerangController::get_command(bool reverse, bool thru, | |||||||||
|
|
||||||||||
| double lin_speed = linear_pid.update(distance_error); | ||||||||||
| if (thru) { | ||||||||||
| lin_speed = copysign(fmax(fabs(lin_speed), this->min_vel), lin_speed); | ||||||||||
| if (thru_behavior == ThruBehavior::FULL_SPEED) { | ||||||||||
| lin_speed = 100; | ||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. warning: 100 is a magic number; consider replacing it with a named constant [cppcoreguidelines-avoid-magic-numbers] lin_speed = 100;
^ |
||||||||||
| } else { | ||||||||||
| lin_speed = fmax(lin_speed, min_vel); | ||||||||||
| } | ||||||||||
| } | ||||||||||
| if (cosine_scaling == CosineScaling::ALL_THE_TIME || distance_error < min_error) { | ||||||||||
| lin_speed *= cos(angle_error); | ||||||||||
| } | ||||||||||
| lin_speed *= dir; | ||||||||||
|
|
||||||||||
| double pose_error = voss::norm_delta(target.theta.value() - current_angle); | ||||||||||
|
|
||||||||||
| double ang_speed; | ||||||||||
| if (distance_error < min_error) { | ||||||||||
| this->can_reverse = true; | ||||||||||
| double pose_error = voss::norm_delta(target_angle - current_angle); | ||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. warning: variable 'pose_error' of type 'double' can be declared 'const' [misc-const-correctness]
Suggested change
|
||||||||||
|
|
||||||||||
| ang_speed = angular_pid.update(pose_error); | ||||||||||
| } else if (distance_error < 2 * min_error) { | ||||||||||
| double scale_factor = (distance_error - min_error) / min_error; | ||||||||||
| double scaled_angle_error = voss::norm_delta( | ||||||||||
| scale_factor * angle_error + (1 - scale_factor) * pose_error); | ||||||||||
|
|
||||||||||
| ang_speed = angular_pid.update(scaled_angle_error); | ||||||||||
| if (min_err_behavior == MinErrBehavior::TARGET_HEADING) { | ||||||||||
| ang_speed = angular_pid.update(pose_error); | ||||||||||
| } else { | ||||||||||
| double min_err_2 = min_error / 2; | ||||||||||
| double scale_factor = (distance_error - min_err_2) / min_err_2; | ||||||||||
| scale_factor = fmax(0.0, scale_factor); | ||||||||||
| double scaled_angle_error = norm_delta(scale_factor * angle_error + (1 - scale_factor) * pose_error); | ||||||||||
| ang_speed = angular_pid.update(scaled_angle_error); | ||||||||||
| } | ||||||||||
| } else { | ||||||||||
| if (fabs(angle_error) > M_PI_2 && this->can_reverse) { | ||||||||||
| angle_error = | ||||||||||
| angle_error - (angle_error / fabs(angle_error)) * M_PI; | ||||||||||
| lin_speed = -lin_speed; | ||||||||||
| if (cosine_scaling != CosineScaling::ALL_THE_TIME) { | ||||||||||
| lin_speed = -lin_speed; | ||||||||||
| } | ||||||||||
| } | ||||||||||
|
|
||||||||||
| ang_speed = angular_pid.update(angle_error); | ||||||||||
| } | ||||||||||
|
|
||||||||||
| lin_speed *= cos(angle_error); | ||||||||||
| lin_speed = std::clamp(lin_speed, -100.0, 100.0); | ||||||||||
| if (enable_overturn) { | ||||||||||
| ang_speed = std::clamp(ang_speed, -100.0, 100.0); | ||||||||||
| lin_speed = std::clamp(lin_speed, -100 + fabs(ang_speed), 100 - fabs(ang_speed)); | ||||||||||
| } | ||||||||||
|
|
||||||||||
| lin_speed = std::max(-100.0, std::min(100.0, lin_speed)); | ||||||||||
| if (get_debug()) { | ||||||||||
| printf("carrot point: %.2f, %.2f, dist_err: %.2f, ang_err: %.2f, lin_speed: %.2f, ang_speed: %.2f\n", carrot_point.x, carrot_point.y, angle_error, lin_speed, ang_speed); | ||||||||||
| } | ||||||||||
|
|
||||||||||
| if (ec->is_met(this->l->get_pose(), thru)) { | ||||||||||
| if (thru) { | ||||||||||
| return chassis::DiffChassisCommand{chassis::diff_commands::Chained{ | ||||||||||
| dir * std::fmax(lin_speed, this->min_vel) - ang_speed, | ||||||||||
| dir * std::fmax(lin_speed, this->min_vel) + ang_speed}}; | ||||||||||
| lin_speed - ang_speed, lin_speed + ang_speed}}; | ||||||||||
| } else { | ||||||||||
| return chassis::Stop{}; | ||||||||||
| } | ||||||||||
|
|
@@ -148,4 +169,20 @@ BoomerangController::modify_lead_pct(double lead_pct) { | |||||||||
| return this->p; | ||||||||||
| } | ||||||||||
|
|
||||||||||
| void BoomerangController::set_thru_behavior(ThruBehavior thru_behavior) { | ||||||||||
| this->thru_behavior = thru_behavior; | ||||||||||
| } | ||||||||||
|
|
||||||||||
| void BoomerangController::set_cosine_scaling(CosineScaling cosine_scaling) { | ||||||||||
| this->cosine_scaling = cosine_scaling; | ||||||||||
| } | ||||||||||
|
|
||||||||||
| void BoomerangController::set_min_err_behavior(MinErrBehavior min_err_behavior) { | ||||||||||
| this->min_err_behavior = min_err_behavior; | ||||||||||
| } | ||||||||||
|
|
||||||||||
| void BoomerangController::set_overturn(bool overturn) { | ||||||||||
| enable_overturn = overturn; | ||||||||||
| } | ||||||||||
|
|
||||||||||
| } // namespace voss::controller | ||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
warning: included header debug.hpp is not used directly [misc-include-cleaner]