Week 3.2 - 2R Robotic Arm Challenge
Aim: To simulate the forward kinematics of a 2R Robotic Arm.
* objective : to simulate the robotic arm
1) to know the basic coding of robotic arm, so that we make it in motion.
2) we use linspace, for loop, to represent the x and y values we use this equation, so that matlab can recognize.
x1 = l1*cosd(THETA1);
y1 = l1*sind(THETA1);
x2= x1+l2*cosd(THETA2);
y2 = y1+l2*sind(THETA2);
*code:
clear all
close all
clc
%inputs
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);
%coordinates
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)
explaination of code:
1) to make understand the to matlab, first add the input such as length of arms.
and for the values of theta using linspace command.
%inputs
l1=1;
l2=0.5;
theta1=linspace(0,90,10);
theta2=linspace(0,90,10);
2) to print theta1 of i and second loop j ,use the command for loop.
for i = 1:length(theta1)
THETA1=theta1(i);
for j = 1:length (theta2)
THETA2 = theta2(j);
3) now co ordinates the values of x and y using a simple equation.
%coordinates
x0 = 0;
y0 = 0;
x1 = l1*cosd(THETA1);
y1 = l1*sind(THETA1);
x2= x1+l2*cosd(THETA2);
y2 = y1+l2*sind(THETA2);
4) plotting the graph using plot command, adding the axis values, and making a movie using (frames, videofiles,writevideo etc). creating an avi file.
%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)
*errors while coding:
1) use plot command for better reprentation than line command. to make it animated.
and reduce the frame for better animation.
screenshot: error..

link:https://drive.google.com/file/d/1Lkp5JApIXZd4iaBf_m8broqOC3Abtgn3/view?usp=sharing