hello
first excuse my bad English
I'm doing a project using two micro motors with encoder Pololu 100:1 cuadratuta:
encoders need to read well as one of the encoders is reading me 2 times and 2 are rotating at the same speed, they need to read each rotation by separate robot configuration is differential here I leave the code and reading the monitor serial.
#include <Servo.h>
#include <PololuWheelEncoders.h>
PololuWheelEncoders encoders;
volatile int encder=0;
volatile int encizq=0;
volatile int countder=0;
volatile int countizq=0;
volatile int resder =0;
volatile int resizq =0;
int Rx = 0;
int rder = 0;
int rizq = 0;
int vueltasIzquierda = 0;
int vueltasDerecha = 0;
int mdb =10; //Azul
int mdf = 11;//Amarillo
int mib = 6;//Amarillo
int mif = 5;//Azul
int count = 0;
int sensor = 0;
int demora = 250;
Servo serv;
void setup(){
Serial.begin(9600);
PololuWheelEncoders::init(2,12,3,13);
attachInterrupt(0,encoderder,CHANGE);
attachInterrupt(1,encoderizq,CHANGE);
}
void loop(){
Rx = Serial.read();
switch(Rx){
case 'F':
analogWrite(mdb,0); analogWrite(mib,0);
analogWrite(mdf,50);
analogWrite(mif,50);
Rx =0;
break;
case 'B': analogWrite(mdf,0); analogWrite(mif,0);
analogWrite(mdb,255);
analogWrite(mib,255);
Rx =0;
break;
case 'S': analogWrite(mdf,0); analogWrite(mif,0);
analogWrite(mdb,0); analogWrite(mib,0);
Rx =0;
break;
case 'R': analogWrite(mdf,0); analogWrite(mif,255);
analogWrite(mdb,0);
analogWrite(mib,0);
Rx =0;
break;
case 'L': analogWrite(mdf,255); analogWrite(mif,0);
analogWrite(mdb,0);
analogWrite(mib,0);
Rx =0;
break;}
}
void encoderder(){
encder = (-1)*encoders.getCountsM1();
if(encder >= 48){
countder++;
resder = encoders.getCountsAndResetM1();
Serial.print("EncDer="); Serial.println(countder);
}}
void encoderizq(){
encizq = encoders.getCountsM2();
if(encizq >= 48){
countizq++;
resizq = encoders.getCountsAndResetM2();
Serial.print("Encizq="); Serial.println(countizq);
}}
Serial Monitor
EncDer=EncDer=2
1
Encizq=1
EncDer=3
EncDer=4
Encizq=2
EncDer=5EncDer=6
EncDer=7
Encizq=3
Encizq=4
EncDer=E
Encizq=5
EncDer=EncDer=11
10
Encizq=6
EncDer=EncDer=13
12
Please Help!!!