Challenge

Week 3.2 - 2R Robotic Arm Challenge

Pseudo code

Flowchart

%Forward kinematics of a 2R robotic arm 
clear all
close all
clc

%inputs

l1=1;                           %arm 1 length 
l2=0.5;                         %arm 2 length   
theta1=(0:5:90);                %Thetha 1 array 
theta2=(0:5:90);                %Thetha 2 array
Counter=1;                      %Counter to sotre frames from the for loop
%for loop
for i=1:length(theta1)          % theha 1 for loop 
   THETA_1 = theta1(i);
   for j=1:length(theta2)       % theha 2 for loop
      THETA_2 = theta2(j) ;
      
      x0=0;                     %x start cordinate l1
      y0=0;                     %y start cordinate l1
      
      x1 = l1*cosd(THETA_1);    %l1 x end coordinate or l2 x start coordinate
      y1 = l1*sind(THETA_1);    %l1 y end coordinate or l2 y start coordinate 
      
      x2 = x1+l2*cosd(THETA_2); %l2 x end coordinate
      y2 = y1+l2*sind(THETA_2); %l2 y end coordinate
      
      %plotting
      plot([x0 x1],[y0 y1],[x1 x2],[y1 y2],[x0,x1],[y0,y1],'.','MarkerSize',20,'linewidth',2) %plot variables,and size
      axis([-0.1 1.5 0 1.5])                           %plot limits
      pause(0.03)                                      %figure pause
      xlabel('x-axis')                                 %label of x axis
      ylabel('y-axis')                                 %label of y axis
      grid on                                          %add grid
      title('Robot Arm 2R Simulation','FontSize',11)   %title 
      PLOT_ANIMATION(Counter) = getframe(gcf);         %figure storage
      Counter=Counter+1;                               %counter push
   end
end
%Animation
movie(PLOT_ANIMATION) %Movie genrator
videofile = VideoWriter('WEEK_3_2_2R_ROBOTIC_ARM_KINEMATIC.avi','Uncompressed AVI'); %movie file creation
open(videofile)                                                                      %open movie 
writeVideo(videofile,PLOT_ANIMATION)                                                 %write movie file using variable
close(videofile)                                                                     %close file

movie link:

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

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.