Skip to content

Commit

Permalink
use rising edge (when estop releases) and no need for delay
Browse files Browse the repository at this point in the history
Revert "update state manager poetry.lock"

This reverts commit 7be7adf.

fix up rebase problems
  • Loading branch information
ahiuchingau committed Jan 22, 2024
1 parent 2cf34bf commit 761ee07
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 31 deletions.
6 changes: 1 addition & 5 deletions gripper/firmware/interfaces_z_motor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -203,17 +203,13 @@ extern "C" void call_motor_handler(void) { motor_interrupt.run_interrupt(); }
extern "C" void call_enc_handler(int32_t direction) {
motor_hardware_iface.encoder_overflow(direction);
}
extern "C" void disengage_z_callback_glue(void) {
motor_hardware_iface.deactivate_motor();
}

void z_motor_iface::initialize() {
if (initialize_spi() != HAL_OK) {
Error_Handler();
}
initialize_hardware_z();
set_z_motor_timer_callback(call_motor_handler, call_enc_handler,
disengage_z_callback_glue);
set_z_motor_timer_callback(call_motor_handler, call_enc_handler);
encoder_background_timer.start();
}

Expand Down
4 changes: 1 addition & 3 deletions gripper/firmware/motor_hardware.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,14 @@ extern TIM_HandleTypeDef htim8;

typedef void (*motor_interrupt_callback)();
typedef void (*z_encoder_overflow_callback)(int32_t);
typedef void (*z_motor_disengage_callback)();


HAL_StatusTypeDef initialize_spi();
void initialize_hardware_z();

void set_z_motor_timer_callback(
motor_interrupt_callback callback,
z_encoder_overflow_callback enc_callback,
z_motor_disengage_callback disengage_callback);
z_encoder_overflow_callback enc_callback);


// G motor specific
Expand Down
14 changes: 7 additions & 7 deletions gripper/firmware/motor_hardware_shared.c
Original file line number Diff line number Diff line change
@@ -1,24 +1,20 @@
#include "motor_hardware.h"
#include "system_stm32g4xx.h"


static motor_interrupt_callback timer_callback = NULL;
static z_encoder_overflow_callback z_enc_overflow_callback = NULL;
static brushed_motor_interrupt_callback brushed_timer_callback = NULL;
static encoder_overflow_callback gripper_enc_overflow_callback = NULL;
static encoder_idle_state_callback gripper_enc_idle_state_overflow_callback =
NULL;
static stopwatch_overflow_callback gripper_force_stopwatch_overflow_callback = NULL;
static z_motor_disengage_callback disengage_z_callback = NULL;


void set_z_motor_timer_callback(
motor_interrupt_callback callback,
z_encoder_overflow_callback enc_callback,
z_motor_disengage_callback disengage_callback) {
z_encoder_overflow_callback enc_callback) {
timer_callback = callback;
z_enc_overflow_callback = enc_callback;
disengage_z_callback = disengage_callback;
}

void set_brushed_motor_timer_callback(
Expand Down Expand Up @@ -218,7 +214,11 @@ void HAL_TIM_IC_CaptureCallback(TIM_HandleTypeDef* htim) {


void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin) {
if (GPIO_Pin == Z_MOT_ENABLE_PIN && disengage_z_callback) {
disengage_z_callback();
if (GPIO_Pin == ESTOP_IN_PIN) {
#if PCBA_PRIMARY_REVISION != 'b' && PCBA_PRIMARY_REVISION != 'a'
HAL_GPIO_WritePin(EBRAKE_PORT, EBRAKE_PIN, GPIO_PIN_RESET);
#endif
// this keeps the motor disengaged when estop is released
HAL_GPIO_WritePin(Z_MOT_ENABLE_PORT, Z_MOT_ENABLE_PIN, GPIO_PIN_RESET);
}
}
7 changes: 1 addition & 6 deletions head/firmware/main_rev1.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -341,10 +341,6 @@ extern "C" void left_enc_overflow_callback_glue(int32_t direction) {
extern "C" void right_enc_overflow_callback_glue(int32_t direction) {
motor_hardware_right.encoder_overflow(direction);
}
extern "C" void motor_disengage_callback_glue() {
motor_hardware_left.deactivate_motor();
motor_hardware_right.deactivate_motor();
}

static auto psd = presence_sensing_driver::PresenceSensingHardware{
gpio::PinConfig{// NOLINTNEXTLINE(cppcoreguidelines-pro-type-cstyle-cast)
Expand Down Expand Up @@ -422,8 +418,7 @@ auto main() -> int {
app_update_clear_flags();

initialize_timer(motor_callback_glue, left_enc_overflow_callback_glue,
right_enc_overflow_callback_glue,
motor_disengage_callback_glue);
right_enc_overflow_callback_glue);

i2c_setup(&i2c_handles);
i2c_comms3.set_handle(i2c_handles.i2c3);
Expand Down
4 changes: 1 addition & 3 deletions head/firmware/motor_hardware.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,11 @@ extern TIM_HandleTypeDef htim3;

typedef void (*motor_interrupt_callback)();
typedef void (*encoder_overflow_callback)(int32_t);
typedef void (*disable_motor_callback)();

HAL_StatusTypeDef initialize_spi(SPI_HandleTypeDef* hspi);
void initialize_timer(motor_interrupt_callback callback,
encoder_overflow_callback left_enc_overflow_callback,
encoder_overflow_callback right_enc_overflow_callback,
disable_motor_callback disengage_callback);
encoder_overflow_callback right_enc_overflow_callback);
void initialize_rev_specific_pins();

#ifdef __cplusplus
Expand Down
17 changes: 10 additions & 7 deletions head/firmware/motor_hardware_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@ motor_interrupt_callback motor_callback = NULL;
encoder_overflow_callback left_enc_overflow_callback = NULL;
encoder_overflow_callback right_enc_overflow_callback = NULL;

disable_motor_callback motor_disengage_callback = NULL;

void HAL_SPI_MspInit(SPI_HandleTypeDef *hspi) {
GPIO_InitTypeDef GPIO_InitStruct = {0};
if (hspi->Instance == SPI2) {
Expand Down Expand Up @@ -338,19 +336,24 @@ void HAL_TIM_Encoder_MspInit(TIM_HandleTypeDef *htim) {

void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin) {
// disengage motor whenever estop is engaged
if (GPIO_Pin == GPIO_PIN_4 && motor_disengage_callback) {
motor_disengage_callback();
if (GPIO_Pin == GPIO_PIN_4) {
#if PCBA_PRIMARY_REVISION != 'b' && PCBA_PRIMARY_REVISION != 'a'
// right & left brake
HAL_GPIO_WritePin(GPIOB, GPIO_PIN_0 | GPIO_PIN_5, GPIO_PIN_RESET);
#endif

// disable both left and right enable pins
HAL_GPIO_WritePin(GPIOC, GPIO_PIN_4, GPIO_PIN_RESET);
HAL_GPIO_WritePin(GPIOB, GPIO_PIN_11, GPIO_PIN_RESET);
}
}

void initialize_timer(motor_interrupt_callback callback,
encoder_overflow_callback l_f_callback,
encoder_overflow_callback r_f_callback,
disable_motor_callback disengage_callback) {
encoder_overflow_callback r_f_callback) {
motor_callback = callback;
left_enc_overflow_callback = l_f_callback;
right_enc_overflow_callback = r_f_callback;
motor_disengage_callback = disengage_callback;
MX_GPIO_Init();
Encoder_GPIO_Init();
encoder_init(&htim2);
Expand Down

0 comments on commit 761ee07

Please sign in to comment.