Challenge

Week 2- 2R Robotic Arm Challenge

%simulating the position of the robotic 2link arm
clear all
close all
clc
%Inputs
l1 = 1; %length of the first link in meters
l2 = 0.5; %length of the second link in meters
%origin is fixed to the base of the first link coordinate will be (0,0)
%point for the first link
theta1 = linspace(0,180,8);%angle of the first link w.r.t xaxis of the origin
theta2 = linspace(0,180,8); % angle of the second link w.r.t xaxis of the origin
%using for loop to calculate for each position of theata1
ct = 1;
for i = 1 : length(theta1)
angle1 = theta1(i);
%using for loop to calculate for each position of theata2 for one
%position of theta1
for j = 1 : length(theta2)
angle2 = theta2(j);
%Starting point coordinates of the first link
x0 = 0;
y0 = 0;
%End point coordinates of the first link
x1 = l1*cosd(angle1); %x component of the link1
y1 = l2*sind(angle1); %y component of the link1
%End point coordinates of the first link
x2 = x1+ l2*cosd(angle2);
y2 = y1+l2*sind(angle2);
%graph the positions in one figure
% line([x0,x1],[y0,y1],'linewidth',10,'color', 'b')
% line([x1,x2],[y1,y2],'linewidth',8,'color', 'r')
%graph the positions using plot command
plot([x0,x1],[y0,y1],[x1,x2],[y1,y2],'linewidth', 3)
axis([-2 2 -2 2])
%plot([x1,x2],[y1,y2],'linewidth',8,'color', 'r')
%getting the figures as a frame and storing it in the form of array
%in M
M(ct) = getframe(gcf);
%using this counter ct we get to plot at the end of the loop in the same figure.without the previous
% position.
ct = ct+1;
end
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.