Project

Forward Kinematics of Robotic Arm

%Forward Kinematics of Robotic Arm

%Octave Program

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));
        
        
        
        plot([x0 x1],[y0 y1],[x1 x2],[y1 y2],'linewidth',3)
        axis([-0.1 1.8 0 1.8])
        pause(0.02)
        
        
        txt=sprintf('roboticarm%d.png',ct);
        saveas(gca,txt);
        ct=ct+1;
        
    end

end 
       

Code Explanation :-

%l1 is the length of first link of arm.

%l2 is the length of second link of arm.

%theta1 is the angular displacement of first link w.r.t. +x-axis.

%theta2 is the angular displacement of second link w.r.t. +x-axis.

Here, linspace command is used to get 10 equally spaced values from 0 to 90.

ct (counter) is used to get each position of links in a separate image of output.

Here, i is loop counter variable for first link and j is loop counter variable for second link.

Co-ordinates of fixed point of first link: x0,y0

Co-ordinates of end-point of first link: x1,y1

Co-ordinates of end-point of second link: x2,y2

Simple Trigonometry is applied to get x1,y1 & x2,y2.

Here, plot command is used to plot a first & second link at Pre-executed position of both.

Here, axis command is used to specify the limits of x-axis & y-axis.

First & Second element specify the lower & upper limit for x-axis.

Third & Fourth element specify the lower & upper limit for y-axis.

And, pause(0.02) indicates that execution of program is suspended for 0.02 seconds. So,that each position will be visible to us.

sprintf command is used to change the filename with every iteration. So that, overwritting of filename will not happen.

txt= sprintf('roboticarm%d.png',ct);

Here, roboticarm is the name of output file and %d is the serial number of image and ct is the variable that changes its value for every loop iteration.

ct=ct+1;

Here, value of ct for a "for loop" of second link will change from 1 to 10. And then, after the end of "for loop" of first link, value "1" will be assigning to ct.

And,this cycle will continue up to the end of the program.

saveas command is used to save all the output files(roboticarm).

Animation Video :-

https://www.youtube.com/watch?v=NtTBHehUqXQ

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.