@@ -48,8 +48,7 @@ def two_joint_arm(GOAL_TH=0.0, theta1=0.0, theta2=0.0):
4848 except ValueError as e :
4949 print ("Unreachable goal" )
5050
51- if show_animation :
52- wrist = plot_arm (theta1 , theta2 , x , y )
51+ wrist = plot_arm (theta1 , theta2 , x , y )
5352
5453 # check goal
5554 d2goal = np .math .sqrt ((wrist [0 ] - x )** 2 + (wrist [1 ] - y )** 2 )
@@ -64,23 +63,24 @@ def plot_arm(theta1, theta2, x, y):
6463 wrist = elbow + \
6564 np .array ([l2 * np .cos (theta1 + theta2 ), l2 * np .sin (theta1 + theta2 )])
6665
67- plt .cla ()
66+ if show_animation :
67+ plt .cla ()
6868
69- plt .plot ([shoulder [0 ], elbow [0 ]], [shoulder [1 ], elbow [1 ]], 'k-' )
70- plt .plot ([elbow [0 ], wrist [0 ]], [elbow [1 ], wrist [1 ]], 'k-' )
69+ plt .plot ([shoulder [0 ], elbow [0 ]], [shoulder [1 ], elbow [1 ]], 'k-' )
70+ plt .plot ([elbow [0 ], wrist [0 ]], [elbow [1 ], wrist [1 ]], 'k-' )
7171
72- plt .plot (shoulder [0 ], shoulder [1 ], 'ro' )
73- plt .plot (elbow [0 ], elbow [1 ], 'ro' )
74- plt .plot (wrist [0 ], wrist [1 ], 'ro' )
72+ plt .plot (shoulder [0 ], shoulder [1 ], 'ro' )
73+ plt .plot (elbow [0 ], elbow [1 ], 'ro' )
74+ plt .plot (wrist [0 ], wrist [1 ], 'ro' )
7575
76- plt .plot ([wrist [0 ], x ], [wrist [1 ], y ], 'g--' )
77- plt .plot (x , y , 'g*' )
76+ plt .plot ([wrist [0 ], x ], [wrist [1 ], y ], 'g--' )
77+ plt .plot (x , y , 'g*' )
7878
79- plt .xlim (- 2 , 2 )
80- plt .ylim (- 2 , 2 )
79+ plt .xlim (- 2 , 2 )
80+ plt .ylim (- 2 , 2 )
8181
82- plt .show ()
83- plt .pause (dt )
82+ plt .show ()
83+ plt .pause (dt )
8484
8585 return wrist
8686
0 commit comments