Challenge

Week 3.2 - 2R Robotic Arm Challenge

https://youtu.be/LE-1vkp51YM

% Clear previous data
clear all;
close all;
clc;
% inputs
L1 = 1; % Length of the first link
L2 = 0.5; % Length of the second link
theta1 = linspace(0, pi/4, 5); % Joint angle for the first link (up to 45 degrees)
theta2 = linspace(0, 2*pi, 100); % Joint angle for the second link
% forward kinematics
x0 = 0; % Base position x
y0 = 0; % Base position y
% Preallocate arrays for end effector positions
x2 = zeros(length(theta1), length(theta2));
y2 = zeros(length(theta1), length(theta2));
% Compute the positions
for i = 1:length(theta1)
for j = 1:length(theta2)
x1 = L1 * cos(theta1(i));
y1 = L1 * sin(theta1(i));
x2(i, j) = x1 + L2 * cos(theta1(i) + theta2(j));
y2(i, j) = y1 + L2 * sin(theta1(i) + theta2(j));
end
end
% Create VideoWriter object
video = VideoWriter('2R_Robotic_Arm_Animation.mp4', 'MPEG-4');
open(video);
% Create the animation and save each frame to the video
figure;
for i = 1:length(theta1)
for j = 1:length(theta2)
% Plot the links
plot([x0 L1*cos(theta1(i)) x2(i, j)], [y0 L1*sin(theta1(i)) y2(i, j)], '-o', 'LineWidth', 2);
axis([-2 2 -2 2]);
title('2R Robotic Arm Simulation');
xlabel('X');
ylabel('Y');
drawnow;
% Capture the frame and write to video
frame = getframe(gcf);
writeVideo(video, frame);
end
end
% Close the video file
close(video);

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.