Beginning Odometry

Hi everyone! We are a team from Texas and were beginning Odometery this season. We were looking at Pilons Guide to Odometry and were confused on the third step. What exactly should we update the previous values to?
Here is our code below:

float conversion;

float encoderLeftPrevious;
float encoderRightPrevious;
float encoderBackPrevious;

float encoderLeftChange;
float encoderRightChange;
float encoderBackChange;

void calculateChange()
{
encoderLeftPrevious = encoderLeft.position(rotationUnits::deg);
encoderRightPrevious = encoderRight.position(rotationUnits::deg);
encoderBackPrevious = encoderBack.position(rotationUnits::deg);
while(true)
{
float encoderLeftCurrent = encoderLeft.position(rotationUnits::deg);;
float encoderRightCurrent = encoderRight.position(rotationUnits::deg);
float encoderBackCurrent = encoderBack.position(rotationUnits::deg);

encoderLeftChange = conversion*(encoderLeftCurrent - encoderLeftPrevious);
encoderRightChange = conversion*(encoderRightCurrent - encoderRightPrevious);
encoderBackChange = conversion*(encoderBackCurrent - encoderBackPrevious);
vex::task::sleep(100);

}
//what to set previous values equal to?
}

Set the previous encoder value to the encoderLeftCurrent (right or back are same thing) before the encoderLeftCurrent is updated. The two ways to do this is either put it at the end or the beginning.

1 Like

Thank you! I have one more question if you don’t mind. Instead of writing this code in main.cpp, I created another class simply for Odometry, but when I call any method from that class in my main.cpp, it is not able to find that method and gives me an error. Would you know how to connect files together?

Since I don’t have your full code I can’t say for sure, but it seems like you may not have told your code to include the code from the new file. Do you have #include "filename.exnention" at the beginning of main.cpp? You can put that line right after #include "vex.h"

1 Like

Hi! Yes, I have, however it tells me that the class is not found.

You should try and make sure the file is in the correct place

1 Like