Axis Camera to Dashboard

I’m fairly new to programming, and I’m my team’s only programmer, with no mentors knowing any programming. So far I’ve been able to piece together some Java, but the camera is beyond me.

I’ve looked at the Javadocs for the Axis camera, and the Circle Tracker demo, but I really don’t understand how it works. If anyone could explain that, and how to implement it (at least to the effect of outputting camera to the dashboard) and the basic idea of image processing, I would be really grateful.

Thanks!

Hey. Theoretically the camera should just show up on the dashboard when you call AxisCamera.getInstance(). At least, that’s what I’ve read. You can see how it’s done in the CircleTrackerDemo example code that’s supplied in netbeans. Unfortunately, neither the example code nor a routine I’ve written seems to be written seems to be working for my team, we’re investigating possible solutions. Anyway, I’m proficient in Java so if you need any help getting anything else working let me know.

Okay, thanks. I’ll try that tomorrow. (And I really need to have a mockup bot in my basement…)

Tell me about it. I’ve written around 1500 lines of code that I have no way to test because the robot is yet to be wired. :stuck_out_tongue:

What I just did was just customizing a copy of the sample CircleTrackerDemo to include our other functions, since the camera code took up most of the coding. That’s probably not the most efficient way, but it works for us.

Let us know what you find, though, since I’d love to shave off a few lines by using the minimal amount of code required.

Well, having done some extensive tracing and finally copying the Target.java and the TrackerDashboard.java files to my project, then copying the following code into the Teleop section:

ColorImage image = null;
try {
       if (cam.freshImage()) {
       image = cam.getImage();
       Thread.yield();
       Target] targets = Target.findCircularTargets(image);
       Thread.yield();
        if (targets.length == 0 || targets[0].m_score < kScoreThreshold) {
             System.out.println("No target found");
             Target] newTargets = new Target[targets.length + 1];
             newTargets[0] = new Target();
             newTargets[0].m_majorRadius = 0;
             newTargets[0].m_minorRadius = 0;
             newTargets[0].m_score = 0;
             for (int i = 0; i < targets.length; i++) {
                   newTargets* = targets*;
             }
             trackerDashboard.updateVisionDashboard(0.0, gyro.getAngle(), 0.0, 0.0, newTargets);
             } else {
             System.out.println(targets[0]);
             System.out.println("Target Angle: " + targets[0].getHorizontalAngle());
             turnController.setSetpoint(gyroAngle + targets[0].getHorizontalAngle());
             trackerDashboard.updateVisionDashboard(0.0, gyro.getAngle(), 0.0, targets[0].m_xPos / targets[0].m_xMax, targets);
              }
      }
} catch (NIVisionException ex) {
       ex.printStackTrace();
} catch (AxisCameraException ex) {
       ex.printStackTrace();
} finally {
    try {
         if (image != null) {
         image.free();
         }
    } catch (NIVisionException ex) {
}

I’ve gone through and figured out (mostly) what this code does, but I don’t understand what the line

turnController.setSetpoint(gyroAngle + targets[0].getHorizontalAngle());

does. In the original file, turnController is:

PIDController turnController = new PIDController(.08, 0.0, 0.5, gyro, new PIDOutput() {

        public void pidWrite(double output) {
            drive.arcadeDrive(0, output);
        }
    }, .005);

but I have no clue what PIDController does. Any help?

EDIT: I know the targeting part probably won’t end up in TeleOp, but for now it can stay.**

turnController drives the robot to point it directly at the target using the gyro angle.

The PIDController is designed to slow the robot turn down as it approaches the target gyro angle. Those values (.08, 0.0, 0.5) are coefficients that must match your robot’s turning characteristics, so plan to adjust those when you get a real robot to practice with.

The gyro angle was calculated from the camera image by the offset of the target from the center line.

Okay, thanks.

Let me make sure I got that straight - I’d be able to use that code in autonomous to point towards the target.

If that’s the case, how would I make it tell the next part that it’s pointing at the target to shoot (Ignoring getting a ball for now)?

You’ll be pointed at the target when targets[0].getHorizontalAngle() gets small. You’ll have to pick your tolerance, e.g., +/- 1 degree, and test for it.

Ok, thanks. If I need more help, I’ll post it, but I think I’ve got the gist of this.