mirror of
https://gitlab.dit.htwk-leipzig.de/phillip.kuehne/dezibot.git
synced 2025-05-21 20:11:46 +02:00
tasks working now
This commit is contained in:
parent
5a731e5fa4
commit
fb3b4211d5
@ -11,6 +11,10 @@
|
|||||||
|
|
||||||
#include "Motion.h"
|
#include "Motion.h"
|
||||||
|
|
||||||
|
TaskHandle_t xMoveTaskHandle = NULL;
|
||||||
|
TaskHandle_t xClockwiseTaskHandle = NULL;
|
||||||
|
TaskHandle_t xAntiClockwiseTaskHandle = NULL;
|
||||||
|
|
||||||
// Constructor
|
// Constructor
|
||||||
Motion::Motion() {
|
Motion::Motion() {
|
||||||
|
|
||||||
@ -20,31 +24,40 @@ Motion::Motion() {
|
|||||||
void Motion::begin(void) {
|
void Motion::begin(void) {
|
||||||
|
|
||||||
}
|
}
|
||||||
void moveTask(void * moveForMs) {
|
void moveTask(void * args) {
|
||||||
analogWrite(MOTOR_LEFT_PIN, 128);
|
analogWrite(MOTOR_LEFT_PIN, 128);
|
||||||
analogWrite(MOTOR_RIGHT_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_LEFT_PIN, 0);
|
||||||
analogWrite(MOTOR_RIGHT_PIN, 0);
|
analogWrite(MOTOR_RIGHT_PIN, 0);
|
||||||
|
vTaskDelete(xMoveTaskHandle);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Move forward for a certain amount of time.
|
// Move forward for a certain amount of time.
|
||||||
void Motion::move(uint32_t moveForMs) {
|
void Motion::move(uint32_t moveForMs) {
|
||||||
xTaskCreate(moveTask, "Move", configMINIMAL_STACK_SIZE, (void*)moveForMs, 1, NULL);
|
xTaskCreate(moveTask, "Move", 4096, (void*)moveForMs, 10, &xMoveTaskHandle);
|
||||||
// analogWrite(MOTOR_LEFT_PIN, 128);
|
|
||||||
// analogWrite(MOTOR_RIGHT_PIN, 128);
|
|
||||||
// vTaskDelay(moveForMs);
|
|
||||||
// analogWrite(MOTOR_LEFT_PIN, 0);
|
|
||||||
// analogWrite(MOTOR_RIGHT_PIN, 0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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.
|
// Rotate clockwise for a certain amount of time.
|
||||||
void Motion::rotateClockwise(uint32_t rotateForMs) {
|
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.
|
// Rotate anticlockwise for a certain amount of time.
|
||||||
void Motion::rotateAnticlockwise(uint32_t rotateForMs) {
|
void Motion::rotateAnticlockwise(uint32_t rotateForMs) {
|
||||||
|
xTaskCreate(rightMotorTask, "RightMotor", 4096, (void*)rotateForMs, 10, &xAntiClockwiseTaskHandle);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user