CPU usage idles at 80% and hits 100% when running teleop code

Just recently we ran into an issue during competition that lead to our robot being disabled due to data pack loss issues. when going over the logs of the roborio we realized that basically since any code was loaded to the RIO the robot’s CPU has been idling at 80%. when teh code is put into teleop mode we max out eh CPU at 100%. until just recently this appears to have not affected us, but today it appears the stars aligned ans cause our robot to fail during competition. We systematically went through our code removing things to try to figure out what was causing the issue. We basically have the code stripped down to the class calls of the attached devices and that is it and the CPU still idles at 80% with a non-existent teleop code at 100%. does anybody have any suggestion on what our problem might be. our code was never that complex to begin with so i see no reason as to why the code would peg the CPU during the teleop mode. here is a link to our robot code: http://pastebin.com/KVbgbMXF

list of trouble shooting we have tried

  1. reflash the roborio – with absloutly no code on the rio the cpu ran at a resonable CPU usage. as soon as code was loaded idle 80%, teleop 100%
  2. strip down code to just class calls, variable ids, and empty voids. – CPU idle 80%, teleop (with basically no code) 100%
  3. load robot with last year code – CPU idle 80%, teleop 100% (last year cod has significantly less in it… no camera, no CANTalon, no encoders for autonomous);

But seriously, a few things I would try:

Why is Scheduler being run at all?, especially in disabled?
Do you have the latest roboRio image?
SSH into the 'rio and run

top

top will tell you the most about your problem.

Try putting a Wait(0.05) at the end of your tele-op periodic.

Right now, your code just hammers through the teleop periodic. Having a tiny Wait() should bring your CPU usage down.

That’s not true


 97     } else {
 98       // call TeleopInit() if we are now just entering teleop mode from
 99       // either a different mode or from power-on
100       if (!m_teleopInitialized) {
101         lw->SetEnabled(false);
102         TeleopInit();
103         m_teleopInitialized = true;
104         // reset the initialization flags for the other modes
105         m_disabledInitialized = false;
106         m_autonomousInitialized = false;
107         m_testInitialized = false;
108         Scheduler::GetInstance()->SetEnabled(true);
109       }
110       HALNetworkCommunicationObserveUserProgramTeleop();
111       TeleopPeriodic();
112     }
113     // wait for driver station data so the loop doesn't hog the CPU
114     m_ds.WaitForData();
115   }
116 }

TeleopPeriodic is called every time you get data from the driver station.

Try removing the CameraServer and seeing if that reduces your CPU usage. I’d suggest trying to comment out parts of your code and see what is causing the high usage.

FYI, you are sleeping in TeleopPeroidic. This will cause none of the rest of your motors to update while you are sleeping.