Merge branch 'integration'
[SugarCubes.git] / _Mappings.pde
1 /**
2 * DOUBLE BLACK DIAMOND DOUBLE BLACK DIAMOND
3 *
4 * //\\ //\\ //\\ //\\
5 * ///\\\ ///\\\ ///\\\ ///\\\
6 * \\\/// \\\/// \\\/// \\\///
7 * \\// \\// \\// \\//
8 *
9 * EXPERTS ONLY!! EXPERTS ONLY!!
10 *
11 * This file implements the mapping functions needed to lay out the physical
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 */
15
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
28 public Model buildModel() {
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.
41
42 final float STACKED_RELATIVE = 1;
43 final float STACKED_REL_SPIN = 2;
44
45 TowerMapping[] mapping = new TowerMapping[] {
46
47 new TowerMapping(0, 0, 0, new float[][] {
48 {STACKED_RELATIVE, 0, 0},
49 {STACKED_RELATIVE, 5, -10, 20},
50 {STACKED_RELATIVE, 0, -6},
51 {STACKED_RELATIVE, -5, -2, -20},
52 }),
53
54 new TowerMapping(Cube.EDGE_WIDTH + 2, 0, 0, new float[][] {
55 {STACKED_RELATIVE, 0, 0},
56 {STACKED_RELATIVE, 0, 5, 10},
57 {STACKED_RELATIVE, 0, 2, 20},
58 {STACKED_RELATIVE, 0, 0, 30},
59 }),
60
61 // Back Cubes behind DJ platform (in order of increasing x)
62 new TowerMapping(50, 5, BASS_DEPTH, new float[][] {
63 {STACKED_RELATIVE, 0, 0},
64 {STACKED_RELATIVE, 2, 0, 20},
65 {STACKED_RELATIVE, -2, 10},
66 {STACKED_RELATIVE, -5, 15, -20},
67 {STACKED_RELATIVE, -2, 13},
68 }),
69
70 new TowerMapping(79, 5, BASS_DEPTH, new float[][] {
71 {STACKED_RELATIVE, 0, 0},
72 {STACKED_RELATIVE, 2, 0, 20},
73 {STACKED_RELATIVE, 4, 10},
74 {STACKED_RELATIVE, 2, 15, -20},
75 {STACKED_RELATIVE, 0, 13},
76 }),
77
78 new TowerMapping(107, 5, BASS_DEPTH, new float[][] {
79 {STACKED_RELATIVE, 0, 0},
80 {STACKED_RELATIVE, 4, 0, 20},
81 {STACKED_RELATIVE, 6, 10},
82 {STACKED_RELATIVE, 3, 15, -20},
83 // {STACKED_RELATIVE, 8, 13},
84 }),
85
86 new TowerMapping(133, 5, BASS_DEPTH, new float[][] {
87 {STACKED_RELATIVE, 0, 0},
88 {STACKED_RELATIVE, -2, 0, 20},
89 {STACKED_RELATIVE, 0, 10},
90 {STACKED_RELATIVE, 2, 15, -20},
91 // {STACKED_RELATIVE, 4, 13}
92 }),
93
94 new TowerMapping(165, 5, BASS_DEPTH, new float[][] {
95 {STACKED_RELATIVE, 0, 0},
96 {STACKED_RELATIVE, -1, 20},
97 {STACKED_RELATIVE, 2, 10},
98 {STACKED_RELATIVE, -2, 15, -20},
99 {STACKED_RELATIVE, 3, 13},
100 }),
101
102 // front DJ cubes
103 new TowerMapping((TRAILER_WIDTH - BASS_WIDTH)/2, BASS_HEIGHT, 10, new float[][] {
104 {STACKED_RELATIVE, 0, 0},
105 {STACKED_RELATIVE, 0, -10, 20},
106 }),
107
108 new TowerMapping((TRAILER_WIDTH - BASS_WIDTH)/2 + Cube.EDGE_HEIGHT, BASS_HEIGHT, 10, new float[][] {
109 {STACKED_RELATIVE, 3, 0},
110 {STACKED_RELATIVE, 2, -10, 20},
111 }),
112
113 new TowerMapping((TRAILER_WIDTH - BASS_WIDTH)/2 + 2*Cube.EDGE_HEIGHT + 5, BASS_HEIGHT, 10, new float[][] {
114 {STACKED_RELATIVE, 0, 0},
115 {STACKED_RELATIVE, 1, 0, 10},
116 }),
117
118 new TowerMapping((TRAILER_WIDTH - BASS_WIDTH)/2 + 3*Cube.EDGE_HEIGHT + 9, BASS_HEIGHT, 10, new float[][] {
119 {STACKED_RELATIVE, 0, 0},
120 {STACKED_RELATIVE, -1, 0},
121 }),
122
123 new TowerMapping((TRAILER_WIDTH - BASS_WIDTH)/2 + 4*Cube.EDGE_HEIGHT + 15, BASS_HEIGHT, 10, new float[][] {
124 {STACKED_RELATIVE, 0, 0},
125 {STACKED_RELATIVE, -1, 0},
126 }),
127
128 // left dj cubes
129 new TowerMapping((TRAILER_WIDTH - BASS_WIDTH)/2, BASS_HEIGHT, Cube.EDGE_HEIGHT + 2, new float[][] {
130 {STACKED_RELATIVE, 0, 0},
131 {STACKED_RELATIVE, 0, 2, 20},
132 }),
133
134 new TowerMapping((TRAILER_WIDTH - BASS_WIDTH)/2, BASS_HEIGHT, 2*Cube.EDGE_HEIGHT + 4, new float[][] {
135 {STACKED_RELATIVE, 0, 0},
136 {STACKED_RELATIVE, 0, 2, 20},
137 }),
138
139 // right dj cubes
140 new TowerMapping((TRAILER_WIDTH - BASS_WIDTH)/2 + 4*Cube.EDGE_HEIGHT + 15, BASS_HEIGHT, Cube.EDGE_HEIGHT + 2, new float[][] {
141 {STACKED_RELATIVE, 0, 0},
142 {STACKED_RELATIVE, 0, 2, 20},
143 }),
144
145 new TowerMapping((TRAILER_WIDTH - BASS_WIDTH)/2 + 4*Cube.EDGE_HEIGHT + 15, BASS_HEIGHT, 2*Cube.EDGE_HEIGHT + 4, new float[][] {
146 {STACKED_RELATIVE, 0, 0},
147 {STACKED_RELATIVE, 0, 2, 20},
148 }),
149
150 new TowerMapping(200, 0, 0, new float[][] {
151 {STACKED_RELATIVE, 0, 10},
152 {STACKED_RELATIVE, 5, 0, 20},
153 {STACKED_RELATIVE, 0, 4},
154 {STACKED_RELATIVE, -5, 8, -20},
155 {STACKED_RELATIVE, 0, 3},
156 }),
157
158 new TowerMapping(0, 0, Cube.EDGE_HEIGHT + 10, new float[][] {
159 {STACKED_RELATIVE, 10, 0, 40},
160 {STACKED_RELATIVE, 3, -2, 20},
161 {STACKED_RELATIVE, 0, 0, 40},
162 {STACKED_RELATIVE, 0, 0, 60},
163 {STACKED_RELATIVE, 0, 0, 40},
164 }),
165
166 new TowerMapping(20, 0, 2*Cube.EDGE_HEIGHT + 18, new float[][] {
167 {STACKED_RELATIVE, 0, 0, 40},
168 {STACKED_RELATIVE, 10, 0, 20},
169 {STACKED_RELATIVE, 5, 0, 40},
170 {STACKED_RELATIVE, 10, 0, 60},
171 {STACKED_RELATIVE, 12, 0, 40},
172 }),
173
174 new TowerMapping(210, 0, Cube.EDGE_HEIGHT + 15, new float[][] {
175 {STACKED_RELATIVE, 0, 0, 40},
176 {STACKED_RELATIVE, 5, 0, 20},
177 {STACKED_RELATIVE, 8, 0, 40},
178 {STACKED_RELATIVE, 3, 0, 60},
179 {STACKED_RELATIVE, 0, 0, 40},
180 }),
181
182 new TowerMapping(210, 0, 2*Cube.EDGE_HEIGHT + 25, new float[][] {
183 {STACKED_RELATIVE, 0, 0, 40},
184 {STACKED_RELATIVE, 5, 0, 20},
185 {STACKED_RELATIVE, 2, 0, 40},
186 {STACKED_RELATIVE, 5, 0, 60},
187 {STACKED_RELATIVE, 0, 0, 40},
188 }),
189
190 };
191
192 ArrayList<Tower> towerList = new ArrayList<Tower>();
193 ArrayList<Cube> tower;
194 Cube[] cubes = new Cube[79];
195 int cubeIndex = 1;
196 float tx, ty, tz, px, pz, ny, dx, dz, ry;
197 for (TowerMapping tm : mapping) {
198 tower = new ArrayList<Cube>();
199 px = tx = tm.x;
200 ny = ty = tm.y;
201 pz = tz = tm.z;
202 int ti = 0;
203 for (float[] cp : tm.cubePositions) {
204 float mode = cp[0];
205 if (mode == STACKED_RELATIVE) {
206 dx = cp[1];
207 dz = cp[2];
208 ry = (cp.length >= 4) ? cp[3] : 0;
209 tower.add(cubes[cubeIndex++] = new Cube(px = tx + dx, ny, pz = tz + dz, 0, ry, 0));
210 ny += Cube.EDGE_HEIGHT;
211 } else if (mode == STACKED_REL_SPIN) {
212 // Same as above but the front left of this cube is actually its back right for wiring
213 // TODO(mcslee): implement this
214 }
215 }
216 towerList.add(new Tower(tower));
217 }
218
219 return new Model(towerList, cubes);
220 }
221
222 public PandaMapping[] buildPandaList() {
223 return new PandaMapping[] {
224 new PandaMapping(
225 "10.200.1.28", new int[][] {
226 { 1, 2, 3, 4 }, // ch1
227 { 5, 6, 7, 8 }, // ch2
228 { 9, 10, 11, 12 }, // ch3
229 { 13, 14, 15, 16 }, // ch4
230 { 17, 18, 19, 20 }, // ch5
231 { 21, 22, 23, 24 }, // ch6
232 { 25, 26, 27, 28 }, // ch7
233 { 29, 30, 31, 32 }, // ch8
234 }),
235
236 new PandaMapping(
237 "10.200.1.29", new int[][] {
238 { 33, 34, 35, 36 }, // ch9
239 { 37, 38, 39, 40 }, // ch10
240 { 41, 42, 43, 44 }, // ch11
241 { 45, 46, 47, 48 }, // ch12
242 { 49, 50, 51, 52 }, // ch13
243 { 53, 54, 55, 56 }, // ch14
244 { 57, 58, 59, 60 }, // ch15
245 { 61, 62, 63, 64 }, // ch16
246 }),
247
248 };
249 }
250
251 class PandaMapping {
252
253 // How many channels are on the panda board
254 public final static int CHANNELS_PER_BOARD = 8;
255
256 // How many cubes per channel xc_PB is configured for
257 public final static int CUBES_PER_CHANNEL = 4;
258
259 // How many total pixels on each channel
260 public final static int PIXELS_PER_CHANNEL = Cube.POINTS_PER_CUBE * CUBES_PER_CHANNEL;
261
262 // How many total pixels on the whole board
263 public final static int PIXELS_PER_BOARD = PIXELS_PER_CHANNEL * CHANNELS_PER_BOARD;
264
265 final String ip;
266 final int[][] channelList = new int[CHANNELS_PER_BOARD][CUBES_PER_CHANNEL];
267
268 PandaMapping(String ip, int[][] rawChannelList) {
269 this.ip = ip;
270 for (int chi = 0; chi < CHANNELS_PER_BOARD; ++chi) {
271 int[] cubes = (chi < rawChannelList.length) ? rawChannelList[chi] : new int[]{};
272 for (int cui = 0; cui < CUBES_PER_CHANNEL; ++cui) {
273 channelList[chi][cui] = (cui < cubes.length) ? cubes[cui] : 0;
274 }
275 }
276 }
277 }
278
279