From 20a779c96136d278f7ef9c93570e28c3d3faad9e Mon Sep 17 00:00:00 2001 From: Lorenzo Date: Sat, 8 Feb 2020 09:48:40 +0000 Subject: [PATCH] Updated vision to get largest block that is the same color as requested Updated vision to get largest block that is the same color as requested --- .../java/frc/robot/subsystems/Vision.java | 23 ++++++++++++------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/src/main/java/frc/robot/subsystems/Vision.java b/src/main/java/frc/robot/subsystems/Vision.java index 4b27ea5..2ee00ec 100644 --- a/src/main/java/frc/robot/subsystems/Vision.java +++ b/src/main/java/frc/robot/subsystems/Vision.java @@ -34,20 +34,27 @@ public Vision() { } /** - * Gets an arraylist of all the current "blocks" the camera detects and returns true - * if the largest block's color matches the one inputed + * Gets an arraylist of all the current "blocks" the camera detects and returns the + * largest block that is the same color as requested in the parameters * - * @param color Color to check if the largest block matches it - * @return Returns true if the colors inputed and of the largest block are the same + * @param color Color to check if the block's color matches it + * @return Returns the largest block of the same color */ - public boolean getRecentBlocks(Color color) { + public Block getLargestSameColorBlock(Color color) { // Get data from all blocks and recieve said data pixyCCC.getBlocks(true, 255, 255); ArrayList blocks = pixyCCC.getBlocks(); - // Send and gets data from largest block (color) - Color myColor = getBlockColor(blocks.get(0)); - return(myColor.equals(color)); + // Goes through every block to get largest same color block + Block myBlock = null; + for (Block block: blocks) { + if (color.equals(getBlockColor(block))) { + myBlock = block; + break; + } + } + + return(myBlock); } /**