Challenge

Week 3.2 - 2R Robotic Arm Challenge

https://youtu.be/2OaadgOjGPE


The Code: clc;

clear;
close all;
% Define link lengths
L1 = 2; % Length of first link
L2 = 1.5; % Length of second link
% Define joint angle range
theta1 = linspace(0, pi, 100); % Joint 1 varies from 0 to 180 degrees
theta2 = linspace(0, pi/2, 100); % Joint 2 varies from 0 to 90 degrees
% Create figure for animation
figure;
axis([-4 4 -4 4]); % Set axis limits
hold on;
grid on;
xlabel('X-axis');
ylabel('Y-axis');
title('2R Robotic Arm Animation');
% Animation loop
for i = 1:length(theta1)
% Compute forward kinematics
x1 = L1 * cos(theta1(i));
y1 = L1 * sin(theta1(i));
x2 = x1 + L2 * cos(theta1(i) + theta2(i));
y2 = y1 + L2 * sin(theta1(i) + theta2(i));
% Plot the robotic arm
cla; % Clear previous frame
plot([0, x1], [0, y1], 'r', 'LineWidth', 3); % First link
hold on;
plot([x1, x2], [y1, y2], 'b', 'LineWidth', 3); % Second link
plot(x2, y2, 'ko', 'MarkerFaceColor', 'k', 'MarkerSize', 8); % End-effector
plot(0, 0, 'go', 'MarkerFaceColor', 'g', 'MarkerSize', 8); % Base
% Pause to simulate animation speed
pause(0.05);
end
disp('Animation completed.');

Your portfolio, next

Ship work like this
in your own course.

Talk to a career counsellor

Free 20-minute call. We'll map the right course to where you want to work.

By submitting you agree to our Terms and Privacy Policy.