capteurs ultrason
This commit is contained in:
parent
0342d17b90
commit
0e0b417b6f
@ -5,5 +5,6 @@ project(smogogus)
|
||||
add_definitions("-x c++")
|
||||
include_directories(${PROJECT_SOURCE_DIR})
|
||||
set_source_files_properties(projet-tuteure-3a/photores.ino PROPERTIES LANGUAGE CXX)
|
||||
add_executable(app projet-tuteure-3a/motorController.cpp projet-tuteure-3a/photores.ino main.cpp)
|
||||
set_source_files_properties(projet-tuteure-3a/principal_ultrason.ino PROPERTIES LANGUAGE CXX)
|
||||
add_executable(app projet-tuteure-3a/motorController.cpp projet-tuteure-3a/principal_ultrason.ino main.cpp)
|
||||
add_definitions(-include ../adapter_ard.h)
|
||||
|
14
HCSR04.h
Normal file
14
HCSR04.h
Normal file
@ -0,0 +1,14 @@
|
||||
#include <stdint.h>
|
||||
|
||||
typedef uint8_t byte;
|
||||
|
||||
class HCSR04_c{
|
||||
public:
|
||||
void begin(byte trig, byte* echos, byte ecnt);
|
||||
double* measureDistanceCm();
|
||||
};
|
||||
|
||||
extern HCSR04_c HCSR04;
|
||||
|
||||
int couloir(void);
|
||||
int rotCouloir(int dir);
|
19
main.cpp
19
main.cpp
@ -1,4 +1,5 @@
|
||||
#include "adapter_ard.h"
|
||||
#include "HCSR04.h"
|
||||
|
||||
#include <ctime>
|
||||
#include <time.h>
|
||||
@ -7,9 +8,13 @@
|
||||
#include <iostream>
|
||||
|
||||
serial_c Serial;
|
||||
|
||||
HCSR04_c HCSR04;
|
||||
|
||||
struct timespec start, end;
|
||||
|
||||
int pinState[16];
|
||||
double dists[2];
|
||||
|
||||
int main(int argc, char** argv){
|
||||
clock_gettime(CLOCK_MONOTONIC_RAW, &start);
|
||||
@ -28,7 +33,10 @@ int main(int argc, char** argv){
|
||||
char* end_ptr;
|
||||
int pin = strtol(&cmd_buff[1], &end_ptr, 10);
|
||||
int level = strtol(&end_ptr[1], &end_ptr, 10);
|
||||
pinState[pin] = level;
|
||||
//printf("pin %d at %d\n", pin, level);
|
||||
if(pin >= 0)
|
||||
pinState[pin] = level;
|
||||
else dists[-pin-1] = level/10.0;
|
||||
cmd_buff_ind = 0;
|
||||
}
|
||||
cmd_buff[cmd_buff_ind++] = c;
|
||||
@ -94,4 +102,13 @@ void serial_c::print(int nb){
|
||||
void serial_c::println(int nb){
|
||||
this->print(nb);
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
void HCSR04_c::begin(byte trig, byte* echos, byte ecnt){
|
||||
//printf("");
|
||||
}
|
||||
|
||||
double* HCSR04_c::measureDistanceCm(){
|
||||
//printf("dists %f %f", dists[0], dists[1]);
|
||||
return dists;
|
||||
}
|
@ -59,4 +59,11 @@ class aip_parser:
|
||||
|
||||
def send_pin_state(self):
|
||||
for ind, p in enumerate(self.robot.pins):
|
||||
self.stdin.write(bytes(f"${ind},{p};", "utf-8"))
|
||||
self.stdin.write(bytes(f"${ind},{p};", "utf-8"))
|
||||
for ind, p in enumerate(self.robot.dists):
|
||||
if not p:
|
||||
p = -10
|
||||
else:
|
||||
p = int(1000*p)
|
||||
print("#######", p)
|
||||
self.stdin.write(bytes(f"${-ind-1},{p};", "utf-8"))
|
@ -1 +1 @@
|
||||
Subproject commit 397f93f67d864dbe52095f9e91dd8bbad8364960
|
||||
Subproject commit a6e75ef26b8896385a994733c114694f14862e20
|
Loading…
x
Reference in New Issue
Block a user