Immediately upon pressing the user button, several of our robots immediately begin turning instead driving straight. It doesn’t matter if I have them use the effort block, the straight block or the arcade block. They simply wont drive straight. I have closed all windows, I tried cleaning the wheels and the castors, I swapped the sides of the motors. I am at a loss and my students are frustrated.
This does sound like an odd and frustrating problem. Let me ask a few questions just to make sure we are all aligned. I assume you are running the code shown below. And that the motors are plugged into MOTOR L and MOTOR R
Assuming that is true. If you put the XRP up on something like a roll of tape so the wheels can run free and then hit RUN. Does only one wheel turn?
If yes, what is the results when you swap the motors? Does the original motor spin or the other motor spin?
This will help us determine if this is a problem with the motor, or with the control board.
Both wheels are spinning. It doesn’t seem to matter if I use the straight code block, the arcade block, the effort block. It is happening across multiple robots. I have tried shutting done the other windows
One thing to remember is that the gyro resets when the program starts. When hitting run or reset on the XRP the XRP should be sitting still on a somewhat flat surface. The gyro stabilization takes about 2 seconds.
I will reiterate what @Fgrossman said with some more elaboration.
When you first run a program on the XRP after it resets, it runs a calibration routine on the gyroscope in the IMU, which can take a few seconds. During this calibration, the XRP needs to be completely stationary to get an accurate calibration. If the robot is turned during the calibration, the gyro will then believe the robot is constantly rotating, which can result in the behavior you’re seeing. To verify this, you can try running the following:
from XRPLib.defaults import *
import time
while True:
print(imu.get_yaw())
time.sleep(0.1)
If you see the yaw angle changing a lot while the XRP is stationary, then the gyro in the IMU did not calibrate correctly; there was likely motion during the calibration. And by “changing a lot” I mean more than 1 degree per second. There will always be some change because the calibration isn’t perfect, but it should be less than 1 degree per minute.
Also, the calibration only happens after the XRP is reset. Clicking the STOP button does not reset the XRP. To force a reset, you can either press the RESET button on the control board, or do a full power cycle.
We’ve had similar problems. It seems to be getting worse throughout the semester. I took one that was drifting left and swapped the motors (moved the left motor to the right and vice versa). The robot then started drifting right. When I swapped the wheels it started drifting left again. Early on, we did a lot of square and circle patterns moving in one direction - perhaps uneven wear on the tires is causing the drift?