Camera code says "output not being updated enough"

We’re attempting to get the image at this phase, and we just stuck the code in the DriveTrain subsystem for the time being. This is through the Command-Base style. Anyone know what’s giving the update error? We think that it has something with the timer, but we’re not really sure since we’re a brand new team of programmers. This is why there is a timer. Again, we are totally clueless on what is causing the error.

/*

  • To change this template, choose Tools | Templates
  • and open the template in the editor.
    */
    package edu.wpi.first.wpilibj.templates.subsystems;

import edu.wpi.first.wpilibj.RobotDrive;
import edu.wpi.first.wpilibj.Servo;
import edu.wpi.first.wpilibj.Timer;
import edu.wpi.first.wpilibj.Victor;
import edu.wpi.first.wpilibj.camera.AxisCamera;
import edu.wpi.first.wpilibj.camera.AxisCameraException;
import edu.wpi.first.wpilibj.command.Subsystem;
import edu.wpi.first.wpilibj.image.ColorImage;
import edu.wpi.first.wpilibj.image.NIVisionException;
import edu.wpi.first.wpilibj.templates.RobotMap;
import edu.wpi.first.wpilibj.templates.commands.DriveWithJoysticks;

/**
*

  • @author John
    */
    public class DriveTrain extends Subsystem //no PID…
    {
    RobotDrive drive;
    Servo vexMotor;
    Victor motor;
    AxisCamera camera;

    public DriveTrain() {
    super(“drivetrain”);

     drive = new RobotDrive(RobotMap.leftBackMotor, RobotMap.leftFrontMotor, RobotMap.rightBackMotor, RobotMap.rightFrontMotor);
     //vexMotor = new Servo(RobotMap.vexMotor);
     //motor = new Victor(RobotMap.rightFrontMotor);
     //throw new RuntimeException("lolol");
    

    }
    public ColorImage obtainImage() throws AxisCameraException, NIVisionException
    {
    camera = AxisCamera.getInstance(“10.40.64.11”);
    camera.writeResolution(AxisCamera.ResolutionT.k640x480);
    camera.writeBrightness(0);

// Timer timer1 = new Timer();
//
// timer1.start();
// while(timer1.get() < .005)
// {
// System.out.println(timer1.get());
// drive.tankDrive(.3, .3);
// }
System.out.println(“hi”);
//Timer.delay(1);
//camera.writeMaxFPS(10);
ColorImage image;
System.out.println("brightness: “+ camera.getBrightness() + "
camera rotation” +camera.getRotation());

    //getWatchdog().kill(); 

// while(!camera.freshImage())
// {
// System.out.println(“help im stuck in a loop making factory”);
//
// image = camera.getImage();
// image.free();
// Timer.delay(.005);
// }
image = camera.getImage();
return image;
}
protected void initDefaultCommand() {
setDefaultCommand(new DriveWithJoysticks());
}
public void tankDrive(double left, double right) {
drive.tankDrive(left, right);
}
public void tankDrive(double time)
{
Timer timer1 = new Timer();

    timer1.start();
    while(timer1.get() &lt; time)
    {
        System.out.println(timer1.get());
        drive.tankDrive(.5, .5);
    }
    
}

public void testDrive()
{
    drive.setExpiration(1);
    drive.tankDrive(0.01, 0);
    Timer.delay(4);
    drive.tankDrive(0,.1);
    Timer.delay(4);
    drive.tankDrive(0,0);
    
}
        
public void servo(double left)  //testing servo
{
    vexMotor.set(left);
}
public void victorTest(double number)
{
    motor.set(number);
}

}

This error is an indirect error message. It tells you that your program broke somewhere. What you want to post is the actual error message with actual line numbers that tell you exactly where it all went wrong. (It’s called the stack trace. Use a try-catch block to print it.)

At the moment, I don’t have a bot to test this code on, but it seems highly likely that this is a nullpointerexception error. The timer code looks okay, so if I were you, I would check if the motors are all plugged in right and if the camera is setup to the exact IP address you’re querying (10.40.64.11).

Also, is that space deliberate between the 640 and x480 in line:

camera.writeResolution(AxisCamera.ResolutionT.k640 x480);

First off, I’d recommend putting your camera image acquisition code either in its own subsystem, or in your teleopPeriodic in your main robot class.

The error you’re getting trips when the jaguars aren’t getting their motor speed values updated often enough from the code, and from looking at this I’d bet you guys aren’t actually calling the methods to update the jaguar values in your robot code anywhere.

EDIT: I think violinuxer is right, I think your image acquisition is causing the code to hang for a little while as it’s capturing the image, and that delay is causing the error.

Hi there!

I have some experience with this problem… Luckily its an easy fix. The reason the message appears is the fact that your jaguars are not getting commands often enough. If you do not call RobotDrive.drive() (or its equivalent) the motors will stop and you will get the error. When you are doing image processing, the jaguars are not getting updated.

Hope this helps!

violinuxer

Yeah. We do it by putting all the subsystems in their own threads. We’re still using SimpleRobot, but with a kinda-conmmand-based interface. It works quite well!

violinuxer

Hello!
I am the other programmer on the team. Thank you for all your advice. So: We’ve created a new project entirely which doesn’t incorporate the drivetrain at all.
We now get an error, in which the “AxisCameraException: No image available” is thrown. This comes from camera.getImage(). Any help would be great. (Got to go home now, unfortunately…)

Thanks for the help. The main aim of our robot is to use the camera to determine distance for our drivetrain during autonomous and tracking the hoops. This is why it’s in the drivetrain subsystem. We’ll obviously change that later. So in theory, the code should work if we are not calling on the drivetrain at all?

In that case, try just commenting out the vision code and see what happens.

The problem was fixed by taking the code out of the drivetrain class. Thanks!