Challenge

Week 2- 2R Robotic Arm Challenge

This program is to simulate how the robot move. The robot contain 2 link with the base in the starting and manipulator in the end and 2 rotational joints. Link1 make angle of theta1 with the x-axis and link2 make angle of theta2 with the x-axis. Length of the link1 is l1 and link2 is l2.

For the genetration of program we can use coordinated in each joints.

ie, (x0 y0), (x1 y1), (x2 y2)

(x0 y0) represence starting point of link1

(x1 y1) represence ending point of link1 and starting point of link2 (l1cosd(theta1), l1 sind(theta1))

(x2 y2) represence ending point of link2 (x1+l2cosd(theta2), y1+l2sind(theta2))

Program

%Program for the forward kinematic of a 2R robotic arm

clear all
close all
clc

%input

%links length

l1 = 1;
l2 = 0.5;

%angles

theta1 = linspace(0,90,10);
theta2 = linspace(0,90,10);
ct = 1;

%for loop

for i = 1:length(theta1);
    Q1 = theta1(i);
    for j = 1:length(theta2);
        Q2 = theta2(j);
        x0=0;
        y0=0;
        x1 = l1*cosd(Q1);
        y1 = l1*sind(Q1);
        x2 = x1+l2*cosd(Q2);
        y2 = y1+l2*sind(Q2);

        plot([x0 x1],[y0 y1],[x1 x2],[y1 y2],'linewidth',3);
        axis([-0,1.5,0,1.5]);
        pause(0.03);
    
    M(ct) = getframe(gcf);
   ct=ct+1;
    end
end

We can play our output graph as movie

movie(M)
videofile = VideoWriter('kinematics.avi','Uncompressed AVI')
open(videofile)
writeVideo(videofile,M)
close(videofile)

The google drive link of the output graph

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

Errors faced while programming

Error 1: execute the program which without Q1 and Q2 ,we get a graph

Error 2: while adding counter (ct) command in the program, error show 'unrecognized function or variable 'ct'' in the command window.

Error 3: instead of 2 'for loop', i just used 1 and also instead of plot command used line, while execute the program i just got the graph as the link1 and link 2 move together from bottom to top. it show in the figure below.

Error 4: while correcting program missing of one coma(,) it show a error 'missing of unbalanced delimiters' in the command window.

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.