From 018017f255c3b9f22f1affed13426ef626c92bb6 Mon Sep 17 00:00:00 2001 From: "timo.altan" <timo.altan@th-koeln.de> Date: Tue, 15 Aug 2023 08:48:45 +0200 Subject: [PATCH] =?UTF-8?q?Kommentare=20erg=C3=A4nzt?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bits_time_of_flight_controller.cpp | 7 +++++++ bits_time_of_flight_controller.h | 9 ++++++--- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/bits_time_of_flight_controller.cpp b/bits_time_of_flight_controller.cpp index 4fb04bb..68fd092 100644 --- a/bits_time_of_flight_controller.cpp +++ b/bits_time_of_flight_controller.cpp @@ -6,18 +6,23 @@ bits_TimeOfFlightController::bits_TimeOfFlightController(const uint16_t max_dist void bits_TimeOfFlightController::init() { bool found_any_sensors = false; + // Deaktivieren aller Sensoren for (int i = 0; i < SENSOR_COUNT; i++) { pinMode(sensors[i].shutdown_pin, OUTPUT); + digitalWrite(sensors[i].shutdown_pin, LOW); } delay(10); + // Die Sensoren nach einander aktivieren und initalisieren for (int i = 0; i < SENSOR_COUNT; i++) { digitalWrite(sensors[i].shutdown_pin, HIGH); + delay(100); + if (sensors[i].psensor->begin(sensors[i].id, false, sensors[i].pwire, sensors[i].sensor_config)) { found_any_sensors = true; @@ -31,6 +36,7 @@ void bits_TimeOfFlightController::init() { if (!found_any_sensors) { _println_tof_("No valid sensors found"); + while (1) { ; @@ -44,6 +50,7 @@ int bits_TimeOfFlightController::get_distance_mm(int index) { sensors[index].psensor->rangingTest(&measure, false); // 'true' um debug Informationen auszugeben int distance; + if ((measure.RangeStatus != 4) && (measure.RangeMilliMeter < max_distance)) { distance = measure.RangeMilliMeter; diff --git a/bits_time_of_flight_controller.h b/bits_time_of_flight_controller.h index e65bc69..ab5577f 100644 --- a/bits_time_of_flight_controller.h +++ b/bits_time_of_flight_controller.h @@ -1,5 +1,5 @@ /* - * Klasse: BITsTimeOfFlight + * Klasse: bits_TimeOfFlightController * * Zur erzeugung eines Arrays gefüllt mit Objekten für die Ansteuerung von mehreren VL53L0X Time of Flight Sensoren * @@ -29,11 +29,12 @@ public: int get_distance_mm(int index); private: -const uint16_t max_distance = 4000; - static const int SENSOR_COUNT = 5; + const uint16_t max_distance = 4000; // Maximal messbare Distanz + static const int SENSOR_COUNT = 5; // Sensoren Anzahl int TOF_XSHUTS [SENSOR_COUNT] = {0, 8, 9, 23, 29}; // XShut Pins der einzelnen Time of Flight Sensoren int TOF_ADDRESSES [SENSOR_COUNT] = {0x30, 0x31, 0x32, 0x33, 0x34}; // Adresse der einzelnen Time of Flight Sensoren + // Struktur der Sensor Liste typedef struct { Adafruit_VL53L0X *psensor; // Zeiger zum Objekt @@ -46,12 +47,14 @@ const uint16_t max_distance = 4000; uint8_t sensor_status; } sensorList_t; + // Sensor Objekte basierend auf der Adafruit Bibliothek Adafruit_VL53L0X tof_sensor_1; Adafruit_VL53L0X tof_sensor_2; Adafruit_VL53L0X tof_sensor_3; Adafruit_VL53L0X tof_sensor_4; Adafruit_VL53L0X tof_sensor_5; + // Liste von Sensor Objekten sensorList_t sensors [SENSOR_COUNT] = { {&tof_sensor_1, &Wire, TOF_ADDRESSES[0], TOF_XSHUTS[0], Adafruit_VL53L0X::VL53L0X_SENSE_DEFAULT, 0, 0}, -- GitLab