HD3000 USB Camera Blues

Finally determined that these 2 lines of code caused us a lot of pain.

CameraServer::GetInstance()->SetQuality(50); 
CameraServer::GetInstance()->StartAutomaticCapture("cam0");  

The USB camera seemed too easy. Small, USB cable, no separate power… With Chief Delphi forum help, added these lines and images displayed on the Standard Dashboard.

Then we moved cameras between usb ports and roborios and again with Chief Delpi help found that cam0, could become cam1, then cam2, etc.

Then found the camera could not be used by Smart Dashboard. Again Chief Delphi help we got a widget to make that work. But the behavior was so erratic, that we reverted back to the Standard Dashboard for video and kept Smart Dashboard for data display and selectors.

Even with the Standard Dashboard the image randomly overexposed. We found reducing the update rate helped, but was never solidly consistent.

During this evolution, we always had difficulty deploying and connecting to roborio. We became timid about make program changes, since the build and deploy, test sequence could take anywhere for 20 seconds to 1 hour, depending on how many times we had to reset the roborio, restart the driver station, disconnect and reconnect to the router.

Again with Chief Delphi help we were directed to the the data charts on the Standard Dashboard as well as the event logs. We were always getting a lots of Lost Packets and the CPU usage was always around 95%. We posted our usage charts on Chief Delphi, but it was at the end of a long thread, so it got no response.

Finally at the PNW regional, the tech staff spend over an hour helping us. Swapped out all hardware, reviewing our code, etc., but could not made problems go away. They had requested that we not turn on the camera “USB Camera HW” at the previous match and we seemed to connect faster, but still had issues.

Issues happened so often, our drive team called it the Ghost Problem. We needed an Exorcism.

The tech staff said the 95% cpu usage was not normal and they were used to 50% for a Command-Based, C++ program. They said since we were not using the camera, we should try removing those 2 lines of code that enabled the camera.

Wow… cpu usage 50%, connection are crisp and consistent, build and deploy in less than 20 seconds.

Our epiphany came a little late with only 3 matches left at the regional, but it was great to end an event feeling like there is hope for next season.

I would like to thank all those who helped at the PNW regional and on Chief Delphi.

Where did you put those two lines of code?

They were in Robot.cpp - RobotInit.

void Robot::RobotInit() {
RobotMap::init();

picker = new Picker();
// BEGIN AUTOGENERATED CODE, SOURCE=ROBOTBUILDER ID=CONSTRUCTORS
chassis = new Chassis();
elevator = new Elevator();


// END AUTOGENERATED CODE, SOURCE=ROBOTBUILDER ID=CONSTRUCTORS
// This MUST be here. If the OI creates Commands (which it very likely
// will), constructing it during the construction of CommandBase (from
// which commands extend), subsystems are not guaranteed to be
// yet. Thus, their requires() statements may grab null pointers. Bad
// news. Don't move it.

oi = new OI();
lw = LiveWindow::GetInstance();

// instantiate the command used for the autonomous period
// BEGIN AUTOGENERATED CODE, SOURCE=ROBOTBUILDER ID=AUTONOMOUS

// END AUTOGENERATED CODE, SOURCE=ROBOTBUILDER ID=AUTONOMOUS

CameraServer::GetInstance()->SetQuality(50);  // %rod
//the camera name (ex "cam0") can be found through the roborio web interface
CameraServer::GetInstance()->StartAutomaticCapture("cam2");  // 3711
//CameraServer::GetInstance()->StartAutomaticCapture("cam0");  // 3712

We had problems using the camera streamer in WPILib also, so we’re using mjpg-streamer instead. Not sure if it works with the SmartDashboard widget… probably not.