A year ago it seems someone else ran into this.
While I’m reading values from the shaft encoder on my perfectly still robot it randomly jumps to huge value. I’ve tried swapping the ports and the like and nothing has changed.
Encoder: 0.000000
Encoder: 0.000000
Encoder: 0.000000
Encoder: 0.000000
Encoder: -838860.736111
Encoder: 0.000000
Try a simple test program, something like this.
demo
/*----------------------------------------------------------------------------*/
/* */
/* Module: main.cpp */
/* Author: james */
/* Created: 1/31/2023, 9:07:19 AM */
/* Description: V5 project */
/* */
/*----------------------------------------------------------------------------*/
#include "vex.h"
using namespace vex;
// A global instance of vex::brain used for printing to the V5 brain screen
vex::brain Brain;
// define your global instances of motors and other devices here
vex::encoder en1( Brain.ThreeWirePort.G );
int main() {
// wait for configuration
this_thread::sleep_for(150);
while(1) {
double v = en1.rotation(degrees);
Brain.Screen.printAt( 10, 50, "%.2f", v );
printf("%.2f\n", v);
// Allow other tasks to run
this_thread::sleep_for(20);
}
}
I just checked that and see no issues, you can also go to the devices screen for the 3wire expander while your code is running and see encoder values there.

3 Likes
The encoder seems to be working fine, but calling:
SideEncoder.rotation(rev);
Still gives me the large values after a bit, despite the fact they are not shown on the brain screen.
I can’t really help with only one line of code out of context. It sounds like you have some other unrelated issue in the code interfering with the encoder, can you write a small complete example that demonstrates the issue.
3 Likes
Position Track is a task. I’ve also tried with different sleep times, all giving the error. (Some random ones between 10 - 50msec)
int positionTrack(void) {
SideEncoder.resetRotation();
while(true)
{
double newHorizontalEncoder = SideEncoder.rotation(deg);
printf("Encoder : %f\n", newHorizontalEncoder );
task::sleep(10);
}
return 0;
}
yea, I need a complete example that shows the issue similar to the program I posted, for all I know you have 25 other tasks all running in addition to positionTrack. If I just use the code above I still have to make several assumptions about how you start that task and what you may be doing with SideEncoder elsewhere in the code.
3 Likes
It’s basically just this. I also have some user control, but PositionTrack is the only place that the encoder is even referenced. Ignoring Comp Template, Position Track is also my only task.
int main() {
task positionTracker = task(positionTrack, task::taskPriorityHigh);
while(true)
{
wait(10, msec);
}
}
int positionTrack(void) {
SideEncoder.resetRotation();
while(true)
{
double newHorizontalEncoder = SideEncoder.rotation(deg);
printf("Encoder : %f\n", newHorizontalEncoder );
task::sleep(10);
}
return 0;
}
Dude, he told you twice to send a complete example. Zip up your code and post it here.
2 Likes