hmm, didn't know i had a git for this one

This commit is contained in:
BOTAlex 2025-01-18 14:09:13 +01:00
parent 2eb0b11c0c
commit d3ef408ebe
3 changed files with 51 additions and 27 deletions

View File

@ -2,8 +2,7 @@
#include "StepperXController.h" #include "StepperXController.h"
#include "Time.h" #include "Time.h"
#define LeftPin 3 #define JoystickPin 63
#define RightPin 2
#define grabPin 19 #define grabPin 19
@ -14,46 +13,71 @@ void setup(){
Serial.begin(115200); Serial.begin(115200);
// Set the pin mode for the defined pins // Set the pin mode for the defined pins
pinMode(LeftPin, INPUT_PULLUP);
pinMode(RightPin, INPUT_PULLUP);
pinMode(grabPin, INPUT_PULLUP); pinMode(grabPin, INPUT_PULLUP);
initSteppers(); initSteppers();
initXStepper(); initXStepper();
} }
float position = 0; bool isGrabbing = false;
float startGrabbingTime = 0;
const float moveToDropZoneTime = 1750; // How long to move right (relative to me)
const int joyCriticalPoint = 10;
void loop(){ void loop(){
// Updates deltatime // Updates deltatime
time.update(); time.update();
stepperXLoop(); stepperXLoop();
bool left = digitalRead(LeftPin) == LOW; // Joystick. TODO: Make this only run when needed. Too lazy now.
bool right = digitalRead(RightPin) == LOW; int joystickValueRaw = analogRead(JoystickPin);
int joystickValue = map(joystickValueRaw, 0, 1023, 0, 100);
bool left = joystickValue > 100-joyCriticalPoint;
bool right = joystickValue < joyCriticalPoint;
processJoystickInput(left, right); // Serial.print("Left: ");
// Serial.print(left);
// Serial.print(" Right: ");
// Serial.println(right);
if (digitalRead(grabPin) == LOW){ if (isGrabbing && millis() > startGrabbingTime + moveToDropZoneTime) {
beginGrabSequence(); isGrabbing = false;
} processJoystickInput(false, false); // Quickly stop motor
delay(1000);
moveStepper(StepperAxis::Head, 10000, 100); // open hand
}
// //Serial.print(millis()); processJoystickInput(left, right);
// Serial.print("Left state: "); if (digitalRead(grabPin) == LOW){
// Serial.print(left); beginGrabSequence();
// Serial.print(" | "); //initGrabber();
// Serial.print("Right state: "); }
// Serial.println(right);
// //Serial.print(millis());
// Serial.print("Left state: ");
// Serial.print(left);
// Serial.print(" | ");
// Serial.print("Right state: ");
// Serial.println(right);
delay(10); // delay in milliseconds delay(10); // delay in milliseconds
}
void initGrabber(){
moveStepper(StepperAxis::Head, 100000, 1000);
} }
void beginGrabSequence(){ void beginGrabSequence(){
moveStepper(StepperAxis::Head, 1000, 100); moveStepper(StepperAxis::Head, 10000, 100); // open hand
moveStepper(StepperAxis::Y, 10000, -1100); moveStepper(StepperAxis::Y, 10000, -1100);
moveStepper(StepperAxis::Head, 1000, -100, 100); moveStepper(StepperAxis::Head, 1000, -100, 100); // close hand
moveStepper(StepperAxis::Y, 10000, 1100); moveStepper(StepperAxis::Y, 10000, 1100);
isGrabbing = true;
startGrabbingTime = millis();
} }

View File

@ -70,7 +70,7 @@ void initSteppers(){
steppers[i].setStepsPerRevolution(200); steppers[i].setStepsPerRevolution(200);
} }
moveStepper(StepperAxis::Y, 10000, 1100); moveStepper(StepperAxis::Y, 10000, 1000);
moveStepper(StepperAxis::Head, 10000, 100);
// moveStepper(StepperAxis::Head, 10000, 50);
} }

View File

@ -20,14 +20,14 @@ void processJoystickInput(bool left, bool right){
// isMovingLeft = true; // isMovingLeft = true;
// stepper.stop(); // stepper.stop();
// } // }
stepper.spin(16000); stepper.spin(14000);
} }
else if (right){ else if (right){
// if (isMovingLeft){ // if (isMovingLeft){
// isMovingLeft = false; // isMovingLeft = false;
// stepper.stop(); // stepper.stop();
// } // }
stepper.spin(-16000); stepper.spin(-14000);
} }
else else
stepper.stop(); stepper.stop();