Magnetic encoder 6CPR? (for Micrometals)

Hello –

I am curious about the resolution I am obtaining from my newly received magnetic encoders for micrometal gearmotors. But, first, sweet job on those Pololu!

So, I am getting 600 counts per wheel revolution. They are advertised as 12 CPR, but seems I am getting 6 CPR, with 100:1 Micro MP gearmotors. My tests returned this value on an Arduino Uno and minimal 1284P-PU @ 16MHz, and tests failed on AMini. On the AMiniLV, my sole remaining pins for pin change ints was the MISO & MOSI lines, single motor tested. From each encoder I can measure HIGH and LOW with ref to GND on the OUTA and OUTB, e.g., 5.02V and ~180mV.When motors are allowed to free-run, the count goes up to 32k, swaps sign, and cycles back around to zero as expected. In the end I will be using the 1284P-PU as the MCU.

I am using the Arduino IDE 1.0.5-r2. Back in December I pulled down the Pololu-Arduino libraries and installed the 2012 version. The “PololuWheelEncoder” folder is where it is expected and no errors appear on verify/compile. In the changelog for the 2015 version (for Arduino 1.6) there is added boards and programmers files, that being the only difference I can tell at present.

I am fine with the results obtained from these as described above, but I am curious what I may be doing wrong to not be receiving the 12CPR from the encoders.

A hui hou, Mark

Code below for review:

[code]
#include <PololuWheelEncoders.h>

/* TB6612FNG to 1284P-PU “Arduino” pins */
#define PWMA 13
#define AIN1 18
#define AIN2 19
#define PWMB 14
#define BIN1 2
#define BIN2 3
#define STBY 12

long previousMillis = 0;
long intervalPrint = 100;

void setup(){
Serial.begin(115200);

//PololuWheelEncoders::init(2,3,4,5); // Arduino UNO
PololuWheelEncoders::init(22,23,20,21); // 1284P-PU

pinMode(PWMA,OUTPUT);
pinMode(AIN1,OUTPUT);
pinMode(AIN2,OUTPUT);
pinMode(PWMB,OUTPUT);
pinMode(BIN1,OUTPUT);
pinMode(BIN2,OUTPUT);
pinMode(STBY,OUTPUT);
Serial.println(“1284 motor test”);
startUp();
delay(2000);
Forward();
}

void loop(){
unsigned long currentMillis = millis();

if (currentMillis - previousMillis > intervalPrint)
{
previousMillis = currentMillis;

Serial.print("M1 = ");
Serial.print(PololuWheelEncoders::getCountsM1());
Serial.print(", M2 = ");
Serial.print(PololuWheelEncoders::getCountsM2());

Serial.print(" // Error M1 = ");
Serial.print(PololuWheelEncoders::checkErrorM1());
Serial.print(", M2 = ");
Serial.println(PololuWheelEncoders::checkErrorM2());

}

}

//****** MOTOR CONTROL *******
//****************************
void Forward ()
{
digitalWrite (AIN1,HIGH);
digitalWrite (AIN2,LOW);
analogWrite(PWMA,255);
digitalWrite (BIN1,HIGH);
digitalWrite (BIN2,LOW);
analogWrite(PWMB,255);
}
void Backward ()
{
digitalWrite (AIN1,LOW);
digitalWrite (AIN2,HIGH);
analogWrite(PWMA,255);
digitalWrite (BIN1,LOW);
digitalWrite (BIN2,HIGH);
analogWrite(PWMB,240);
}
void stopAll ()
{
digitalWrite (AIN1,HIGH);
digitalWrite (AIN2,HIGH);
analogWrite(PWMA,255);
digitalWrite (BIN1,HIGH);
digitalWrite (BIN2,HIGH);
analogWrite(PWMB,255);
}
void startUp ()
{
digitalWrite(STBY,HIGH);
}
void shutDown ()
{
digitalWrite(STBY,LOW);
}[/code]

Hello. I think you are encountering a known issue in the PololuWheelEncoders library that causes half of the counts to be lost. As a workaround, you should be able to fix your copy of the library by finding the PololuWheelEncoders.cpp file that you installed, and adding “? 1 : 0” in the right places to convert the output of OrangutanDigital::isInputHigh into proper booleans. There are 8 places where you should insert that code into the file.

For example, line 105 is

and you would change it to:

We plan on fixing this soon and re-releasing the library.

–David

Aloha David and thank you for the pointers.

Say, um, I honestly did search around the forum for an answer to this but nothing turned up. If it is a known issue, and has been discussed here prior, could you add a link to this in a reply post?

Much appreciated, and thank you for the wonderful support.

A hui hou, Mark

EDIT: Sorry, found the in text URL in your original reply. And the workaround was a success.

Hello, Mark.

We updated our libraries for the Arduino environment to fix this issue. It sounds like you already got your system working, but the latest version is available in the Programming Orangutans and the 3pi Robot from the Arduino Environment guide.

–David