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

Merge to the main #37

Merged
merged 16 commits into from
Dec 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 16 additions & 21 deletions smart_bridge/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,38 +29,33 @@ void setup()
scheduler.init(50); // NOTE: Might be set higher to use less power, needs testing.

/**CREATE TASKS**/
BlinkTask *blinkTaskTransit = new BlinkTask(L2_PIN);
BlinkTask *blinkTaskWashing = new BlinkTask(L2_PIN);
// CountDown *countDownTask = new CountDown(N3);
TemperatureTask *temperatureTask = new TemperatureTask();
// SleepingTask *sleepingTask = new SleepingTask();
CheckInTask *checkInTask = new CheckInTask();
TransitTask *transitTask = new TransitTask(blinkTaskTransit);
BlinkTask *blinkTask = new BlinkTask(L2_PIN);
TransitTask *transitTask = new TransitTask(blinkTask);
WaitForClickTask *waitForClickTask = new WaitForClickTask();
// WashingTask *washingTask = new WashingTask(blinkTaskTransit, nullptr, temperatureTask);
// CheckOutTask *checkOutTask = new CheckOutTask();
// ExitTransitTask *exitTransitTask = new ExitTransitTask();
CountDown *countDownTask = new CountDown(N3);
TemperatureTask *temperatureTask = new TemperatureTask();
WashingTask *washingTask = new WashingTask(blinkTask, countDownTask, temperatureTask);
CheckOutTask *checkOutTask = new CheckOutTask();
ExitTransitTask *exitTransitTask = new ExitTransitTask();

/**DEPENDENCIES**/
// checkInTask->addDependency(sleepingTask);
transitTask->addDependency(checkInTask);
waitForClickTask->addDependency(transitTask);
//washingTask->addDependency(waitForClickTask);
// checkOutTask->addDependency(washingTask);
// exitTransitTask->addDependency(checkOutTask);
washingTask->addDependency(waitForClickTask);
checkOutTask->addDependency(washingTask);
exitTransitTask->addDependency(checkOutTask);

/**ADD TASKS TO THE SCHEDULER**/
// scheduler.addTask(sleepingTask);
scheduler.addTask(checkInTask);
scheduler.addTask(transitTask);
scheduler.addTask(blinkTaskTransit);
scheduler.addTask(blinkTaskWashing);
// scheduler.addTask(countDownTask);
scheduler.addTask(temperatureTask);
scheduler.addTask(blinkTask);
scheduler.addTask(waitForClickTask);
// scheduler.addTask(washingTask);
// scheduler.addTask(checkOutTask);
// scheduler.addTask(exitTransitTask);
scheduler.addTask(washingTask);
scheduler.addTask(countDownTask);
scheduler.addTask(temperatureTask);
scheduler.addTask(checkOutTask);
scheduler.addTask(exitTransitTask);
}

void loop()
Expand Down
7 changes: 6 additions & 1 deletion smart_bridge/src/tasks/CheckOutTask.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
#include "CheckOutTask.h"

CheckOutTask::CheckOutTask() : DependantTaskWithState()
CheckOutTask::CheckOutTask()
: DependantTaskWithState(),
GATE_OPEN_POSITION(90),
GATE_CLOSE_POSITION(0)
{
Serial.println("CheckOutTask created");
this->sonar = new Sonar(SONAR_TRIG_PIN, SONAR_ECHO_PIN, SONAR_MAX_TIME);
Expand Down Expand Up @@ -29,6 +32,8 @@ void CheckOutTask::tick()
}
}
}
else
Serial.println("CheckOutTask::tick()::getDependency(0) is nullptr");
}

void CheckOutTask::handleTurnOnL3()
Expand Down
15 changes: 7 additions & 8 deletions smart_bridge/src/tasks/CheckOutTask.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ class CheckOutTask : public DependantTaskWithState
*/
void tick() override;

private:
/**
* @brief Handles the turning on of the L3 LED.
*
Expand All @@ -46,7 +47,6 @@ class CheckOutTask : public DependantTaskWithState
*/
void handleOpensGate();

private:
/**
* @brief Enum for the possible states of the task.
*
Expand All @@ -57,13 +57,12 @@ class CheckOutTask : public DependantTaskWithState
OPENS_GATE, ///< The task is currently opening the gate.
};

Led *L3; ///< Pointer to the L3 LED object
Sonar *sonar; ///< Pointer to the sonar object
ServoImpl *gate; ///< Pointer to the ServoImpl object that controls the gate.
float distance; ///< The current distance read from the sonar sensor.
unsigned long timeInExit = 0; ///< The time in milliseconds when the car entered the exit area.
const int GATE_OPEN_POSITION = 90; ///< The position of the gate when it is open.
const int GATE_CLOSE_POSITION = 0; ///< The position of the gate when it is closed.
Led *L3; ///< Pointer to the L3 LED object
Sonar *sonar; ///< Pointer to the sonar object
ServoImpl *gate; ///< Pointer to the ServoImpl object that controls the gate.
float distance; ///< The current distance read from the sonar sensor.
const int GATE_OPEN_POSITION; ///< The position of the gate when it is open.
const int GATE_CLOSE_POSITION; ///< The position of the gate when it is closed.
};

#endif // __CHECK_OUT_TASK__
5 changes: 4 additions & 1 deletion smart_bridge/src/tasks/CountDown.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ CountDown::CountDown(int countDown) : Task()
this->lcd = new LCD(0x27, 16, 2);
this->resetCountDown(N3);
this->init(1000);
this->setActive(false);
}

int CountDown::getCountDown()
Expand Down Expand Up @@ -50,7 +51,9 @@ void CountDown::startCountDown()
void CountDown::printCountDown()
{
int count = getCountDown();
lcd->write(("Countdown: " + String(count)).c_str(), 0, 0);
char buffer[3];
sprintf(buffer, "%02d", count);
lcd->write(("Countdown: " + String(buffer)).c_str(), 0, 0);
}

void CountDown::endsCountDown()
Expand Down
12 changes: 6 additions & 6 deletions smart_bridge/src/tasks/ExitTransitTask.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ ExitTransitTask::ExitTransitTask()
this->sonar = new Sonar(SONAR_TRIG_PIN, SONAR_ECHO_PIN, SONAR_MAX_TIME);
this->L3 = new Led(L3_PIN);
this->gate = new ServoImpl(SERVO_PIN);
this->init(1000);
this->init();
this->setState(READING_DISTANCE);
};

Expand Down Expand Up @@ -39,6 +39,8 @@ void ExitTransitTask::tick()
}
}
}
else
Serial.println("ExitTransitTask::tick()::getDependency(0) is nullptr");
}

void ExitTransitTask::handleReadingDistance()
Expand All @@ -52,15 +54,13 @@ void ExitTransitTask::handleCheckingDistance()
{
if (this->distance > MAXDIST)
{
if (timeInExit == 0)
{
timeInExit = millis();
}
else if (millis() - timeInExit >= N4_FOR_DIST * 1000)
if (this->elapsedTime() >= N4_FOR_DIST * 1000)
{
this->setState(CLOSES_GATE);
}
}
else
this->resetTime();
}

void ExitTransitTask::handleClosesGate()
Expand Down
2 changes: 1 addition & 1 deletion smart_bridge/src/tasks/ExitTransitTask.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ class ExitTransitTask : public DependantTaskWithState
*/
void tick() override;

private:
/**
* @brief Handles the reading of the distance from the sonar sensor.
*
Expand Down Expand Up @@ -61,7 +62,6 @@ class ExitTransitTask : public DependantTaskWithState
*/
void handleSwitchOffL3();

private:
/**
* @brief Enum for the possible states of the task.
*
Expand Down
1 change: 1 addition & 0 deletions smart_bridge/src/tasks/TemperatureTask.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ TemperatureTask::TemperatureTask()
this->lcd = new LCD(0x27, 16, 2);
this->setTemperature(this->getTemperature());
this->init(1000);
this->setActive(false);
}

float TemperatureTask::readVoltage()
Expand Down
43 changes: 24 additions & 19 deletions smart_bridge/src/tasks/WashingTask.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,37 +12,44 @@ WashingTask::WashingTask(BlinkTask *blinkTask,
this->lcd = new LCD(0x27, 16, 2);
this->gate = new ServoImpl(SERVO_PIN);
this->blinkTask = blinkTask;
this->blinkTask->init(500); // Blink every 500 ms the red led
this->blinkTask->setActive(false); // TODO: Check if this is necessary
this->blinkTask->init(500);
this->blinkTask->setActive(false);
this->countDownTask = countDownTask;
this->temperatureTask = temperatureTask;
this->init(1000);
// this->countDownTask->setActive(false); TODO: uncomment if you want to test
// this->temperatureTask->setActive(false); TODO: uncomment if you want to test
this->init();
this->setState(START_WASHING);
}

void WashingTask::tick()
{
if (this->DependantTask::getDependency(0)->isCompleted())
if (this->getDependency(0) != nullptr)
{
switch (this->getState())
if (this->DependantTask::getDependency(0)->isCompleted())
{
case START_WASHING:
handleStartWashing();
break;
switch (this->getState())
{
case START_WASHING:
handleStartWashing();
break;

case STARTS_COUNTDOWN:
handleStartsCountdown();
break;
case STARTS_COUNTDOWN:
handleStartsCountdown();
break;

case ENDS_COUNTDOWN:
handleEndsCountdown();
break;
case ENDS_COUNTDOWN:
handleEndsCountdown();
break;

case ERROR:
handleError();
break;
case ERROR:
handleError();
break;
}
}
}
else
Serial.println("WashingTask::tick()::getDependency(0) is nullptr");
}

void WashingTask::printWashingCompletedMessage()
Expand All @@ -60,8 +67,6 @@ void WashingTask::handleStartWashing()

void WashingTask::handleStartsCountdown()
{
// this->countDownTask->tick();
// this->temperatureTask->tick();
if (this->elapsedTime() >= checkInterval)
{
this->resetTime();
Expand Down
2 changes: 1 addition & 1 deletion smart_bridge/src/tasks/WashingTask.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ class WashingTask : public DependantTaskWithState
*/
void tick() override;

private:
/**
* @brief Handles the start of the washing process.
*
Expand Down Expand Up @@ -73,7 +74,6 @@ class WashingTask : public DependantTaskWithState
*/
void printWashingCompletedMessage();

private:
/**
* @brief Enum for the possible states of the task.
*
Expand Down