I’m Chris, head programmer from Team 3878 in Hawaii.
I am having a problem concerning motor control with our robot. When Teleoperated mode is enabled on our Driver Station, the motors will jerk for a second, then stop moving. The motors do not respond to any joystick input after that, and I am at a blank to what could be causing this problem. I have rechecked this code at least 10 times and the other programmers on my team can’t spot anything wrong with it either. A weird thing is, the code worked perfectly an hour before, and nothing was wrong with it.
I am really confused. Has anyone had this problem before? Please help.
We had reset the code back to a previous version that worked, and it still was doing that. I am at a complete loss as to why this is happening. Here is a photo of the code we have that works:
Try holding the joysticks in the drive forward position while enabling the robot. I have seen this problem when the code was only reading the joysticks once at the very start of the match.
Make sure that no matter what happens you always call a Robot Drive every time the Teleop vi is iterated and that if you’re running a loop inside Teleop you continue executing a Robot Drive.
There’s a thing called Watchdog used to make sure the robot safely stops in case of a program hang. If Robot Drive isn’t called frequently enough, it will disable all motors.
The DS contains a tab called Charts. The red trace is the CPU usage of the cRIO. You may want to see if the CPU is maxed out. Second, the project template contains a Support Code folder, and in it is an Elapsed Times VI.
Drag Elapsed Times from the project and place it in Teleop. Run your program, with your robot on blocks, and open the Elapsed Times panel. It will how you the time between successive calls to Teleop.
Some of the other advice given is good. You need to call RobotDrive at least every 100ms or the safety mechanism will assume your code is forgetful and will set the speed to 0. You do not need to put a loop around Teleop because Teleop is called within a loop each time a new joystick packet arrives. If you were to put a continuous loop in Teleop, you would never return, and since you likely wouldn’t have a delay in it, you would read the joystick far faster than necessary and update the robot drive more often than necessary. This would interfere with the directions given by the DS and would cause issues with needing to reset the robot after teleop.
Once you have some info about Elapsed Times and CPU usage, I may have other ideas about what is going on.