From 4deb0287c9551390851c715d0ed85de055eb367d Mon Sep 17 00:00:00 2001 From: Blizzard Finnegan Date: Thu, 9 Mar 2023 13:06:21 -0500 Subject: [PATCH 1/2] Last-second patches to ensure working code - ConfigFacade now properly imports without overwriting old data - DataSaving now doesn't fail and cause pre-emptive crashing - DataSaving now creates pass % line outside of data lines for quick access --- src/main/java/org/baxter/disco/ocr/Cli.java | 11 ++++++-- .../org/baxter/disco/ocr/ConfigFacade.java | 20 +++++++------ .../java/org/baxter/disco/ocr/DataSaving.java | 28 +++++++++++++------ 3 files changed, 40 insertions(+), 19 deletions(-) diff --git a/src/main/java/org/baxter/disco/ocr/Cli.java b/src/main/java/org/baxter/disco/ocr/Cli.java index b4ae445..8012638 100644 --- a/src/main/java/org/baxter/disco/ocr/Cli.java +++ b/src/main/java/org/baxter/disco/ocr/Cli.java @@ -448,7 +448,11 @@ public class Cli } //Exit loop - else break; + else + { + ConfigFacade.saveCurrentConfig(); + break; + } } while(true); } while(true); @@ -613,7 +617,7 @@ public class Cli LOCK.unlock(); //Wait for the DUT to display an image - try{ Thread.sleep(1500); } catch(Exception e){ ErrorLogging.logError(e); } + try{ Thread.sleep(2000); } catch(Exception e){ ErrorLogging.logError(e); } //For all available cameras: // take an image, process it, and save it to a file @@ -648,9 +652,12 @@ public class Cli result >= 100 || result == Double.NEGATIVE_INFINITY) { + ErrorLogging.logError("Invalid OCR reading! Resetting DUTs..."); MovementFacade.goUp(); + ErrorLogging.logError("Waiting for 20 seconds to allow devices to fall asleep."); try{ Thread.sleep(20000); } catch(Exception e){ ErrorLogging.logError(e); } + ErrorLogging.logError("Waking devices..."); MovementFacade.pressButton(); fail = true; break; diff --git a/src/main/java/org/baxter/disco/ocr/ConfigFacade.java b/src/main/java/org/baxter/disco/ocr/ConfigFacade.java index 48ba6ef..2a79741 100644 --- a/src/main/java/org/baxter/disco/ocr/ConfigFacade.java +++ b/src/main/java/org/baxter/disco/ocr/ConfigFacade.java @@ -437,16 +437,20 @@ public class ConfigFacade Map savedSection = new HashMap<>(); for(String cameraName : cameraNames) { - if(!sectionName.equals(cameraName)) - { saveSingleDefault(cameraName); } + if(sectionName.equals(cameraName)) + { + for(ConfigProperties configState : ConfigProperties.values()) + { + Double configValue = CONFIG_STORE.getDouble(sectionName + "." + configState.getConfig()); + //ErrorLogging.logError("DEBUG: Imported config value: " + Double.toString(configValue)); + savedSection.put(configState,configValue); + } + } } - for(ConfigProperties configState : ConfigProperties.values()) - { - Double configValue = CONFIG_STORE.getDouble(sectionName + "." + configState.getConfig()); - //ErrorLogging.logError("DEBUG: Imported config value: " + Double.toString(configValue)); - savedSection.put(configState,configValue); - } + if(savedSection.size() == 0) + { saveSingleDefault(sectionName); } + if(emptyMap) configMap.put(sectionName,savedSection); else { diff --git a/src/main/java/org/baxter/disco/ocr/DataSaving.java b/src/main/java/org/baxter/disco/ocr/DataSaving.java index df92e94..ba47b76 100644 --- a/src/main/java/org/baxter/disco/ocr/DataSaving.java +++ b/src/main/java/org/baxter/disco/ocr/DataSaving.java @@ -172,28 +172,37 @@ public class DataSaving int rowIndex = 0; FormulaEvaluator formulaEvaluator = outputWorkbook.getCreationHelper().createFormulaEvaluator(); int lastColumnOfData = outputSheet.getRow(rowIndex).getLastCellNum(); - int serialColumn = lastColumnOfData + 1; - int percentColumn = lastColumnOfData + 2; + int serialColumn = lastColumnOfData - 2; + int percentColumn = lastColumnOfData - 1; //Get the last row, add another row below it, and name the first cell "Totals:" int lastRowOfData = outputSheet.getLastRowNum(); //For each camera, create a unique total line - for(int column = 3; column <= (cameraCount*3); column+=3) + int column = 1; + for(int i = 0; i < cameraCount; i++) { - String columnName = CellReference.convertNumToColString(column); + String serialColumnName = CellReference.convertNumToColString(column); + String dataColumnName = CellReference.convertNumToColString(column + 2); + ErrorLogging.logError("DEBUG: Serial Column name: " + serialColumnName); HSSFRow row = outputSheet.getRow(++rowIndex); + if(row == null) + { + row = outputSheet.createRow(rowIndex); + } + ErrorLogging.logError("DEBUG: Row index: " + rowIndex); + ErrorLogging.logError("DEBUG: Column (int): " + serialColumn); HSSFCell serialCell = row.createCell(serialColumn); - String formula = "$" + columnName + "$" + rowIndex; + String formula = "$" + serialColumnName + "$" + (rowIndex+1); serialCell.setCellFormula(formula); formulaEvaluator.evaluate(serialCell); HSSFCell percentCell = row.createCell(percentColumn); - String verticalArray = String.format("$%s$2:$%s$%s",columnName,columnName,lastRowOfData); + String verticalArray = String.format("$%s$2:$%s$%s",dataColumnName,dataColumnName,(lastRowOfData+1)); ErrorLogging.logError("DEBUG: Vertical Array: " + verticalArray); formula = String.format( - "(COUNT(%s)-(COUNTIF(%s,\"<%s\")+COUNTIF(%s,\">%s\",))/(COUNT(%s))", + "(COUNT(%s)-(COUNTIF(%s,\"<%s\")+COUNTIF(%s,\">%s\")))/(COUNT(%s))", verticalArray, verticalArray, (targetTemp - failRange), verticalArray, (targetTemp + failRange), @@ -207,6 +216,7 @@ public class DataSaving formulaEvaluator.evaluate(percentCell); ErrorLogging.logError("DEBUG: Formula: " + formula); + column += 4; } //Once all totals have been created, write to the file @@ -228,7 +238,7 @@ public class DataSaving boolean output = false; int cellnum = 0; int startingRow = outputSheet.getLastRowNum(); - HSSFRow row = outputSheet.createRow(++startingRow); + HSSFRow row = (startingRow == 1) ? outputSheet.getRow(++startingRow) : outputSheet.createRow(++startingRow); List cameraNames = new ArrayList<>(cameraToFile.keySet()); //ErrorLogging.logError("DEBUG: image locations: " + imageLocations.toString()); //List objectArray = new LinkedList<>(); @@ -287,10 +297,10 @@ public class DataSaving //Create a blank cell as a spacer row.createCell(cellnum++); } - updateFormulas(cameraNames.size()); try (FileOutputStream outputStream = new FileOutputStream(outputFile)) { outputWorkbook.write(outputStream); output = true; } catch(Exception e) {ErrorLogging.logError(e);} + updateFormulas(cameraNames.size()); return output; } } -- 2.47.2 From 1bab6887ba460e0e6a48e5d49228bd7b94cb928a Mon Sep 17 00:00:00 2001 From: Blizzard Finnegan Date: Thu, 9 Mar 2023 13:12:30 -0500 Subject: [PATCH 2/2] Update documentation and todos --- README.md | 7 ++++--- toDoList.md | 5 ----- 2 files changed, 4 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 2623cac..a8fa39b 100644 --- a/README.md +++ b/README.md @@ -84,7 +84,7 @@ The first command stops all currently running `pigpio` daemon processes. The sec 4. Unplug *ONE* camera, and plug it back in to the same port. This will generate several lines of text in your terminal window. 5. Copy one of the lines, starting with `platform`, and, *crucially*, ending `.0`. 6. Paste this into your `udev` rule file, replacing the `fillerText` portion, but leaving the quotes. If you are using a terminal text editor, this will require you to either right click to paste, or press `Ctrl-Shift-v` rather than `Ctrl-v`, as `Ctrl-v` is used by the terminal for a separate purpose. The first line of the file distributed in this repo contains a commented-out example line, with the correct syntax. - 7. Repeat steps 4-6 for all cameras in the fixture. If there are no new lines available, copy and paste the line into a new line to create a new rule, *ensuring to increment the number at the end of the line in the `SYMLINK` section*. + 7. Repeat steps 4-6 for all cameras in the fixture. If there are no new lines available, copy and paste the line into a new line to create a new rule, *ensuring to add a unique name to the end of the line in the `SYMLINK` section*. 8. Save the file. If the file fails to save, you most likely have insufficient permissions to save the file, and will need to follow the terminal text editor instructions. 9. Once the file has been saved, reboot the Raspberry Pi to load the new `udev` rule. 9. Open a terminal, and check that the new symlinks were created successfully. This can be done by running the below command. If the symlinks have not been created successfully, restart from step 3 until all symlinks are created properly. @@ -112,9 +112,10 @@ To use this program, it *must* be run on a Raspberry Pi, with available GPIO. sudo java -jar [name of JAR file, including extension] ``` 4. What will happen next depends on your current version: - - Versions `4.0.0-rc1`,`4.0.0-rc2`, and `4.0.0` will create a terminal window. From there, use the numbers shown in the menu to control the fixture, and run tests as necessary. + - Versions `4.0.0-rc1`, `4.0.0-rc2`, `4.1.x`, and `4.3.x` will create a terminal window. From there, use the numbers shown in the menu to control the fixture, and run tests as necessary. - An upcoming version will create a terminal window, which load things for a moment before also creating a GUI. This GUI can be used to control the fixture, and run tests as necessary. - GUI development is currently limited to the `gui` branch. + - Version `4.2` contains a partially GUI design which is by now relatively out of date. ### Potential Errors @@ -127,7 +128,7 @@ sudo killall pigpiod - If the file contains a `CAMERA INIT ERROR`, this means that the associated camera was not picked up properly. This can be due to several reasons. Below are some debugging steps to take. Note that this will cause cascading errors, if attempting to import a camera's config from a pre-existing config file, so config-related errors can be ignored. 1. Ensure that both cameras are plugged in properly. 2. Unplug, and then plug back in, the erroring camera. - 3. Ensure that the `/dev/video-cam1` and `/dev/video-cam2` files are both created. If they are not, then you will need to update your `udev` rules, as in the Installation section. + 3. Ensure that the `/dev/video-cam-left` and `/dev/video-cam-right` files are both created. If they are not, then you will need to update your `udev` rules, as in the Installation section. 4. Reboot the Raspberry Pi. (This can be done by opening the terminal, and typing `reboot`, then hitting enter.) Camera drivers occasionally fail to load on boot, and will unload after a long time with no use. Rebooting generally solves this issue (although it may take multiple reboots.) ## Building from source diff --git a/toDoList.md b/toDoList.md index 727b5ae..9ecbeeb 100644 --- a/toDoList.md +++ b/toDoList.md @@ -2,11 +2,6 @@ ## High-priority fixes -### DataSaving - -- [ ] Modify initialisation to create formula cells outside data lines - - Will need to evaluate functions on every line write - ### OpenCVFacade - [ ] completeProcess should have more robust file output checking -- 2.47.2