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 | |
f0cc0ba5 MS |
16 | public Model buildModel() { |
17 | ||
f0cc0ba5 MS |
18 | // Shorthand helpers for specifying wiring more quickly |
19 | final Cube.Wiring WFL = Cube.Wiring.FRONT_LEFT; | |
20 | final Cube.Wiring WFR = Cube.Wiring.FRONT_RIGHT; | |
21 | final Cube.Wiring WRL = Cube.Wiring.REAR_LEFT; | |
22 | final Cube.Wiring WRR = Cube.Wiring.REAR_RIGHT; | |
95c50032 | 23 | |
a3ccf23a | 24 | // Utility value if you need the height of a cube shorthand |
95c50032 | 25 | final float CH = Cube.EDGE_HEIGHT; |
73687629 | 26 | final float CW = Cube.EDGE_WIDTH ; |
ae579223 | 27 | |
a3ccf23a | 28 | // Positions for the bass box |
ae579223 MS |
29 | final float BBY = BassBox.EDGE_HEIGHT + BoothFloor.PLEXI_WIDTH; |
30 | final float BBX = 56; | |
31 | final float BBZ = 2; | |
32 | ||
46fc29d4 MS |
33 | // The model is represented as an array of towers. The cubes in the tower |
34 | // are represenented relatively. Each tower has an x, y, z reference position, | |
35 | // which is typically the base cube's bottom left corner. | |
36 | // | |
37 | // Following that is an array of floats. A 2-d array contains an x-offset | |
f0cc0ba5 MS |
38 | // and a z-offset from the previous reference position. Typically the first cube |
39 | // will just be {0, 0}. Each successive cube uses the position of the previous | |
40 | // cube as its reference. | |
46fc29d4 MS |
41 | // |
42 | // A 3-d array contains an x-offset, a z-offset, and a rotation about the | |
43 | // y-axis. | |
44 | // | |
45 | // The cubes automatically increment their y-position by Cube.EDGE_HEIGHT. | |
e27a8652 | 46 | |
73687629 | 47 | // To-Do: (Mark Slee, Alex Green, or Ben Morrow): The Cube # is determined by the order in this list. |
48 | // "raw object index" is serialized by running through towermapping and then individual cube mapping below. | |
49 | // We can do better than this. The raw object index should be obvious from the code-- looking through the | |
50 | // rendered simulation and counting through cubes in mapping mode is grossly inefficient. | |
e28f168c | 51 | |
73687629 | 52 | TowerMapping[] towerCubes = new TowerMapping[] {}; |
f0cc0ba5 MS |
53 | |
54 | // Single cubes can be constructed directly here if you need them | |
55 | Cube[] singleCubes = new Cube[] { | |
73687629 | 56 | // new Cube(15, int( Cube.EDGE_HEIGHT), 39, 0, 10, 0, WRL), // Back left channel behind speaker |
f0cc0ba5 MS |
57 | // new Cube(x, y, z, rx, ry, rz, wiring), |
58 | }; | |
59 | ||
60 | // The bass box! | |
73687629 | 61 | // BassBox bassBox = BassBox.unlitBassBox(BBX, 0, BBZ); // frame exists, no lights |
62 | BassBox bassBox = BassBox.noBassBox(); // no bass box at all | |
e89eda9f | 63 | // BassBox bassBox = new BassBox(BBX, 0, BBZ); // bass box with lights |
e28f168c | 64 | |
f0cc0ba5 | 65 | // The speakers! |
3b2e0b4a MS |
66 | List<Speaker> speakers = Arrays.asList(new Speaker[] { |
67 | // Each speaker parameter is x, y, z, rotation, the left speaker comes first | |
73687629 | 68 | // new Speaker(TRAILER_WIDTH - Speaker.EDGE_WIDTH + 8, 6, 3, -15) |
3b2e0b4a | 69 | }); |
f0cc0ba5 | 70 | |
73687629 | 71 | |
72 | //////////////////////////////////////////////////////////////////////// | |
73 | // dan's proposed lattice | |
7e3329d2 | 74 | ArrayList<StaggeredTower> scubes = new ArrayList<StaggeredTower>(); |
75 | if (NumBackTowers != 9) exit(); | |
76 | for (int i=0; i<NumBackTowers; i++) scubes.add(new StaggeredTower( | |
77 | (i+1)*CW, // x | |
78 | (i % 2 == 0) ? 0 : CH * 2./3. , // y | |
79 | - ((i % 2 == 0) ? 0 : 11) + 97 , // z | |
80 | -135, (i % 2 == 0) ? MaxCubeHeight : MaxCubeHeight-1)); // num cubes | |
81 | ||
82 | ArrayList<Cube> dcubes = new ArrayList<Cube>(); | |
83 | for (int i=1; i<6; i++) { | |
84 | if (i>1) dcubes.add(new Cube(-6+CW*4/3*i , 0, 0, 0, 0, 0, WRR)); | |
85 | dcubes.add(new Cube(-6+CW*4/3*i+CW*2/3., CH*.5, 0, 0, 0, 0, WRR)); | |
86 | } | |
73687629 | 87 | |
a3ccf23a MS |
88 | ////////////////////////////////////////////////////////////////////// |
89 | // BENEATH HERE SHOULD NOT REQUIRE ANY MODIFICATION!!!! // | |
90 | ////////////////////////////////////////////////////////////////////// | |
91 | ||
f0cc0ba5 | 92 | // These guts just convert the shorthand mappings into usable objects |
46fc29d4 MS |
93 | ArrayList<Tower> towerList = new ArrayList<Tower>(); |
94 | ArrayList<Cube> tower; | |
7e3329d2 | 95 | Cube[] cubes = new Cube[100]; |
46fc29d4 | 96 | int cubeIndex = 1; |
f0cc0ba5 MS |
97 | float px, pz, ny; |
98 | for (TowerMapping tm : towerCubes) { | |
99 | px = tm.x; | |
100 | ny = tm.y; | |
101 | pz = tm.z; | |
46fc29d4 | 102 | tower = new ArrayList<Cube>(); |
f0cc0ba5 MS |
103 | for (CubeMapping cm : tm.cubeMappings) { |
104 | tower.add(cubes[cubeIndex++] = new Cube(px = px + cm.dx, ny, pz = pz + cm.dz, 0, cm.ry, 0, cm.wiring)); | |
105 | ny += Cube.EDGE_HEIGHT; | |
46fc29d4 MS |
106 | } |
107 | towerList.add(new Tower(tower)); | |
108 | } | |
73687629 | 109 | |
73687629 | 110 | for (StaggeredTower st : scubes) { |
111 | tower = new ArrayList<Cube>(); | |
112 | for (int i=0; i < st.n; i++) | |
113 | tower.add(cubes[cubeIndex++] = new Cube(st.x, st.y + CH* 4/3.*i, st.z, 0, st.r, 0, WRR)); | |
114 | towerList.add(new Tower(tower)); | |
f0cc0ba5 | 115 | } |
e76480d4 | 116 | |
7e3329d2 | 117 | for (Cube cube : singleCubes) cubes[cubeIndex++] = cube; |
118 | for (Cube cube : dcubes) cubes[cubeIndex++] = cube; | |
119 | ||
120 | return new Model(towerList, cubes, bassBox, speakers); | |
186bc4d3 | 121 | } |
e73ef85d | 122 | |
a3ccf23a MS |
123 | /** |
124 | * This function maps the panda boards. We have an array of them, each has | |
125 | * an IP address and a list of channels. | |
126 | */ | |
186bc4d3 | 127 | public PandaMapping[] buildPandaList() { |
1d75c8a9 MS |
128 | final int LEFT_SPEAKER = 0; |
129 | final int RIGHT_SPEAKER = 1; | |
130 | ||
3b2e0b4a | 131 | // 8 channels map to: 3, 4, 7, 8, 13, 14, 15, 16. |
186bc4d3 | 132 | return new PandaMapping[] { |
73687629 | 133 | // new PandaMapping( |
134 | // "10.200.1.30", new ChannelMapping[] { | |
135 | // new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 39, 40, 41, 42 }), // 30 J3 * | |
136 | // new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 37, 38, 36, 35}), // 30 J4 //ORIG * | |
137 | // new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { }), // 30 J7 * | |
138 | // new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 16, 17, 18, 19}), // 30 J8 * | |
139 | // new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { }), // 30 J13 (not working) | |
140 | // new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { }), // 30 J14 (unplugged) | |
141 | // new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { }), // 30 J15 (unplugged) | |
142 | // new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 53, 54, 55, 72 }), // 30 J16 | |
143 | // }), | |
144 | // new PandaMapping( | |
145 | // "10.200.1.29", new ChannelMapping[] { | |
146 | // new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { }), // 29 J3 (not connected) | |
147 | // new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { }), // 29 J4 (not connected) | |
148 | // new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 28, 29, 30, 2}), // 29 J7 | |
149 | // new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 33, 34, 32, 31}), // 29 J8 //XXX | |
150 | // new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { }), // 29 J13 //XX //bassbox (not working) | |
151 | // new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { }), // 29 J14 (not working) | |
152 | // new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 12, 13, 14, 15 }), // 29 J15 | |
153 | // new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 8, 9, 10, 11 }), // 29 J16 | |
154 | // }), | |
186bc4d3 | 155 | new PandaMapping( |
29674806 | 156 | "10.200.1.28", new ChannelMapping[] { |
73687629 | 157 | /* new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 60, 61, 62, 63 }), // 28 J3 |
158 | new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 33, 34, 32, 31}), // 28 J4 | |
3b2e0b4a | 159 | new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 45, 46, 47, 48 }), // 28 J7 |
73687629 | 160 | new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 24, 25, 26, 27}), // 28 J8 |
3b2e0b4a MS |
161 | new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 4, 5, 6, 7}), // 28 J13 |
162 | new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 64, 65, 66, 67 }), // 28 J14 | |
163 | new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 68, 69, 70, 71 }), // 28 J15 | |
164 | new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 49, 50, 51, 52}), // 28 J16 | |
73687629 | 165 | */ |
166 | }), | |
167 | // new PandaMapping( | |
168 | // "10.200.1.31", new ChannelMapping[] { | |
169 | // new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { }), // 31 J3 | |
170 | // new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { }), // 31 J4 | |
171 | // new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 73}), // 31 J7 | |
172 | // new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 24, 25, 26, 27}), // 31 J8 | |
173 | // new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { }), // 31 J13 | |
174 | // new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 56, 57, 58, 59}), // 31 J14 | |
175 | // new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 20, 21, 22, 23}), // 31 J15 | |
176 | // new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { }), // 31 J16 | |
177 | // }), | |
3b2e0b4a | 178 | }; |
45f43cc2 | 179 | } |
e73ef85d | 180 | |
f0cc0ba5 MS |
181 | class TowerMapping { |
182 | public final float x, y, z; | |
183 | public final CubeMapping[] cubeMappings; | |
184 | ||
185 | TowerMapping(float x, float y, float z, CubeMapping[] cubeMappings) { | |
186 | this.x = x; | |
187 | this.y = y; | |
188 | this.z = z; | |
189 | this.cubeMappings = cubeMappings; | |
190 | } | |
191 | } | |
192 | ||
193 | class CubeMapping { | |
194 | public final float dx, dz, ry; | |
195 | public final Cube.Wiring wiring; | |
196 | ||
197 | CubeMapping(float dx, float dz, Cube.Wiring wiring) { | |
73687629 | 198 | this(dx, dz, 0., wiring); |
f0cc0ba5 | 199 | } |
f0cc0ba5 MS |
200 | CubeMapping(float dx, float dz, float ry) { |
201 | this(dz, dz, ry, Cube.Wiring.FRONT_LEFT); | |
202 | } | |
203 | ||
204 | CubeMapping(float dx, float dz, float ry, Cube.Wiring wiring) { | |
205 | this.dx = dx; | |
206 | this.dz = dz; | |
207 | this.ry = ry; | |
208 | this.wiring = wiring; | |
209 | } | |
210 | } | |
211 | ||
73687629 | 212 | class StaggeredTower { |
213 | public final float x, y, z, r; | |
214 | public final int n; | |
215 | StaggeredTower(float _x, float _y, float _z, float _r, int _n) { x=_x; y=_y; z=_z; r=_r; n=_n;} | |
216 | } | |
217 | ||
a922e963 MS |
218 | /** |
219 | * Each panda board has an IP address and a fixed number of channels. The channels | |
220 | * each have a fixed number of pixels on them. Whether or not that many physical | |
221 | * pixels are connected to the channel, we still send it that much data. | |
222 | */ | |
45f43cc2 MS |
223 | class PandaMapping { |
224 | ||
045b432d | 225 | // How many channels are on the panda board |
e28f168c | 226 | public final static int CHANNELS_PER_BOARD = 8; |
045b432d | 227 | |
44b8de9c | 228 | // How many total pixels on the whole board |
84086fa3 | 229 | public final static int PIXELS_PER_BOARD = ChannelMapping.PIXELS_PER_CHANNEL * CHANNELS_PER_BOARD; |
44b8de9c | 230 | |
45f43cc2 | 231 | final String ip; |
84086fa3 | 232 | final ChannelMapping[] channelList = new ChannelMapping[CHANNELS_PER_BOARD]; |
45f43cc2 | 233 | |
84086fa3 | 234 | PandaMapping(String ip, ChannelMapping[] rawChannelList) { |
45f43cc2 | 235 | this.ip = ip; |
a922e963 MS |
236 | |
237 | // Ensure our array is the right length and has all valid items in it | |
84086fa3 MS |
238 | for (int i = 0; i < channelList.length; ++i) { |
239 | channelList[i] = (i < rawChannelList.length) ? rawChannelList[i] : new ChannelMapping(); | |
a922e963 MS |
240 | if (channelList[i] == null) { |
241 | channelList[i] = new ChannelMapping(); | |
242 | } | |
045b432d | 243 | } |
e73ef85d | 244 | } |
1ecdb44a MS |
245 | } |
246 | ||
a922e963 | 247 | /** |
e27a8652 | 248 | * Each channel on a pandaboard can be mapped in a number of modes. The typical is |
a922e963 MS |
249 | * to a series of connected cubes, but we also have special mappings for the bass box, |
250 | * the speaker enclosures, and the DJ booth floor. | |
251 | * | |
252 | * This class is just the mapping meta-data. It sanitizes the input to make sure | |
253 | * that the cubes and objects being referenced actually exist in the model. | |
254 | * | |
255 | * The logic for how to encode the pixels is contained in the PandaDriver. | |
256 | */ | |
84086fa3 MS |
257 | class ChannelMapping { |
258 | ||
259 | // How many cubes per channel xc_PB is configured for | |
260 | public final static int CUBES_PER_CHANNEL = 4; | |
45f43cc2 | 261 | |
84086fa3 MS |
262 | // How many total pixels on each channel |
263 | public final static int PIXELS_PER_CHANNEL = Cube.POINTS_PER_CUBE * CUBES_PER_CHANNEL; | |
264 | ||
265 | public static final int MODE_NULL = 0; | |
266 | public static final int MODE_CUBES = 1; | |
267 | public static final int MODE_BASS = 2; | |
268 | public static final int MODE_SPEAKER = 3; | |
1d75c8a9 | 269 | public static final int MODE_STRUTS_AND_FLOOR = 4; |
84086fa3 MS |
270 | public static final int MODE_INVALID = 5; |
271 | ||
272 | public static final int NO_OBJECT = -1; | |
273 | ||
274 | final int mode; | |
275 | final int[] objectIndices = new int[CUBES_PER_CHANNEL]; | |
276 | ||
277 | ChannelMapping() { | |
278 | this(MODE_NULL); | |
279 | } | |
280 | ||
281 | ChannelMapping(int mode) { | |
282 | this(mode, new int[]{}); | |
283 | } | |
284 | ||
285 | ChannelMapping(int mode, int rawObjectIndex) { | |
286 | this(mode, new int[]{ rawObjectIndex }); | |
287 | } | |
288 | ||
289 | ChannelMapping(int mode, int[] rawObjectIndices) { | |
290 | if (mode < 0 || mode >= MODE_INVALID) { | |
291 | throw new RuntimeException("Invalid channel mapping mode: " + mode); | |
292 | } | |
293 | if (mode == MODE_SPEAKER) { | |
294 | if (rawObjectIndices.length != 1) { | |
295 | throw new RuntimeException("Speaker channel mapping mode must specify one speaker index"); | |
296 | } | |
297 | int speakerIndex = rawObjectIndices[0]; | |
298 | if (speakerIndex < 0 || speakerIndex >= glucose.model.speakers.size()) { | |
3b2e0b4a | 299 | throw new RuntimeException("Invalid speaker channel mapping: " + speakerIndex); |
84086fa3 | 300 | } |
1d75c8a9 | 301 | } else if ((mode == MODE_STRUTS_AND_FLOOR) || (mode == MODE_BASS) || (mode == MODE_NULL)) { |
84086fa3 | 302 | if (rawObjectIndices.length > 0) { |
3b2e0b4a | 303 | throw new RuntimeException("Bass/floor/null mappings cannot specify object indices"); |
84086fa3 MS |
304 | } |
305 | } else if (mode == MODE_CUBES) { | |
306 | for (int rawCubeIndex : rawObjectIndices) { | |
307 | if (glucose.model.getCubeByRawIndex(rawCubeIndex) == null) { | |
308 | throw new RuntimeException("Non-existing cube specified in cube mapping: " + rawCubeIndex); | |
309 | } | |
310 | } | |
311 | } | |
312 | ||
313 | this.mode = mode; | |
314 | for (int i = 0; i < objectIndices.length; ++i) { | |
315 | objectIndices[i] = (i < rawObjectIndices.length) ? rawObjectIndices[i] : NO_OBJECT; | |
316 | } | |
317 | } | |
318 | } |