Upgraded steps & removed end courses
This commit is contained in:
@@ -87,22 +87,26 @@ void move_motor(motor motor, int *signals)
|
||||
}
|
||||
|
||||
// home_motors is used to get all motors to home position
|
||||
// This function is disabled since no more end course
|
||||
|
||||
void home_motors()
|
||||
{
|
||||
bench_motor.delay = motorHigh+30;
|
||||
while (bench_motor.pups.home.state == LOW)
|
||||
{
|
||||
move_motor(bench_motor, forward);
|
||||
bench_motor.pups.home.state = digitalRead(bench_motor.pups.home.pin);
|
||||
}
|
||||
// bench_motor.delay = motorHigh+30;
|
||||
// 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);
|
||||
// }
|
||||
refresh_motors_states();
|
||||
}
|
||||
|
||||
// refresh all motors pullups states
|
||||
// This function is disabled since no more end course
|
||||
void refresh_motors_states()
|
||||
{
|
||||
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.home.state = digitalRead(bench_motor.pups.home.pin);
|
||||
// bench_motor.pups.end.state = digitalRead(bench_motor.pups.end.pin);
|
||||
}
|
||||
|
||||
// move_using_joystick is used to move motors depending on joystick position
|
||||
@@ -111,30 +115,35 @@ void move_using_joystick()
|
||||
// fetch joystick position
|
||||
cmd.joystick_x.state = analogRead(cmd.joystick_x.pin);
|
||||
cmd.joystick_y.state = analogRead(cmd.joystick_y.pin);
|
||||
// Check if Joystick button is pressed
|
||||
if (cmd.joystick_y.state > 1000 && bench_motor.pups.end.state == LOW)
|
||||
// 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)
|
||||
{
|
||||
home_motors();
|
||||
}
|
||||
// if forward, go forward
|
||||
while (cmd.joystick_x.state > centerright && bench_motor.pups.end.state == LOW)
|
||||
// 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)
|
||||
{
|
||||
SpeedDelay = map(cmd.joystick_x.state , centerright, farright, motorLow, motorHigh);
|
||||
bench_motor.delay = SpeedDelay;
|
||||
for (int i = 0; i < steps; i++)
|
||||
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);
|
||||
}
|
||||
|
||||
// if backward, go backward
|
||||
while (cmd.joystick_x.state < centerleft && bench_motor.pups.home.state == LOW)
|
||||
// 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)
|
||||
{
|
||||
SpeedDelay = map(cmd.joystick_x.state , centerleft, farleft, motorLow, motorHigh);
|
||||
bench_motor.delay = SpeedDelay;
|
||||
for (int i = 0; i < steps; i++)
|
||||
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);
|
||||
}
|
||||
}
|
||||
@@ -145,8 +154,8 @@ void setup_motors()
|
||||
pinMode(bench_motor.step, OUTPUT);
|
||||
pinMode(bench_motor.dir, OUTPUT);
|
||||
pinMode(bench_motor.enable, OUTPUT);
|
||||
pinMode(bench_motor.pups.home.pin, INPUT_PULLUP);
|
||||
pinMode(bench_motor.pups.end.pin, INPUT_PULLUP);
|
||||
// pinMode(bench_motor.pups.home.pin, INPUT_PULLUP);
|
||||
// pinMode(bench_motor.pups.end.pin, INPUT_PULLUP);
|
||||
}
|
||||
|
||||
// -- Setup function, needed by Arduino
|
||||
@@ -170,9 +179,10 @@ void loop()
|
||||
{
|
||||
|
||||
// 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();
|
||||
|
||||
}
|
||||
|
||||
@@ -89,7 +89,7 @@ float datasec;
|
||||
float datams;
|
||||
|
||||
// Steps for actionscript variable
|
||||
const int actionsteps = 11;
|
||||
const int actionsteps = 31;
|
||||
int runningstep = 0;
|
||||
int stepstate = LOW;
|
||||
int burningstate = LOW; // Will keep track of burner for actionscript
|
||||
|
||||
Reference in New Issue
Block a user