Challenge

Week 2- 2R Robotic Arm Challenge

% Program forward kinematics of 2R robotic arm
clear all
close all
clc
% inputs length of the two links of robotic arm
l1=1;
l2=0.4;
% input of counter variable
ct=1;
% inputs of 10 values which makes angle with both links(x axis)
alpha1=linspace(0,90,10);
alpha2=linspace(0,90,10);
% inputs to make loop
for i=1:length(alpha1)
theta1=alpha1(i);
for j=1:length(alpha2)
theta2=alpha2(j);
% inputs co-ordinates for the base link
x0=0;
y0=0;
% calculate co-ordinates for the link 1
x1=l1*cosd(theta1);
y1=l1*sind(theta1);
% calculate co-ordinates for the link 2
x2=x1+l2*cosd(theta2);
y2=y1+l2*sind(theta2);
%plotting the co-oridnates
plot([x0,x1],[y0,y1],[x1,x2],[y1,y2],'linewidth',3)
axis([-0.1 1.5 0 1.5]);
pause(0.2)
% an array to store frame of graphs
M(ct)=getframe(gcf);
ct=ct+1;
end
end
% creat a movie where the frames are saved in array M
movie(M)
% details to make video file
videofile = VideoWriter ('2r_forwrdkinematics.avi', 'Uncompressed AVI');
open(videofile);
writeVideo(videofile,M);
close(videofile);

Explanation

Step1: Inputs two length of links of the 2R robotics arm and the variables are l1 and l2

Step2: Input a counter variable

Step3: Taking two array alpha1 and alpha2 which contains ten values of angles with the x-axis

Step4: Start a for loop starting from value 1 to alpha1 that is 10 named theta1

Step5: Start a for inside previous for loop that is alpha2 named theta2

Step6: Inputs value of the base link co-ordinates i.e. x0 & y0

Step7: calculate the values of the co-ordinates x1,y1 and x2,y2 and plot the graph

Step8: the graphs are stored in an array M and end for loop

Step9: create a movie from all those graphs

Step10: Created a name to that videofile

Step11: call a function to open the videofile and write the video an array M

Step 12: call a function to close the video file

Error comes during programing

1. Error-command input wrong

soln-correct the linspace commad

2.Error-Forgot to enter multiplying sign

soln-after giving this it works

Output-

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.