Challenge

Week 2- 2R Robotic Arm Challenge

Aim : A program in Matlab to simulate the forward kinematics of a 2R Robotic Arm

Main code:

clear all
close all
clc

%Inputs
l1 = 1;
l2 = 0.5;
%Using linspace command we get all the possibility movements of the robtic
%arm in different angels
theta1 = linspace(0,90,10);
theta2 = linspace(0,90,10);
ct =1


%Using for-loop inside the for loop because the first for-loop we use for
%link1 and inside the second for-loop we used to link2 we done it because the number of
%movement of the link2 is more that link1 at different position
%Each for-loop the loop counter variable must be different
for i = 1:length(theta1)
    THETA1 =theta1(i);
    for g = 1:length(theta2);
    THETA2=theta2(g);
    %Starting coordinates of the first link (0,0)
    x0 = 0;
    y0 = 0;
%Using trigonometric equation for link 1
x1= l1*cosd(THETA1);
y1= l1*sind(THETA1);
%Using trigonometric equation for link 2
x2= l2*cosd(THETA2)+x1;
y2= l2*sind(THETA2)+y1;

%Plotting
%While plotting use the 1st link coordinates at first and then secound link
%coordiantes
%Using the getframe command we can save the figure window
%After saying the farmes we have to use the counter
plot([x0 x1],[y0 y1],[x1 x2],[y1 y2],'linewidth',3)
axis([-0.2 1.5 0  1.5])
pause(0.03)
M(ct)= getframe(gcf)
ct = ct+1
    end
end
%To make a movie or a video
movie(M)
videofile = VideoWriter('forward_kinematics.avi','Uncompressed AVI');
open(videofile)
writeVideo(videofile,M)
close(videofile)
  

https://drive.google.com/file/d/1-4KZVTXprrdbysXF0zqPAD4uyb7vLvBz/view?usp=sharing

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.

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.