simulate robot arm using python

Solutions on MaxInterview for simulate robot arm using python by the best coders in the world

showing results for - "simulate robot arm using python"
Leia
31 Sep 2016
1import math
2import matplotlib.pyplot as plt
3
4l1 = 0.8
5l2 = 0.5
6
7n_theta = 10 # No of divisions
8theta_start = 0 # Starting angle
9theta_end = math.pi/2 # Ending angle
10theta1 = []
11theta2 = []
12
13for i in range(0,n_theta):
14   theta1.append(theta_start+ (theta_end-theta_start)*i/(n_theta-1)) # Angles of link 1
15   theta2.append(theta_start+ (theta_end-theta_start)*i/(n_theta-1)) # Angles of link 2
16
17# Base posotion 
18x0 = 0 # Base position
19y0 = 0 # Base position
20ct = 1 # Counter
21
22# Link 1 end point
23for t1 in theta1:
24	
25	x1 = l1*math.cos(t1) # End of link 1
26	y1 = l1*math.sin(t1) # End of link 1
27	for t2 in theta2:
28		
29		x2 = x1+l2*math.cos(t2) # End of link 2
30		y2 = y1+l2*math.sin(t2) # End of link 2
31
32		filename = str(ct) + '.png'
33		ct = ct+1
34		plt.figure()
35		plt.plot([x0,x1],[y0,y1])
36		plt.plot([x1,x2],[y1,y2])
37		plt.xlim([-1,2])
38		plt.ylim([-1,2])
39		plt.savefig(filename)