Challenge

Week 2- 2R Robotic Arm Challenge

Program for forward kinematics of 2R robotic arm

%forward kinematics of 2r robotic arm using for loop
clear all
close all
clc

%lenght
l1= 1;
l2 = 0.5;
%degree
theta1 = linspace(0,90,5);
theta2 = linspace(0,90,5);

%loop
ct=1
for i = 1:length(theta1)
    THETA1 = theta1(i);
    for j =1: length(theta2)
        THETA2 = theta2(j);
        % coordinates
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 1.5 0 1.5])
pause(0.3)
M(ct)= getframe(gcf);
ct=ct+1;


    end
end
movie(M)
videofile = VideoWriter("forward_kinematics_2r_robotimarm_prog.m","Uncompressed AVI")
open(videofile)
writeVideo(videofile,M)
close(videofile)


Explanation:

First we define the length of the both links and the set of degress from 0 to 90 using linspace command,then using the for loop first give the range of theta 1 degree and inside the loop give the range of theta 2 degrees for looping the results for various degrees we given.

then the coordinates are define and formulated using basic trignometries,and then plot the results using the plot command and kept the both links in single plot command.

then I define the axis by given the x and y limits and give pause command for stopping the program at intervals to get a animation plot.

then get the current frames in M(ct) variable and store the frames and the contour in changing from 1 to ct+1 to get the different countours while looping and end the loop using end command.

Creating the movie.

The movie is created by using the commands videwriter where we assign name and format and the open,write and close the video using the open,writevideo,close commands.In writevideo command we write the videofile with figures in M variable.

ERRORS OCCURED IN PROGRAM:

Forget to put the theta numbers in program instead of theta1,theta2 i mentioned theta without numbers

for i = 1:length(theta1)
THETA1 = theta(i);
for j =1: length(theta2)
THETA2 = theta(j);

STEPS TAKEN TO OVERCOME ERROR:

Correct the mistakes by adding the numbers.

for i = 1:length(theta1)
THETA1 = theta1(i);
for j =1: length(theta2)
THETA2 = theta2(j);

I have attached the screenshots of error and the drive link of animation video and the plot figures.

https://drive.google.com/file/d/1fzfp3X_RDhWjuYzp9rJBq_HKlqh_C2ik/view?usp=sharing

Thank you.

Regards

B.Riyaz

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.