feat: add MotorTask + add tests

This commit is contained in:
dd060606
2025-02-07 15:26:17 +01:00
parent 379dcc3870
commit 598ea79d5b
3 changed files with 80 additions and 0 deletions

26
test/main.cpp Normal file
View File

@@ -0,0 +1,26 @@
#include "Arduino.h"
#include "motor_control.h"
#include "tasks/motor_task.h"
MotorTask motorTask;
void setup()
{
initMotors();
motorTask = MotorTask();
}
void loop()
{
// Imaginons un obstacle
if (false)
{
motorTask.stop();
}
else if (!motorTask.isRunning())
{
motorTask.start();
motorTask.goForward(200, 20);
}
delay(20);
}

37
test/tasks/motor_task.cpp Normal file
View File

@@ -0,0 +1,37 @@
#include "motor_task.h"
#include "motor_control.h"
MotorTask::MotorTask() : Task() {}
MotorTask::~MotorTask()
{
stop();
}
void MotorTask::start()
{
Task::start();
}
void MotorTask::stop()
{
Task::stop();
stopMotors();
}
void MotorTask::goForward(int speed, int delayTime)
{
if (isRunning())
{
// Code pour accélérer vers l'avant
accelerateForward(speed, delayTime);
}
}
void MotorTask::goReverse(int speed, int delayTime)
{
if (isRunning())
{
// Code pour accélérer en marche arrière
accelerateReverse(speed, delayTime);
}
}

17
test/tasks/motor_task.h Normal file
View File

@@ -0,0 +1,17 @@
#ifndef MOTORTASK_H
#define MOTORTASK_H
#include "Task.h"
class MotorTask : public Task
{
public:
MotorTask();
~MotorTask();
void start();
void stop();
void goForward(int speed, int delayTime);
void goReverse(int speed, int delayTime);
};
#endif // MOTORTASK_H