2D Robotic Arm by Matlab
Aim
Write a program in Matlab to simulate the forward kinematics of a 2R Robotic Arm and Create an animation file of the plot.
THEORY
To control the movements of arm of robot, I control the angle between arm with x-axis. To achieve this I use the coordinate system and trignometric equations.
Objective
The objective of this progam is to control the movement of manipulator of the robot so that we can perform our desire task.
BODY
CODES
- phi1 and phi2=angle between link 1 with horizontal and angle between link 2 with horizontal respectively.
- l1 and l2=arm 1 and arm2 respectively
clear all; close all; clc; %input phi1=linspace(0,90,10); phi2=linspace(0,90,10); %origin x0=0; y0=0; %length of links l1=1.5; l2=1; a=1; for i=1:length(phi1)%this loop is for first link rotation x1=l1*cosd(phi1(i)); y1=l1*sind(phi1(i)); for j=1:length(phi2)%this loop is for second link rotation x2=x1+l2*cosd(phi2(j)); y2=y1+l2*sind(phi2(j)); %Plotting of links plot([x0 x1],[y0 y1],[x1 x2],[y1 y2],'LineWidth',3); axis([-0.1 2.5 0 2.5]) pause(0.03) A(a)=getframe(gcf); a=a+1; end end %Animation movie(A); vf=VideoWriter('forward_kinematics.avi','Uncompressed AVI'); open(vf) writeVideo(vf,A) close(vf)
OUTPUT
Video link-https://www.youtube.com/watch?v=rOeDXVj_2qM
EXPLANATION
First I create variables called phi for angle of rotation of two arms.Then after fixing my origin of my first arm, I use the trignometric function to find out end point of first arm. NOw, using this as origin for my second arm I use again trignometry to find out location of manipulator.
For Animation, I use FOR Loop. First FOR Loop is for first arm so when first loop executed then our first arm rotate with certain angle and then I use second Loop inside first loop for second arm. So, when this loop executed then at same position of first arm, the second arm rotates. The rotation can be shown with the help of PLOT function.Now when first plot is done then I store that figure in variable called A.
After ending loop, I got different figures in my array A. I use movie function and videowriter to make video of program.