pathfinding almost works

This commit is contained in:
Kevin Santo Cappuccio 2023-06-06 09:10:19 -07:00
parent f755507508
commit 11ffe37b32
9 changed files with 543 additions and 111 deletions

View File

@ -21,6 +21,13 @@ D9,18,
D5-44,
A2-33,
25-55,
7-27,
6-26,
5-25,
4-24,
3-28,
2-29,
8-23,
}
special functions //these are connected first so DNIs will be applied to all the nets

View File

@ -52,7 +52,7 @@
#define I2C0_SDA 4
#define I2C0_SCL 5
#define LED_DATA_OUT 25
#define LED_DATA_OUT 6
#define ADC0_5V 26
#define ADC1_5V 27

View File

@ -35,7 +35,7 @@ void rainbowy(int saturation, int brightness, int wait)
// saturation and value (brightness) (both 0-255, similar to the
// ColorHSV() function, default 255), and a true/false flag for whether
// to apply gamma correction to provide 'truer' colors (default true).
leds.rainbow(firstPixelHue, 1, saturation, 220, true);
leds.rainbow(firstPixelHue, 1, saturation, 255, true);
// Above line is equivalent to:
// strip.rainbow(firstPixelHue, 1, 255, 255, true);
leds.show(); // Update strip with new contents

View File

@ -6,8 +6,8 @@
#include "Adafruit_NeoPixel.h"
#define LED_PIN 25
#define LED_COUNT 80
#define BRIGHTNESS 50
#define LED_COUNT 160
#define BRIGHTNESS 100
extern Adafruit_NeoPixel leds;

View File

@ -103,7 +103,7 @@ struct chipStatus ch[12] = {
{10,'K',
{-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1}, // x status
{-1,-1,-1,-1,-1,-1,-1,-1}, //y status
{NANO_A0, NANO_A1, NANO_A2, NANO_A3, NANO_A4, NANO_A5, NANO_A6, NANO_A7, NANO_D2, NANO_D3, NANO_D4, NANO_D5, NANO_D6, NANO_D7, NANO_D8, NANO_D9},
{NANO_A0, NANO_A1, NANO_A2, NANO_A3, NANO_D2, NANO_D3, NANO_D4, NANO_D5, NANO_D6, NANO_D7, NANO_D8, NANO_D9, NANO_D10, NANO_D11, NANO_D12, ADC2_5V},
{CHIP_A,CHIP_B,CHIP_C,CHIP_D,CHIP_E,CHIP_F,CHIP_G,CHIP_H}},
{11,'L',

View File

@ -96,9 +96,9 @@ struct pathStruct{
int node2;
int net;
int chip[3];
int x[3];
int y[3];
int chip[4];
int x[4];
int y[4];
int candidates[3][3]; //[node][candidate]
int altPathNeeded;
enum pathType pathType;

View File

@ -179,8 +179,6 @@ void commitPaths(void)
for (int i = 0; i < numberOfPaths; i++)
{
// Serial.print(i);
// Serial.print(" \t");
@ -195,7 +193,6 @@ void commitPaths(void)
printNodeOrName(path[i].node1);
Serial.print(" to ");
printNodeOrName(path[i].node2);
}
if (path[i].altPathNeeded == true)
{
@ -284,7 +281,6 @@ void commitPaths(void)
path[i].altPathNeeded = true;
Serial.print(" \t ");
Serial.print(ch[path[i].chip[0]].xStatus[xMapL0c0]);
Serial.print(" \t ");
@ -363,33 +359,42 @@ void commitPaths(void)
break;
}
case NANOtoSF:
{
//Serial.print(" NANOtoSF ");
}
case BBtoNANO:
case BBtoSF: // nodes should always be in order of the enum, so node1 is BB and node2 is SF
{
if (path[i].chip[0] != CHIP_L && path[i].chip[1] == CHIP_L) // if theyre both chip L we'll deal with it differently
{
//Serial.print("\tBBtoCHIP L ");
int yMapBBc0 = 0; // y 0 is always connected to chip L
int xMapChipL = xMapForNode(path[i].node1, path[i].chip[0]);
int xMapChipL = xMapForNode(path[i].node2, CHIP_L);
int yMapChipL = path[i].chip[0];
ch[path[i].chip[0]].yStatus[yMapForNode(path[i].node1, path[i].chip[0])] = path[i].net;
if ((ch[path[i].chip[0]].yStatus[0] == -1) || ch[path[i].chip[0]].yStatus[0] == path[i].net)
{
ch[path[i].chip[0]].yStatus[0] = path[i].net;
ch[CHIP_L].xStatus[yMapChipL] = path[i].net;
ch[CHIP_L].yStatus[yMapChipL] = path[i].net;
ch[CHIP_L].xStatus[xMapChipL] = path[i].net;
path[i].y[0] = 0;
path[i].x[0] = -2; // we have to wait to assign a free x pin to bounce from
path[i].y[1] = yMapChipL;
path[i].x[1] = xMapChipL;
path[i].x[2] = -2; // we need another hop to get to the node
path[i].y[2] = yMapForNode(path[i].node1, path[i].chip[0]);
// path[i].sameChip = true; //so we know both -2 values need to be the same
if (debugNTCC2 == true)
{
@ -411,14 +416,17 @@ void commitPaths(void)
Serial.print(" y[1]: ");
Serial.print(path[i].y[1]);
// Serial.println(" ");
}
// path[i].sameChip = true;
}
else
{
path[i].x[2] = -2; // we need another hop to get to the node
path[i].y[2] = yMapForNode(path[i].node1, path[i].chip[0]);
path[i].x[1] = xMapChipL;
Serial.print("\tno free lanes for path, setting altPathNeeded flag");
path[i].altPathNeeded = true;
}
@ -428,11 +436,11 @@ void commitPaths(void)
int xMapBBc0 = xMapForChipLane0(path[i].chip[0], path[i].chip[1]); // find x connection to sf chip
int xMapSFc1 = xMapForNode(path[i].node2, path[i].chip[1]);
int yMapSFc1 = path[i].chip[0];
if (((ch[path[i].chip[0]].xStatus[xMapBBc0] == path[i].net) || (ch[path[i].chip[0]].xStatus[xMapBBc0] == -1)) && (ch[path[i].chip[1]].yStatus[path[i].chip[0]] == path[i].net || ch[path[i].chip[1]].yStatus[path[i].chip[0]] == -1)) // how's that for a fuckin if statement
if ((ch[path[i].chip[0]].xStatus[xMapBBc0] == path[i].net || ch[path[i].chip[0]].xStatus[xMapBBc0] == -1) && (ch[path[i].chip[1]].yStatus[yMapSFc1] == path[i].net || ch[path[i].chip[1]].yStatus[yMapSFc1] == -1)) // how's that for a fuckin if statement
{
path[i].x[0] = xMapBBc0;
path[i].x[1] = xMapSFc1;
@ -440,13 +448,12 @@ void commitPaths(void)
path[i].y[1] = path[i].chip[0]; // bb to sf connections are always in chip order, so chip A is always connected to sf y 0
ch[path[i].chip[0]].xStatus[xMapBBc0] = path[i].net;
ch[path[i].chip[0]].yStatus[path[i].y[0]] = path[i].net;
ch[path[i].chip[0]].xStatus[xMapBBc0] == path[i].net;
ch[path[i].chip[0]].yStatus[path[i].y[0]] == path[i].net;
ch[path[i].chip[1]].xStatus[path[i].x[1]] == path[i].net;
ch[path[i].chip[1]].yStatus[path[i].chip[0]] == path[i].net;
ch[path[i].chip[1]].xStatus[path[i].x[1]] = path[i].net;
ch[path[i].chip[1]].yStatus[path[i].chip[0]] = path[i].net;
if (debugNTCC2 == true)
{
@ -486,13 +493,14 @@ void commitPaths(void)
if (debugNTCC2)
{
Serial.print("\tno direct path, setting altPathNeeded flag");
Serial.print("\tno direct path, setting altPathNeeded flag (BBtoSF)");
}
break;
}
break;
}
case NANOtoNANO: // this doesn't work yet
case NANOtoNANO:
{
// Serial.print(" NANOtoNANO ");
@ -507,6 +515,7 @@ void commitPaths(void)
{
ch[path[i].chip[0]].xStatus[xMapNANOC0] = path[i].net;
ch[path[i].chip[1]].xStatus[xMapNANOC1] = path[i].net;
path[i].x[0] = xMapNANOC0;
path[i].x[1] = xMapNANOC1;
@ -528,41 +537,398 @@ void commitPaths(void)
Serial.print("\t chip[1]: ");
Serial.print(chipNumToChar(path[i].chip[1]));
Serial.print(" x[1]: ");
Serial.print(path[i].x[1]);
Serial.print(" y[1]: ");
Serial.print(path[i].y[1]);
}
}
} else {
}
else
{
path[i].altPathNeeded = true;
if (debugNTCC2)
{
Serial.print("\tno direct path, setting altPathNeeded flag");
Serial.print("\tno direct path, setting altPathNeeded flag (NANOtoNANO)");
}
}
}
// case BBtoNANO:
}Serial.println("\n\r");
}
Serial.println("\n\r");
}
printPathsCompact();
printChipStatus();
resolveAltPaths();
}
void commitBBtoBB(int i)
{
}
void resolveAltPaths(void)
{
for (int i = 0; i < numberOfPaths; i++)
{
if (path[i].altPathNeeded == true)
{
switch (path[i].pathType)
{
case BBtoBB:
{
int foundPath = 0;
Serial.println("BBtoBB");
// try chip L first
int yNode1 = yMapForNode(path[i].node1, path[i].chip[0]);
int yNode2 = yMapForNode(path[i].node2, path[i].chip[1]);
ch[path[i].chip[0]].yStatus[yNode1] = path[i].net;
ch[path[i].chip[1]].yStatus[yNode2] = path[i].net;
if ((ch[CHIP_L].yStatus[path[i].chip[0]] == path[i].net || ch[CHIP_L].yStatus[path[i].chip[0]] == -1) && (ch[CHIP_L].yStatus[path[i].chip[1]] == path[i].net || ch[CHIP_L].yStatus[path[i].chip[1]] == -1))
{
ch[CHIP_L].yStatus[path[i].chip[0]] = path[i].net;
ch[CHIP_L].yStatus[path[i].chip[1]] = path[i].net;
path[i].chip[2] = CHIP_L;
path[i].x[2] = -2;
path[i].y[2] = path[i].chip[0];
path[i].y[3] = path[i].chip[1];
path[i].altPathNeeded = false;
path[i].x[0] = -2;//bounce
path[i].x[1] = -2;
path[i].y[0] = yMapForNode(path[i].node1,path[i].chip[0]);//connect to chip L
path[i].y[1] = yMapForNode(path[i].node2,path[i].chip[1]);
//if chip L is set, we'll infer that y is 0
if (debugNTCC2)
{
Serial.print(i);
Serial.print(" chip[2]: ");
Serial.print(chipNumToChar(path[i].chip[2]));
Serial.print(" x[2]: ");
Serial.print(path[i].x[2]);
Serial.print(" y[2]: ");
Serial.print(path[i].y[2]);
Serial.print(" y[3]: ");
Serial.print(path[i].y[3]);
Serial.print(" \n\r");
}
foundPath = 1;
break;
}
else
{
for (int ijk = 8; ijk < 11; ijk++) // check other sf chips
{
if ((ch[ijk].yStatus[path[i].chip[0]] == path[i].net || ch[ijk].yStatus[path[i].chip[0]] == -1) && (ch[ijk].yStatus[path[i].chip[1]] == path[i].net || ch[ijk].yStatus[path[i].chip[1]] == -1))
{
ch[ijk].yStatus[path[i].chip[0]] = path[i].net;
ch[ijk].yStatus[path[i].chip[1]] = path[i].net;
path[i].chip[2] = ijk;
path[i].x[2] = -2;
path[i].y[2] = path[i].chip[0];
path[i].y[3] = path[i].chip[1];
path[i].altPathNeeded = false;
path[i].x[0] = -2;//bounce
path[i].x[1] = -2;
path[i].y[0] = yMapForNode(path[i].node1,path[i].chip[0]);//connect to chip L
path[i].y[1] = yMapForNode(path[i].node2,path[i].chip[1]);
//if chip L is set, we'll infer that y is 0
if (debugNTCC2)
{
Serial.print(i);
Serial.print(" chip[2]: ");
Serial.print(chipNumToChar(path[i].chip[2]));
Serial.print(" x[2]: ");
Serial.print(path[i].x[2]);
Serial.print(" y[2]: ");
Serial.print(path[i].y[2]);
Serial.print(" y[3]: ");
Serial.print(path[i].y[3]);
Serial.print(" \n\r");
}
foundPath = 1;
break;
}
}
if (foundPath == 1)
{
break;
}
for (int bb = 0; bb < 8; bb++) // this is a long winded way to do this but it's at least slightly readable
{
int xMapL0c0 = xMapForChipLane0(bb, path[i].chip[0]);
int xMapL0c1 = xMapForChipLane0(bb, path[i].chip[1]);
int xMapL1c0 = xMapForChipLane1(bb, path[i].chip[0]);
int xMapL1c1 = xMapForChipLane1(bb, path[i].chip[1]);
if (ch[bb].xStatus[xMapL0c0] == path[i].net || ch[bb].xStatus[xMapL0c0] == -1) // were going through each bb chip to see if it has a connection to both chips free
{
if (ch[bb].xStatus[xMapL0c1] == path[i].net || ch[bb].xStatus[xMapL0c1] == -1) // lanes 0 0
{
ch[bb].xStatus[xMapL0c0] = path[i].net;
ch[bb].xStatus[xMapL0c1] = path[i].net;
path[i].chip[2] = bb;
path[i].x[2] = xMapL0c0;
path[i].x[3] = xMapL0c1;
path[i].y[2] = -2;
path[i].y[3] = -2;
path[i].altPathNeeded = false;
path[i].x[0] = xMapForChipLane0(path[i].chip[0],bb);
path[i].x[1] = xMapForChipLane0(path[i].chip[1],bb);
path[i].y[0] = yMapForNode(path[i].node1,path[i].chip[0]);
path[i].y[1] = yMapForNode(path[i].node2,path[i].chip[1]);
if (debugNTCC2)
{
Serial.print(i);
Serial.print(" chip[2]: ");
Serial.print(chipNumToChar(path[i].chip[2]));
Serial.print(" x[2]: ");
Serial.print(path[i].x[2]);
Serial.print(" x[3]: ");
Serial.print(path[i].x[3]);
Serial.print(" \n\r");
}
break;
}
}
if (ch[bb].xStatus[xMapL1c0] == path[i].net || ch[bb].xStatus[xMapL1c0] == -1)
{
if (ch[bb].xStatus[xMapL1c1] == path[i].net || ch[bb].xStatus[xMapL1c1] == -1) // lanes 1 1
{
ch[bb].xStatus[xMapL1c0] = path[i].net;
ch[bb].xStatus[xMapL1c1] = path[i].net;
path[i].chip[2] = bb;
path[i].x[2] = xMapL1c0;
path[i].x[3] = xMapL1c1;
path[i].y[2] = -2;
path[i].y[3] = -2;
path[i].altPathNeeded = false;
path[i].x[0] = xMapForChipLane1(path[i].chip[0],bb);
path[i].x[1] = xMapForChipLane1(path[i].chip[1],bb);
path[i].y[0] = yMapForNode(path[i].node1,path[i].chip[0]);
path[i].y[1] = yMapForNode(path[i].node2,path[i].chip[1]);
if (debugNTCC2)
{
Serial.print(i);
Serial.print(" chip[2]: ");
Serial.print(chipNumToChar(path[i].chip[2]));
Serial.print(" x[2]: ");
Serial.print(path[i].x[2]);
Serial.print(" x[3]: ");
Serial.print(path[i].x[3]);
Serial.print(" \n\r");
}
break;
}
}
if (ch[bb].xStatus[xMapL0c0] == path[i].net || ch[bb].xStatus[xMapL0c0] == -1)
{
if (ch[bb].xStatus[xMapL1c1] == path[i].net || ch[bb].xStatus[xMapL1c1] == -1) // lanes 0 1
{
ch[bb].xStatus[xMapL0c0] = path[i].net;
ch[bb].xStatus[xMapL1c1] = path[i].net;
path[i].chip[2] = bb;
path[i].x[2] = xMapL0c0;
path[i].x[3] = xMapL1c1;
path[i].y[2] = -2;
path[i].y[3] = -2;
path[i].altPathNeeded = false;
path[i].x[0] = xMapForChipLane0(path[i].chip[0],bb);
path[i].x[1] = xMapForChipLane1(path[i].chip[1],bb);
path[i].y[0] = yMapForNode(path[i].node1,path[i].chip[0]);
path[i].y[1] = yMapForNode(path[i].node2,path[i].chip[1]);
if (debugNTCC2)
{
Serial.print(i);
Serial.print(" chip[2]: ");
Serial.print(chipNumToChar(path[i].chip[2]));
Serial.print(" x[2]: ");
Serial.print(path[i].x[2]);
Serial.print(" x[3]: ");
Serial.print(path[i].x[3]);
Serial.print(" \n\r");
}
break;
}
}
if (ch[bb].xStatus[xMapL1c0] == path[i].net || ch[bb].xStatus[xMapL1c0] == -1)
{
if (ch[bb].xStatus[xMapL0c1] == path[i].net || ch[bb].xStatus[xMapL0c1] == -1) // lanes 1 0
{
ch[bb].xStatus[xMapL0c1] = path[i].net;
ch[bb].xStatus[xMapL1c0] = path[i].net;
path[i].chip[2] = bb;
path[i].x[2] = xMapL0c1;
path[i].x[3] = xMapL1c0;
path[i].y[2] = -2;
path[i].y[3] = -2;
path[i].altPathNeeded = false;
path[i].x[0] = xMapForChipLane1(path[i].chip[0],bb);
path[i].x[1] = xMapForChipLane0(path[i].chip[1],bb);
path[i].y[0] = yMapForNode(path[i].node1,path[i].chip[0]);
path[i].y[1] = yMapForNode(path[i].node2,path[i].chip[1]);
if (debugNTCC2)
{
Serial.print(i);
Serial.print(" chip[2]: ");
Serial.print(chipNumToChar(path[i].chip[2]));
Serial.print(" x[2]: ");
Serial.print(path[i].x[2]);
Serial.print(" x[3]: ");
Serial.print(path[i].x[3]);
Serial.print(" \n\r");
}
break;
}
if (debugNTCC2)
{
Serial.print(i);
Serial.print(" chip[2]: ");
Serial.print(chipNumToChar(path[i].chip[2]));
Serial.print(" x[2]: ");
Serial.print(path[i].x[2]);
Serial.print(" x[3]: ");
Serial.print(path[i].x[3]);
Serial.print(" \n\r");
}
}
}
}
break;
}
case BBtoNANO:
case BBtoSF:
{
Serial.println("BBtoSF");
int foundPath = 0;
break;
}
case NANOtoSF:
case NANOtoNANO:
{
Serial.println("NANOtoNANO");
break;
}
}
}
}
printPathsCompact();
printChipStatus();
}
void printPathsCompact(void)
{
Serial.println("\n\rpath\tnode1\ttype\tchip0\tx0\ty0\tnode2\ttype\tchip1\tx1\ty1\taltPath\tsameChp\tpath type\n\r");
Serial.println("\n\rpath\tnet\tnode1\ttype\tchip0\tx0\ty0\tnode2\ttype\tchip1\tx1\ty1\taltPath\tsameChp\tpthType\t\tchipL\tchip3\tx2\ty2\tx3\ty3\n\r");
for (int i = 0; i < numberOfPaths; i++)
{
Serial.print(i);
Serial.print("\t");
Serial.print(path[i].net);
Serial.print("\t");
printNodeOrName(path[i].node1);
Serial.print("\t");
Serial.print(path[i].nodeType[0]);
@ -589,9 +955,63 @@ void printPathsCompact(void)
Serial.print("\t");
printPathType(i);
Serial.print("\t");
Serial.print(path[i].Lchip);
if (path[i].chip[2] != -1)
{
Serial.print(" \t");
Serial.print(chipNumToChar(path[i].chip[2]));
Serial.print(" \t");
Serial.print(path[i].x[2]);
Serial.print(" \t");
Serial.print(path[i].y[2]);
Serial.print(" \t");
Serial.print(path[i].x[3]);
Serial.print(" \t");
Serial.print(path[i].y[3]);
}
Serial.println(" ");
}
}
void printChipStatus(void)
{
Serial.println("chip\tX\t\t\t\ty");
for (int i = 0; i < 12; i++)
{
int spaces = 0;
Serial.print(chipNumToChar(i));
Serial.print("\t");
for (int j = 0; j < 16; j++)
{
spaces += printNodeOrName(ch[i].xStatus[j]);
for (int k = 0; k < 4 - spaces; k++)
{
Serial.print(" ");
}
Serial.print(" ");
spaces = 0;
}
Serial.print("\t");
for (int j = 0; j < 8; j++)
{
spaces += printNodeOrName(ch[i].yStatus[j]);
for (int k = 0; k < 4 - spaces; k++)
{
Serial.print(" ");
}
Serial.print(" ");
spaces = 0;
}
Serial.println(" ");
}
}
void findStartAndEndChips(int node1, int node2, int pathIdx)
{
bothNodes[0] = node1;
@ -814,7 +1234,7 @@ void assignPathType(int pathIndex)
path[pathIndex].sameChip = false;
}
if (path[pathIndex].node1 == 1 || path[pathIndex].node1 == 30 || path[pathIndex].node1 == 31 || path[pathIndex].node1 == 60)
if (path[pathIndex].node1 == 1 || path[pathIndex].node1 == 30 || path[pathIndex].node1 == 31 || path[pathIndex].node1 == 60 || path[pathIndex].chip[0] == CHIP_L)
{
swapNodes(pathIndex);
path[pathIndex].Lchip = true;
@ -835,7 +1255,7 @@ void assignPathType(int pathIndex)
path[pathIndex].nodeType[0] = SF;
}
if (path[pathIndex].node2 == 1 || path[pathIndex].node2 == 30 || path[pathIndex].node2 == 31 || path[pathIndex].node2 == 60)
if (path[pathIndex].node2 == 1 || path[pathIndex].node2 == 30 || path[pathIndex].node2 == 31 || path[pathIndex].node2 == 60 || path[pathIndex].chip[1] == CHIP_L)
{
path[pathIndex].Lchip = true;
path[pathIndex].nodeType[1] = SF;
@ -934,7 +1354,7 @@ void swapNodes(int pathIndex)
int xMapForNode(int node, int chip)
{
int nodeFound = 0;
int nodeFound = -1;
for (int i = 0; i < 16; i++)
{
if (ch[chip].xMap[i] == node)
@ -947,8 +1367,6 @@ int xMapForNode(int node, int chip)
return nodeFound;
}
int yMapForNode(int node, int chip)
{
int nodeFound = -1;
@ -965,7 +1383,7 @@ int yMapForNode(int node, int chip)
int xMapForChipLane0(int chip1, int chip2)
{
int nodeFound = 0;
int nodeFound = -1;
for (int i = 0; i < 16; i++)
{
if (ch[chip1].xMap[i] == chip2)

View File

@ -58,6 +58,10 @@ void commitPaths(void);
void printPathsCompact(void);
void resolveAltPaths(void);
void printChipStatus(void);

View File

@ -16,7 +16,7 @@ void setup()
{
Serial.begin(115200);
pinMode(25, OUTPUT);
pinMode(LED_PIN, OUTPUT);
LittleFS.begin();
delay(3000);
@ -45,8 +45,11 @@ void loop()
bridgesToPaths();
assignNetColors();
while (1)
;
//rainbowy(180, 55, 20); // Red
while (1);
//rainbowy(180, 55, 20); // Red
// Serial.println("\n\r");