Challenge

Week 2- 2R Robotic Arm Challenge

Forward kinematics of a 2R Robotic Arm

clear all
close all
clc
%defining link 
l1=1;
l2=0.5;
%defining the link space
%angle with x axis
theta1=linspace(0,90,10);
%angle  th y axes
theta2=linspace(0,90,10);
ct=1;
%nested for loop
%calculating the coordinates of links
for i=1:length(theta1)
    THETA1=theta1(i);
    for j=1:length(theta2)
        THETA2=theta2(j);
        x0=0;
        y0=0;
    x1=l1*cosd(THETA1);
    y1=l1*sind(THETA1);
    x2=x1+l2*cosd(THETA2);
    y2=y1+l2*sind(THETA2);
%plotting    
    plot([x0 x1],[y0 y1],[x1 x2],[y1 y2],'linewidth',3)
    axis([0 1.5 0 1.5])
    pause(.001)
%getframe capture the figures as frames
%gcf current figure handle
%ct counter variable helps in indexing of frames
    M(ct)=getframe(gcf);
    ct=ct+1;
    end
end
%Movie creation
%M array M for movie array
movie(M)
%videowriter command will create a video file
Videofile=VideoWriter('robotic arm.avi','Uncompressed AVI')
open(Videofile)
%writeVideo to write created video file with the frames in M array
writeVideo(Videofile,M)
close(Videofile)

Video link for the above program result movie

https://drive.google.com/file/d/1J8l-6xDCzDeZFFqsLQXAbjj14AGujX3V/view?usp=sharing

Explanation:

To write a program in Matlab to simulate the forward kinematics of a 2R Robotic Arm:

First we define the length of the arms has to be defined depending on the space which manipulator can move.

we are sating bothe the links can move from 0 to 90 degree.

The linspace command is used to make the array of angles.

As per trigonometric relations for a line of length l1 and angle theta between x axis X=l*cos*theta
similarly we define the starting and end points of the links.

Then we use nested loop structure to find the values of coordinates of the arm.

in this simulation we are computing all possible moves of link 2 for one single movement of link1.
then we define origin as x0=0 and y0=0

then we plot the cordinates using basic commands.

then we define the axis of figure.

then pause command is used for controlling the speed of the animation.

We use video M(ct)=getframe(gcf);

we are using an array, M with counter variable ct to capture the frames of the current figure.

we use an iteration for ct to capture all the frames.

Then we create a movie with the captured frames using the commands Movie, Videowriter,Videfile etc

WriteVideo command writes the craptured frames into the videofile by defining the name of the file and the compression method.

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.