Ihr seid ja richtig fix bei der Hitze.
Ich habe in der Zwischenzeit doch noch mit float herum gespielt, zum Geradeausfahren reicht das leider noch nicht, mal dreht er nach links, mal nach rechts ab.
Hat jemand einen Tipp dazu aus euren bisherigen Überlegungen?Code:#include "asuro.h" #include <string.h> //strlen void TimeSleep(unsigned int time) { unsigned int i; for (i = 0; i < time; ++i) Sleep(72); } void Write(char * msg) { SerWrite( msg, strlen(msg)); } unsigned int is_bright(unsigned int darkness) { if (darkness > 512) return 0; else return 1; } float CalibrateWheels(void) { Write("Start calibration"); unsigned int i; // counter unsigned int data[2]; // odometry data // 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[0] = is_bright(data[0]); last_state[1] = 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); TimeSleep(500); //Zum Hochfahren // 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[0] = is_bright(data[0]); last_state[1] = is_bright(data[1]); TimeSleep(50); } relation = (float) count_right / (float) count_left; // done testing, stop wheels MotorSpeed(0, 0); Write("Finished calibration"); return relation; } int main(void) { Init(); MotorSpeed(120, 120.0f * CalibrateWheels()); while(1); return 0; }







Zitieren

Lesezeichen