Project

To simulate the forward kinematics of 2R Robotic arm using python.

Aim: To simulate the forward kinematics of 2R Robotic arm using python.

Objective: i) Write a program to simulate forward kinematics of 2R Robotic arm.

  1. ii) To create the animation for different positions of manipulator.

Procedure:

  • First the inputs are defined like
  1. L1 =1m (Length of link 1)
  2. L2 = 0.5m (Length of link 2)
  • n_theta=10 (No. of different orientations for theta)
  1. theta_start = 0 (Starting angle of manipulator)
  2. theta_end = math.pi/2 (End angle of manipulator)
  • Creating the empty arrays for theta1 and theta2

Theta1 = []

Theta2 = []

  • For loop is created for the range(0,n_theta) and tmp variable is created.

tmp = theta_start + i*(theta_end-theta_start)/(n_theta-1)

  • The above tmp variable is appended into theta1 and theta 2 empty arrays.

Theta1.append(tmp)

Theta2.append(tmp)

  • Defining the base co-ordinates of the 2R robotic arm.

X0 = 0

Y0 = 0

  • Defining the counter variable ct = 1
  • Creating the for loop to define the co-ordinates of x1,y1

for t1 in theta1:

for t2 in theta2:

# Co-ordinates of link 1, link 2

x1 = l1*math.cos(t1)

y1 = l1*math.sin(t1)

# Co-ordinates of manipulator

x2 = x1 + l2*math.cos(t2)

y2 = y1 + l2*math.sin(t2)

  • filename = str(ct) + '.png' …….(This command is used to save the file name in .png format)
  • ct = ct+1 …….(counter variable used for generating the next image)
  • Final comments are to plot the co-ordinates defined above, and to define the xlim and ylim for the graph.
  • Animation for different positions of manipulator is done using software image magick.
  • Youtube link for the animation is https://youtu.be/RR_-MnG2EJE.

Conclusion: A practical scenario regarding the functioning of robotic arm is experienced.

Python Code:

import math
import matplotlib.pyplot as plt

# Inputs

l1=1
l2=0.5

n_theta=10

theta_start = 0
theta_end = math.pi/2

theta1 = []
theta2 = []

for i in range (0, n_theta):
tmp = theta_start + i*(theta_end-theta_start)/(n_theta-1)

theta1.append(tmp)
theta2.append(tmp)

x0 = 0
y0 = 0

ct=1

for t1 in theta1:
for t2 in theta2:

# Co-ordinates of link 1, link 2

x1 = l1*math.cos(t1)
y1 = l1*math.sin(t1)

# Co-ordinates of manipulator

x2 = x1 + l2*math.cos(t2)
y2 = y1 + l2*math.sin(t2)

filename = str(ct) + '.png'
ct=ct+1

plt.figure()
plt.plot([x0,x1],[y0,y1])
plt.plot([x1,x2],[y1,y2])
plt.xlim([0,2])
plt.ylim([0,2])
plt.savefig(filename)

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.