Skip to content

Commit

Permalink
Improve Z-axis homing/raising
Browse files Browse the repository at this point in the history
  • Loading branch information
DeflateAwning committed Jan 6, 2024
1 parent 455742a commit b71a7f3
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 12 deletions.
1 change: 1 addition & 0 deletions GNCTR_Claw_Machine/include/main_drivers.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ void loop_moveMotorsBasedOnButtons();
void loop_dropOrRaiseClaw();
void home_x_axis();
void home_y_axis();
void home_z_motor(uint16_t max_up_duration_ms);
void endgame_move_to_bin();
void move_claw_to_absolute_xy(long x, long y);

Expand Down
15 changes: 11 additions & 4 deletions GNCTR_Claw_Machine/src/main_drivers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -380,6 +380,15 @@ void home_y_axis() {
Serial.println("INFO: Y axis homed.");
}

void home_z_motor(uint16_t max_up_duration_ms) {
// wait for claw to raise all the way, and then drop it a touch
set_z_motor_state(Z_MOTOR_DIRECTION_RAISE);
delay(max_up_duration_ms); // TODO: make it only raise a little bit, if it's aware of how far down it is
set_z_motor_state(Z_MOTOR_DIRECTION_DROP);
delay(50);
set_z_motor_state(Z_MOTOR_DIRECTION_STOP);
}

void endgame_move_to_bin() {
// moves axes over the bin; blocking
// also zeros the Y axis
Expand Down Expand Up @@ -409,9 +418,7 @@ void endgame_move_to_bin() {
delay(500);

// move the claw back up
set_z_motor_state(Z_MOTOR_DIRECTION_RAISE);
delay(500);
set_z_motor_state(Z_MOTOR_DIRECTION_STOP);
home_z_motor(2000);

// move to middle
move_claw_to_absolute_xy(xAxisLength/2, yAxisLength/2);
Expand Down Expand Up @@ -581,7 +588,7 @@ void display_duration_ms(uint32_t duration_ms) {
}

void display_blinking_zeros() {
display.displayColon(0);
display.displayColon(1);
display.displayInt(0);
display.setBlink(1);
}
Expand Down
19 changes: 11 additions & 8 deletions GNCTR_Claw_Machine/src/states.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#include "main_drivers.h"

uint16_t start_btn_led_blink_rate_ms = 400; // half-period
uint16_t game_play_max_time_sec = 10; // FIXME: set to 45 for deployment
uint16_t game_play_max_time_sec = 45; // FIXME: set to 45 for deployment

// persistent vars for GAME_STATE_IDLE
bool start_btn_led_state = false;
Expand Down Expand Up @@ -40,6 +40,7 @@ game_state_t homing_state(game_state_t prev)
display_raw_message(seg_zero_message_for_display);

Serial.println("Starting xy-axis homing because it's past the start button waiting.");
home_z_motor(3000);
home_x_axis();
home_y_axis();

Expand Down Expand Up @@ -124,11 +125,18 @@ game_state_t play_state(game_state_t prev)
// }

// do a countdown: 4321 removing the numbers
set_enclosure_led(false);
uint16_t countdown_nums[] = {4321, 321, 21, 1};
for (uint16_t i = 0; i < 4; i++) {
display_int_no_leading_zeros(countdown_nums[i]);
delay(700);

delay(500);
set_enclosure_led(true);
delay(200);
set_enclosure_led(false);

}
set_enclosure_led(true);

uint32_t play_state_start_time_ms = millis();
uint32_t last_play_state_tenthsec = 0;
Expand Down Expand Up @@ -176,13 +184,8 @@ game_state_t reset_state(game_state_t prev)
set_start_button_led(false);
set_claw_state(CLAW_ENGAGE);
delay(250); // wait for claw to close before lifting
set_z_motor_state(Z_MOTOR_DIRECTION_RAISE);

// wait for claw to raise all the way, and then drop it a touch
delay(1000); // TODO: make it only raise a little bit, if it's aware of how far down it is
set_z_motor_state(Z_MOTOR_DIRECTION_DROP);
delay(50);
set_z_motor_state(Z_MOTOR_DIRECTION_STOP);
home_z_motor(2000);

// move claw over bin in front
endgame_move_to_bin();
Expand Down

0 comments on commit b71a7f3

Please sign in to comment.