9
9
import matplotlib .pyplot as plt
10
10
11
11
12
- class EllipsePlot ():
13
-
14
- def __init__ (self , robot , q , etype , opt = 'trans' , centre = [0 , 0 , 0 ], scale = 1 ):
12
+ class EllipsePlot :
13
+ def __init__ (self , robot , q , etype , opt = "trans" , centre = [0 , 0 , 0 ], scale = 1 ):
15
14
16
15
super (EllipsePlot , self ).__init__ ()
17
16
@@ -21,10 +20,10 @@ def __init__(self, robot, q, etype, opt='trans', centre=[0, 0, 0], scale=1):
21
20
centre = base .getvector (centre , 2 )
22
21
centre = np .array ([centre [0 ], centre [1 ], 0 ])
23
22
except TypeError :
24
- if centre != 'ee' :
23
+ if centre != "ee" :
25
24
raise ValueError (
26
- ' Centre must be a three vector or \ ' ee\ ' meaning'
27
- 'end-effector' )
25
+ " Centre must be a three vector or 'ee' meaning" "end-effector"
26
+ )
28
27
29
28
self .ell = None
30
29
self .robot = robot
@@ -38,12 +37,12 @@ def __init__(self, robot, q, etype, opt='trans', centre=[0, 0, 0], scale=1):
38
37
else :
39
38
self .q = q
40
39
41
- if etype == 'v' :
40
+ if etype == "v" :
42
41
self .vell = True
43
- self .name = ' Velocity Ellipse'
44
- elif etype == 'f' :
42
+ self .name = " Velocity Ellipse"
43
+ elif etype == "f" :
45
44
self .vell = False
46
- self .name = ' Force Ellipse'
45
+ self .name = " Force Ellipse"
47
46
48
47
def draw (self ):
49
48
self .make_ellipsoid ()
@@ -52,33 +51,32 @@ def draw(self):
52
51
self .ax .collections .remove (self .ell )
53
52
54
53
self .ell = self .ax .plot_wireframe (
55
- self .x , self .y , self .z , rstride = 6 ,
56
- cstride = 6 , color = '#2980b9' , alpha = 0.2 )
54
+ self .x , self .y , self .z , rstride = 6 , cstride = 6 , color = "#2980b9" , alpha = 0.2
55
+ )
57
56
58
57
def draw2 (self ):
59
58
self .make_ellipsoid2 ()
60
59
61
60
if self .ell is not None :
62
61
self .ell [0 ].set_data (self .x , self .y )
63
62
else :
64
- self .ell = self .ax .plot (
65
- self .x , self .y , color = '#2980b9' )
63
+ self .ell = self .ax .plot (self .x , self .y , color = "#2980b9" )
66
64
67
65
def plot (self , ax = None ):
68
66
if ax is None :
69
67
ax = self .ax
70
-
68
+
71
69
if ax is None :
72
70
fig = plt .figure ()
73
- ax = plt .axes (projection = '3d' )
71
+ ax = plt .axes (projection = "3d" )
74
72
self .ax = ax
75
-
73
+
76
74
self .draw ()
77
75
78
76
def plot2 (self , ax = None ):
79
77
if ax is None :
80
78
ax = self .ax
81
-
79
+
82
80
if ax is None :
83
81
ax = plt .axes ()
84
82
self .ax = ax
@@ -91,18 +89,18 @@ def make_ellipsoid(self):
91
89
92
90
"""
93
91
94
- if self .opt == ' trans' :
92
+ if self .opt == " trans" :
95
93
J = self .robot .jacobe (self .q )[3 :, :]
96
94
A = J @ J .T
97
- elif self .opt == ' rot' :
95
+ elif self .opt == " rot" :
98
96
J = self .robot .jacobe (self .q )[:3 , :]
99
97
A = J @ J .T
100
98
101
99
if not self .vell :
102
100
# Do the extra step for the force ellipse
103
101
A = np .linalg .inv (A )
104
102
105
- if isinstance (self .centre , str ) and self .centre == 'ee' :
103
+ if isinstance (self .centre , str ) and self .centre == "ee" :
106
104
centre = self .robot .fkine (self .q ).t
107
105
else :
108
106
centre = self .centre
@@ -121,8 +119,9 @@ def make_ellipsoid(self):
121
119
# transform points to ellipsoid
122
120
for i in range (len (x )):
123
121
for j in range (len (x )):
124
- [x [i , j ], y [i , j ], z [i , j ]] = \
125
- np .dot ([x [i , j ], y [i , j ], z [i , j ]], rotation )
122
+ [x [i , j ], y [i , j ], z [i , j ]] = np .dot (
123
+ [x [i , j ], y [i , j ], z [i , j ]], rotation
124
+ )
126
125
127
126
self .x = x * self .scale + centre [0 ]
128
127
self .y = y * self .scale + centre [1 ]
@@ -134,13 +133,13 @@ def make_ellipsoid2(self):
134
133
135
134
"""
136
135
137
- if self .opt == ' trans' :
136
+ if self .opt == " trans" :
138
137
J = self .robot .jacob0 (self .q )[:2 , :]
139
138
A = J @ J .T
140
- elif self .opt == ' rot' :
139
+ elif self .opt == " rot" :
141
140
raise ValueError (
142
- "Can not do rotational ellipse for a 2d robot plot."
143
- " Set opt='trans'" )
141
+ "Can not do rotational ellipse for a 2d robot plot." " Set opt='trans'"
142
+ )
144
143
145
144
# if not self.vell:
146
145
# # Do the extra step for the force ellipse
@@ -149,7 +148,7 @@ def make_ellipsoid2(self):
149
148
# except:
150
149
# A = np.zeros((2,2))
151
150
152
- if isinstance (self .centre , str ) and self .centre == 'ee' :
151
+ if isinstance (self .centre , str ) and self .centre == "ee" :
153
152
centre = self .robot .fkine (self .q ).t
154
153
else :
155
154
centre = self .centre
@@ -158,7 +157,7 @@ def make_ellipsoid2(self):
158
157
theta = np .linspace (0.0 , 2.0 * np .pi , 50 )
159
158
y = np .array ([np .cos (theta ), np .sin (theta )])
160
159
# RVC2 p 602
161
- x = sp .linalg .sqrtm (A ) @ y
160
+ # x = sp.linalg.sqrtm(A) @ y
162
161
163
162
x , y = base .ellipse (A , inverted = True , centre = centre [:2 ], scale = self .scale )
164
163
self .x = x
0 commit comments