Lemlib is off by a few inches for every 20

I was setting up a lemlib odometry system but it is having problems calculating a straight line. I will push it forward a field tile in the Y direction and it will give me around 24 Y and 2 X even when I push it against a wall. This same thing happens with the X direction. Is this normal or is there a problem with my code.

If it is necessary this is my code

this is my main section
main.zip (3.0 KB)
this is all of it
curveDriveAndOdom.zip (28.7 MB)

Can you send a picture of your robot? If your tracking wheels are not perfectly perpendicular with the drivetrain you might run into issues.

These are the pictures


Two things that might be happening is that if you are using 2.75 wheels for the odometry and your drivetrain is 3.25 you might have to account for that if you already haven’t. Also while this is unlikely because you are using old sensors they might be going bad or be less accurate then the new ones.

Change lines 131-134 in main.cpp to this code temporarily:

// print sensor values to the brain screen
pros::lcd::print(0, "IMU: %d", imu.get_rotation());
pros::lcd::print(1, "Horizontal: %f", horizontal_tracking_wheel.getDistanceTraveled());
pros::lcd::print(2, "Vertical: %f", vertical_tracking_wheel.getDistanceTraveled());

Then try pushing it against a wall again with the new code. The value for the IMU should not change by more than a few degrees. If it does, try swapping the IMU.

2 Likes

I started working on some odometry code. 2 perpendicular encoders and an IMU. The code is just way off like when I drive forward for around 4 tiles turn 180 degrees go back around 4 tiles turn 180 degrees and align the robot to the starting point with my hands it will be off by a few inches in each direction. It still happened even when I tried using arc tracking or even a lemlib tutorial. I want to know if there is a way to tune the code or something else that I don’t know or if it is a hardware malfunction.

Here is the main section of my own arc tracking attempt
main+test+arc.zip (2.0 KB)

here is all of it (past attempts are commented out)
src.zip (11.8 KB)