3
3
# @author Jesse Haviland
4
4
# """
5
5
6
+ from math import pi
6
7
import roboticstoolbox as rtb
7
- import spatialmath as sm
8
+ from spatialmath import SO3 , SE3
8
9
import numpy as np
9
10
import pathlib
10
11
import os
17
18
18
19
path = pathlib .Path (path ) / 'roboticstoolbox' / 'data'
19
20
21
+
20
22
g1 = rtb .Mesh (
21
23
filename = str (path / 'gimbal-ring1.stl' ),
22
- base = sm . SE3 (0 , 0 , 1.3 ),
24
+ base = SE3 (0 , 0 , 1.3 ),
23
25
color = [34 , 143 , 201 ]
24
26
)
25
27
# g1.v = [0, 0, 0, 0.4, 0, 0]
26
28
27
29
g2 = rtb .Mesh (
28
30
filename = str (path / 'gimbal-ring2.stl' ),
29
- base = sm . SE3 (0 , 0 , 1.3 ),
31
+ base = SE3 (0 , 0 , 1.3 ),
30
32
color = [31 , 184 , 72 ]
31
33
)
32
34
# g2.v = [0, 0, 0, 0.4, 0.0, 0]
33
35
34
36
g3 = rtb .Mesh (
35
37
filename = str (path / 'gimbal-ring3.stl' ),
36
- base = sm . SE3 (0 , 0 , 1.3 ),
38
+ base = SE3 (0 , 0 , 1.3 ),
37
39
color = [240 , 103 , 103 ]
38
40
)
39
41
# g3.v = [0, 0, 0, 0.4, 0, 0]
40
42
43
+ plane = rtb .Mesh (
44
+ filename = str (path / 'spitfire_assy-gear_up.stl' ),
45
+ base = SE3 (0 , 0 , 1.3 ),
46
+ scale = (1. / 180 ,) * 3 ,
47
+ color = [240 , 103 , 103 ]
48
+ )
49
+
41
50
env .add (g1 )
42
51
env .add (g2 )
43
52
env .add (g3 )
53
+ env .add (plane )
54
+
55
+ print ('Supermarine Spitfire Mk VIII by Ed Morley @GRABCAD' )
56
+ print ('Gimbal models by Peter Corke using OpenSCAD' )
57
+
58
+ # compute the three rotation matrices
59
+
60
+ R1 = SO3 ()
61
+ R2 = SO3 ()
62
+ R3 = SO3 ()
63
+
64
+ # rotation angle sequence
65
+ sequence = "zyx"
44
66
67
+ def update_gimbals (theta , ring ):
68
+ global R1 , R2 , R3
45
69
70
+ # update the relevant transform, depending on which ring's slider moved
71
+
72
+ def Rxyz (theta , which ):
73
+ theta = np .radians (theta )
74
+ if which == 'x' :
75
+ return SO3 .Rx (theta )
76
+ elif which == 'y' :
77
+ return SO3 .Ry (theta )
78
+ elif which == 'z' :
79
+ return SO3 .Rz (theta )
80
+
81
+ if ring == 1 :
82
+ R1 = Rxyz (theta , sequence [ring - 1 ])
83
+ elif ring == 2 :
84
+ R2 = Rxyz (theta , sequence [ring - 1 ])
85
+ elif ring == 3 :
86
+ R3 = Rxyz (theta , sequence [ring - 1 ])
87
+
88
+ # figure the transforms for each gimbal and the plane, and update their
89
+ # pose
90
+
91
+ def convert (R ):
92
+ return SE3 .SO3 (R )
93
+
94
+ g3 .base = convert (R1 * SO3 .Ry (pi / 2 ))
95
+ g2 .base = convert (R1 * R2 * SO3 .Rz (pi / 2 ))
96
+ g1 .base = convert (R1 * R2 * R3 * SO3 .Rx (pi / 2 ))
97
+ plane .base = convert (R1 * R2 * R3 * SO3 .Ry (pi / 2 ) * SO3 .Rz (pi / 2 ))
98
+
99
+ # slider call backs, invoke the central handler
46
100
def set_one (x ):
47
- g1 . base = sm . SE3 ( 0 , 0 , 1.3 ) * sm . SE3 . Rz ( np . deg2rad ( float (x )) )
101
+ update_gimbals ( float (x ), 1 )
48
102
49
103
def set_two (x ):
50
- g2 . base = sm . SE3 ( 0 , 0 , 1.3 ) * sm . SE3 . Ry ( np . deg2rad ( float (x )) )
104
+ update_gimbals ( float (x ), 2 )
51
105
52
106
def set_three (x ):
53
- g3 .base = sm .SE3 (0 , 0 , 1.3 ) * sm .SE3 .Rx (np .deg2rad (float (x )))
54
- # g2.base = sm.SE3(0, 0, 1.3) * sm.SE3.Rz(np.pi/2) * sm.SE3.Ry(-np.deg2rad(float(x)))
55
- # g2.base = g3.base
107
+ update_gimbals (float (x ), 3 )
56
108
57
109
58
110
env .add_slider (
@@ -73,6 +125,10 @@ def set_three(x):
73
125
step = 1 , value = 0 ,
74
126
desc = 'Ring Three' , unit = '°' )
75
127
128
+ update_gimbals (0 , 1 )
129
+ update_gimbals (0 , 2 )
130
+ update_gimbals (0 , 3 )
131
+
76
132
while (True ):
77
133
env .process_events ()
78
134
env .step (0 )
0 commit comments