I a currently working on a program that will use the camera to guide the robot, but the problem is I can't get it to work. When I try the drive or the camera separately, it works without an issue, but when I use one to control the other, it does not work and it fills my console with
Code:
"Robot Drive... Output not updated often enough."
It I am not able to figure out what the problem is? Here is the code I used (without the teleop and class declaration, but it extends SimpleRobot)
Code:
AxisCamera camera; // the axis camera object (connected to the switch)
CriteriaCollection cc; // the criteria for doing the particle filter operation
RobotDrive drive;
public void robotInit() {
camera = AxisCamera.getInstance(); // get an instance ofthe camera
cc = new CriteriaCollection(); // create the criteria for the particle filter
cc.addCriteria(MeasurementType.IMAQ_MT_BOUNDING_RECT_WIDTH, 30, 400, false);
cc.addCriteria(MeasurementType.IMAQ_MT_BOUNDING_RECT_HEIGHT, 40, 400, false);
drive = new RobotDrive(1, 3);
}
public void autonomous() {
while (isAutonomous() && isEnabled()) {
try
{
ColorImage image = camera.getImage();
BinaryImage thresholdImage = image.thresholdRGB(0, 45, 25, 255, 0, 47);
BinaryImage bigObjectsImage = thresholdImage.removeSmallObjects(false, 2);
BinaryImage convexHullImage = bigObjectsImage.convexHull(false);
BinaryImage filteredImage = convexHullImage.particleFilter(cc);
ParticleAnalysisReport[] reports = filteredImage.getOrderedParticleAnalysisReports();
if(reports.length > 0)
{
if(reports[0].center_mass_x > image.getWidth() / 2 + 10)
drive.arcadeDrive(0, 1);
else if(reports[0].center_mass_x < image.getWidth() / 2 - 10)
drive.arcadeDrive(0, -1);
else
drive.arcadeDrive(0, 0);
}
filteredImage.free();
convexHullImage.free();
bigObjectsImage.free();
thresholdImage.free();
image.free();
} catch (NIVisionException ex) {
ex.printStackTrace();
} catch (AxisCameraException e) {
e.printStackTrace();
}
}
}