Optical encoder question

I am experimenting with odometry and am using optical shaft encoders, but I cannot get them to read anything when I try to have them read values on the controller any coding things that i need to add to get them to work??

this is what my code looks like:

Controller1.Screen.setCursor(10,1);
Controller1.Screen.print(RightE.rotation(rotationUnits::deg));

the controller screen doesnt work like that afaik. The V5 brain screen is much better for displaying data.

You are close. I would use a variable for the encoder value.

For example:

At the beginning of your program:

double RightEncoderValue;

In your loop:

RightEncoderValue=RightE.rotation(degrees);
Controller1.Screen.ClearLine(1);
Controller1.Screen.setCursor(1,1);
Controller1.Screen.print(RightEncoderValue);

Please note that you can only output lines on the controller. Each line can handle somewhere around 30-35 characters of text. You can realistically display 2 values per line. For the second value, you would set the cursor to about column 15.

2 Likes

Yeah, Controller.Screen.print() could take ints and doubles via special template override (see vex_controller.h line 445), but I would rather stick with more generic printf() formatting:

int    encoderTicks = RightE.value();
double encoderDeg = RightE.rotation(degrees);

Controller1.Screen.print("Ticks=%d Deg=%f", encoderTicks, encoderDeg);

https://api.vexcode.cloud/v5/html/classvex_1_1encoder.html