for i = 1:length(t) % Calculate the linear and angular velocities of the robot V = (R1 * W1(i) + R2 * W2(i)) / 2; angular_velocity = (R2 * W2(i) - R1 * W1(i)) / B;
% Calculate the change in position of the robot
delta_x = V * cos(angular_velocity * t(i)); delta_y = V * sin(angular_velocity * t(i));
% Update the robot's position
if i == 1 robot_x(i) = delta_x; robot_y(i) = delta_y; else robot_x(i) = robot_x(i - 1) + delta_x; robot_y(i) = robot_y(i - 1) + delta_y; end
% Calculate the ICC (Instantaneous Center of Curvature)
if angular_velocity == 0 % Robot moves in a straight line, ICC at infinity icc_x(i) = NaN; icc_y(i) = NaN; else icc_radius = V / angular_velocity; icc_x(i) = robot_x(i) - icc_radius * sin(angular_velocity * t(i)); icc_y(i) = robot_y(i) + icc_radius * cos(angular_velocity * t(i)); end end
% Plot the robot's path and ICC
figure; plot(robot_x, robot_y, 'b', 'LineWidth', 2); hold on; plot(icc_x, icc_y, 'r--', 'LineWidth', 1.5); xlabel('X (cm)'); ylabel('Y (cm)'); title('Robot Path and Instantaneous Center of Curvature (ICC)'); legend('Robot Path', 'ICC'); grid on;