Joystick controls done
This commit is contained in:
parent
3e1418257a
commit
02f63057bf
|
@ -6,6 +6,7 @@
|
||||||
#include "ZCodeParser.h"
|
#include "ZCodeParser.h"
|
||||||
#include "Shared/MotorMoveParams.h"
|
#include "Shared/MotorMoveParams.h"
|
||||||
#include "Shared/Steppers.h"
|
#include "Shared/Steppers.h"
|
||||||
|
#include "InputController.h"
|
||||||
|
|
||||||
// [X, Y, Head]
|
// [X, Y, Head]
|
||||||
#define NUM_STEPPERS 3
|
#define NUM_STEPPERS 3
|
||||||
|
@ -75,7 +76,7 @@ void anotherFunc(void * params){
|
||||||
{
|
{
|
||||||
StepperController::SetMotorEnabled('x', true);
|
StepperController::SetMotorEnabled('x', true);
|
||||||
StepperController::SetMovementEnabled('x', true);
|
StepperController::SetMovementEnabled('x', true);
|
||||||
StepperController::QueueMove('x', 2000);
|
StepperController::QueueMove('x', -2000);
|
||||||
Serial.println("Added to queue");
|
Serial.println("Added to queue");
|
||||||
vTaskDelay(pdMS_TO_TICKS(5000));
|
vTaskDelay(pdMS_TO_TICKS(5000));
|
||||||
}
|
}
|
||||||
|
@ -90,7 +91,8 @@ void setup() {
|
||||||
StepperController::Init(steppers, NUM_STEPPERS);
|
StepperController::Init(steppers, NUM_STEPPERS);
|
||||||
|
|
||||||
xTaskCreate(StepperController::MotorTask, "Motors", 1024, NULL, 5, NULL);
|
xTaskCreate(StepperController::MotorTask, "Motors", 1024, NULL, 5, NULL);
|
||||||
xTaskCreate(anotherFunc, "Other loop", 1024, NULL, 5, NULL);
|
// xTaskCreate(anotherFunc, "Other loop", 1024, NULL, 5, NULL);
|
||||||
|
xTaskCreate(InputControlTask, "Input", 1024, NULL, 5, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
void loop() {
|
void loop() {
|
||||||
|
|
|
@ -0,0 +1,31 @@
|
||||||
|
#include <Arduino.h>
|
||||||
|
#ifndef ESP32
|
||||||
|
#include <Arduino_FreeRTOS.h>
|
||||||
|
#endif
|
||||||
|
#include "StepperController.h"
|
||||||
|
|
||||||
|
#define JOYSTICK_PIN 63
|
||||||
|
#define JOY_CRITICAL_POINT 25
|
||||||
|
|
||||||
|
void InputControlTask(void *params) {
|
||||||
|
while (true) {
|
||||||
|
int joystickValueRaw = analogRead(JOYSTICK_PIN);
|
||||||
|
int joystickValue = map(joystickValueRaw, 0, 1023, 0, 100);
|
||||||
|
bool leftMovement = (joystickValue > (100 - JOY_CRITICAL_POINT));
|
||||||
|
bool rightMovement = (joystickValue < JOY_CRITICAL_POINT);
|
||||||
|
|
||||||
|
if (leftMovement) {
|
||||||
|
StepperController::SetMotorEnabled('x', true);
|
||||||
|
StepperController::SetMovementEnabled('x', true);
|
||||||
|
StepperController::SetMoveQueue('x', 150);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (rightMovement) {
|
||||||
|
StepperController::SetMotorEnabled('x', true);
|
||||||
|
StepperController::SetMovementEnabled('x', true);
|
||||||
|
StepperController::SetMoveQueue('x', -150);
|
||||||
|
}
|
||||||
|
|
||||||
|
vTaskDelay(pdMS_TO_TICKS(100)); // Poll every x
|
||||||
|
}
|
||||||
|
}
|
|
@ -105,7 +105,7 @@ void StepperController::MotorTask(void *params)
|
||||||
}
|
}
|
||||||
|
|
||||||
StepperController::lastUpdateTime = millis();
|
StepperController::lastUpdateTime = millis();
|
||||||
vTaskDelay(pdMS_TO_TICKS(100));
|
vTaskDelay(pdMS_TO_TICKS(50));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue