Robot Drive Error

When I run my LabVIEW code on the practice bot, an error appears saying “The loop that contains RobotDrive is not fast enough. This error can occur if the loop contains too much code, or if one or more other loops are starving the RobotDrive loop.” This is on RobotMain.vi. Can you find a way to fix this?

Well… as the error says… there’s probably too much in your loop. I think we need way more information to provide guidance on what can be causing this…

  • Do you have a code snippet of Teleop.vi? Assuming this happens in Teleop period…
  • Does this just happen in the practice bot?
  • Did it happen before? Which code changes did you do?

Help us help you :slight_smile:


I indeed have a snippet of my Teleop code. This does happen to the practice bot, as there is a delay before the wheels spin. This has never happened to me before.

Thanks for providing that information. Here my comments:

  1. You are putting everything in Teleop (from opening the motors to using them), therefore you are making Teleop have to open the motor references every 20 ms. You want to open motor references in Begin (runs just once at the beginning of your program) and just use them later.
  2. You are writing to the NT tables twice for Right Driver Joystick/Axes and Right Driver Joystick/Buttons. This is called a race condition in LabVIEW because there is no dependency between the top code and the bottom code (everything in LabVIEW executes as soon as it has its inputs available - this is the code principle of LabVIEW and is called Dataflow: it is super powerful when you use it to your advantage)
  3. The Drive VIs are designed to control all your drive train, not just one side. Therefore, by opening a reference to one side and then a reference to the other, you are essentially making each side behave as a complete drive train. Use the Open 4 Existing Motors VI available from the WPI Robotics palette under Drive.
  4. After you are opening your SPARKs, you are not wiring anything to its output, effectively losing whatever reference you opened. This comes back to Dataflow, and ensuring the Data goes through your diagram using wires. Wire those references in order to use them!

Here is my recommendation:

  1. Use Begin.vi for what it is designed, and open your references there. Moreover, use the Open 4 Existing Motors and wire those SPARK references.
    Begin

  2. Use the Teleop.vi to what is is intended to do: drive your robot. Don’t open references, take advantage of the Drive VIs that already translate your joysticks into the left and right sides of your drive train and write to the Network Tables just once (note that the Network Tables portions are just to ease debugging by sending the values to the Dashboard).
    Teleop

You can find more SPARK examples in the REV robotics Github site: SPARK-MAX-Examples

Good luck with Infinite Recharge!

PS: The attached images are LabVIEW snippets that you can use dragging them to the environment and use them as code.

Thanks for the snippets, but can you make the bottom one so it can run 2 joysticks?

Even though I have made these snippets, please try wiring it yourself. Partly just to learn the mechanics of wiring and everything in LabVIEW.

To do that you would:

  1. In the Begin.vi make a copy of the Joystick code making sure to open it at a different USB port and call it a different name (e.g. Joystick 1).
    1
  2. Make a copy of the Joystick RefNum Registry Get, Joystick Get Values, refnum name constant, and the index array. You may collapse the index arrays if you want since you will only need 1 axis from each joystick. Put a 1 constant on both index arrays as shown in the picture (they are blue).
    2

The reason to use ‘1’ for the index array is that most joysticks (like this one) have the X (side to side) axis as index 0, and the Y (forward/backward) axis as index 1. You can look at all the axes in LabVIEW by “probing” the array of axes (fat orange wire) while TeleOp is enabled. Let me know if I should explain more.

1 Like

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.