Project

2R Robotic Arm Challenge (Python)

AIM: To simulate the forward kinematics of a 2R Robotic Arm

GOVERNING EQUATIONS:

for First Arm:

`x1 = l1*cos(theta1)`

`y1 = l1 * sin(theta1)`

For Second Arm:

`x2 = x1 + l2*cos(theta2)`

`y2 = y1 + l2*sin(theta2)`

Where,

`(x1,y1) implies` end points of First Arm

`(x2,y2) implies` end points of Second Arm

`l1` is the length of First Arm in 'm'

`l2` is the length of Second Arm in 'm'

`theta1` is the angle made by First Arm with horizontal in degree

`theta2` is the angle made by Second Arm with horizontal in degree

OBJECTIVE:

1. To write a program in Python to simulate the forward kinematics of a 2R Robotic Arm.

2. Create an animation file of the plot

PYTHON CODE:

# Forward Kinematics of a 2R Robotic Manipualator
# Importing libraries
import math
import matplotlib.pyplot as plt

# Inputs
l1 = 1
l2 = 0.5

# Thta Parameters
n_theta = 10
theta_start = 0
theta_end = math.pi/2

# Defining an empty array of Theta
theta1 = []
theta2 = []

# Generating Theta Values
for i in range(0,n_theta):
	theta = theta_start + i * (theta_end - theta_start)/(n_theta - 1)
	theta1.append(theta)
	theta2.append(theta)


# Base of the Robot
x0 = 0
y0 = 0

# Defining counter variable
ct = 1

# Statring Simulator
for t1 in theta1:
	for t2 in theta2:
		# Link 1, Link 2 connector
		x1 = l1 * math.cos(t1)
		y1 = l1 * math.sin(t1)

		# Coordinates of the Manipualtor
		x2 = x1 + l2 * math.cos(t2)
		y2 = y1 + l2 * math.sin(t2)

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

		# Plotting
		plt.figure()
		plt.plot([x0,x1],[y0,y1])
		plt.plot([x1,x2],[y1,y2])
		
		# Axis Limit
		plt.xlim([0,2])
		plt.ylim([0,2])
		
		# Axix Label
		plt.xlabel('x-axis')
		plt.ylabel('y-axis')

		# Title of the Plot
		plt.title('Forward Kinematics of a 2R Robotic Arm')
		plt.grid()

		# Saving Plots
		plt.savefig(filename)

PROCEDURE FOR CREATING ANIMATION:

I have stored all figures in a folder. After that, I have used imgflip(https://imgflip.com/gif-maker) to generate the GIF.

ANIMATION:

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.