Challenge

Week 2- 2R Robotic Arm Challenge

A Program to simulate the forward kinematics of a 2R Robotic Arm.

This code simulates the forward kinematic motion of a 2R robotic arm.

The input given are:

  • Length of robotic arm 1 = 0.5m
  • Length of robotic arm 2 = 0.5m
  • Angle of rotation of the robotic arm 1 = 90 degrees
  • Angle of rotation of the robotic arm 2 = 90 degrees
  • The code takes in the inputs and by using the below formulas, calculates the position of the arms

The First Arm :

  • x1 = l1*cosd(THETA1)
    y1 = l1*sind(THETA1)

The Second Arm :

  • x2 = x1 + l2*cosd(THETA2)
    y2 = y1 + l2*sind(THETA2)
  • Through this we get the different combination of the first and second arms position in 2d.
  • The code changes the position of each arm from 0-90 degrees with total intervals being 10 giving a total combination of 100 different position.
  • This combinations are saved as 100 seprate png's and then are made a video using a external application(since i was using octave).
close all
clear all
clc

%Program to simulate the forward kinematics of a 2R robotic arm 

%inputs

%length of the robotic arm in m
l1 = 0.5
l2 = 0.5

%angle of rotation of the robotic arm
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 of endpoints of the arms
      x0 = 0;
      y0 = 0;
    
      x1 = l1*cosd(THETA1);
      y1 = l1*sind(THETA1);
    
      x2 = x1 + l2*cosd(THETA2);
      y2 = y1 + l2*sind(THETA2);
    
      %plot of forward kinematics of a 2R robotic arm
      plot([x0,x1],[y0,y1],[x1,x2],[y1,y2],'linewidth',3)
      axis([-0.01 1.5 0 1.4])
      file_name=sprintf("output%05d.png",ct)
      saveas (gca,file_name)
      ct =ct+1;
    end
end  
  • Link for the animation on Youtube:

https://youtu.be/fop8j8lz5rA

Difficulties/errors faced during the coding phase:

The biggest problem faced while programing was since i was using Octave the program didn't make a video file because the of the unusability of the function "getframe" in Octave.

The problem was solved when i asked for help from the Sir Sai Krishna through a one on one session, through sir's guidance i learnt how to make a gif of all the pictures using the application ImageMagick through command prompt using a silightly changed code .

Some other error i made:

Invalid value for double property "linewidth" .

I solved this by making changes to code.

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.