diegorobot / diego1

11 stars 11 forks source link

Issue with encoder readings #1

Open didrif14 opened 6 years ago

didrif14 commented 6 years ago

We are trying to use your modifications for our differential drive robot. The left encoder is giving us negative values, however when we modify the encoder_driver.ino with "0-left_enc_pos;" the left motor recieves 255 PWM singnal.

long readEncoder(int i)
{
if (i == LEFT) return 0-left_enc_pos;
else (i == RIGHT) return right_enc_pos;
}

It fixes the encoder values, but it affects somthing else. Same thing happens if we change the encoder wires.

Do you have any tips on how to fix this issue?

didrif14 commented 6 years ago

Resolved. Turns out there is an error in the doleftPID() function.

  input = p->Encoder - p->PrevEnc;
  Perror =p->TargetTicksPerFrame + input;`

Should be:

  input = p->Encoder - p->PrevEnc;
  Perror =p->TargetTicksPerFrame - input;`