wip: add reference to motionDetection to motion

This commit is contained in:
Hans Haupt
2024-06-13 17:20:22 +02:00
parent 841202897b
commit d4cb8af3b3
6 changed files with 98 additions and 24 deletions

View File

@@ -16,6 +16,8 @@ TaskHandle_t xClockwiseTaskHandle = NULL;
TaskHandle_t xAntiClockwiseTaskHandle = NULL;
// Initialize the movement component.
void Motion::begin(void) {
ledc_timer_config_t motor_timer = {
.speed_mode = LEDC_MODE,
@@ -31,7 +33,8 @@ void Motion::begin(void) {
void Motion::moveTask(void * args) {
Motion::left.setSpeed(LEFT_MOTOR_DUTY);
Motion::right.setSpeed(RIGHT_MOTOR_DUTY);
vTaskDelay((uint32_t) args / portTICK_PERIOD_MS);
//moveCMD cmd = (moveCMD)args;
//vTaskDelay( cmd.duration/ portTICK_PERIOD_MS);
Motion::left.setSpeed(0);
Motion::right.setSpeed(0);
vTaskDelete(xMoveTaskHandle);
@@ -39,12 +42,10 @@ void Motion::moveTask(void * args) {
// 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{
// moveCMD cmd = {moveForMs,imuInst};
// xTaskCreate(moveTask, "Move", 4096, (void*)cmd, 10, &xMoveTaskHandle);
Motion::left.setSpeed(LEFT_MOTOR_DUTY);
Motion::right.setSpeed(RIGHT_MOTOR_DUTY);
}
};
void Motion::leftMotorTask(void * args) {
@@ -86,5 +87,7 @@ void Motion::rotateAntiClockwise(uint32_t rotateForMs) {
void Motion::stop(void){
Motion::left.setSpeed(0);
Motion::right.setSpeed(0);
//just for testing
// Serial.println(imu->getAcceleration().z);
}

View File

@@ -16,12 +16,18 @@
#include <freertos/FreeRTOS.h>
#include <freertos/task.h>
#include "driver/ledc.h"
#include "motionDetection/MotionDetection.h"
#define LEDC_MODE LEDC_LOW_SPEED_MODE
#define TIMER LEDC_TIMER_2
#define CHANNEL_LEFT LEDC_CHANNEL_3
#define CHANNEL_RIGHT LEDC_CHANNEL_4
#define DUTY_RES LEDC_TIMER_13_BIT // Set duty resolution to 13 bits
#define FREQUENCY (5000) // Frequency in Hertz. Set frequency at 5 kHz
struct moveCMD{
uint32_t duration;
MotionDetection* imu;
};
class Motor{
public:
Motor(uint8_t pin, ledc_timer_t timer, ledc_channel_t channel);
@@ -38,6 +44,7 @@ class Motor{
class Motion{
protected:
static MotionDetection* imuInst;
static const uint16_t RIGHT_MOTOR_DUTY = 4096;
static const uint16_t LEFT_MOTOR_DUTY = 4096;
static const int MOTOR_RIGHT_PIN = 11;
@@ -50,6 +57,11 @@ public:
//Shared Timer to sync movement
static inline Motor left = Motor(MOTOR_LEFT_PIN,TIMER,CHANNEL_LEFT);
static inline Motor right = Motor(MOTOR_RIGHT_PIN,TIMER,CHANNEL_RIGHT);
friend class Dezibot;
/**
* constructor gets a pointer to the motiondetection class, which enables correction of the motion
*/
/**
* @brief Initialize the movement component.