Robert,
I was actually able to get almost exactly what you have to work. The only difference is I made sure to update the camera before opening the camera and starting the capture.
Code:
public class Robot extends IterativeRobot {
Preferences prefs;
CameraServer server;
USBCamera targetCam;
public static int g_exp;
/**
* This function is run when the robot is first started up and should be
* used for any initialization code.
*/
public void robotInit() {
prefs = Preferences.getInstance();
g_exp = prefs.getInt("exp", 1);
SmartDashboard.putNumber("Exp", g_exp);
targetCam = new USBCamera("cam0");
targetCam.setBrightness(5);
// We actually still had trouble setting exposure. It didn't actually like values 0-100. We found that setting the brightness did enough though.
// targetCam.setExposureManual(g_exp);
targetCam.updateSettings();
SmartDashboard.putNumber("Brightness", targetCam.getBrightness());
targetCam.openCamera();
server = CameraServer.getInstance();
server.setQuality(50);
server.startAutomaticCapture(targetCam);
}
We then don't get anything in the teleopPeriodic. In order to change the parameter for brightness (or exposure) you could change the value on the smart dashboard, click on the tab 2nd from the top on the left side of the driver station and click robot code restart (or whatever it's called). You don't need to do a full reboot.
Now if you find anyway to turn off the autofocus...that'd be handy.