Set up an x-drive with Okapi

Our team just started using Okapi today and we’re having difficulty on setting up an x drive

This is the documentation for an x-drive in okapi that I found at this link: https://okapilib.github.io/OkapiLib/classokapi_1_1XDriveModel.html
Screen Shot 2020-12-05 at 9.37.33 PM

I’m sure it’s not supposed to work if I just copy and paste it, but I’m not sure what to change.
Screen Shot 2020-12-05 at 9.39.32 PM

This is one of the errors that I get and I’m not sure what to do about it.
Screen Shot 2020-12-05 at 9.39.40 PM

One other thing: This is how our team used to set up our motors. Can we still do this with okapi or do I have to do something different since I’m creating a chassis or something with okapi?
Screen Shot 2020-12-05 at 9.44.30 PM

Thank you so so much for any help!

Hey there!

std::shared_ptr<ChassisController> chassis =
ChassisControllerBuilder()
    .withMotors(
        1,  // Top left
        -2, // Top right (reversed)
        -3, // Bottom right (reversed)
        4   // Bottom left
    )
        // Green gearset, 4 in wheel diam, 11.5 in wheel track
    .withDimensions(AbstractMotor::gearset::green, {{4_in, 11.5_in}, imev5GreenTPR})
    .build();

Try this out. Make sure to replace the motor ports and the dimensions!

2 Likes

Thanks! Would you by any chance know how I can use okapi to program an x-drive to strafe during auton? My team wants to use distance-based strafing but we can only find time-based strafing in the API.

Well, try this. Say you’re running auton. Initialize your initial position first by doing;

chassis->setState({0_ft, 0_ft, 0_deg});

In order to make it so that you can use the field tiles as “coordinates”, I suggest calculating how much the center of your robot is offset from the back of the field in the y direction. I am assuming your robot is centered within the tile with respect to the x-axis.

Then, if you want the robot to go to the left, you will tell it to

chassis->moveToPoint({0_ft, 1_ft});

I believe you will need three encoders mounted on your drive thusly;
image
And then add a snippet to your chassis code with the encoder ports like this;

    .withSensors(
        ADIEncoder{'A', 'B'}, // left encoder in ADI ports A & B
        ADIEncoder{'C', 'D', true},  // right encoder in ADI ports C & D (reversed)
        ADIEncoder{'E', 'F'}  // middle encoder in ADI ports E & F
    )

So, your final chassis initialization might look something like this.

std::shared_ptr<OdomChassisController> chassis =
ChassisControllerBuilder()
        .withMotors(
        1,  // Top left
        -2, // Top right (reversed)
        -3, // Bottom right (reversed)
        4   // Bottom left
    )
    // green gearset, 4 inch wheel diameter, 11.5 inch wheelbase
    .withDimensions(AbstractMotor::gearset::green, {{4_in, 11.5_in}, imev5GreenTPR})
    .withSensors(
        ADIEncoder{'A', 'B'}, // left encoder in ADI ports A & B
        ADIEncoder{'C', 'D', true},  // right encoder in ADI ports C & D (reversed)
        ADIEncoder{'E', 'F'}  // middle encoder in ADI ports E & F
    )
    // specify the tracking wheels diameter (2.75 in), track (7 in), and TPR (360)
    // specify the middle encoder distance (1 in) and diameter (2.75 in)
    .withOdometry({{2.75_in, 7_in, 1_in, 2.75_in}, quadEncoderTPR})
    .buildOdometry();

Now I have not tried an x-drive with okapi, however this should function. Note that you may have to change the reversal of your motors. Hope this helps!

4 Likes