Project

2R Robotic Arm Simulator (Python)

2R Robotic Arm Simulator (Python)

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

2. OBJECTIVE :

  • To solve and simulate the forward kinematics of a 2R Robotic Arm.
  • To create the animation of working of a 2R Robotic Arm.

3. THEORY : A robotic arm is a robot manipulator, usually programmable, with similar functions to a human arm. The links of such a manipulator are connected by joints allowing either rotational motion (such as in an articulated robot) or translational (linear) displacement. The links of the manipulator can be considered to form a kinematic chain. The use of industrial robots is increasing in areas such as food, consumer goods, wood, plastics, and electronics, but is still mostly concentrated in the automotive industry.

fig.1: 2R Robotic Arm

In the image shown above, the robotic arm consists of 4 components -

  1. The Base, which is clamped to the surface and all other links are joined through the hinge joint.
  2. Link 1 (l1) making θ1 with horizontal.
  3. Link 2 (l2) making θ2 with horizontal.
  4. The device attached to the manipulator which interacts with its environment to perform tasks is called the end-effector.

4. PROCEDURE :

  1. For our program, we have assumed the length of link 1 and link 2 to 1 m and 0.5 m.
  2. In order to simulate the robotic arm, it is necessary to vary θ1andθ2 to obtain the desired animation and it cannot be possible if we manually enter the respective data every time. So we have created an array from 0°−90° with 10 evenly spaced points and stored θ1andθ2 as θStartandθend between them and a loop counter is initiated from 1.
  3. The coordinates of the base, i.e., is assumed to be at origin (0,0) and the initial value of θ1andθ2 array is null. Then a for loop is executed with a range of 0 to 10 and each value of the loop is temporarily stored in a separate variable.
  4. Another for loop is executed which stores each value obtained from the previous one and dumps into the trigonometric relation for simulating different values of angles and the loop counter increases by one for each iteration.
  5. For plotting graph 'plt.plot' the command is used with 'plt.figure' and 'plt.lim' to set the axis and connector in the desired way.
  6. The coordinates of endpoints of link 1 (L1) can be found by using trigonometry as,x1=l1⋅cos(θ1) and y1=l1⋅sin(θ1) .

Similarly, the coordinates of endpoint of link 2 (L2) can also be found from trigonometry as,

x2=x1+l2⋅cos(θ2) and y2=y1+l2⋅sin(θ2)

5. BODY OF CONTENT :

Code:

# A program to create simulation of 2R robotic arm manipulator
import math
import matplotlib.pyplot as plt
# Inputs
l1 = 1
l2 = 0.5
x0 = 0
y0 = 0
n_theta = 10
theta_start = 0
theta_end = math.pi/2
counter = 1

theta_1 = []
theta_2 = []

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


for T1 in theta_1:
	for T2 in theta_2:
		# Link 1 & Link 2 connector
		x1 = l1*math.cos(T1)
		y1 = l1*math.sin(T1)
		# Coordinates of manipulator
		x2 = x1 + l2*math.cos(T2)
		y2 = y1 + l2*math.sin(T2)
		filename = str(counter) + '.png'
		counter = counter + 1
		plt.figure()
		plt.plot([x0,x1],[y0,y1])
		plt.plot([x1,x2],[y1,y2])
		plt.xlim([0,3])
		plt.ylim([0,3])
		plt.savefig(filename)

6. RESULT :

Upon executing the given code, it will generate 100 plots as the program was inputted to have 10 values between 0°−90° and due to iterating it two times for two different angles. The obtained gif is as follows :

7. CONCLUSION : Animation of 2R robotic arm has been created using python and image magick animation tool.

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.