Commit | Line | Data |
---|---|---|
1ecdb44a MS |
1 | /** |
2 | * DOUBLE BLACK DIAMOND DOUBLE BLACK DIAMOND | |
3 | * | |
4 | * //\\ //\\ //\\ //\\ | |
5 | * ///\\\ ///\\\ ///\\\ ///\\\ | |
6 | * \\\/// \\\/// \\\/// \\\/// | |
7 | * \\// \\// \\// \\// | |
8 | * | |
9 | * EXPERTS ONLY!! EXPERTS ONLY!! | |
10 | * | |
186bc4d3 | 11 | * This file implements the mapping functions needed to lay out the physical |
1ecdb44a MS |
12 | * cubes and the output ports on the panda board. It should only be modified |
13 | * when physical changes or tuning is being done to the structure. | |
14 | */ | |
45f43cc2 | 15 | |
46fc29d4 MS |
16 | class TowerMapping { |
17 | public final float x, y, z; | |
18 | public final float[][] cubePositions; | |
19 | ||
20 | TowerMapping(float x, float y, float z, float[][] cubePositions) { | |
21 | this.x = x; | |
22 | this.y = y; | |
23 | this.z = z; | |
24 | this.cubePositions = cubePositions; | |
25 | } | |
26 | } | |
27 | ||
186bc4d3 | 28 | public Model buildModel() { |
46fc29d4 MS |
29 | // The model is represented as an array of towers. The cubes in the tower |
30 | // are represenented relatively. Each tower has an x, y, z reference position, | |
31 | // which is typically the base cube's bottom left corner. | |
32 | // | |
33 | // Following that is an array of floats. A 2-d array contains an x-offset | |
34 | // and a z-offset from the reference position. Typically the first cube | |
35 | // will just be {0, 0}. | |
36 | // | |
37 | // A 3-d array contains an x-offset, a z-offset, and a rotation about the | |
38 | // y-axis. | |
39 | // | |
40 | // The cubes automatically increment their y-position by Cube.EDGE_HEIGHT. | |
03c7b35a MS |
41 | |
42 | final float STACKED_RELATIVE = 1; | |
43 | final float STACKED_REL_SPIN = 2; | |
92c06c97 | 44 | final float BASS_DEPTH = BassBox.EDGE_DEPTH + 4; |
03c7b35a | 45 | |
46fc29d4 | 46 | TowerMapping[] mapping = new TowerMapping[] { |
92c06c97 | 47 | |
e76480d4 MS |
48 | // Front left cubes |
49 | // new TowerMapping(0, 0, 0, new float[][] { | |
50 | // {STACKED_RELATIVE, 0, 0}, | |
51 | // {STACKED_RELATIVE, 5, -10, 20}, | |
52 | // {STACKED_RELATIVE, 0, -6}, | |
53 | // {STACKED_RELATIVE, -5, -2, -20}, | |
54 | // }), | |
55 | // | |
56 | // new TowerMapping(Cube.EDGE_WIDTH + 2, 0, 0, new float[][] { | |
57 | // {STACKED_RELATIVE, 0, 0}, | |
58 | // {STACKED_RELATIVE, 0, 5, 10}, | |
59 | // {STACKED_RELATIVE, 0, 2, 20}, | |
60 | // {STACKED_RELATIVE, 0, 0, 30}, | |
61 | // }), | |
46fc29d4 MS |
62 | |
63 | // Back Cubes behind DJ platform (in order of increasing x) | |
64 | new TowerMapping(50, 5, BASS_DEPTH, new float[][] { | |
03c7b35a MS |
65 | {STACKED_RELATIVE, 0, 0}, |
66 | {STACKED_RELATIVE, 2, 0, 20}, | |
67 | {STACKED_RELATIVE, -2, 10}, | |
68 | {STACKED_RELATIVE, -5, 15, -20}, | |
69 | {STACKED_RELATIVE, -2, 13}, | |
46fc29d4 MS |
70 | }), |
71 | ||
72 | new TowerMapping(79, 5, BASS_DEPTH, new float[][] { | |
03c7b35a MS |
73 | {STACKED_RELATIVE, 0, 0}, |
74 | {STACKED_RELATIVE, 2, 0, 20}, | |
75 | {STACKED_RELATIVE, 4, 10}, | |
76 | {STACKED_RELATIVE, 2, 15, -20}, | |
77 | {STACKED_RELATIVE, 0, 13}, | |
46fc29d4 MS |
78 | }), |
79 | ||
80 | new TowerMapping(107, 5, BASS_DEPTH, new float[][] { | |
03c7b35a MS |
81 | {STACKED_RELATIVE, 0, 0}, |
82 | {STACKED_RELATIVE, 4, 0, 20}, | |
83 | {STACKED_RELATIVE, 6, 10}, | |
84 | {STACKED_RELATIVE, 3, 15, -20}, | |
85 | // {STACKED_RELATIVE, 8, 13}, | |
46fc29d4 MS |
86 | }), |
87 | ||
88 | new TowerMapping(133, 5, BASS_DEPTH, new float[][] { | |
03c7b35a MS |
89 | {STACKED_RELATIVE, 0, 0}, |
90 | {STACKED_RELATIVE, -2, 0, 20}, | |
91 | {STACKED_RELATIVE, 0, 10}, | |
92 | {STACKED_RELATIVE, 2, 15, -20}, | |
93 | // {STACKED_RELATIVE, 4, 13} | |
46fc29d4 MS |
94 | }), |
95 | ||
96 | new TowerMapping(165, 5, BASS_DEPTH, new float[][] { | |
03c7b35a MS |
97 | {STACKED_RELATIVE, 0, 0}, |
98 | {STACKED_RELATIVE, -1, 20}, | |
99 | {STACKED_RELATIVE, 2, 10}, | |
100 | {STACKED_RELATIVE, -2, 15, -20}, | |
101 | {STACKED_RELATIVE, 3, 13}, | |
46fc29d4 MS |
102 | }), |
103 | ||
104 | // front DJ cubes | |
39011e7e | 105 | new TowerMapping((TRAILER_WIDTH - BassBox.EDGE_WIDTH)/2, BassBox.EDGE_HEIGHT + BoothFloor.PLEXI_WIDTH, 10, new float[][] { |
03c7b35a MS |
106 | {STACKED_RELATIVE, 0, 0}, |
107 | {STACKED_RELATIVE, 0, -10, 20}, | |
46fc29d4 MS |
108 | }), |
109 | ||
39011e7e | 110 | new TowerMapping((TRAILER_WIDTH - BassBox.EDGE_WIDTH)/2 + Cube.EDGE_HEIGHT, BassBox.EDGE_HEIGHT + BoothFloor.PLEXI_WIDTH, 10, new float[][] { |
03c7b35a MS |
111 | {STACKED_RELATIVE, 3, 0}, |
112 | {STACKED_RELATIVE, 2, -10, 20}, | |
46fc29d4 MS |
113 | }), |
114 | ||
39011e7e | 115 | new TowerMapping((TRAILER_WIDTH - BassBox.EDGE_WIDTH)/2 + 2*Cube.EDGE_HEIGHT + 5, BassBox.EDGE_HEIGHT + BoothFloor.PLEXI_WIDTH, 10, new float[][] { |
03c7b35a MS |
116 | {STACKED_RELATIVE, 0, 0}, |
117 | {STACKED_RELATIVE, 1, 0, 10}, | |
46fc29d4 MS |
118 | }), |
119 | ||
39011e7e | 120 | new TowerMapping((TRAILER_WIDTH - BassBox.EDGE_WIDTH)/2 + 3*Cube.EDGE_HEIGHT + 9, BassBox.EDGE_HEIGHT + BoothFloor.PLEXI_WIDTH, 10, new float[][] { |
03c7b35a MS |
121 | {STACKED_RELATIVE, 0, 0}, |
122 | {STACKED_RELATIVE, -1, 0}, | |
46fc29d4 MS |
123 | }), |
124 | ||
39011e7e | 125 | new TowerMapping((TRAILER_WIDTH - BassBox.EDGE_WIDTH)/2 + 4*Cube.EDGE_HEIGHT + 15, BassBox.EDGE_HEIGHT + BoothFloor.PLEXI_WIDTH, 10, new float[][] { |
03c7b35a MS |
126 | {STACKED_RELATIVE, 0, 0}, |
127 | {STACKED_RELATIVE, -1, 0}, | |
46fc29d4 MS |
128 | }), |
129 | ||
130 | // left dj cubes | |
39011e7e | 131 | new TowerMapping((TRAILER_WIDTH - BassBox.EDGE_WIDTH)/2, BassBox.EDGE_HEIGHT + BoothFloor.PLEXI_WIDTH, Cube.EDGE_HEIGHT + 2, new float[][] { |
03c7b35a MS |
132 | {STACKED_RELATIVE, 0, 0}, |
133 | {STACKED_RELATIVE, 0, 2, 20}, | |
46fc29d4 MS |
134 | }), |
135 | ||
39011e7e | 136 | new TowerMapping((TRAILER_WIDTH - BassBox.EDGE_WIDTH)/2, BassBox.EDGE_HEIGHT + BoothFloor.PLEXI_WIDTH, 2*Cube.EDGE_HEIGHT + 4, new float[][] { |
03c7b35a MS |
137 | {STACKED_RELATIVE, 0, 0}, |
138 | {STACKED_RELATIVE, 0, 2, 20}, | |
46fc29d4 MS |
139 | }), |
140 | ||
141 | // right dj cubes | |
39011e7e | 142 | new TowerMapping((TRAILER_WIDTH - BassBox.EDGE_WIDTH)/2 + 4*Cube.EDGE_HEIGHT + 15, BassBox.EDGE_HEIGHT + BoothFloor.PLEXI_WIDTH, Cube.EDGE_HEIGHT + 2, new float[][] { |
03c7b35a MS |
143 | {STACKED_RELATIVE, 0, 0}, |
144 | {STACKED_RELATIVE, 0, 2, 20}, | |
46fc29d4 MS |
145 | }), |
146 | ||
39011e7e | 147 | new TowerMapping((TRAILER_WIDTH - BassBox.EDGE_WIDTH)/2 + 4*Cube.EDGE_HEIGHT + 15, BassBox.EDGE_HEIGHT + BoothFloor.PLEXI_WIDTH, 2*Cube.EDGE_HEIGHT + 4, new float[][] { |
03c7b35a MS |
148 | {STACKED_RELATIVE, 0, 0}, |
149 | {STACKED_RELATIVE, 0, 2, 20}, | |
46fc29d4 | 150 | }), |
186bc4d3 | 151 | |
e76480d4 MS |
152 | // new TowerMapping(200, 0, 0, new float[][] { |
153 | // {STACKED_RELATIVE, 0, 10}, | |
154 | // {STACKED_RELATIVE, 5, 0, 20}, | |
155 | // {STACKED_RELATIVE, 0, 4}, | |
156 | // {STACKED_RELATIVE, -5, 8, -20}, | |
157 | // {STACKED_RELATIVE, 0, 3}, | |
158 | // }), | |
46fc29d4 | 159 | |
e76480d4 MS |
160 | // new TowerMapping(0, 0, Cube.EDGE_HEIGHT + 10, new float[][] { |
161 | // {STACKED_RELATIVE, 10, 0, 40}, | |
162 | // {STACKED_RELATIVE, 3, -2, 20}, | |
163 | // {STACKED_RELATIVE, 0, 0, 40}, | |
164 | // {STACKED_RELATIVE, 0, 0, 60}, | |
165 | // {STACKED_RELATIVE, 0, 0, 40}, | |
166 | // }), | |
46fc29d4 MS |
167 | |
168 | new TowerMapping(20, 0, 2*Cube.EDGE_HEIGHT + 18, new float[][] { | |
03c7b35a MS |
169 | {STACKED_RELATIVE, 0, 0, 40}, |
170 | {STACKED_RELATIVE, 10, 0, 20}, | |
171 | {STACKED_RELATIVE, 5, 0, 40}, | |
172 | {STACKED_RELATIVE, 10, 0, 60}, | |
173 | {STACKED_RELATIVE, 12, 0, 40}, | |
46fc29d4 MS |
174 | }), |
175 | ||
e76480d4 MS |
176 | // new TowerMapping(210, 0, Cube.EDGE_HEIGHT + 15, new float[][] { |
177 | // {STACKED_RELATIVE, 0, 0, 40}, | |
178 | // {STACKED_RELATIVE, 5, 0, 20}, | |
179 | // {STACKED_RELATIVE, 8, 0, 40}, | |
180 | // {STACKED_RELATIVE, 3, 0, 60}, | |
181 | // {STACKED_RELATIVE, 0, 0, 40}, | |
182 | // }), | |
46fc29d4 MS |
183 | |
184 | new TowerMapping(210, 0, 2*Cube.EDGE_HEIGHT + 25, new float[][] { | |
03c7b35a MS |
185 | {STACKED_RELATIVE, 0, 0, 40}, |
186 | {STACKED_RELATIVE, 5, 0, 20}, | |
187 | {STACKED_RELATIVE, 2, 0, 40}, | |
188 | {STACKED_RELATIVE, 5, 0, 60}, | |
189 | {STACKED_RELATIVE, 0, 0, 40}, | |
46fc29d4 MS |
190 | }), |
191 | ||
192 | }; | |
51d0d59a | 193 | |
46fc29d4 MS |
194 | ArrayList<Tower> towerList = new ArrayList<Tower>(); |
195 | ArrayList<Cube> tower; | |
196 | Cube[] cubes = new Cube[79]; | |
197 | int cubeIndex = 1; | |
03c7b35a | 198 | float tx, ty, tz, px, pz, ny, dx, dz, ry; |
46fc29d4 MS |
199 | for (TowerMapping tm : mapping) { |
200 | tower = new ArrayList<Cube>(); | |
03c7b35a MS |
201 | px = tx = tm.x; |
202 | ny = ty = tm.y; | |
203 | pz = tz = tm.z; | |
204 | int ti = 0; | |
46fc29d4 | 205 | for (float[] cp : tm.cubePositions) { |
03c7b35a MS |
206 | float mode = cp[0]; |
207 | if (mode == STACKED_RELATIVE) { | |
208 | dx = cp[1]; | |
209 | dz = cp[2]; | |
210 | ry = (cp.length >= 4) ? cp[3] : 0; | |
211 | tower.add(cubes[cubeIndex++] = new Cube(px = tx + dx, ny, pz = tz + dz, 0, ry, 0)); | |
212 | ny += Cube.EDGE_HEIGHT; | |
213 | } else if (mode == STACKED_REL_SPIN) { | |
214 | // Same as above but the front left of this cube is actually its back right for wiring | |
215 | // TODO(mcslee): implement this | |
216 | } | |
46fc29d4 MS |
217 | } |
218 | towerList.add(new Tower(tower)); | |
219 | } | |
92c06c97 MS |
220 | |
221 | BassBox bassBox = new BassBox(56, 0, 2); | |
e76480d4 MS |
222 | |
223 | List<Speaker> speakers = new ArrayList<Speaker>(); | |
254fbb68 | 224 | speakers.add(new Speaker(-12, 6, 0, 15)); |
e76480d4 MS |
225 | speakers.add(new Speaker(TRAILER_WIDTH - Speaker.EDGE_WIDTH, 6, 6, -15)); |
226 | ||
227 | return new Model(towerList, cubes, bassBox, speakers); | |
186bc4d3 | 228 | } |
e73ef85d | 229 | |
186bc4d3 MS |
230 | public PandaMapping[] buildPandaList() { |
231 | return new PandaMapping[] { | |
232 | new PandaMapping( | |
84086fa3 MS |
233 | "10.200.1.28", new ChannelMapping[] { |
234 | new ChannelMapping(ChannelMapping.MODE_BASS), | |
235 | new ChannelMapping(ChannelMapping.MODE_FLOOR), | |
236 | new ChannelMapping(ChannelMapping.MODE_SPEAKER, 0), | |
237 | new ChannelMapping(ChannelMapping.MODE_SPEAKER, 1), | |
238 | new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 1, 2, 3, 4 }), | |
239 | new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 5, 6, 7, 8 }), | |
240 | new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 9, 10, 11, 12 }), | |
241 | new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 13, 14, 15, 16 }), | |
186bc4d3 | 242 | }), |
45f43cc2 | 243 | |
186bc4d3 | 244 | new PandaMapping( |
84086fa3 MS |
245 | "10.200.1.29", new ChannelMapping[] { |
246 | new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 17, 18, 19, 20 }), | |
247 | new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 21, 22, 23, 24 }), | |
248 | new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 25, 26, 27, 28 }), | |
249 | new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 29, 30, 31, 32 }), | |
250 | new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 33, 34, 35, 36 }), | |
251 | new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 37, 38, 39, 40 }), | |
252 | new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 41, 42, 43, 44 }), | |
253 | new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 45, 46, 47, 48 }), | |
186bc4d3 | 254 | }), |
186bc4d3 | 255 | }; |
45f43cc2 | 256 | } |
e73ef85d | 257 | |
a922e963 MS |
258 | /** |
259 | * Each panda board has an IP address and a fixed number of channels. The channels | |
260 | * each have a fixed number of pixels on them. Whether or not that many physical | |
261 | * pixels are connected to the channel, we still send it that much data. | |
262 | */ | |
45f43cc2 MS |
263 | class PandaMapping { |
264 | ||
045b432d MS |
265 | // How many channels are on the panda board |
266 | public final static int CHANNELS_PER_BOARD = 8; | |
267 | ||
44b8de9c | 268 | // How many total pixels on the whole board |
84086fa3 | 269 | public final static int PIXELS_PER_BOARD = ChannelMapping.PIXELS_PER_CHANNEL * CHANNELS_PER_BOARD; |
44b8de9c | 270 | |
45f43cc2 | 271 | final String ip; |
84086fa3 | 272 | final ChannelMapping[] channelList = new ChannelMapping[CHANNELS_PER_BOARD]; |
45f43cc2 | 273 | |
84086fa3 | 274 | PandaMapping(String ip, ChannelMapping[] rawChannelList) { |
45f43cc2 | 275 | this.ip = ip; |
a922e963 MS |
276 | |
277 | // Ensure our array is the right length and has all valid items in it | |
84086fa3 MS |
278 | for (int i = 0; i < channelList.length; ++i) { |
279 | channelList[i] = (i < rawChannelList.length) ? rawChannelList[i] : new ChannelMapping(); | |
a922e963 MS |
280 | if (channelList[i] == null) { |
281 | channelList[i] = new ChannelMapping(); | |
282 | } | |
045b432d | 283 | } |
e73ef85d | 284 | } |
1ecdb44a MS |
285 | } |
286 | ||
a922e963 MS |
287 | /** |
288 | * Each channel on a pandaboard can be mapped in a number of modes. The typial is | |
289 | * to a series of connected cubes, but we also have special mappings for the bass box, | |
290 | * the speaker enclosures, and the DJ booth floor. | |
291 | * | |
292 | * This class is just the mapping meta-data. It sanitizes the input to make sure | |
293 | * that the cubes and objects being referenced actually exist in the model. | |
294 | * | |
295 | * The logic for how to encode the pixels is contained in the PandaDriver. | |
296 | */ | |
84086fa3 MS |
297 | class ChannelMapping { |
298 | ||
299 | // How many cubes per channel xc_PB is configured for | |
300 | public final static int CUBES_PER_CHANNEL = 4; | |
45f43cc2 | 301 | |
84086fa3 MS |
302 | // How many total pixels on each channel |
303 | public final static int PIXELS_PER_CHANNEL = Cube.POINTS_PER_CUBE * CUBES_PER_CHANNEL; | |
304 | ||
305 | public static final int MODE_NULL = 0; | |
306 | public static final int MODE_CUBES = 1; | |
307 | public static final int MODE_BASS = 2; | |
308 | public static final int MODE_SPEAKER = 3; | |
309 | public static final int MODE_FLOOR = 4; | |
310 | public static final int MODE_INVALID = 5; | |
311 | ||
312 | public static final int NO_OBJECT = -1; | |
313 | ||
314 | final int mode; | |
315 | final int[] objectIndices = new int[CUBES_PER_CHANNEL]; | |
316 | ||
317 | ChannelMapping() { | |
318 | this(MODE_NULL); | |
319 | } | |
320 | ||
321 | ChannelMapping(int mode) { | |
322 | this(mode, new int[]{}); | |
323 | } | |
324 | ||
325 | ChannelMapping(int mode, int rawObjectIndex) { | |
326 | this(mode, new int[]{ rawObjectIndex }); | |
327 | } | |
328 | ||
329 | ChannelMapping(int mode, int[] rawObjectIndices) { | |
330 | if (mode < 0 || mode >= MODE_INVALID) { | |
331 | throw new RuntimeException("Invalid channel mapping mode: " + mode); | |
332 | } | |
333 | if (mode == MODE_SPEAKER) { | |
334 | if (rawObjectIndices.length != 1) { | |
335 | throw new RuntimeException("Speaker channel mapping mode must specify one speaker index"); | |
336 | } | |
337 | int speakerIndex = rawObjectIndices[0]; | |
338 | if (speakerIndex < 0 || speakerIndex >= glucose.model.speakers.size()) { | |
339 | throw new RuntimeException("Invalid speaker channel mapping: " + speakerIndex); | |
340 | } | |
341 | } else if ((mode == MODE_FLOOR) || (mode == MODE_BASS) || (mode == MODE_NULL)) { | |
342 | if (rawObjectIndices.length > 0) { | |
343 | throw new RuntimeException("Bass/floor/null mappings cannot specify object indices"); | |
344 | } | |
345 | } else if (mode == MODE_CUBES) { | |
346 | for (int rawCubeIndex : rawObjectIndices) { | |
347 | if (glucose.model.getCubeByRawIndex(rawCubeIndex) == null) { | |
348 | throw new RuntimeException("Non-existing cube specified in cube mapping: " + rawCubeIndex); | |
349 | } | |
350 | } | |
351 | } | |
352 | ||
353 | this.mode = mode; | |
354 | for (int i = 0; i < objectIndices.length; ++i) { | |
355 | objectIndices[i] = (i < rawObjectIndices.length) ? rawObjectIndices[i] : NO_OBJECT; | |
356 | } | |
357 | } | |
358 | } | |
a922e963 | 359 |