Challenge

Week 2- 2R Robotic Arm Challenge

Aim = Programme to simulate the forward kinematics of 2R robotic arm

  • create an animation file on plot and uploading animation

Theory =

  1. Step wise explanation of code
  • firstly we need to give inputs i.e. values of l1 & l2 , theta1 & theta2.
  • now we get 3 coordinates from the fig and the derivation where the base of the robot is (x0 y0).
  • now the end point of link 1 are (x1 y1) and finally the end point of link 2 are (x2 y2).
  • here by deriving formulae we can write code as mentioned in code.
  • now we need to plot the graph for both robotic arm.
  • here we need to make animation of these robotic arm with different values of theta1 and theta2
  • here we need to use linspace command for values of theta 1 and theta 2.
  • now we need to use function of for loop for values of theta1 & theta2
  • here again we need to plot the graph for new code with using function of linewidth
  • use function of counter for as each time for loop is executed there increase value of counter (ct) = ct+1
  • as now we execute our programme we get plots overwritten so now we use the command hold on to not overwritten plots
  • now we will use pause(0.3)
  • now accounding to thetaa1 values of theta2 changes
  • now we need to fix the axis so changwe x limits and y limits
  • now we need to make Movie of code so we use frame command (getframe(_))
  • now we need to make videofile using command videofile
  • now the lastcommand use is close(videofile)

Errors faced during programme and steps to slove it =

Not able to use values of theta1 & theta2 as we need to use there for loop

  • i = 1:length(theta1)
THETA1 = theta1(i)
  • i am getting link2 moving in wrong direction because in for loop for function of (j) i was using (i)
  • getting error in counter function showing that unrecognized function because the input of ct = 1 i forgot to give
    all programme was running but video .avi file was not saving in folder location so i did 1 on 1 session with technical support engineer and he helped me to solve mistake i was doingthat i had to put videowriter over there i need to put W capital but i was putting w over there but after session i ressolveddd my mistake.


    Results =

    i did simulation on 2R robotic arm and also able to create video file for that.

    link for vieo file is as below =

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);
    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.3)

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)
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.