Created
December 24, 2011 17:08
-
-
Save matael/1517817 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_1 | |
#define Couleur IN_2 | |
#define Touch IN_3 | |
#define motors OUT_BC | |
int distance = 0; | |
int distance_precedente = 0; | |
byte data_file; // global pour simplifier | |
int bytesWritten; // inutilisé mais requis par WriteLnString | |
void setup(){ | |
SetSensorLowspeed(Telemetre); | |
SetSensorColorFull(Couleur); | |
SetSensorTouch(Touch); | |
DeleteFile("data.txt"); | |
CreateFile("data.txt", 1024, data_file); | |
} | |
void add_to_file(){ | |
WriteLnString(data_file, Num2Str(distance), bytesWritten); | |
} | |
task BlueTick(){ | |
while(true){ | |
until(Sensor(Couleur) == INPUT_BLUECOLOR); | |
distance = SensorUs(Telemetre); | |
// Sécurité pour éviter les doubles mesures | |
if ((distance-distance_precedente) > 5) { | |
add_to_file(); | |
distance_precedente = distance; | |
} | |
} | |
} | |
task main(){ | |
StartTask(BlueTick); | |
// --- On étalonne la mesure (prise d'origine) --- | |
distance = SensorUs(Telemetre); | |
distance_precedente = distance; | |
add_to_file(); | |
// --------- | |
OnRev(motors, 50); | |
until(SensorTouch(Touch)); | |
CloseFile(data_file); | |
StopAllTasks(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment