Merge branch 'master' of github.com:sugarcubes/SugarCubes into BenMorrow
[SugarCubes.git] / _Mappings.pde
CommitLineData
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
16class 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 28public 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;
44
46fc29d4
MS
45 TowerMapping[] mapping = new TowerMapping[] {
46
47 new TowerMapping(0, 0, 0, new float[][] {
03c7b35a
MS
48 {STACKED_RELATIVE, 0, 0},
49 {STACKED_RELATIVE, 5, -10, 20},
50 {STACKED_RELATIVE, 0, -6},
51 {STACKED_RELATIVE, -5, -2, -20},
46fc29d4 52 }),
a797d019 53
46fc29d4 54 new TowerMapping(Cube.EDGE_WIDTH + 2, 0, 0, new float[][] {
03c7b35a
MS
55 {STACKED_RELATIVE, 0, 0},
56 {STACKED_RELATIVE, 0, 5, 10},
57 {STACKED_RELATIVE, 0, 2, 20},
58 {STACKED_RELATIVE, 0, 0, 30},
46fc29d4
MS
59 }),
60
61 // Back Cubes behind DJ platform (in order of increasing x)
62 new TowerMapping(50, 5, BASS_DEPTH, new float[][] {
03c7b35a
MS
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},
46fc29d4
MS
68 }),
69
70 new TowerMapping(79, 5, BASS_DEPTH, new float[][] {
03c7b35a
MS
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},
46fc29d4
MS
76 }),
77
78 new TowerMapping(107, 5, BASS_DEPTH, new float[][] {
03c7b35a
MS
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},
46fc29d4
MS
84 }),
85
86 new TowerMapping(133, 5, BASS_DEPTH, new float[][] {
03c7b35a
MS
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}
46fc29d4
MS
92 }),
93
94 new TowerMapping(165, 5, BASS_DEPTH, new float[][] {
03c7b35a
MS
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},
46fc29d4
MS
100 }),
101
102 // front DJ cubes
103 new TowerMapping((TRAILER_WIDTH - BASS_WIDTH)/2, BASS_HEIGHT, 10, new float[][] {
03c7b35a
MS
104 {STACKED_RELATIVE, 0, 0},
105 {STACKED_RELATIVE, 0, -10, 20},
46fc29d4
MS
106 }),
107
108 new TowerMapping((TRAILER_WIDTH - BASS_WIDTH)/2 + Cube.EDGE_HEIGHT, BASS_HEIGHT, 10, new float[][] {
03c7b35a
MS
109 {STACKED_RELATIVE, 3, 0},
110 {STACKED_RELATIVE, 2, -10, 20},
46fc29d4
MS
111 }),
112
113 new TowerMapping((TRAILER_WIDTH - BASS_WIDTH)/2 + 2*Cube.EDGE_HEIGHT + 5, BASS_HEIGHT, 10, new float[][] {
03c7b35a
MS
114 {STACKED_RELATIVE, 0, 0},
115 {STACKED_RELATIVE, 1, 0, 10},
46fc29d4
MS
116 }),
117
118 new TowerMapping((TRAILER_WIDTH - BASS_WIDTH)/2 + 3*Cube.EDGE_HEIGHT + 9, BASS_HEIGHT, 10, new float[][] {
03c7b35a
MS
119 {STACKED_RELATIVE, 0, 0},
120 {STACKED_RELATIVE, -1, 0},
46fc29d4
MS
121 }),
122
123 new TowerMapping((TRAILER_WIDTH - BASS_WIDTH)/2 + 4*Cube.EDGE_HEIGHT + 15, BASS_HEIGHT, 10, new float[][] {
03c7b35a
MS
124 {STACKED_RELATIVE, 0, 0},
125 {STACKED_RELATIVE, -1, 0},
46fc29d4
MS
126 }),
127
128 // left dj cubes
129 new TowerMapping((TRAILER_WIDTH - BASS_WIDTH)/2, BASS_HEIGHT, Cube.EDGE_HEIGHT + 2, new float[][] {
03c7b35a
MS
130 {STACKED_RELATIVE, 0, 0},
131 {STACKED_RELATIVE, 0, 2, 20},
46fc29d4
MS
132 }),
133
134 new TowerMapping((TRAILER_WIDTH - BASS_WIDTH)/2, BASS_HEIGHT, 2*Cube.EDGE_HEIGHT + 4, new float[][] {
03c7b35a
MS
135 {STACKED_RELATIVE, 0, 0},
136 {STACKED_RELATIVE, 0, 2, 20},
46fc29d4
MS
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[][] {
03c7b35a
MS
141 {STACKED_RELATIVE, 0, 0},
142 {STACKED_RELATIVE, 0, 2, 20},
46fc29d4
MS
143 }),
144
145 new TowerMapping((TRAILER_WIDTH - BASS_WIDTH)/2 + 4*Cube.EDGE_HEIGHT + 15, BASS_HEIGHT, 2*Cube.EDGE_HEIGHT + 4, new float[][] {
03c7b35a
MS
146 {STACKED_RELATIVE, 0, 0},
147 {STACKED_RELATIVE, 0, 2, 20},
46fc29d4 148 }),
186bc4d3 149
46fc29d4 150 new TowerMapping(200, 0, 0, new float[][] {
03c7b35a
MS
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},
46fc29d4
MS
156 }),
157
158 new TowerMapping(0, 0, Cube.EDGE_HEIGHT + 10, new float[][] {
03c7b35a
MS
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},
46fc29d4
MS
164 }),
165
166 new TowerMapping(20, 0, 2*Cube.EDGE_HEIGHT + 18, new float[][] {
03c7b35a
MS
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},
46fc29d4
MS
172 }),
173
174 new TowerMapping(210, 0, Cube.EDGE_HEIGHT + 15, new float[][] {
03c7b35a
MS
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},
46fc29d4
MS
180 }),
181
182 new TowerMapping(210, 0, 2*Cube.EDGE_HEIGHT + 25, new float[][] {
03c7b35a
MS
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},
46fc29d4
MS
188 }),
189
190 };
51d0d59a 191
46fc29d4
MS
192 ArrayList<Tower> towerList = new ArrayList<Tower>();
193 ArrayList<Cube> tower;
194 Cube[] cubes = new Cube[79];
195 int cubeIndex = 1;
03c7b35a 196 float tx, ty, tz, px, pz, ny, dx, dz, ry;
46fc29d4
MS
197 for (TowerMapping tm : mapping) {
198 tower = new ArrayList<Cube>();
03c7b35a
MS
199 px = tx = tm.x;
200 ny = ty = tm.y;
201 pz = tz = tm.z;
202 int ti = 0;
46fc29d4 203 for (float[] cp : tm.cubePositions) {
03c7b35a
MS
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 }
46fc29d4
MS
215 }
216 towerList.add(new Tower(tower));
217 }
186bc4d3
MS
218
219 return new Model(towerList, cubes);
220}
e73ef85d 221
186bc4d3
MS
222public 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 }),
45f43cc2 235
186bc4d3
MS
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 };
45f43cc2 249}
e73ef85d 250
45f43cc2
MS
251class PandaMapping {
252
045b432d
MS
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
44b8de9c
MS
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
45f43cc2 265 final String ip;
045b432d 266 final int[][] channelList = new int[CHANNELS_PER_BOARD][CUBES_PER_CHANNEL];
45f43cc2 267
045b432d 268 PandaMapping(String ip, int[][] rawChannelList) {
45f43cc2 269 this.ip = ip;
045b432d
MS
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 }
e73ef85d 276 }
1ecdb44a
MS
277}
278
45f43cc2 279