FTC Freight Frenzy TensorFlow Programming Issue

Background
Our middle school FTC team uses Android Studio and JAVA to code our robot. We are trying to use the FTC provided TensorFlowObjectDetection capability to find our team shipping element on the barcode. For those of you unfamiliar with the game, there are 3 - 2" colored squares (either red or blue depending on alliance). Either a duck or the team’s shipping element will be randomly placed on one of the 3 squares.

We have chosen to create a class for each of our robot’s sub-systems – the camera being one, the drive train being another. The methods in these classes are then used to create our opModes (the programs that the user can run from the drive station).

We have used the sample code and successfully identify a “Marker” (one of the 2" colored squares (ConceptTensorFlowObjectDetectionWebcam.java). NOTE: This opMode allows the user to view the camera stream and the object Detection after INIT but before START.

We converted the sample code from an opMode to a class library (BarcodeReading.java)

We use these in our autonomous opMode (AutonBlueCarousel.java)

Problem
When we run our AutonBlueCarousel opMode:

After INIT: The camera stream shows the Marker and identifies it as such – it is in the center of the field of view.

After START (the camera stream can no longer be viewed), the class returns no object found instead of finding the Marker!

I have no idea what is happening here and am fresh out of debugging ideas – any help would be appreciated. I am uploading the code.AutonBlueCarousel.java (6.8 KB) BarcodeReading.java (10.9 KB) ConceptTensorFlowObjectDetectionWebcam.java (9.1 KB)

Your current code doesn’t appear capable of returning anything except True. If it actually returning “no object” or is it just looping forever? Did you mean an error was being thrown saying “no object”?

If it's infinitely looping

Determine which if statement of the ones below is false:
if (tfod != null)
if (updatedRecognitions != null)
if (recognition.getLabel().equals(“Marker”))
If all were true, then markerFound == True. Try to determine which is the problem and let us know

If it's an error thrown of "no object"

Let us know what the error is and what line it’s on.


Logic Error
Even if you get this figured out, you’re still going to have issues with your opmode. Notice how your isMarkerFound() method can only return true? This means that, presuming the method does finish, it’s equivalent to the following:

if (True) {
            robot.rotateToHeading(25, .4);
            if (True){
                deliveryPosition = 1;
            }
            else {
                deliveryPosition = 3;
            }
        }
        else {
            deliveryPosition = 2;
        }

This means that your robot will always believe the deliveryPosition is 1.


My 2 Cents
Though it doesn’t change how the code functions, the methods isMarkerFound() and isDuckFound() are misleadingly labeled. It’s like if you asked me if it was raining outside, and I went outside and stood there for 2 days until a thunderstorm came before telling you, “Yes, in fact, it is raining.” If someone were to try to use this code without knowing the internals, it would do something entirely different than what was expected. Maybe something like acquireMarkerTarget() would be more appropriate.


Closing Word
I dumped a lot on you, so feel free to ask follow up questions so that we can help get this code working. It looks like it’s made wonderful progress so far!

In the current code, that is correct. However, this was a last minute test last night to determine if for some reason the tensorflow detection needed “time to recognize” – it doesn’t and it wasn’t very logical, but it was late. Normally the while (!markerFound) is not part of the code.

The telemetry commands spit information to the driver’s station – In this case we get “# Object Detected 0”.

So really, the issue boils down to this – When we run the ConceptTensorFlowObjectDetectionWebcam.java, the driver station displays Marker Found true, plus the label, left top, and right bottom numbers.

When we use the “same” code as part of a class, we receive “# Object Detected 0” even though a view of the camera stream says we should have a display of Marker Found true plus the label, left top, and right bottom numbers.

So is there some weird thing with tensorflow that dislikes class libraries or dislikes other stuff (like driving) happening between activation and recognizing?