Robot is lagging behind our controller inputs

When we try to drive or do any action on our robot, the robot has like a delay. Sometimes it is half a second, sometimes even longer. An example would be when we push our joysticks forward, the robot doesn’t instantaneously move forward, it waits for like half a second to like 2 seconds before it actually moves. Please help! We have disable/commented out everything except driving for the the mecanum wheels. Still, lag.

Edit: We also just updated our control hub when this issue arised. We don’t know if the update actually had to do anything with it.

When I’ve seen this, there’s a bunch of possible reasons:

  1. Something in your code has changed how your program loops through your main or repeated loop. If your program takes a considerable amount of time, you might be looping through code slower and thus updates are slower. It is recommended to put a telemetry call at the beginning of your main loop that outputs the amount of time between “now“ and the last time the time was obtained in that same place.
  2. Your code may be calling a sensor that is having problems communicating, and may be calling the sensor more often than necessary. Most sensors should only be read once per loop, as reading sensors can be a very expensive (time) operation. Functions that use the value of a sensor more than once (if logic, comparisons, etc) without caching/saving the value, is going to be a problem. This is especially true if the sensor is an I2C sensor. Check the sensors to make sure they’re working properly.
  3. Check the ping times on the Driver Station - if ping gets high, you’re going to have issues with lag. Make sure your Control Hub antenna is not covered (the antenna is on the middle of the face of the control hub where it says “Control Hub“).
  4. Reboot your Driver Hub. Rarely this can be caused because something on your driver hub is slowing down sending commands to the robot.

These are the issues that come to mind immediately. Almost always I find out the problem is (1) or (2), but you can troubleshoot it using the telemetry recommendation in (1).

-Danny

Hi Danny,

Thank you so much for the response! We isolated every single part of our code until we found the issue. We isolated the mecanum wheels functions just by itself, and slowly added in other functions and actions that we wanted. At first, when we isolated the mecanum wheels, the robot was still laggy, but not as much. I also unplugged and replugged all the I2C cables, and that did the trick (I don’t know why it worked but I saw something about that online). We also got data on the loop count to help us pinpoint the part of our code that was causing the slowing. Afterwards, we found out that our code for our color sensors was causing the lag, so we plan on fixing that. Without the color sensor code, everything was back to normal!

Thank you so much!