New to XRP and trying to get the drivetrain.turn(90, 0.5) to work. I have a new XRP robot and am using XRP Code Editor, which updated my robot when first connected. When I run drivetrain.turn(90, 0.5) it rotates about 107 degrees. If I add a drivetrain.turn(-90, 0.5) it returns to the starting position. I was under the impression turns were controlled by the IMU and therefore wheel slippage etc. should not be an issue, although I’m running on a mat with good traction. Am I doing something wrong? It seems like that much error is way too much to just try to correct using fudge factors.
I also see in the examples using differential_drive instead of drivetrain. Should I be using that instead?
I also tried
while True:
print(imu.get_yaw())
time.sleep(0.1)
which gives a 0 initially then when manually rotating the robot to 90 degrees it returns 103 degrees. So I don’t think it has anything to do with mechanical issues with the robot. Is there a hard IMU reset that might help? Thanks in advance for any help.
I recently purchased a 2nd XRP set, so I tried just the control board. It updated the software and then I loaded my program from above to display the yaw and found the exact same results, with a reading of 84 when it is at an actual 90 degrees and it reads 90 when at actual 103 degrees. So I don’t think I have a “bad” control board. Is the issue with software? What am I doing wrong?? Thanks!
I reset the yaw to zero before using the turn() methods. I don’t know if that matters or not, but my robot made degree-accurate turns while competing in the mountain mayhem game. Also, I use an effort of 0.6. I don’t recall why I use this effort value, but there must have been some reason I changed it from the default. Maybe try that as well?
imu.reset_yaw()
The IMU gyroscope reports the orientation of the robot. The encoders on the motors keep track of fractional rotations of the motor. The drivetrain commands use PID to incorporate information from both of these measurements.
The gyroscope MUST be calibrated prior to each run in order to be useful. Gyro drift is a serious issue.
I’ve modified the original code so much that I don’t recall if there’s a calibration routine included in the XRP libraries, if not, LLM can write one for you trivially.
Thank you for the responses! Here is the code I’m running. I do a IMU calibrate, at least I think I do. It does report a yaw of 0 after the calibration, and then reports 91.8 after the rotation, but the robot has actually rotated 104 degrees. I understand that the motors use the encoders, but doesn’t drivetrain.turn(90, 0.5) use the gyro to make its turn, and not the encoders? I was under the impression that the purpose of this was so that wheel slippage etc. would not impact the spin. I also don’t understand why the IMU would report 91.8 degrees when the robot is clearly not at that heading. I really appreciate the help!!
from XRPLib.defaults import *
import time
imu.calibrate(5)
imu.reset_yaw()
print(f"Yaw after Calibrate: {imu.get_yaw():.2f} degrees")
drivetrain.turn(90, 0.5)
time.sleep(0.5)
print(f"Yaw after turn: {imu.get_yaw():.2f} degrees")
With result:
Yaw after Calibrate: 0.00 degrees
Yaw after turn: 91.98 degrees