i have written a program for contorlling 2 lineair concens actuators. I included the library Encoder.h for reading the encoder pulses, but the problem is that the counting of the pulses is going wrong. For example, i start my code with going to a switch to set the value of the encoder to 0. Then i move up to a encoder value of 40, after this i move down back to the switch, so what I normaly hope by reaching the switch is that the value of the encoder is zero again. But the encoder value is not 0 but its 7. So there is difference between counting by going up and going down. in addition, the value can also differ slightly each time the actuator goes up or down.
does anybody know what the problem can be by counting encoder (roratry encoder / hall sensor ) values.
are your encoders just rotary knobs, or attached to motor shafts spinning quickly?
if you try the demo example, what do you see in the console:
/* Encoder Library - TwoKnobs Example
* http://www.pjrc.com/teensy/td_libs_Encoder.html
*
* This example code is in the public domain.
*/
#include <Encoder.h>
// Change these pin numbers to the pins connected to your encoder.
// Best Performance: both pins have interrupt capability
// Good Performance: only the first pin has interrupt capability
// Low Performance: neither pin has interrupt capability
// avoid using pins with LEDs attached
Encoder knobLeft(18,19);
Encoder knobRight(20,21);
void setup() {
Serial.begin(115200);
Serial.println("TwoKnobs Encoder Test:");
}
long positionLeft = -999;
long positionRight = -999;
void loop() {
long newLeft, newRight;
newLeft = knobLeft.read();
newRight = knobRight.read();
if (newLeft != positionLeft || newRight != positionRight) {
Serial.print("Left = ");
Serial.print(newLeft);
Serial.print(", Right = ");
Serial.print(newRight);
Serial.println();
positionLeft = newLeft;
positionRight = newRight;
}
// if a character is sent from the serial monitor,
// reset both back to zero.
if (Serial.available()) {
Serial.read();
Serial.println("Reset both knobs to zero");
knobLeft.write(0);
knobRight.write(0);
}
}
Have you written a very simple test program for the homing routine and specified move? You may have mechanical issues of switch make/break positional differences and mechanical backlash in the actuators.