Please Help - Limelight Issues

We are having an issue with our limelight where the array for botpose_targetspace will return null based on the current orientation of out robot. This only happens on initial powerup of the robot and results in a fatal exception in the code. When redeploying the code after having this error, the array stays stable and the error doesn’t reappear.

This is where we are initializing the array that is having the issue:

public double[] getPositionTargetSpace() {
    if (!hasTarget())
      return new double[6];


    return limelight.getEntry("botpose_targetspace").getDoubleArray(new double[6]);

The stack trace ends at return –getPositiontargetSpace() [2]:

public double distanceFromTarget() {
    if (!hasTarget())
      return 0;


    return -getPositionTargetSpace()[2];
  }

Stack Trace:
ERROR  1  Unhandled exception: java.lang.ArrayIndexOutOfBoundsException: Index 2 out of bounds for length 0  frc.robot.subsystems.LimeLight.distanceFromTarget(LimeLight.java:205) 
 Error at frc.robot.subsystems.LimeLight.distanceFromTarget(LimeLight.java:205): Unhandled exception: java.lang.ArrayIndexOutOfBoundsException: Index 2 out of bounds for length 0 
 at frc.robot.subsystems.LimeLight.distanceFromTarget(LimeLight.java:205) 
 at frc.robot.subsystems.StatusLight.periodic(StatusLight.java:73)
At edu.wpi.first.wpilibj2.command.CommandScheduler.run(CommandScheduler.java:260) 
 at frc.robot.Robot.robotPeriodic(Robot.java:46) 
 at edu.wpi.first.wpilibj.IterativeRobotBase.loopFunc(IterativeRobotBase.java:381) 
 at edu.wpi.first.wpilibj.TimedRobot.startCompetition(TimedRobot.java:131) 
 at edu.wpi.first.wpilibj.RobotBase.runRobot(RobotBase.java:365) 
 at edu.wpi.first.wpilibj.RobotBase.startRobot(RobotBase.java:453) 
 at frc.robot.Main.main(Main.java:23)

Until we redeploy code, the array will continually disappear and reappear in the network tables depending on the rotation of the robot. We are also experiencing the limelight feed using the web browser dropping out on our limelights. Also, before the error happens the latency of the image being displayed back to the driver station slowly gets worse to the point right before the error happens its take around 3 seconds for the image to update. The limelight we are experiencing the issue on is a limelight 3g and is connected through a brainbox and being powered from a REV mini power module connected to the PDH. We have another limelight 3 on out robot, but it is not experiencing the same issue.

So far in diagnosing the issue we have swapped the radio and ethernet cable connecting to the limelight.

Listed is a video of the array issue appearing in the network table and images of the errors we received with the stack trace. We have been struggling with this error for a couple days now and have a competition next week and have no clue how to debug this issue.

Video of Error Happening
Video showing botpose_targetspace array from limelight disappearing

Images of the console logs:


Any troubleshooting steps would be super helpful and we are willing to try anything.

We’ve noticed a similar set of surprising behaviors as the limelight boots up, or if the limelight only sees unselected tags. I would recommend having your “hasTarget” method check a few things, like if the array is null, of zero length, or if the count of tags seen (data[7]) is greater than zero.

If your “hasTarget” method returns false in these scenarios, then it looks like you won’t try to dereference an invalid array.

Make sure to short circuit ( Short circuit evaluation - DEV Community ) these checks in the sequence of:
-Not null
-Not zero length
-data[7]

1 Like