Hi,
ich habe ein Programm für Asuro geschrieben, das die Unterschiede der Drehgeschwindigkeiten der beiden Motoren rausfinden und ausgleichen soll. Beim Ausprobieren fährt Asuro nach der Kalibrierung aber nur im Kreis und ich komme nicht drauf, woran das liegen könnte :/
Das ist mein Code:
Code:
#include "asuro.h"
int main(void)
{
unsigned int wheel_factor;
Init();
wheel_factor = CalibrateWheels();
MotorSpeed(120, 120 * wheel_factor);
while(1);
return 0;
}
float CalibrateWheels(void) {
Write("Start calibration");
// counter
unsigned int i;
// odometry data
unsigned int data[2];
// rotation count of the wheels
unsigned int count_left = 0;
unsigned int count_right = 0;
// contains the last brightness state for the wheels
unsigned int last_state[2];
OdometrieData(data);
last_state[2] = is_bright(data[0]), is_bright(data[1]);
// the relation between the left amd the right wheel's rotation count
float relation;
// start driving
MotorDir(FWD, FWD);
MotorSpeed(120, 120);
// 5 seconds
for (i = 0; i < 100; i++) {
OdometrieData(data);
// if a wheel's brightness changed, increase the counter
if (is_bright(data[0]) != last_state[0]) {
count_left++;
}
if (is_bright(data[1]) != last_state[1]) {
count_right++;
}
last_state[2] = is_bright(data[0]), is_bright(data[1]);
TimeSleep(50);
}
relation = count_right / count_left;
// done testing, stop wheels
MotorSpeed(0, 0);
Write("Finished calibration");
return relation;
}
unsigned int is_bright(unsigned int darkness) {
if (darkness > 512) {
return 0;
} else {
return 1;
}
}
void Write(char msg) {
// Send a string via IR without having to think about the length of the string
SerWrite(msg, strlen(msg));
}
void TimeSleep(unsigned int time) {
// Sleep for ``time`` miliseconds
unsigned int i;
for (i = 0; i < time; i++) {
Sleep(72);
}
}
Die Odometriesensoren funktionieren beide, habe sie mit dem SelfTest getestet.
Weiß jemand, woran das liegen könnte?
BeeWee[fade:e7bfbc102e][/fade:e7bfbc102e]
Lesezeichen