hi everyone
I'm in the process of building a simple robot that can navigate by dead reckoning.
I've come to a really weird issue and I'm not really sure exactly what's the problem,
though I think it has something to do with data types, in this case specifically floats.
I'm using stepper motors to control wheel movement and try to calculate how much
steps are necessary to travel a certain distance for example. Maybe you can look at the
code... the thing is if I calculate the steps by hand it turns out perfectly, though if
I let it be calculated by my arduino there seems to be some kind of error happening:
int DIR1 = 2;
int STEP1 = 3;
int DIR2 = 4;
int STEP2 = 5;
float pi = 3.14159265;
float wheelCircumference = 0.949;
float wholeTurn = 0.422*pi; //distance of the two wheels
float gearRatio = 11/3;
void doTurn(double radius){ //turn around certain radius
lcdWrite("do turn", "radius");
float stepAmount;
stepAmount = (radius/360)*(wholeTurn/wheelCircumference)*1600*gearRatio;
//360° turn would equal: 8196 steps
//judging by the behavior of my robot, something else gets calculated, if I enter
// 8196 directly everything works fine...
if (stepAmount < 0){
digitalWrite(DIR1, HIGH);
digitalWrite(DIR2, HIGH);
}
else{
digitalWrite(DIR1, LOW);
digitalWrite(DIR2, LOW);
}
int i = 0;
while (i < stepAmount){
i++;
digitalWrite(STEP1, LOW);
digitalWrite(STEP2, LOW);
delayMicroseconds(1200);
digitalWrite(STEP1, HIGH);
digitalWrite(STEP2, HIGH);
}
}
can anybody help me with that?
thanks in advance!