Improvements in odometry kinematics

This commit is contained in:
Alexander Lampalzer 2022-06-09 10:25:11 +02:00
parent b3eb01ad6e
commit 80ed5e5bf9

View file

@ -49,8 +49,10 @@ OdometryController::OdometryController() {
last_run = clock::now();
auto encoder_positions = Encoders::getInstance().get_positions();
auto current_position_left = encoder_positions.at(ROBOT_ODOMETRY_CONTROLLER_LEFT_PORT) * ROBOT_ODOMETRY_CONTROLLER_LEFT_MULT;
auto current_position_right = encoder_positions.at(ROBOT_ODOMETRY_CONTROLLER_RIGHT_PORT) * ROBOT_ODOMETRY_CONTROLLER_RIGHT_MULT;
auto current_position_left =
encoder_positions.at(ROBOT_ODOMETRY_CONTROLLER_LEFT_PORT) * ROBOT_ODOMETRY_CONTROLLER_LEFT_MULT;
auto current_position_right =
encoder_positions.at(ROBOT_ODOMETRY_CONTROLLER_RIGHT_PORT) * ROBOT_ODOMETRY_CONTROLLER_RIGHT_MULT;
auto distance_left = (current_position_left - last_position_left) / ROBOT_TICKS_PER_METER;
auto distance_right = (current_position_right - last_position_right) / ROBOT_TICKS_PER_METER;
last_position_left = current_position_left;
@ -60,34 +62,28 @@ OdometryController::OdometryController() {
// Refer to Computational Principles of Mobile Robotics, Dudek and Jenkin
// or Chapter "Mobile Robot Kinematics" Introduction to Autonomous Mobile Robots, Roland Siegwart
// and Illah R. Nourbakhsh
auto v = (distance_right + distance_left) / 2.0;
auto w = (distance_right - distance_left) / ROBOT_ARBOR_LENGTH_M;
// Forward and Rotational velocity have already been integrated.
auto dist_forward = (distance_right + distance_left) / 2.0;
auto dist_rot = (distance_right - distance_left) / ROBOT_ARBOR_LENGTH_M;
auto curr_x = current_odometry.get_x_position();
auto curr_y = current_odometry.get_y_position();
auto curr_theta = current_odometry.get_angular_orientation();
auto x = dist_forward * cos(dist_rot);
auto y = dist_forward * sin(dist_rot);
auto theta = dist_rot;
auto x = v * cos(w);
auto y = v * sin(w);
auto new_x_position = current_odometry.get_x_position();
auto new_y_position = current_odometry.get_y_position();
auto new_angular_orientation = current_odometry.get_angular_orientation();
auto new_x = curr_x + (cos(curr_theta) * x - sin(curr_theta) * y);
auto new_y = curr_y + (sin(curr_theta) * x + cos(curr_theta) * y);
auto new_theta = curr_theta + w;
if (dist_forward != 0) {
new_x_position = cos(theta) * x - sin(theta) * y + current_odometry.get_x_position();
new_y_position = sin(theta) * x + cos(theta) * y + current_odometry.get_y_position();
}
new_theta = mathUtils::wrap_angle_to_pi(new_theta);
current_odometry = Odometry(new_x, new_y, new_theta);
if (theta != 0) {
new_angular_orientation = mathUtils::wrap_angle_to_pi(current_odometry.get_angular_orientation() + theta);
}
current_odometry = Odometry(new_x_position, new_y_position, new_angular_orientation);
spdlog::info("{:03.4f} {:03.4f} {:03.4f} {:03.4f} {:03.4f} {:03.4f}",
current_position_left, current_position_right,
distance_left, distance_right,
dist_forward, dist_rot);
// spdlog::info("{:03.4f} {:03.4f} {:03.4f} {:03.4f} {:03.4f} {:03.4f}",
// current_position_left, current_position_right,
// distance_left, distance_right,
// dist_forward, dist_rot);
}
}
}