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

View File

@ -2,9 +2,9 @@
#define NUM_STEPPERS 3 #define NUM_STEPPERS 3
// [X, Y, Head] // [X, Y, Head]
const int stepPins[NUM_STEPPERS] = {60, 26}; const int stepPins[NUM_STEPPERS] = {60, 36};
const int dirPins[NUM_STEPPERS] = {61, 28}; const int dirPins[NUM_STEPPERS] = {61, 34};
const int enablePins[NUM_STEPPERS] = {56, 24}; const int enablePins[NUM_STEPPERS] = {56, 30};
enum StepperAxis{ enum StepperAxis{
@ -15,6 +15,43 @@ enum StepperAxis{
SpeedyStepper steppers[NUM_STEPPERS]; SpeedyStepper steppers[NUM_STEPPERS];
bool isMoving[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(){ void initSteppers(){
for (int i = 0; i < NUM_STEPPERS; i++) { for (int i = 0; i < NUM_STEPPERS; i++) {
pinMode(stepPins[i], OUTPUT); pinMode(stepPins[i], OUTPUT);
@ -33,42 +70,7 @@ void initSteppers(){
steppers[i].setStepsPerRevolution(200); steppers[i].setStepsPerRevolution(200);
} }
moveStepper(StepperAxis::Y, 10000, 1000); moveStepper(StepperAxis::Y, 10000, 1100);
steppers[StepperAxis::Y]
}
// void stepperLoop(){ // moveStepper(StepperAxis::Head, 10000, 50);
// 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);}