Tune turning a bit

This commit is contained in:
Konstantin Lampalzer 2022-05-29 15:20:11 +02:00
parent 9000316350
commit 4ee0b8045f
5 changed files with 42 additions and 18 deletions

View file

@ -105,12 +105,12 @@ void GoToController::drive_distance(double distance_m, double v_m_s) {
}
void GoToController::turn_degrees(double angle_deg, double v_rad_s) {
if (angle_deg < 0 && v_rad_s > 0) {
auto angle_rad = mathUtils::wrap_angle_to_pi(angle_deg * (M_PI / 180.0));
if (angle_rad < 0 && v_rad_s > 0) {
v_rad_s *= -1;
}
auto angle_rad = mathUtils::wrap_angle_to_pi(angle_deg * (M_PI / 180.0));
auto was_enabled = OdometryController::getInstance().is_enabled();
OdometryController::getInstance().enable();
auto start_pos = OdometryController::getInstance().get();
@ -118,19 +118,22 @@ void GoToController::turn_degrees(double angle_deg, double v_rad_s) {
auto sleep_duration = std::chrono::microseconds(US_IN_S / ROBOT_MOTOR_SPEED_CONTROL_RATE_HZ);
auto angle_to_target = angle_rad;
while (fabs(angle_to_target) > ROBOT_GO_TO_ANGLE_END_RAD) {
auto angle_turned = 0.0;
while (fabs(angle_to_target) > ROBOT_GO_TO_ANGLE_END_RAD && angle_turned < angle_rad) {
std::this_thread::sleep_for(sleep_duration);
auto current_pos = OdometryController::getInstance().get();
auto angle_turned = current_pos.get_angular_orientation() - start_pos.get_angular_orientation();
angle_turned = current_pos.get_angular_orientation() - start_pos.get_angular_orientation();
angle_to_target = mathUtils::wrap_angle_to_pi(angle_rad - angle_turned);
diff_drive_inverse_kinematics(0.0, v_rad_s);
auto speed_mult = mathUtils::limit_max(fabs(angle_to_target) * ROBOT_GO_TO_ANGLE_ALPHA_P, 0.0, 1.0);
auto adjusted_speed = mathUtils::limit_min(v_rad_s * speed_mult, ROBOT_GO_TO_ANGLE_MIN_VEL);
diff_drive_inverse_kinematics(0.0, adjusted_speed);
spdlog::debug("{:03.4f}; {:03.4f}; {:03.4f}; {:03.4f}; {:03.4f};",
spdlog::debug("{:03.4f}; {:03.4f}; {:03.4f}; {:03.4f}; {:03.4f}; {:03.4f};",
current_pos.get_x_position(), current_pos.get_y_position(), current_pos.get_angular_orientation(),
angle_turned, angle_to_target
angle_turned, angle_to_target, adjusted_speed
);
}

View file

@ -80,10 +80,10 @@ OdometryController::OdometryController() {
}
current_odometry = Odometry(new_x_position, new_y_position, new_angular_orientation);
// spdlog::info("{} {} {} {} {} {}",
// current_position_left, current_position_right,
// distance_left, distance_right,
// distance, theta);
spdlog::info("{} {} {} {} {} {}",
current_position_left, current_position_right,
distance_left, distance_right,
distance, theta);
}
}
}

View file

@ -38,7 +38,7 @@ int main(int argc, char *argv[]) {
// GoToGoalController::go_to_point(2, 0, 0.2);
// GoToController::drive_distance(-4, 0.2);
// GoToController::turn_degrees(-90, M_PI_2);
GoToController::turn_degrees(180, M_PI);
// GoToController::drive_distance(2, 0.2);
// GoToController::turn_degrees(-90, M_PI_2);
@ -52,10 +52,10 @@ int main(int argc, char *argv[]) {
// GoToController::drive_distance(2, 0.2);
// GoToController::turn_degrees(-90, M_PI_2);
ClosedLoopMotorController::getInstance().calibrate_wheel_ticks(5, stoi(argv[1]));
// ClosedLoopMotorController::getInstance().calibrate_wheel_ticks(5, stoi(argv[1]));
// ClosedLoopMotorController::getInstance().generate_step_response_data();
// ClosedLoopMotorController::getInstance().generate_tuned_step_response_data();
// std::this_thread::sleep_for(std::chrono::hours(12));
std::this_thread::sleep_for(std::chrono::hours(12));
return 0;
}