tasks working now

This commit is contained in:
99cardz 2024-01-10 15:56:26 +01:00
parent 5a731e5fa4
commit fb3b4211d5

View File

@ -11,6 +11,10 @@
#include "Motion.h"
TaskHandle_t xMoveTaskHandle = NULL;
TaskHandle_t xClockwiseTaskHandle = NULL;
TaskHandle_t xAntiClockwiseTaskHandle = NULL;
// Constructor
Motion::Motion() {
@ -20,31 +24,40 @@ Motion::Motion() {
void Motion::begin(void) {
}
void moveTask(void * moveForMs) {
void moveTask(void * args) {
analogWrite(MOTOR_LEFT_PIN, 128);
analogWrite(MOTOR_RIGHT_PIN, 128);
vTaskDelay((uint32_t) moveForMs);
vTaskDelay((uint32_t) args / portTICK_PERIOD_MS);
analogWrite(MOTOR_LEFT_PIN, 0);
analogWrite(MOTOR_RIGHT_PIN, 0);
vTaskDelete(xMoveTaskHandle);
}
// Move forward for a certain amount of time.
void Motion::move(uint32_t moveForMs) {
xTaskCreate(moveTask, "Move", configMINIMAL_STACK_SIZE, (void*)moveForMs, 1, NULL);
// analogWrite(MOTOR_LEFT_PIN, 128);
// analogWrite(MOTOR_RIGHT_PIN, 128);
// vTaskDelay(moveForMs);
// analogWrite(MOTOR_LEFT_PIN, 0);
// analogWrite(MOTOR_RIGHT_PIN, 0);
xTaskCreate(moveTask, "Move", 4096, (void*)moveForMs, 10, &xMoveTaskHandle);
}
void leftMotorTask(void * args) {
analogWrite(MOTOR_LEFT_PIN, 128);
vTaskDelay((uint32_t) args / portTICK_PERIOD_MS);
analogWrite(MOTOR_LEFT_PIN, 0);
vTaskDelete(xClockwiseTaskHandle);
}
// Rotate clockwise for a certain amount of time.
void Motion::rotateClockwise(uint32_t rotateForMs) {
xTaskCreate(leftMotorTask, "LeftMotor", 4096, (void*)rotateForMs, 10, &xClockwiseTaskHandle);
}
void rightMotorTask(void * args) {
analogWrite(MOTOR_RIGHT_PIN, 128);
vTaskDelay((uint32_t) args / portTICK_PERIOD_MS);
analogWrite(MOTOR_RIGHT_PIN, 0);
vTaskDelete(xAntiClockwiseTaskHandle);
}
// Rotate anticlockwise for a certain amount of time.
void Motion::rotateAnticlockwise(uint32_t rotateForMs) {
xTaskCreate(rightMotorTask, "RightMotor", 4096, (void*)rotateForMs, 10, &xAntiClockwiseTaskHandle);
}