Upgraded steps & removed end courses

This commit is contained in:
chakiral
2021-08-24 10:52:43 +02:00
parent 3035477b83
commit 0d14c0b1ef
2 changed files with 958 additions and 948 deletions

View File

@@ -87,22 +87,26 @@ void move_motor(motor motor, int *signals)
} }
// home_motors is used to get all motors to home position // home_motors is used to get all motors to home position
// This function is disabled since no more end course
void home_motors() void home_motors()
{ {
bench_motor.delay = motorHigh+30; // bench_motor.delay = motorHigh+30;
while (bench_motor.pups.home.state == LOW) // Remove End course
{ // while (bench_motor.pups.home.state == LOW)
move_motor(bench_motor, forward); // {
bench_motor.pups.home.state = digitalRead(bench_motor.pups.home.pin); // move_motor(bench_motor, forward);
} // bench_motor.pups.home.state = digitalRead(bench_motor.pups.home.pin);
// }
refresh_motors_states(); refresh_motors_states();
} }
// refresh all motors pullups states // refresh all motors pullups states
// This function is disabled since no more end course
void refresh_motors_states() void refresh_motors_states()
{ {
bench_motor.pups.home.state = digitalRead(bench_motor.pups.home.pin); // bench_motor.pups.home.state = digitalRead(bench_motor.pups.home.pin);
bench_motor.pups.end.state = digitalRead(bench_motor.pups.end.pin); // bench_motor.pups.end.state = digitalRead(bench_motor.pups.end.pin);
} }
// move_using_joystick is used to move motors depending on joystick position // move_using_joystick is used to move motors depending on joystick position
@@ -111,30 +115,35 @@ void move_using_joystick()
// fetch joystick position // fetch joystick position
cmd.joystick_x.state = analogRead(cmd.joystick_x.pin); cmd.joystick_x.state = analogRead(cmd.joystick_x.pin);
cmd.joystick_y.state = analogRead(cmd.joystick_y.pin); cmd.joystick_y.state = analogRead(cmd.joystick_y.pin);
// Check if Joystick button is pressed // Check if Joystick button is pressed - Remove end course
if (cmd.joystick_y.state > 1000 && bench_motor.pups.end.state == LOW) // if (cmd.joystick_y.state > 1000 && bench_motor.pups.end.state == LOW)
if (cmd.joystick_y.state > 1000)
{ {
home_motors(); home_motors();
} }
// if forward, go forward // if forward, go forward - Remove end course
while (cmd.joystick_x.state > centerright && bench_motor.pups.end.state == LOW) // while (cmd.joystick_x.state > centerright && bench_motor.pups.end.state == LOW)
while (cmd.joystick_x.state > centerright)
{ {
SpeedDelay = map(cmd.joystick_x.state , centerright, farright, motorLow, motorHigh); SpeedDelay = map(cmd.joystick_x.state , centerright, farright, motorLow, motorHigh);
bench_motor.delay = SpeedDelay; bench_motor.delay = SpeedDelay;
for (int i = 0; i < steps; i++) for (int i = 0; i < steps; i++)
move_motor(bench_motor, forward); move_motor(bench_motor, forward);
bench_motor.pups.end.state = digitalRead(bench_motor.pups.end.pin); // Remove End course
// bench_motor.pups.end.state = digitalRead(bench_motor.pups.end.pin);
cmd.joystick_x.state = analogRead(cmd.joystick_x.pin); cmd.joystick_x.state = analogRead(cmd.joystick_x.pin);
} }
// if backward, go backward // if backward, go backward - Remove end course
while (cmd.joystick_x.state < centerleft && bench_motor.pups.home.state == LOW) // while (cmd.joystick_x.state < centerleft && bench_motor.pups.home.state == LOW)
while (cmd.joystick_x.state < centerleft)
{ {
SpeedDelay = map(cmd.joystick_x.state , centerleft, farleft, motorLow, motorHigh); SpeedDelay = map(cmd.joystick_x.state , centerleft, farleft, motorLow, motorHigh);
bench_motor.delay = SpeedDelay; bench_motor.delay = SpeedDelay;
for (int i = 0; i < steps; i++) for (int i = 0; i < steps; i++)
move_motor(bench_motor, backward); move_motor(bench_motor, backward);
bench_motor.pups.home.state = digitalRead(bench_motor.pups.home.pin); // Remove end course
// bench_motor.pups.home.state = digitalRead(bench_motor.pups.home.pin);
cmd.joystick_x.state = analogRead(cmd.joystick_x.pin); cmd.joystick_x.state = analogRead(cmd.joystick_x.pin);
} }
} }
@@ -145,8 +154,8 @@ void setup_motors()
pinMode(bench_motor.step, OUTPUT); pinMode(bench_motor.step, OUTPUT);
pinMode(bench_motor.dir, OUTPUT); pinMode(bench_motor.dir, OUTPUT);
pinMode(bench_motor.enable, OUTPUT); pinMode(bench_motor.enable, OUTPUT);
pinMode(bench_motor.pups.home.pin, INPUT_PULLUP); // pinMode(bench_motor.pups.home.pin, INPUT_PULLUP);
pinMode(bench_motor.pups.end.pin, INPUT_PULLUP); // pinMode(bench_motor.pups.end.pin, INPUT_PULLUP);
} }
// -- Setup function, needed by Arduino // -- Setup function, needed by Arduino
@@ -170,9 +179,10 @@ void loop()
{ {
// refresh states from all inputs // refresh states from all inputs
refresh_state(); // This function is disabled since no more end course
// refresh_state();
// move joystick if neeed // move joystick if needed
move_using_joystick(); move_using_joystick();
} }

View File

@@ -89,7 +89,7 @@ float datasec;
float datams; float datams;
// Steps for actionscript variable // Steps for actionscript variable
const int actionsteps = 11; const int actionsteps = 31;
int runningstep = 0; int runningstep = 0;
int stepstate = LOW; int stepstate = LOW;
int burningstate = LOW; // Will keep track of burner for actionscript int burningstate = LOW; // Will keep track of burner for actionscript