Challenge

Week 2- 2R Robotic Arm Challenge

Stepwise Explanation of Code:

The problem is to program a code to perform the two hand manipulator. A robotic arm manipulator can be used to perform tooling, welding as well as machining operations. Before going into the programming, we have to understand the different links and the points that will be considered while programming a 2R kinematics.

First we defined the starting point of the first hand which is origin and fixed. We have mentioned the cordinates of x0 = 0, y0=0. Then we define the end point of the first arm as x1,y1.

L1 = 1

L2 = 0.5

theta1 and theta2 are defined as an array because we need multiple values of theta1 and theta2 in order to create the video. so we defined theta1 and theta2 by using linspace command

theta1 = linspace(0,90,10)
theta2 = linspace(0,90,10)

Next step is to put the logic by using for loop:

To create a video file we have defined the THETA1 and THETA2 that shows us one value at a time but uses 10 values from the array theta1 and theta2. it execute the values for every increment of 1 by using ct command

Step1: Calculate the position of link1

x1 = L1*cosd(THETA1)
y1 = L1*sind(THETA1)


step2: Calculate the position of link2

x2 = L2*cosd(THETA2)
y2 = L2*sind(THETA2)

Step3: after defining all the links we plotted the links based on the for loop by using a single line plot. we aslo defined the axis for better visual of the links and given pause command to control the speed of the movement. Then we provided a frame and defined the frame to create the movie. we have used the below code in order to create the video file and save it in location.


movie(M)
videofile = VideoWriter('forward_kinematics.avi','uncompressed AVI');
open(videofile)
writeVideo(videofile,M)
close(videofile)

Error faced while programming:

1. Faced typo errors while programming
2. Faced error in video creation and saving the file

Steps taken to overcome errors:
1. corrected the typos by matlab suggestions
2. Watched the video many to time to undersatnd the errors in video creation

% Forward kinematics of a 2R robotic arm manipulator 
clear all
close all
clc

%input
L1 = 1;
L2 = 0.5;

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

ct = 1;
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 1.5 0 1.5])
pause(0.03)
M(ct) = getframe(gcf);
ct = ct+1;

  end
end

movie(M)
videofile = VideoWriter('forward_kinematics.avi','uncompressed AVI');
open(videofile)
writeVideo(videofile,M)
close(videofile)

The link for the video animation is mentioned below:

https://youtu.be/c5FB0ekljxA

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.