Project

forward kinematics of a 2 arm robotic arm

% forward kinematics of two arm robotic arm
clear all 
close all 
clc 

%inputs 
l1= 2;
l2=1;
theta1= linspace(0,90,10);
theta2= linspace(0,180,10);
ct=1;

%for loop
for i= 1:length(theta1)
th1= theta1(i);

for j= 1:length(theta2)
th2= theta2(j);

% co ordinates of the two arm robotic arm  
x0= 0;
y0= 0;

x1= l1*cosd(th1);
y1= l1*sind(th1);

x2= x1+ (l2*cosd(th2));
y2= y1+ (l2*sind(th2));

%plots 
figure(ct)
plot([x0 x1], [y0 y1],'linewidth',3,[x1 x2], [y1 y2],'linewidth',3)
xlabel('x axis')
ylabel('y axis')
axis([-1.5 3.5 0 3.5])
grid on 
file_text = sprintf("op%0005d.png",ct)
saveas(gca,file_text)
ct= ct+1
end
end 

Below is the link for the animated plot

https://youtu.be/hmZEo9zNtOI

The above code was programmed to animate and display the workspace of the 2 arm robotic.

The robotic arm consists of 2 links of length 2m and 1m with 180 degree of rotation for both the links. 2 for loops have been used in the code to take into account every combination of DOF that the links make with each other. For eg: when theta1=0 degrees for link 1, it forms 10 different combinations with link 2 ( theta2= 20,40,60,80,100,120,140,160,180 degree respectively). The origin of the robotic arm is taken as x0 and y0. x1 and y1 are the end co ordinates of link 1. x2 and y2 are the end co ordinates of link 2. Individual plots are generated for each combination and stitched together to generate an animation.

step-wise explanation

1. the program starts with the standard codes clear all, close all, clc.

2. inputs such as length of the links and theta (dof of rotation) of the arms are given.

3. for loop is incorporated in the program to valuate different values of theta. 4.

when i is equal to 1 to 10(length of theta1) the program enters the loop and executes the set of commands in the loop (ie theta1(i) is assigned to th1)

5. when j is eaual to 1 to 10(length of theta2) the program enters the next for loop and executes the next set of commands in the loop(ie theta(j) is assigned to th2)

6. the values of the co ordinates are then calculated using the formula mentioned in the program and a graph is plotted and saved using saveas command

7. The for loop is executed until the i and j values does not satisfy the condition mentioned for the loop.

8. A values for ct is given, which keeps on incrementing after each for loop to get different graphs for different values of theta1 and theta2

Problem that i faced was that each and every plot were not being generated with error as shown below in the snippet.

Hence I included 0005 before saving the plots with the name "output" and typed graphics_toolkit('gnuplot') in 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.