Vision Programming

My team has been struggling with vision code and we cannot figure it out for anything. We are able to isolate but we cannot figure out how to make the robot lock onto the target.
I want to be able to hold a button and the robot locks onto a target, how would I go about doing this with java?

2 Likes

The typical trend is to have a Raspberry Pi loaded with the WPILib Image and then some sort of software like ChickenVision located on that Raspberry Pi. Then you connect everything to ethernet into either the radio or a switch (my team prefers a switch as you lose the ability to tether without unplugging something if you go into the radio). ChickenVision will publish values to NetworkTables that you can grab on the roboRIO. The roboRIO then can use PID to align to the target. An example psuedo-implementation of this could be

P = some constant;
error = angle_error - actual_angle;
while(button pressed) {
   motorTurn = P * error;
}

There are various implementations of this throughout other teams code. Our teams can be found here

3 Likes

In a more general sense, break the problem down:

  1. Capture an image
  2. Identify a target within an image
  3. Calculate where that target is, relative to the robot
  4. Calculate where you want the robot to be
  5. Provide motor commands that cause #4 to become true

ChickenVision & Limelight are pre-canned solutions for #1 and #2, and sometimes #3

A JeVois camera accomplishes #1, but must be programmed to do #2 and #3 .

For #3, simply converting the X/Y Pixel location of the target to an angle relative to the camera is often sufficient. Some teams use algorithms like solvePNP to get more info.

For #4, you use something like that button from the driver to determine where you want the robot to be. In your case, the algorithm could be “when button pressed, desired robot angle relative to target is 0 degrees”

For #5, PID control of a drivetrain is generally where most teams end up.

Any part of this chain of steps which does not occur on the roboRIO also adds a minor hitch - you have to transfer data from wherever the calculation is done back to the roboRIO. This may be ethernet (maybe NetworkTables), serial, or something more exotic.

OP - With this in mind, can you describe what portions of the process you’ve had success with, and which ones you’re struggling on?

1 Like