Project

Week - 1.3 2R Robotic Arm Simulator

Simulation of Forward Kinematics of A 2R Robotic Arm

Aim: -

Write a program in python to simulate the forward kinematics of a 2R Robotic Arm, as shown in the video.

Procedure: -

  1. Define all the inputs variables in the editor workspace like theta values, lengths of links. l1=1m, l2 = 0.5m, theta1 = 0-600, theta2 = 0 to 600. with 10, 10 divisions respectively
  2. Extract each combination from theta1, theta2.
  3. Start with combination 1 from theta1 and theta 2
  4. Solve the equations to find the starting and ending coordinates of each link1,2.
  5. Plot the results, define axis ranges, pause the frame for every 0.02 seconds.
  6. Save the individual frame.
  7. Increment the combination number by 1, solve to get various coordinates of links for different combinations.
  8. use image magic to stitch all the images together to form a gif file.

Code:-

# Robotic Arm Simulator Program

import math                         # importing math library
import matplotlib.pyplot as plt     # importing ploting library  
 
#inputs
L_1 = 1.0    # length of first Arm
L_2 = 0.5    # length of second Arm

# Velocity vs Drag force
n    = 10           # number of positions for each arm
theta_start  = 0    # starting angle
theta_end    = math.pi/3  # endinging angle
theta_1 = []
theta_2 = []
# combination table for theta 1,2
for i in range(0,n):               
	theta = theta_start+i*(theta_end-theta_start)/(n-1)
	theta_1.append(theta)
	theta_2.append(theta)
# fixed point
x0 = 0
y0 = 0
ct = 1

for t1 in theta_1:           
	# ending position of first Arm & starting position of second arm 
	x1 = L_1 *math.cos(t1)
	y1 = L_1 *math.sin(t1)
	
	for t2 in theta_2:
		# ending position of second Arm
		x2 = x1 + L_2 *math.cos(t2)
		y2 = y1 + L_2 *math.sin(t2)

		figure = str(ct) + '.png'
		ct = ct + 1
		# creating and saving of plot as image 
		plt.figure()
		plt.plot([x0, x1],[y0, y1])
		plt.plot([x1, x2],[y1, y2])
		plt.xlabel('X position')   
		plt.ylabel('Y position')  
		plt.axis([-0.1, 1.5, -0.1, 1.5])
		plt.title('Robotic arm motion')
		plt.grid('on')
		plt.savefig(figure)

Gif:-

https://drive.google.com/file/d/1GVIofor7nIe1AUfS8RcJeWoi_67dqgXE/view?usp=sharing

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.