-
-
Notifications
You must be signed in to change notification settings - Fork 584
Expand file tree
/
Copy pathtripleangledemo.py
More file actions
236 lines (178 loc) · 5.27 KB
/
Copy pathtripleangledemo.py
File metadata and controls
236 lines (178 loc) · 5.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
#!/usr/bin/env python
"""
@author Peter Corke
@author Jesse Haviland
"""
import swift
from math import pi
import roboticstoolbox as rtb
from spatialgeometry import Mesh
from spatialmath import SO3, SE3
import numpy as np
path = rtb.rtb_path_to_datafile("data")
# rotation angle sequence
sequence = "ZYX"
# compute the three rotation matrices
BASE = SE3(0, 0, 0.5)
R1 = SO3()
R2 = SO3()
R3 = SO3()
g1 = Mesh(
filename=str(path / "gimbal-ring1.stl"),
color=[34, 143, 201],
scale=(1.0 / 3,) * 3,
)
g2 = Mesh(
filename=str(path / "gimbal-ring2.stl"),
color=[31, 184, 72],
scale=(1.1 / 3,) * 3,
)
g3 = Mesh(
filename=str(path / "gimbal-ring3.stl"),
color=[240, 103, 103],
scale=(1.1**2 / 3,) * 3,
)
plane = Mesh(
filename=str(path / "spitfire_assy-gear_up.stl"),
scale=(1.0 / (180 * 3),) * 3,
color=[240, 103, 103],
)
def update_gimbals(theta, ring):
global R1, R2, R3
# update the relevant transform, depending on which ring's slider moved
def Rxyz(theta, which):
theta = np.radians(theta)
if which == "X":
return SO3.Rx(theta)
elif which == "Y":
return SO3.Ry(theta)
elif which == "Z":
return SO3.Rz(theta)
if ring == 1:
R1 = Rxyz(theta, sequence[ring - 1])
elif ring == 2:
R2 = Rxyz(theta, sequence[ring - 1])
elif ring == 3:
R3 = Rxyz(theta, sequence[ring - 1])
# figure the transforms for each gimbal and the plane, and update their
# pose
def convert(R):
return BASE * SE3.Rt(R, t=[0, 0, 0])
g3.T = convert(R1 * SO3.Ry(pi / 2))
g2.T = convert(R1 * R2 * SO3.Rz(pi / 2))
g1.T = convert(R1 * R2 * R3 * SO3.Rx(pi / 2))
plane.T = convert(R1 * R2 * R3 * SO3.Ry(pi / 2) * SO3.Rz(pi / 2))
def demo():
# TODO
# rotate the rings according to the rotation axis, so that the axles
# point the right way
# Launch the simulator Swift
env = swift.Swift()
env.launch()
print(path / "spitfire_assy-gear_up.stl")
env.add(g1)
env.add(g2)
env.add(g3)
env.add(plane)
print("Supermarine Spitfire Mk VIII by Ed Morley @GRABCAD")
print("Gimbal models by Peter Corke using OpenSCAD")
# slider call backs, invoke the central handler
def set_one(x):
update_gimbals(float(x), 1)
def set_two(x):
update_gimbals(float(x), 2)
def set_three(x):
update_gimbals(float(x), 3)
r_one = swift.Slider(
set_one, min=-180, max=180, step=1, value=0, desc="Outer gimbal", unit="°"
)
r_two = swift.Slider(
set_two, min=-180, max=180, step=1, value=0, desc="Middle gimbal", unit="°"
)
r_three = swift.Slider(
set_three,
min=-180,
max=180,
step=1,
value=0,
desc="Inner gimbal",
unit="°",
)
# buttons to set a 3-angle sequence
ZYX_button = swift.Button(
lambda x: change_sequence("ZYX"), desc="ZYX (roll-pitch-yaw angles)"
)
XYZ_button = swift.Button(
lambda x: change_sequence("XYZ"), desc="XYZ (roll-pitch-yaw angles)"
)
ZYZ_button = swift.Button(
lambda x: change_sequence("ZYZ"), desc="ZYZ (Euler angles)"
)
swift.Button(lambda x: set("ZYX"), desc="Set to Zero")
# button to reset joint angles
def reset(e):
r_one.value = 0
r_two.value = 0
r_three.value = 0
# env.step(0)
zero_button = swift.Button(reset, desc="Set to Zero")
def update_all_sliders():
update_gimbals(float(r_one.value), 1)
update_gimbals(float(r_two.value), 2)
update_gimbals(float(r_three.value), 3)
def change_sequence(new):
global sequence
xyz = "XYZ"
# update the state of the ring_axis dropdowns
ring1_axis.checked = xyz.find(new[0])
ring2_axis.checked = xyz.find(new[1])
ring3_axis.checked = xyz.find(new[2])
sequence = new
update_all_sliders()
# handle radio button on angle slider
def angle(index, ring):
global sequence
# print('angle', index, ring)
xyz = "XYZ"
s = list(sequence)
s[ring] = xyz[int(index)]
sequence = "".join(s)
update_all_sliders()
ring1_axis = swift.Radio(lambda x: angle(x, 0), options=["X", "Y", "Z"], checked=2)
ring2_axis = swift.Radio(lambda x: angle(x, 1), options=["X", "Y", "Z"], checked=1)
ring3_axis = swift.Radio(lambda x: angle(x, 2), options=["X", "Y", "Z"], checked=0)
label = swift.Label(desc="Triple angle")
# def chekked(e, el):
# nlabel = "s: "
# if e[0]:
# nlabel += "a"
# r_one.value = 0
# if e[1]:
# nlabel += "b"
# r_two.value = 0
# if e[2]:
# nlabel += "c"
# r_three.value = 0
# if e[3]:
# el.value = 1
# label.desc = nlabel
env.add(label)
env.add(r_one)
env.add(ring1_axis)
env.add(r_two)
env.add(ring2_axis)
env.add(r_three)
env.add(ring3_axis)
env.add(ZYX_button)
env.add(XYZ_button)
env.add(ZYZ_button)
env.add(zero_button)
update_gimbals(0, 1)
update_gimbals(0, 2)
update_gimbals(0, 3)
while True:
env.step(0)
def main():
demo()
if __name__ == "__main__":
main()