Week 3.2 - 2R Robotic Arm Challenge
Aim-Write a program in matlab to simulate the forward kinematics of a 2R robotic arm.
Objective-
- Simulate the forward kinematics of a 2R robotic arm
- Create an animation of the arm movements from the plots obtained in the simulation.
Procedure-
%Forward kinematics of a 2R robotic arm manipulator
clear all
close all
clc
% inputs
l1=1;
l2=0.5;
%angular range of motion of link 1 and 2
theta1=linspace(0,90,10);
theta2=linspace(0,90,10);
%l1=length of the link 1
%l2=length of the link 2
%theta1=angle between link 1 and x axis
%theta2=angle between link 2 and x axis
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)
% x axis and y axis limits
axis([-0.1 1.5 0 1.5])
pause(0.03)
M(ct)=getframe(gcf);
ct=ct+1;
end
end
% making a video of the plots
movie(M)
videofile=VideoWriter('forward_kinematics.avi','uncompressed AVI');
open(videofile)
writeVideo(videofile,M)
close(videofile)
Explanation of algorithm-
1. At the very first part, the length of link1 (arm 1) and link 2(arm 2) have been defined.
2. Create an array using linspace command to set the values of theta1 and theta2.
3. For iterating different values of the variables theta1 and theta2 use for loop.
4. provide the coordinates of the links.
5. Plot all the cordinates of the arms.
6. All figures are saved indevedually by using getframe command.
7. At the end, use movie command to create an animation of the robotic arm movement by combining all the figures and save it in .avi format.
Conclusion- In this project, the workspace and movements of the two link robotic arm has been simulated by using Matlab code.
The YouTube video link for the animation has been given below-