-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implemented Ultrasonic Sensor #43
base: main
Are you sure you want to change the base?
Conversation
… are not implemented in this branch. this is based off of them theoretically being in our codebase. Co-authored-by: Lily Johnson <41386414+lilyjohnson@users.noreply.github.com>
… class Co-authored-by: Lily Johnson <41386414+lilyjohnson@users.noreply.github.com>
Co-authored-by: Lily Johnson <41386414+lilyjohnson@users.noreply.github.com>
src/fullnessTask.cpp
Outdated
digitalWrite(trigPin, LOW); | ||
vTaskDelay(1000 / portTICK_PERIOD_MS); // Delay for 1000 milliseconds | ||
digitalWrite(trigPin, HIGH); | ||
vTaskDelay(1000 / portTICK_PERIOD_MS); // Delay for 1000 milliseconds | ||
digitalWrite(trigPin, LOW); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add all of the library code to a new class called UltrasonicDistance
that inherits from IDistance
src/fullnessTask.cpp
Outdated
|
||
using namespace Zotbins; | ||
|
||
static const char *name = "fullnessTask"; | ||
static const int priority = 1; | ||
static const uint32_t stackSize = 4096; | ||
|
||
const int trigPin = 5; | ||
const int echoPin = 18; | ||
int amount = 0; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does not need to be in global scope. Move to loop()
src/fullnessTask.cpp
Outdated
const int trigPin = 5; | ||
const int echoPin = 18; | ||
int amount = 0; | ||
std::vector<int32_t> distances; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Change to std::array because std::vector uses the heap
src/fullnessTask.cpp
Outdated
// log_i("Hello from Fullness Task"); | ||
|
||
// distance sensor | ||
// Fullness::IDistance distanceSensor; | ||
|
||
// log_i(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🤝
int32_t UltrasonicDistance::startDistance() | ||
{ | ||
for (int i = 0; i < 8; i++) | ||
{ | ||
digitalWrite(trigPin, LOW); | ||
vTaskDelay(1000 / portTICK_PERIOD_MS); // Delay for 1000 milliseconds | ||
digitalWrite(trigPin, HIGH); | ||
vTaskDelay(1000 / portTICK_PERIOD_MS); // Delay for 1000 milliseconds | ||
digitalWrite(trigPin, LOW); | ||
|
||
long duration = pulseIn(echoPin, HIGH); | ||
int32_t intDuration = duration * .034 / 2; | ||
|
||
distances[i] = intDuration; | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove startDistance(). Just call 8 times in getDistance()
@@ -1,13 +1,19 @@ | |||
#include "fullnessTask.hpp" | |||
#include "FullnessMetric.hpp" | |||
#include "MockDistance.hpp" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove this - this is only for unit tests
#include <Arduino.h> | ||
#include <vector> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove this
@@ -27,13 +33,22 @@ void FullnessTask::taskFunction(void *task) | |||
|
|||
void FullnessTask::setup() | |||
{ | |||
Serial.begin(115200); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove this
vTaskDelay(1000 / portTICK_PERIOD_MS); // Delay for 1000 milliseconds | ||
log_i("Hello from Fullness Task"); | ||
log_i("made it 1"); | ||
Fullness::UltrasonicDistance ultrasonicSensor(trigPin, echoPin, 0); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Make ultrasonicDistance and FullnessMetric a member variable
Description
Interfaced fullness class with ultrasonic sensor and ESP-32 .
Type of change
Testing and Verification Instructions
Checklist: