ESP Line Following Buggy
2nd Year Embedded System Project (Group 48 - 2023/24)
All Classes Files Functions Variables Enumerations Enumerator Macros Pages
sensor_array.h
Go to the documentation of this file.
1
7#pragma once
8
9#include "mbed.h"
10
11
18{
19private:
20
21 DigitalOut led[6]; // Array of DigitalOut objects to control the LEDs.
22 AnalogIn sens[6]; // Array of AnalogIn objects to read the sensors.
23
24 float output; // The output value of the sensor array.
25 float prev_output;
26 float filtered_output;
27 float prev_filtered_output;
28 float sens_values[6]; // Array to store sensor values.
29 bool prev_left_true;
30
31 const int sample_count_; // The number of samples to take for averaging sensor readings.
32 const float detect_range_; // The detection threshold for line detection.
33 const float angle_coeff; // The gain at which the sensor output is multiplied to represent the angle.
34 bool line_detected; // Flag indicating whether a line is detected.
35
36 float cali_min[6] = {0.15, 0.15, 0.15, 0.15, 0.15, 0.15};
37 float cali_max[6] = {0.90, 0.90, 0.90, 0.90, 0.90, 0.90};
38 const int coef[6] = {5, 3, 1, -1, -3, -5};
39
40 // 2 Hz Pole Freq:
41 // Filter coefficients b_i: [0.0591174 0.0591174]
42 // Filter coefficients a_i: [0.88176521]
43 // 5 Hz Pole Freq:
44 // Filter coefficients b_i: [0.13575525 0.13575525]
45 // Filter coefficients a_i: [0.7284895]
46 // 7 Hz Pole Freq:
47 // Filter coefficients b_i: [0.1802684 0.1802684]
48 // Filter coefficients a_i: [0.63946321]
49
50 const float LP_a0 = 0.63946321;
51 const float LP_b0 = 0.1802684;
52 const float LP_b1 = 0.1802684;
53
54 //{15, 5, 1, -1, -5, -15};
61 float read(AnalogIn sensor);
62
63public:
64
74 SensorArray(PinName sens0, PinName sens1, PinName sens2, PinName sens3, PinName sens4, PinName sens5,
75 PinName led0, PinName led1, PinName led2, PinName led3, PinName led4, PinName led5, int sample_count, float detect_range, float angle_coefficient);
76
82 void reset(void);
83
89 void update(void);
90
96 bool is_line_detected(void);
97
103 void set_all_led_on(bool status);
104
111 float get_sens_output(int index);
112
118 float* get_sens_output_array(void);
119
125 float get_array_output(void);
126
127 float get_filtered_output(void);
128
129 void calibrate_sensors(void);
130
131 float* get_calibration_constants(void);
132};
Represents an array of sensors with corresponding LEDs for detection.
void calibrate_sensors(void)
SensorArray(PinName sens0, PinName sens1, PinName sens2, PinName sens3, PinName sens4, PinName sens5, PinName led0, PinName led1, PinName led2, PinName led3, PinName led4, PinName led5, int sample_count, float detect_range, float angle_coefficient)
Constructs a new SensorArray object.
float get_array_output(void)
Gets the output value of the sensor array.
float * get_sens_output_array(void)
Gets an array of sensor output values.
float get_filtered_output(void)
void update(void)
Updates the sensor array.
float get_sens_output(int index)
Gets the output value of a sensor at the specified index.
float * get_calibration_constants(void)
bool is_line_detected(void)
Checks if a line is detected (in the last update).
void set_all_led_on(bool status)
Sets the status of all LEDs.
void reset(void)
Resets the sensor array.