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 "Time.h"
#define LeftPin 3
#define RightPin 2
#define JoystickPin 63
#define grabPin 19
@ -14,46 +13,71 @@ void setup(){
Serial.begin(115200);
// Set the pin mode for the defined pins
pinMode(LeftPin, INPUT_PULLUP);
pinMode(RightPin, INPUT_PULLUP);
pinMode(grabPin, INPUT_PULLUP);
initSteppers();
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(){
// Updates deltatime
time.update();
// Updates deltatime
time.update();
stepperXLoop();
stepperXLoop();
bool left = digitalRead(LeftPin) == LOW;
bool right = digitalRead(RightPin) == LOW;
// Joystick. TODO: Make this only run when needed. Too lazy now.
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){
beginGrabSequence();
}
if (isGrabbing && millis() > startGrabbingTime + moveToDropZoneTime) {
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: ");
// Serial.print(left);
// Serial.print(" | ");
// Serial.print("Right state: ");
// Serial.println(right);
if (digitalRead(grabPin) == LOW){
beginGrabSequence();
//initGrabber();
}
// //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(){
moveStepper(StepperAxis::Head, 1000, 100);
moveStepper(StepperAxis::Head, 10000, 100); // open hand
moveStepper(StepperAxis::Y, 10000, -1100);
moveStepper(StepperAxis::Head, 1000, -100, 100);
moveStepper(StepperAxis::Head, 1000, -100, 100); // close hand
moveStepper(StepperAxis::Y, 10000, 1100);
isGrabbing = true;
startGrabbingTime = millis();
}

View File

@ -70,7 +70,7 @@ void initSteppers(){
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;
// stepper.stop();
// }
stepper.spin(16000);
stepper.spin(14000);
}
else if (right){
// if (isMovingLeft){
// isMovingLeft = false;
// stepper.stop();
// }
stepper.spin(-16000);
stepper.spin(-14000);
}
else
stepper.stop();