nouvelles fonctions

This commit is contained in:
leo 2022-12-01 14:54:33 +01:00
parent 6bff550993
commit 95dcc68055
Signed by: leo
GPG Key ID: 0DD993BFB2B307DB
5 changed files with 40 additions and 3 deletions

View File

@ -6,7 +6,10 @@ void loop();
void setup(); void setup();
long millis(); long millis();
long micros(); long micros();
void delay(unsigned long milli);
int abs(int in); int abs(int in);
double max(double a, double b);
double min(double a, double b);
void pinMode(int pin, int mode); void pinMode(int pin, int mode);
int analogRead(int pin); int analogRead(int pin);
void digitalWrite(int pin, int level); void digitalWrite(int pin, int level);
@ -21,6 +24,10 @@ class serial_c{
void print(std::string txt); void print(std::string txt);
void println(int nb); void println(int nb);
void print(int nb); void print(int nb);
void print(float nb);
void println(float nb);
void print(double nb);
void println(double nb);
}; };
extern serial_c Serial; extern serial_c Serial;

View File

@ -22,7 +22,7 @@ class Laby:
L17=0.20 L17=0.20
walls = [ walls = [
((0,0),(0,L17)), ((0,0),(0,L17)),
((0,L17+L4),(0,L17+L4+L2)), #((0,L17+L4),(0,L17+L4+L2)),
((0,0),(L8,0)), ((0,0),(L8,0)),
((L8,0),(L8,L7)), ((L8,0),(L8,L7)),
((L8,L7),(L8+L3,L7)), ((L8,L7),(L8+L3,L7)),

View File

@ -43,11 +43,17 @@ int main(int argc, char** argv){
} }
printf("$dt,%ld;", micros()); printf("$dt,%ld;", micros());
loop(); loop();
delay(10);
printf("*"); printf("*");
fflush(stdout); fflush(stdout);
} }
} }
void delay(unsigned long milli){
unsigned long end = millis() + milli;
while(millis() <= end);
}
long millis(){ long millis(){
clock_gettime(CLOCK_MONOTONIC_RAW, &end); clock_gettime(CLOCK_MONOTONIC_RAW, &end);
uint64_t milli = (end.tv_sec - start.tv_sec) * 1000 + (end.tv_nsec - start.tv_nsec) / 1000000; uint64_t milli = (end.tv_sec - start.tv_sec) * 1000 + (end.tv_nsec - start.tv_nsec) / 1000000;
@ -66,6 +72,13 @@ int abs(int in){
return abs(in); return abs(in);
} }
double min(double a, double b){
return a<b?a:b;
}
double max(double a, double b){
return a>b?a:b;
}
void pinMode(int pin, int mode){ void pinMode(int pin, int mode){
printf("$pm,%d,%d;",pin, mode); printf("$pm,%d,%d;",pin, mode);
} }
@ -99,6 +112,23 @@ void serial_c::print(int nb){
printf("serial : %d", nb); printf("serial : %d", nb);
} }
void serial_c::print(float nb){
printf("serial : %f", nb);
}
void serial_c::println(float nb){
this->print(nb);
printf("\n");
}
void serial_c::print(double nb){
printf("serial : %f", nb);
}
void serial_c::println(double nb){
this->print(nb);
printf("\n");
}
void serial_c::println(int nb){ void serial_c::println(int nb){
this->print(nb); this->print(nb);
printf("\n"); printf("\n");

@ -1 +1 @@
Subproject commit c54363fde2edebb39355ba264c1b85dd2258bef4 Subproject commit 55b6ea6ff947589b354610e1d07d872e799be815

View File

@ -12,7 +12,7 @@ class Robot:
# velocite des roues (non angulaire) # velocite des roues (non angulaire)
wv=[0,0] wv=[0,0]
# velocite max # velocite max
wmv=0.1 wmv=0.3
# espace entre les deux roues # espace entre les deux roues
l=0.1 l=0.1
# time # time