I need help on driveToPoint() function for odometry

This is my first time programming and I’m a little confused about odometry functions, especially driveToPoint() function. I have been trying to figure it out but I cannot understand how to get the values to put in the parameters. I found this under tutorials:

// turn 45 degrees and turn approximately 1.4 ft
chassis->driveToPoint({1_ft, 1_ft});

I understand the 1.4 feet part (sqrt(1^2 + 1^2)), but how do they calculate the degrees? Does it have something to do with unit circle? Any help will be greatly appreciated.
Thank you!

I assume the starting point is (0, 0). In this case, the code is likely using arctangents:

atan2(y2 - y1, x2 - x1)
= atan2(1-0, 1-0)
= atan2(1, 1)
= ~0.785 rad
= 45 deg

The relevant code is here in OkapiLib’s source code (I assume this is what you are using): https://github.com/OkapiLib/OkapiLib/blob/2a67a01a81b067447c42683f59c3609946f4bd54/src/api/odometry/odomMath.cpp#L42

3 Likes