mirror of
https://gitlab.dit.htwk-leipzig.de/phillip.kuehne/dezibot.git
synced 2025-05-21 12:01:47 +02:00
introduced possibility to run move commands without timelimit
This commit is contained in:
parent
45977c95b9
commit
c8f7e95363
@ -1,18 +0,0 @@
|
||||
#include <Dezibot.h>
|
||||
|
||||
Dezibot dezibot = Dezibot();
|
||||
const uint8_t MYFOO = 10;
|
||||
void setup() {
|
||||
dezibot.begin();
|
||||
|
||||
}
|
||||
|
||||
void loop() {
|
||||
dezibot.multiColorLight.setLed(TOP_LEFT,0x000000FF);
|
||||
dezibot.multiColorLight.setLed(TOP_RIGHT,dezibot.multiColorLight.color(0,100,0));
|
||||
dezibot.multiColorLight.blink(10,0x00FF0000,BOTTOM,500);
|
||||
|
||||
delay(1000);
|
||||
dezibot.multiColorLight.turnOff(ALL);
|
||||
delay(1000);
|
||||
}
|
19
example/example/example.ino
Normal file
19
example/example/example.ino
Normal file
@ -0,0 +1,19 @@
|
||||
#include <Dezibot.h>
|
||||
|
||||
Dezibot dezibot = Dezibot();
|
||||
const uint8_t MYFOO = 10;
|
||||
void setup() {
|
||||
dezibot.begin();
|
||||
|
||||
}
|
||||
|
||||
void loop() {
|
||||
dezibot.motion.move();
|
||||
delay(1000);
|
||||
dezibot.motion.rotateAntiClockwise();
|
||||
delay(1000);
|
||||
dezibot.motion.rotateClockwise();
|
||||
delay(1000);
|
||||
dezibot.motion.stop();
|
||||
delay(1000);
|
||||
}
|
@ -1,5 +0,0 @@
|
||||
#include "Dezibot.h"
|
||||
|
||||
int main(){
|
||||
return 0;
|
||||
}
|
@ -1,6 +1,6 @@
|
||||
/**
|
||||
* @file Motion.cpp
|
||||
* @author Jonathan Schulze, Nick Hübenthal
|
||||
* @author Jonathan Schulze, Nick Hübenthal, Hans Haupt
|
||||
* @brief Implementation of the Motion class.
|
||||
* @version 0.1
|
||||
* @date 2023-12-13
|
||||
@ -15,49 +15,67 @@ TaskHandle_t xMoveTaskHandle = NULL;
|
||||
TaskHandle_t xClockwiseTaskHandle = NULL;
|
||||
TaskHandle_t xAntiClockwiseTaskHandle = NULL;
|
||||
|
||||
// Constructor
|
||||
Motion::Motion() {
|
||||
|
||||
}
|
||||
|
||||
// Initialize the movement component.
|
||||
void Motion::begin(void) {
|
||||
|
||||
}
|
||||
void moveTask(void * args) {
|
||||
analogWrite(MOTOR_LEFT_PIN, 128);
|
||||
analogWrite(MOTOR_RIGHT_PIN, 128);
|
||||
};
|
||||
void Motion::moveTask(void * args) {
|
||||
analogWrite(MOTOR_LEFT_PIN, LEFT_MOTOR_DUTY);
|
||||
analogWrite(MOTOR_RIGHT_PIN, RIGHT_MOTOR_DUTY);
|
||||
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) {
|
||||
if (moveForMs > 0){
|
||||
xTaskCreate(moveTask, "Move", 4096, (void*)moveForMs, 10, &xMoveTaskHandle);
|
||||
}
|
||||
} else{
|
||||
analogWrite(MOTOR_LEFT_PIN, LEFT_MOTOR_DUTY);
|
||||
analogWrite(MOTOR_RIGHT_PIN, RIGHT_MOTOR_DUTY);
|
||||
}
|
||||
};
|
||||
|
||||
void leftMotorTask(void * args) {
|
||||
analogWrite(MOTOR_LEFT_PIN, 128);
|
||||
void Motion::leftMotorTask(void * args) {
|
||||
analogWrite(MOTOR_LEFT_PIN, LEFT_MOTOR_DUTY);
|
||||
analogWrite(MOTOR_RIGHT_PIN, 0);
|
||||
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);
|
||||
}
|
||||
if (rotateForMs > 0){
|
||||
xTaskCreate(leftMotorTask, "LeftMotor", 4096, (void*)rotateForMs, 10, &xClockwiseTaskHandle);
|
||||
} else {
|
||||
analogWrite(MOTOR_LEFT_PIN,LEFT_MOTOR_DUTY);
|
||||
analogWrite(MOTOR_RIGHT_PIN,0);
|
||||
}
|
||||
};
|
||||
|
||||
void rightMotorTask(void * args) {
|
||||
analogWrite(MOTOR_RIGHT_PIN, 128);
|
||||
void Motion::rightMotorTask(void * args) {
|
||||
analogWrite(MOTOR_RIGHT_PIN, RIGHT_MOTOR_DUTY);
|
||||
analogWrite(MOTOR_LEFT_PIN,0);
|
||||
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);
|
||||
void Motion::rotateAntiClockwise(uint32_t rotateForMs) {
|
||||
if(rotateForMs > 0){
|
||||
xTaskCreate(rightMotorTask, "RightMotor", 4096, (void*)rotateForMs, 10, &xAntiClockwiseTaskHandle);
|
||||
} else {
|
||||
analogWrite(MOTOR_RIGHT_PIN,RIGHT_MOTOR_DUTY);
|
||||
analogWrite(MOTOR_LEFT_PIN,0);
|
||||
}
|
||||
};
|
||||
|
||||
void Motion::stop(void){
|
||||
analogWrite(MOTOR_LEFT_PIN,0);
|
||||
analogWrite(MOTOR_RIGHT_PIN,0);
|
||||
}
|
||||
|
||||
|
@ -16,17 +16,17 @@
|
||||
#include <freertos/FreeRTOS.h>
|
||||
#include <freertos/task.h>
|
||||
|
||||
const int MOTOR_RIGHT_PIN = 11;
|
||||
const int MOTOR_LEFT_PIN = 12;
|
||||
|
||||
|
||||
class Motion{
|
||||
protected:
|
||||
static const uint8_t RIGHT_MOTOR_DUTY = 128;
|
||||
static const uint8_t LEFT_MOTOR_DUTY = 128;
|
||||
static const int MOTOR_RIGHT_PIN = 11;
|
||||
static const int MOTOR_LEFT_PIN = 12;
|
||||
static void moveTask(void * args);
|
||||
static void leftMotorTask(void * args);
|
||||
static void rightMotorTask(void * args);
|
||||
|
||||
public:
|
||||
|
||||
Motion();
|
||||
|
||||
/**
|
||||
* @brief Initialize the movement component.
|
||||
*
|
||||
@ -35,21 +35,30 @@ public:
|
||||
|
||||
/**
|
||||
* @brief Move forward for a certain amount of time.
|
||||
* Call with moveForMs 0 will start movement, that must be stopped explicit by call to stop().
|
||||
* @param moveForMs Representing the duration of forward moving in milliseconds.
|
||||
*/
|
||||
void move(uint32_t moveForMs);
|
||||
static void move(uint32_t moveForMs=0);
|
||||
|
||||
/**
|
||||
* @brief Rotate clockwise for a certain amount of time.
|
||||
* Call with moveForMs 0 will start movement, that must be stopped explicit by call to stop().
|
||||
* @param rotateForMs Representing the duration of rotating clockwise in milliseconds.
|
||||
*/
|
||||
void rotateClockwise(uint32_t rotateForMs);
|
||||
static void rotateClockwise(uint32_t rotateForMs=0);
|
||||
|
||||
/**
|
||||
* @brief Rotate anticlockwise for a certain amount of time.
|
||||
* Call with moveForMs 0 will start movement, that must be stopped explicit by call to stop().
|
||||
* @param rotateForMs Representing the duration of rotating anticlockwise in milliseconds.
|
||||
*/
|
||||
void rotateAnticlockwise(uint32_t rotateForMs);
|
||||
static void rotateAntiClockwise(uint32_t rotateForMs=0);
|
||||
|
||||
/**
|
||||
* @brief stops any current movement, no matter if timebased or endless
|
||||
*
|
||||
*/
|
||||
static void stop(void);
|
||||
|
||||
};
|
||||
#endif //Motion_h
|
Loading…
x
Reference in New Issue
Block a user