Boboter
Loading...
Searching...
No Matches
ultrasonic.h
Go to the documentation of this file.
1
7
8#pragma once
9
10#include <cstdint>
11#include <soc/gpio_num.h>
12#include "include/log_sources.h"
13
14class Robot;
15
16namespace Device {
17 class Ultrasonic {
18 private:
19 static constexpr const char* TAG = "Device::Ultrasonic";
20 static constexpr log_source LOG_SOURCE = LOG_SOURCE_DEVICE_ULTRASONIC;
21
22 static constexpr gpio_num_t TRIGGER_PIN = GPIO_NUM_25;
23 static constexpr gpio_num_t ECHO_PIN = GPIO_NUM_26;
24
25 static constexpr float MAX_DISTANCE = 200.0f;
26 static constexpr uint16_t ECHO_TIMEOUT_US = 50'000;
27
28 Robot& robot;
29 float distance;
30
31 public:
32 explicit Ultrasonic(Robot& robot);
34
38 void initialize();
39
44 void measure();
45
52 [[nodiscard]] float get_distance() const { return distance; }
53 };
54}
~Ultrasonic()
Definition ultrasonic.cpp:23
float get_distance() const
Returns the distance in centimeters.
Definition ultrasonic.h:52
void initialize()
Sets up the necessary GPIO pins.
Definition ultrasonic.cpp:27
Ultrasonic(Robot &robot)
Definition ultrasonic.cpp:16
void measure()
Measures the distance of any object to the sensor.
Definition ultrasonic.cpp:49
Class containing all the components of the robot.
Definition robot.h:32
log_source
Definition log_sources.h:12
@ LOG_SOURCE_DEVICE_ULTRASONIC
Definition log_sources.h:27
Definition battery.cpp:14