Tick Diff

I am getting the exact same error that was mentioned in this thread. But I saw that he was not able to fix the issue. Both of my encoders are working as expected. I’m not sure what the issue is and any help would be greatly appreciated.

#include "subsystems/drivetrain.h"
#include "okapi/api/odometry/odomState.hpp"
#include "okapi/api/odometry/odometry.hpp"
#include "okapi/api/util/logging.hpp"
#include "okapi/api/util/mathUtil.hpp"
#include "okapi/impl/device/motor/motorGroup.hpp"
#include "pros/motors.h"


ADIEncoder leftEncoder = ADIEncoder ('A', 'B', true);
ADIEncoder rightEncoder = ADIEncoder ('C', 'D', true);

ADIEncoder middleEncoder('E', 'F');

Motor topLeft(1);
Motor bottomLeft(2);
Motor topRight(-5);
Motor bottomRight(-10);

MotorGroup leftDrive = MotorGroup({topLeft, topRight});
MotorGroup rightDrive = MotorGroup({bottomLeft, bottomRight});


auto chassis = ChassisControllerBuilder()
    .withMotors(leftDrive, rightDrive)
    // .withGains(
    //     {0.001, 0, 0.0001}, // distance controller gains
    //     {0.001, 0, 0.0001}, // turn controller gains
    //     {0.001, 0, 0.0001}  // angle controller gains (helps drive straight)
    // )
    .withSensors(leftEncoder, rightEncoder)
    .withLogger(defaultLogger)
    .withDimensions(AbstractMotor::gearset::green, {{3.25_in, 8_in}, quadEncoderTPR})
    .withOdometry() // use the same scales as the chassis (above)
    .buildOdometry(); // build an odometry chassis

 
void drivetrain::dosomething() {
    
    // set the state to zero
    defaultLogger->info(chassis->getState());
    chassis->setState({0_in, 0_in, 0_deg});
    defaultLogger->info(chassis->getState());
    chassis->driveToPoint({10_in, 10_in});
}

I had this same error (I switched to using RyanLib bc i couldn’t figure this out) but I think I got rid of the error by deleting the .withGains if I remember correctly.


I could never get it exactly working though I kept getting stupid errors like this:

Sorry this post might not be helpful but I have had the same problems

Is there any good documentation for ryanlib and odometry?

That error is probably happening if you are running the terminal by being connected to the controller. It does not have enough bandwidth to print a message every 10 milliseconds. Try 50ms and the errors should go away.

1 Like

Thanks! Will definitely try this

Ryan walked me through it :)) actually he wrote the turning part of the controller just for me I feel special

If I change the time to 50ms, will this fix the original issue or the issue Ian is having?

If I remove with gains and try that, should it work?

I will say- the “with gains” part was commented out and it still didn’t change the error.

It *should * fix the issue Ian is having. Sorry, I am not familiar with okapi so I’m not sure how to resolve the error. To answer your question about odometry, this PDF by Pilons explains the math and idea behind it very well. I would recommend reading it if you want to learn more about how it works.

This has been an issue for a while. I don’t think a patch ever came out.