inspektors/robot/include/sonar.h

32 lines
779 B
C
Raw Normal View History

#ifndef SONAR_H
#define SONAR_H
#include "common.h"
// Trigger
#define TRIG_DDR DDRC
#define TRIG_PORT PORTC
#define TRIG_PIN PINC
#define TRIG_BIT PC4
// Echo
#define ECHO_DDR DDRC
#define ECHO_PORT PORTC
#define ECHO_PIN PINC
#define ECHO_BIT PC5
2018-01-17 21:56:48 +02:00
#define SPEED_OF_SOUND 343 // 20°C dry air (m/s)
#define MAX_SONAR_RANGE 8 // Trigger + echo (m)
2018-01-23 23:23:18 +02:00
#define MIN_SONAR_RANGE 4 // Minimum distance that is still reliable
2018-01-17 21:56:48 +02:00
#define SONAR_DELAY 60 // Timeout for return signal
2018-01-23 23:23:18 +02:00
#define TIMER_MAX 255 // For 8-bit timer
2018-01-17 21:56:48 +02:00
#define CYCLES_PER_US (F_CPU / 1000000)
#define SONAR_TIMEOUT (F_CPU * MAX_SONAR_RANGE) / SPEED_OF_SOUND
#define ECHO_TIMEOUT -1
void init_sonar(void);
int32_t read_sonar(void);
#endif /* SONAR_H */