Much of it is finished!

This commit is contained in:
BOTAlex 2024-06-01 05:18:44 +02:00
parent 19de389bbe
commit 2eb0b11c0c
2 changed files with 54 additions and 50 deletions

View File

@ -5,6 +5,8 @@
#define LeftPin 3
#define RightPin 2
#define grabPin 19
Time time;
void setup(){
@ -14,6 +16,7 @@ void setup(){
// Set the pin mode for the defined pins
pinMode(LeftPin, INPUT_PULLUP);
pinMode(RightPin, INPUT_PULLUP);
pinMode(grabPin, INPUT_PULLUP);
initSteppers();
initXStepper();
@ -32,6 +35,10 @@ void loop(){
processJoystickInput(left, right);
if (digitalRead(grabPin) == LOW){
beginGrabSequence();
}
// //Serial.print(millis());
// Serial.print("Left state: ");
@ -40,18 +47,13 @@ void loop(){
// Serial.print("Right state: ");
// Serial.println(right);
if (Serial.available() > 0){
beginGrabSequence();
Serial.flush();
}
delay(10); // delay in milliseconds
}
void beginGrabSequence(){
moveStepper(StepperAxis::Head, 100000, 75);
moveStepper(StepperAxis::Y, 10000, 0);
moveStepper(StepperAxis::Head, 1000, 0, 100);
moveStepper(StepperAxis::Y, 10000, 1000);
moveStepper(StepperAxis::Head, 1000, 100);
moveStepper(StepperAxis::Y, 10000, -1100);
moveStepper(StepperAxis::Head, 1000, -100, 100);
moveStepper(StepperAxis::Y, 10000, 1100);
}

View File

@ -2,9 +2,9 @@
#define NUM_STEPPERS 3
// [X, Y, Head]
const int stepPins[NUM_STEPPERS] = {60, 26};
const int dirPins[NUM_STEPPERS] = {61, 28};
const int enablePins[NUM_STEPPERS] = {56, 24};
const int stepPins[NUM_STEPPERS] = {60, 36};
const int dirPins[NUM_STEPPERS] = {61, 34};
const int enablePins[NUM_STEPPERS] = {56, 30};
enum StepperAxis{
@ -15,6 +15,43 @@ enum StepperAxis{
SpeedyStepper steppers[NUM_STEPPERS];
bool isMoving[NUM_STEPPERS];
// void stepperLoop(){
// for (int i = 0; i < NUM_STEPPERS; i++) {
// SpeedyStepper* selectedStepper = &(steppers[i]);
// if (!selectedStepper->motionComplete())
// {
// selectedStepper->processMovement();
// }
// }
// }
void moveStepperByIndex(int stepperIndex, int speed, int dist, int accel = 2000){
isMoving[stepperIndex] = true;
SpeedyStepper* selectedStepper = &(steppers[stepperIndex]);
selectedStepper->setAccelerationInMillimetersPerSecondPerSecond(accel);
selectedStepper->setSpeedInStepsPerSecond(speed);
selectedStepper->setupRelativeMoveInMillimeters(dist);
while (!selectedStepper->motionComplete())
{
selectedStepper->processMovement();
}
}
void moveStepper(StepperAxis axis, int speed, int dist, int accel = 2000) {moveStepperByIndex(axis, speed, dist, accel);}
void stopStepperByIndex(int stepperIndex){
if (!isMoving[stepperIndex]) return;
if (!steppers[stepperIndex].motionComplete()) return;
steppers[stepperIndex].setupStop();
isMoving[stepperIndex] = false;
}
void stopStepper(StepperAxis axis){stopStepperByIndex(axis);}
void initSteppers(){
for (int i = 0; i < NUM_STEPPERS; i++) {
pinMode(stepPins[i], OUTPUT);
@ -33,42 +70,7 @@ void initSteppers(){
steppers[i].setStepsPerRevolution(200);
}
moveStepper(StepperAxis::Y, 10000, 1000);
steppers[StepperAxis::Y]
}
moveStepper(StepperAxis::Y, 10000, 1100);
// void stepperLoop(){
// for (int i = 0; i < NUM_STEPPERS; i++) {
// SpeedyStepper* selectedStepper = &(steppers[i]);
// if (!selectedStepper->motionComplete())
// {
// selectedStepper->processMovement();
// }
// }
// }
void moveStepperByIndex(int stepperIndex, int speed, int position, int accel = 2000){
isMoving[stepperIndex] = true;
SpeedyStepper* selectedStepper = &(steppers[stepperIndex]);
selectedStepper->setAccelerationInMillimetersPerSecondPerSecond(accel);
selectedStepper->setSpeedInStepsPerSecond(speed);
selectedStepper->setupMoveInMillimeters(position);
while (!selectedStepper->motionComplete())
{
selectedStepper->processMovement();
}
}
void moveStepper(StepperAxis axis, int speed, int position, int accel = 2000) {moveStepperByIndex(axis, speed, position, accel);}
void stopStepperByIndex(int stepperIndex){
if (!isMoving[stepperIndex]) return;
if (!steppers[stepperIndex].motionComplete()) return;
steppers[stepperIndex].setupStop();
isMoving[stepperIndex] = false;
}
void stopStepper(StepperAxis axis){stopStepperByIndex(axis);}
// moveStepper(StepperAxis::Head, 10000, 50);
}