Project

2R Robotic Arm Simulator in Python

AIM: Write a program in python to simulate the forward kinematics of a 2R Robotic Arm and create a animation file of the plots.

SOLUTION:

Coding:

# Simulation of 2R robotic arm

import math
import matplotlib.pyplot as plt

# total number of theta
tot_theta=10

# starting and ending of theta
theta_start=0
theta_end=math.pi/2

# length of two robotic arm
l1=1
l2=0.5

# calculating both theta1 and theta2
theta1=[]
theta2=[]

for i in range(0,tot_theta):
	temp=theta_start + i*(theta_end-theta_start)/(tot_theta-1)
	theta1.append(temp)
	theta2.append(temp)

# calculating coordinates for two robotic arms
x0=0
y0=0

count=1

for t1 in theta1:
	for t2 in theta2:
		# link 1
		x1=l1*math.cos(t1)
		y1=l1*math.sin(t1)

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

		# creating file for saving plots
		filename=str(count)+'.png'
		count=count+1

		# plotting the coordinates
		plt.figure()
		plt.plot([x0,x1],[y0,y1])
		plt.plot([x1,x2],[y1,y2])
		plt.xlim([0,2])
		plt.ylim([0,2])

		# saving all plots
		plt.savefig(filename)

Output:

Report:

  • In this project, we create a two arm robotic simulator. This robot has two arm of different length(l1=1m and l2=0.5m).
  • Then we choose the total number of theta1 and theta2 for simulation. In this program I choose 10 values for both theta1 and theta2.
  • For each values of theta1 we get 10 values of theta2. So we get 100 combinations.
  • Then calculating the three coordinates for 100 combinations by using the below formula, first_coordinate: x0=0 and y0=0 for all the 100 combinations, second_coordinate: x1=l1*math.cos(t1) and y1=l1*math.sin(t1), thrid_coordinate: x2=x1+l2*math.cos(t2) and y2=y1+l2*math.sin(t2).
  • Here l1 and l2 be the length of arms and t1 and t2 be the theta values.
  • For 100 combinations we use for loop as shown in the program.
  • After calculating coordinates for 100 combinations, we plot all the coordinates for all 100 combinations in separate figure.
  • So we get 100 plots, finally create a animation file by using all the 100 plots.
  • In thsi project I create a gif animation file for all the 100 plots by using imgflip.com as shown in the outputs.
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.