Challenge

Week 2- 2R Robotic Arm Challenge

% Kinematics of a Robotic Arm Manipulator

clear all
close all
clc

% Known data

L1 = 0.7; % length of first link in metres
L2 = 0.4; % length of second link in metres

theta1 = 0:10:90; % angle of rotation in degrees for first link
theta2 = 0:10:90; % angle of rotation in degrees for second link

x0 = 0;
y0 = 0;

% codes for getting the simulation of robotic arm

ct = 1;
for i = 1:length(theta1)
    theta_1 = theta1(i);
    for j = 1:length(theta2)
        theta_2 = theta2(j);

        x1 = L1.*cosd(theta_1);
        y1 = L1.*sind(theta_1);
        x2 = x1 + L2.*cosd(theta_2);
        y2 = y1 + L2.*sind(theta_2);

        plot([x0 x1], [y0 y1], [x1 x2], [y1 y2],'LineWidth', 2.5);
        axis ([-0.2 1.4 -0.2 1.4])   % setting limits of postive and negative axes
        pause (0.02)                 % pause interval in seconds
        M(ct) = getframe(gcf);       % capture of the current axes or figures as a movie frame

        ct=ct+1;         
    end
end

movie(M)     % generates a movie with all the frames captured in M
video_file = VideoWriter("Robotic_arm_challenge.avi","Uncompressed AVI");  % creating an object to write video data to an AVI file
open (video_file)
writeVideo(video_file, M)     % writes the captured frames to video_file
close (video_file)

Explanation:

After giving the inputs associated with the robotic arm, the codes are written for the simulation of its movement. For this purpose the 'for' loop has been used twice. This is because the first loop defines or sets the position of the first link, and corresponding to each position of the first link the second link will have multiple positions, i.e, from zero degree to 90 degrees. Accordingly the second 'for' loop within the first loop sets or defines the position of second link. After the loops the variables 'theta_1' and 'theta_2' are created to store a specific value of the angles stored in the arrays 'theta1' and 'theta2' respectively, each time the loops execute. Then the basic arithmetic equations for obtaining the end position of arm manipulator is written.

Thereafter the plot command is used to see the movement of robotic arm manipulator on a graph.

Note:- I had a small trouble in obtaining the desired movement of the robotic arm (shown in screenshot named 'Error1'). That was sorted once I removed the 'hold on' command (shown in screenshot named 'Fixed Error1'). It was not needed as the 'plot' command was used only once.

For the sequence of commands to keep executing until the end position of the robotic arm is reached, 'ct +1' is used at the end of second 'for' loop.

The commands further used in order to generate the video file of the simulation have been explained by comments (%) besides the commands.

Google drive link for the video:

https://drive.google.com/file/d/1cvTYJ_43CXDShlTyjIIPAQ3sj0cWLuK8/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.