-
-
Save Aluriak/1554905 to your computer and use it in GitHub Desktop.
Distance télémetre
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// On cherche à qualifier la précision du télémètre. | |
// Des marques bleues sont disposées sur la piste à intervale régulier. | |
// Le robot mesure la distance entre son point de départ et chacune des marques bleues rencontrées. | |
#define Telemetre IN_3 | |
#define Couleur IN_2 | |
#define Touch IN_4 | |
#define motors OUT_BC | |
int distance = 0; | |
int distance_precedente = 0; | |
byte data_file; // global pour simplifier | |
void setup(){ | |
SetSensorLowspeed(Telemetre); | |
SetSensorColorFull(Couleur); | |
SetSensorTouch(Touch); | |
DeleteFile("data.txt"); | |
CreateFile("data.txt", 1024, data_file); | |
} | |
void add_to_file(){ | |
int bytesWritten = 0; // inutilisé mais requis par WriteLnString | |
string inter = NumToStr(distance); | |
WriteLnString(data_file, inter, bytesWritten); | |
} | |
task BlueTick(){ | |
while(true){ | |
until(Sensor(Couleur) == INPUT_BLUECOLOR); | |
distance = SensorUS(Telemetre); | |
// Sécurité pour éviter les doubles mesures | |
if ((distance-distance_precedente) > 3) { | |
add_to_file(); | |
distance_precedente = distance; | |
} | |
} | |
} | |
task main(){ | |
setup(); | |
// --- On étalonne la mesure (prise d'origine) --- | |
distance = SensorUS(Telemetre); | |
distance_precedente = distance; | |
// --------- | |
StartTask(BlueTick); | |
OnRev(motors, 50); | |
until(Sensor(Touch)); | |
CloseFile(data_file); | |
StopAllTasks(); | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment