Help Shaft encoder ..,

Hello good evening I would like someone to help me urgently to create a program for the shaft encoder sensor not very accurate and when I start it again the program does different things, does anyone know why that happens?

Gonna need more context than that… what exactly are you trying to do? what does your code look like? if it could potentially be a mechanical problem (slop might be a factor), can you post a pic of the bot?

1 Like

void avanza(int distancia){
  //insertamos la posicion, velocidad y direccion que deseamos que tengan los motores. 
  EncoderA.setPosition(0, degrees);
  rightmotor.setVelocity(50, percent);
  leftmotor.setVelocity(50, percent);
  /*mientras la posicion del encoder sea mayor a la distancia introducida, los motores 
  iran hacia adelante.
  while (!(EncoderA.position(degrees) > distancia)) {
    Brain.Screen.print(".%2f", EncoderA.position(degrees));
    Brain.Screen.setCursor(1, 1);//brain screen sirve para imprimir los grados que avanza el enconder, en la pantalla del brain.
    wait(100, msec);
    Brain.Screen.clearScreen();//la pantalla se limpia cuando se cumple la condicion.
    wait(5, msec);
  // los motores se detienen cuando se cumple la condicion.

This is my program friend


1 Like

I’m still not sure what you’re using the encoder for exactly

Are you using the integrated motor encoders or a separate one, and where and for what? are you trying to make the robot drive a certain distance?

there will always be backlash/slop in the parts so it’ll never move perfectly. you need to account for that mechanically with things like lock bars and shoulder bolts, and/or compensate on the software side with something like PID loop

1 Like

I am using it to turn the encoder certain degrees separately, I have one encoder in the base part and another in the launcher part, but I would like something more complex like using it for distance and to be able to make a good launch and that it is not changed, so sometimes yes and sometimes no

So you are attempting the print the encoder value on the Brain Screen until its reaches the desired distance?