hmm, didn't know i had a git for this one
This commit is contained in:
parent
2eb0b11c0c
commit
d3ef408ebe
|
@ -2,8 +2,7 @@
|
|||
#include "StepperXController.h"
|
||||
#include "Time.h"
|
||||
|
||||
#define LeftPin 3
|
||||
#define RightPin 2
|
||||
#define JoystickPin 63
|
||||
|
||||
#define grabPin 19
|
||||
|
||||
|
@ -14,15 +13,17 @@ 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
|
||||
|
@ -30,13 +31,29 @@ void loop(){
|
|||
|
||||
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;
|
||||
|
||||
// Serial.print("Left: ");
|
||||
// Serial.print(left);
|
||||
// Serial.print(" Right: ");
|
||||
// Serial.println(right);
|
||||
|
||||
if (isGrabbing && millis() > startGrabbingTime + moveToDropZoneTime) {
|
||||
isGrabbing = false;
|
||||
processJoystickInput(false, false); // Quickly stop motor
|
||||
delay(1000);
|
||||
moveStepper(StepperAxis::Head, 10000, 100); // open hand
|
||||
}
|
||||
|
||||
processJoystickInput(left, right);
|
||||
|
||||
if (digitalRead(grabPin) == LOW){
|
||||
beginGrabSequence();
|
||||
//initGrabber();
|
||||
}
|
||||
|
||||
// //Serial.print(millis());
|
||||
|
@ -51,9 +68,16 @@ void loop(){
|
|||
delay(10); // delay in milliseconds
|
||||
}
|
||||
|
||||
void beginGrabSequence(){
|
||||
moveStepper(StepperAxis::Head, 1000, 100);
|
||||
moveStepper(StepperAxis::Y, 10000, -1100);
|
||||
moveStepper(StepperAxis::Head, 1000, -100, 100);
|
||||
moveStepper(StepperAxis::Y, 10000, 1100);
|
||||
void initGrabber(){
|
||||
moveStepper(StepperAxis::Head, 100000, 1000);
|
||||
}
|
||||
|
||||
void beginGrabSequence(){
|
||||
moveStepper(StepperAxis::Head, 10000, 100); // open hand
|
||||
moveStepper(StepperAxis::Y, 10000, -1100);
|
||||
moveStepper(StepperAxis::Head, 1000, -100, 100); // close hand
|
||||
moveStepper(StepperAxis::Y, 10000, 1100);
|
||||
|
||||
isGrabbing = true;
|
||||
startGrabbingTime = millis();
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
|
@ -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();
|
||||
|
|
Loading…
Reference in New Issue