Skip to content
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

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

aahsue
Copy link
Contributor

@aahsue aahsue commented May 25, 2022

Description

Interfaced fullness class with ultrasonic sensor and ESP-32 .

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Code improvement (a non-breaking change that improves the quality of the code)
  • Documentation Change (update to the documentation with no changes to the code)

Testing and Verification Instructions

  1. Wire ESP-32 and ultrasonic sensor (trig pin 5, echo pin 18)
  2. Build
  3. Upload
  4. Open serial monitor

Checklist:

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings

Comment on lines 48 to 52
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);
Copy link
Contributor

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


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;
Copy link
Contributor

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()

const int trigPin = 5;
const int echoPin = 18;
int amount = 0;
std::vector<int32_t> distances;
Copy link
Contributor

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

Comment on lines 72 to 77
// log_i("Hello from Fullness Task");

// distance sensor
// Fullness::IDistance distanceSensor;

// log_i();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove

Copy link
Contributor

@dskin344 dskin344 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤝

Comment on lines +11 to +26
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;
}
}
Copy link
Contributor

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"
Copy link
Contributor

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>
Copy link
Contributor

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);
Copy link
Contributor

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);
Copy link
Contributor

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants