Problems with USB camera(Lifecam)

Hey there,
We have been experiencing problems trying to integrate the USB camera into our actual driving code. The LifeCam code disables the driving code, specifically the motor controllers, and we are not exactly sure of why. What we have been trying to troubleshoot it for the last week, without any considerable success. Any help is greatly appreciated.

#include "WPILib.h"
/**
 * This is a demo program showing the use of the RobotDrive class.
 * The SampleRobot class is the base of a robot application that will automatically call your
 * Autonomous and OperatorControl methods at the right time as controlled by the switches on
 * the driver station or the field controls.
 *
 * WARNING: While it may look like a good choice to use for your code if you're inexperienced,
 * don't. Unless you know what you are doing, complex code will be much more difficult under
 * this system. Use IterativeRobot or Command-Based instead if you're new.
 */
class Robot: public SampleRobot
{
	 // robot drive system
	RobotDrive ArcadeRobot;
	Joystick joy, joy2;
	Servo ServoX, ServoY;
	double servoIn, servoIn2;
	VictorSP intake;
	TalonSRX flywheel;
	USBCamera cam0;

public:
	Robot() :
		ArcadeRobot(0,1),
		cam0(0),
		joy(0),
			joy2(1),
			ServoX(5),
			ServoY(4),
			intake(3),
			flywheel(2)

	{
		    cam0.SetWhiteBalanceAuto();
		    cam0.SetExposureAuto();
			flywheel.SetSafetyEnabled(false);
			intake.SetSafetyEnabled(false);
			ArcadeRobot.SetExpiration(0.1);
	}

	/**
	 * Runs the motors with arcade steering.
	 */
	void OperatorControl()
	{
		while (IsOperatorControl() && IsEnabled())
		{

			if (joy2.GetRawButton(3))
			{
				//ShootLowGoal();
				intake.Set(-1.0);
			}
			if (joy2.GetRawButton(5))
			{
				//ShootHighGoal();
				intake.Set(1.0);
			}
			if (joy2.GetRawButton(4))
			{
				//ShootLowGoal();
				flywheel.Set(-1.0);
			}
			if (joy2.GetRawButton(6))
			{
				//ShootHighGoal();
				flywheel.Set(1.0);
			}

			servoIn = (joy.GetY() +1)*0.5;
			servoIn2 = (joy.GetX() +1)*0.5;
			ServoX.Set(servoIn);
		    ServoY.Set(servoIn2);
		    ArcadeRobot.ArcadeDrive(joy2);
		    Wait(0.005);
		}
	}







};

START_ROBOT_CLASS(Robot)


You’re declaring cam0 at the end of the list of Robot variables. Does it work if you move the cam0(0) line to the end of the initializations, after flywheel(w)?

Alan,
We tried what you said but we still are getting the following errors

For cam(0)

no matching function for call to ‘USBCamera::USBCamera(int)’

For Joystick joy, joy2

Joystick Robot::joy’ -Wreorder]

**For USBCamera cam0 **

‘Robot::cam0’ will be initialized after -Wreorder]

It sounds like you might have fumbled some of the commas or semicolons when you moved the cam0(0) line. Can you post the part of the code that you modified?

I’m assuming you retyped the errors into the post by hand rather than copying them, because of the missing zero in cam(0). If you actually did copy and paste, then it seems you introduced a misspelling it when you moved it in your code.

I have double checked the comas and semicolons and nothing seems weird, but you are welcome to check if you want to.

#include "WPILib.h"

class Robot: public SampleRobot
{
	 // robot drive system
	RobotDrive ArcadeRobot;
	Joystick joy, joy2;
	Servo ServoX, ServoY;
	double servoIn, servoIn2;
	VictorSP intake;
	TalonSRX flywheel;
	USBCamera cam0;

public:
	Robot() :
		ArcadeRobot(0,1),
		joy(0),
		joy2(1),
		ServoX(5),
		ServoY(4),
		intake(3),
		flywheel(2),
		cam0(0)

	{
		    cam0.SetWhiteBalanceAuto();
		    cam0.SetExposureAuto();
			flywheel.SetSafetyEnabled(false);
			intake.SetSafetyEnabled(false);
			ArcadeRobot.SetExpiration(0.1);
	}

	/**
	 * Runs the motors with arcade steering.
	 */
	void OperatorControl()
	{
		while (IsOperatorControl() && IsEnabled())
		{

			if (joy2.GetRawButton(3))
			{
				//ShootLowGoal();
				intake.Set(-1.0);
			}
			if (joy2.GetRawButton(5))
			{
				//ShootHighGoal();
				intake.Set(1.0);
			}
			if (joy2.GetRawButton(4))
			{
				//ShootLowGoal();
				flywheel.Set(-1.0);
			}
			if (joy2.GetRawButton(6))
			{
				//ShootHighGoal();
				flywheel.Set(1.0);
			}

			servoIn = (joy.GetY() +1)*0.5;
			servoIn2 = (joy.GetX() +1)*0.5;
			ServoX.Set(servoIn);
		    ServoY.Set(servoIn2);
		    ArcadeRobot.ArcadeDrive(joy2);
		    Wait(0.005);
		}
	}







};

START_ROBOT_CLASS(Robot)

Shouldn’t the USBCamera constructor called with cam0(“cam0”, true) ?

Only USBCamera constructor is
USBCamera (std::string name, bool useJpeg)
http://first.wpi.edu/FRC/roborio/release/docs/cpp/classUSBCamera.html

Are you just trying to view the cam on dashboard, or are you trying vision processing? If you just want to view on dashboard, it is probably easier to just use CameraServer.
http://first.wpi.edu/FRC/roborio/release/docs/cpp/classCameraServer.html

Check your CPU usage. Ours skyrocketed when we enabled the camera, no matter the resolution / fps. We had two incidents on the field when we could not drive, but other motors worked just fine. It turns out we were hovering at 110% cpu usage for all of our matches, and that somehow disabled the drivetrain. Our rudimentary solution was to use a raspberry pi with MJPG streamer to get the feed to our driverstation.