TeamCode/src/main/java/org/firstinspires/ftc/teamcode/libraries/LineFollowLib.java
private static int findAvgOverZeroDebug(byte[] ray, OpMode mode){
        int totalPos = 0;
        int totalNum = 0;
        for(int i = 0; i < ray.length; i++){
            if(ray[i] != 0){
                totalPos += i;
                totalNum++;
            }
        }

        mode.telemetry.addData("Total Num Pixel", totalNum);

        //and return it in a value between -1 and 1, or and error if there is too much noise
        if(totalNum > ray.length / 4 || totalNum < ray.length / 16) return -400;
        else if(totalNum == 0) return 0;
        else return totalPos/totalNum;
    }
//find the average position of all numbers > 0 in an array
find the average position of all numbers > 0 in an array
find the average position of all numbers > 0 in an array
private static int findAvgOverZeroDebug(byte[] ray, OpMode mode){
        int totalPos = 0;
        int totalNum = 0;
        for(int i = 0; i < ray.length; i++){
            if(ray[i] != 0){
                totalPos += i;
                totalNum++;
            }
        }
        mode.telemetry.addData("Total Num Pixel", totalNum);
        if(totalNum > ray.length / 4 || totalNum < ray.length / 16) return -400;
        else if(totalNum == 0) return 0;
        else return totalPos/totalNum;
    }
private static int findAvgOverZeroDebug ( byte [ ] ray , OpMode mode ) { int totalPos = 0 ; int totalNum = 0 ; for ( int i = 0 ; i < ray . length ; i ++ ) { if ( ray [ i ] != 0 ) { totalPos += i ; totalNum ++ ; } } mode . telemetry . addData ( "Total Num Pixel" , totalNum ) ; if ( totalNum > ray . length / 4 || totalNum < ray . length / 16 ) return - 400 ; else if ( totalNum == 0 ) return 0 ; else return totalPos / totalNum ; }
find the average position of all numbers > 0 in an array
find the average position of all numbers > 0 in an array
//and return it in a value between -1 and 1, or and error if there is too much noise