-
Notifications
You must be signed in to change notification settings - Fork 2
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
Add angular PID to ArcPIDController, fix issue with SettleExitCondition #89
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 |
---|---|---|
|
@@ -10,9 +10,12 @@ class ArcPIDController : public AbstractController { | |
protected: | ||
std::shared_ptr<ArcPIDController> p; | ||
utils::PID linear_pid; | ||
utils::PID angular_pid; | ||
double track_width; | ||
double min_error; | ||
double can_reverse; | ||
double arc_radius; | ||
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 'arc_radius' has protected visibility [cppcoreguidelines-non-private-member-variables-in-classes] double arc_radius;
^ |
||
Point arc_center; | ||
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 'arc_center' has protected visibility [cppcoreguidelines-non-private-member-variables-in-classes] Point arc_center;
^ |
||
double prev_t; | ||
double slew; | ||
double prev_lin_speed; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,6 +18,7 @@ class ArcPIDControllerBuilder { | |
|
||
ArcPIDControllerBuilder& with_linear_constants(double kP, double kI, | ||
double kD); | ||
ArcPIDControllerBuilder& with_angular_constants(double kP, double kI, double kD); | ||
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: parameter name 'kP' is too short, expected at least 3 characters [readability-identifier-length] ArcPIDControllerBuilder& with_angular_constants(double kP, double kI, double kD);
^ 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: parameter name 'kI' is too short, expected at least 3 characters [readability-identifier-length] ArcPIDControllerBuilder& with_angular_constants(double kP, double kI, double kD);
^ 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: parameter name 'kD' is too short, expected at least 3 characters [readability-identifier-length] ArcPIDControllerBuilder& with_angular_constants(double kP, double kI, double kD);
^ |
||
/* | ||
* The track width is measured from your robot. | ||
* Due to turning scrub, you want to use a track width a few inches larger | ||
|
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -39,11 +39,20 @@ ArcPIDController::get_command(bool reverse, bool thru, | |||||
t = (c * e - f * b) / (a * e - d * b); | ||||||
} | ||||||
|
||||||
if (std::isnan(arc_radius)) { | ||||||
arc_radius = t; | ||||||
arc_center = { | ||||||
current_pos.x + t * a, | ||||||
current_pos.y + t * d | ||||||
}; | ||||||
//printf("arc center: %f %f\n", arc_center.x, arc_center.y); | ||||||
} | ||||||
|
||||||
double distance_error = sqrt(b * b + e * e); | ||||||
double angle_error = atan2(b, -e) - current_angle; | ||||||
|
||||||
if (reverse) { | ||||||
angle_error = atan2(-b, -e) - current_angle; | ||||||
angle_error = atan2(-b, e) - current_angle; | ||||||
} | ||||||
|
||||||
angle_error = voss::norm_delta(angle_error); | ||||||
|
@@ -67,11 +76,22 @@ ArcPIDController::get_command(bool reverse, bool thru, | |||||
lin_speed *= reverse ? -1 : 1; | ||||||
|
||||||
double left_speed, right_speed; | ||||||
if (t != 0.0) { | ||||||
if (arc_radius != 0.0) { | ||||||
// left_speed = (t - track_width / 2) / t * lin_speed; | ||||||
// right_speed = (t + track_width / 2) / t * lin_speed; | ||||||
left_speed = lin_speed * (2 - track_width / t) / 2; | ||||||
right_speed = lin_speed * (2 + track_width / t) / 2; | ||||||
left_speed = lin_speed * (2 - track_width / arc_radius) / 2; | ||||||
right_speed = lin_speed * (2 + track_width / arc_radius) / 2; | ||||||
double tangent = atan2(current_pos.y - arc_center.y, current_pos.x - arc_center.x); | ||||||
if ((bool)(arc_radius > 0) != 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 ((bool)(arc_radius > 0) != reverse) {
^ Additional contextsrc/VOSS/controller/ArcPIDController.cpp:86: else branch starts here } else {
^ |
||||||
tangent += M_PI_2; | ||||||
} else { | ||||||
tangent -= M_PI_2; | ||||||
} | ||||||
//printf("current %f target %f\n", voss::to_degrees(current_angle), voss::to_degrees(tangent)); | ||||||
printf("x %f y %f\n", current_pos.x, current_pos.y); | ||||||
double ang_speed = angular_pid.update(voss::norm_delta(tangent - 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 'ang_speed' of type 'double' can be declared 'const' [misc-const-correctness]
Suggested change
|
||||||
left_speed -= ang_speed; | ||||||
right_speed += ang_speed; | ||||||
} else { | ||||||
left_speed = lin_speed; | ||||||
right_speed = lin_speed; | ||||||
|
@@ -98,7 +118,9 @@ chassis::DiffChassisCommand ArcPIDController::get_angular_command( | |||||
|
||||||
void ArcPIDController::reset() { | ||||||
this->linear_pid.reset(); | ||||||
this->angular_pid.reset(); | ||||||
this->prev_lin_speed = 0.0; | ||||||
this->arc_radius = NAN; | ||||||
} | ||||||
|
||||||
std::shared_ptr<ArcPIDController> | ||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -42,9 +42,11 @@ auto swing = voss::controller::SwingControllerBuilder::new_builder(odom) | |
.build(); | ||
|
||
auto arc = voss::controller::ArcPIDControllerBuilder(odom) | ||
.with_track_width(14) | ||
.with_track_width(16) | ||
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: 16 is a magic number; consider replacing it with a named constant [cppcoreguidelines-avoid-magic-numbers] .with_track_width(16)
^ |
||
.with_linear_constants(20, 0.02, 169) | ||
.with_angular_constants(250, 0.05, 2435) | ||
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: 250 is a magic number; consider replacing it with a named constant [cppcoreguidelines-avoid-magic-numbers] .with_angular_constants(250, 0.05, 2435)
^ 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: 0.05 is a magic number; consider replacing it with a named constant [cppcoreguidelines-avoid-magic-numbers] .with_angular_constants(250, 0.05, 2435)
^ 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: 2435 is a magic number; consider replacing it with a named constant [cppcoreguidelines-avoid-magic-numbers] .with_angular_constants(250, 0.05, 2435)
^ |
||
.with_min_error(5) | ||
.with_slew(8) | ||
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: 8 is a magic number; consider replacing it with a named constant [cppcoreguidelines-avoid-magic-numbers] .with_slew(8)
^ |
||
.build(); | ||
|
||
pros::Controller master(pros::E_CONTROLLER_MASTER); | ||
|
@@ -141,26 +143,8 @@ void opcontrol() { | |
master.get_analog(ANALOG_RIGHT_X)); | ||
|
||
if (master.get_digital_new_press(DIGITAL_Y)) { | ||
odom->set_pose({0.0, 0.0, 270}); | ||
chassis.move({24, 24, 45}, boomerang, 100, | ||
voss::Flags::THRU | voss::Flags::REVERSE); | ||
printf("1.\n"); | ||
master.rumble("--"); | ||
chassis.turn(90, 100, voss::Flags::THRU); | ||
printf("2.\n"); | ||
master.rumble("--"); | ||
chassis.move({-10, 60, 180}, boomerang, 100, voss::Flags::THRU); | ||
printf("3.\n"); | ||
master.rumble("--"); | ||
chassis.turn(270, swing, 100, | ||
voss::Flags::REVERSE | voss::Flags::THRU); | ||
printf("4.\n"); | ||
master.rumble("--"); | ||
chassis.move({10, 30}, 100, voss::Flags::THRU); | ||
printf("5.\n"); | ||
master.rumble("--"); | ||
chassis.turn(0); | ||
printf("end\n"); | ||
odom->set_pose({0.0, 0.0, 90}); | ||
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: 90 is a magic number; consider replacing it with a named constant [cppcoreguidelines-avoid-magic-numbers] odom->set_pose({0.0, 0.0, 90});
^ |
||
chassis.move({-24, 24}, arc); | ||
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: 24 is a magic number; consider replacing it with a named constant [cppcoreguidelines-avoid-magic-numbers] chassis.move({-24, 24}, arc);
^ 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: 24 is a magic number; consider replacing it with a named constant [cppcoreguidelines-avoid-magic-numbers] chassis.move({-24, 24}, arc);
^ |
||
} | ||
|
||
pros::lcd::clear_line(1); | ||
|
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: member variable 'angular_pid' has protected visibility [cppcoreguidelines-non-private-member-variables-in-classes]