Hallo Alexander,
Yes, Code is quite clear ( I hope so ), but I see, that here is a error.
Measured current value which is jumping isn't current in Amps. Example :
Value "SEN_MOTOR_RIGHT" is readed from aml50.h:
case SEN_MOTOR_RIGHT: return(analogRead(pinMotorLeftSense)-motorSenseRightZero); break;
pinMotorLeftSense - it's value from analog input which is relevant to voltage connected to analog input and is 0-1023. When current is 0, ALC972-5 will send to analog input 2,5 V ( for Vcc = 5V ) and pinMotorLeftSense is 512.
motorSenseRightZero is 511 ( Can be adjusted )
So when current is 0, then : (analogRead(pinMotorLeftSense)-motorSenseRightZero) = 512 - 1 = 1 - But it isn't 1Ampere, it's one bit and it means that's necessary adjust zero position and change motorSenseRightZero to 512. After this adjustment : Zero current = SEN_MOTOR_RIGHT - 512 = motorRightSense = 0.
And with load :
pinMotorLeftSense will increase to aprox. 514. Then : (analogRead(pinMotorLeftSense)-motorSenseRightZero) = 514 - 512 = 2 - It isn't in Amps.
When we want value in Amps, we must measurement recalculate - see this web site :
www.lucadentella.it/en/2011/11/29/sensor...orrente-con-
arduino/
i.e. for pinMotorSense = 514 : 0,0264 * 514 - 13,51 = 0,0596A
For ALC972-5.
So we have a value in amps, but it's jumping. To decrease jumping radically, we must measure more values and calculate average :
motorRightSense = 0;
for(int i = 0; i < 1000; i++) {
motorRightSense = motorRightSense + (.0264 * (512+(readSensor(SEN_MOTOR_RIGHT))) -13.51) / 1000;
delay(1);
}
This code is for 1000 measurements, but not unusable, because will decrease radically system reactions.
Now I'm using this code :
motorRightSense = (motorRightSense * 0.95) + ((double)abs(.0264 * ((readSensor(SEN_MOTOR_RIGHT))) -13.51)) * 0.05;
Which give me a correct current value, but unstable and "motorSenseRightZero" is normally 0 with possibility adjust -100 to 100 and code in aml50.h is :
case SEN_MOTOR_RIGHT: return(analogRead(pinMotorLeftSense)+motorSenseRightZero); break;
So SEN_MOTOR_RIGHT value is for zero current = 512.
But it's for ALC972-5. For ALC972-30 code is :
motorMowSense = (motorMowSense * 0.95) + ((double)abs(.0742 * ((readSensor(SEN_MOTOR_MOW))) -37.88)) * 0.05;
Hope it's more understable in English.
Alex