-
Notifications
You must be signed in to change notification settings - Fork 2
Refactor valve control logic and improve error handling #118
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
611ac3c
9f4d1f3
82b1ec8
9b234bd
91efe1a
f2c81a2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -60,9 +60,9 @@ | |||||
|
|
||||||
| /* Hash table of sensor readout sizes and offsets */ | ||||||
| static SENSOR_DATA_SIZE_OFFSETS sensor_size_offsets_table[ NUM_SENSORS ]; | ||||||
| extern volatile uint32_t tdelta, previous_time; | ||||||
|
|
||||||
| #ifdef FLIGHT_COMPUTER | ||||||
| extern volatile uint32_t tdelta, previous_time; | ||||||
| extern GPS_DATA gps_data; | ||||||
| extern IMU_OFFSET imu_offset; | ||||||
| #endif | ||||||
|
|
@@ -468,8 +468,10 @@ switch ( subcommand ) | |||||
| } | ||||||
| #endif | ||||||
|
|
||||||
| #ifdef FLIGHT_COMPUTER | ||||||
| // Reset start time | ||||||
| previous_time = HAL_GetTick(); | ||||||
| #endif | ||||||
|
|
||||||
| /* Start polling sensors */ | ||||||
| while ( sensor_poll_cmd != SENSOR_POLL_STOP ) | ||||||
|
|
@@ -513,8 +515,10 @@ switch ( subcommand ) | |||||
| /* Poll Sensors */ | ||||||
| case SENSOR_POLL_REQUEST: | ||||||
| { | ||||||
| #ifdef FLIGHT_COMPUTER | ||||||
| tdelta = HAL_GetTick() - previous_time; | ||||||
| previous_time = HAL_GetTick(); | ||||||
| #endif /* FLIGHT_COMPUTER */ | ||||||
| sensor_status = sensor_poll( &sensor_data , | ||||||
| &poll_sensors[0], | ||||||
| num_sensors ); | ||||||
|
|
@@ -543,9 +547,11 @@ switch ( subcommand ) | |||||
| /* STOP Executtion */ | ||||||
|
||||||
| /* STOP Executtion */ | |
| /* STOP Execution */ |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -165,10 +165,13 @@ switch(solenoid_base_code) | |
| case SOL_GETSTATE_CODE: | ||
| { | ||
| sol_state = solenoid_get_state(); | ||
| #if defined( TERMINAL ) | ||
| #if defined( TERMINAL ) | ||
| usb_transmit( &sol_state, sizeof( sol_state ), HAL_DEFAULT_TIMEOUT ); | ||
| #elif defined( HOTFIRE ) | ||
| valve_transmit( &sol_state, sizeof( sol_state ), HAL_DEFAULT_TIMEOUT ); | ||
| #elif defined( HOTFIRE ) | ||
| if (USB_MODE) | ||
| usb_transmit( &sol_state, sizeof( sol_state ), HAL_DEFAULT_TIMEOUT ); | ||
| else | ||
| valve_transmit( &sol_state, sizeof( sol_state ), HAL_DEFAULT_TIMEOUT ); | ||
|
Comment on lines
+170
to
+174
|
||
| #endif | ||
| break; | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -282,9 +282,14 @@ switch( subcommand ) | |||||
| { | ||||||
| main_valve_states = valve_get_valve_states(); | ||||||
| #if defined( HOTFIRE ) | ||||||
| valve_transmit( &main_valve_states , | ||||||
| sizeof( main_valve_states ), | ||||||
| HAL_DEFAULT_TIMEOUT ); | ||||||
| if (USB_MODE){ | ||||||
| usb_transmit( &main_valve_states , | ||||||
| sizeof( main_valve_states ), | ||||||
| HAL_DEFAULT_TIMEOUT ); | ||||||
| } else | ||||||
| valve_transmit( &main_valve_states , | ||||||
| sizeof( main_valve_states ), | ||||||
| HAL_DEFAULT_TIMEOUT ); | ||||||
|
Comment on lines
+285
to
+292
|
||||||
| #elif defined( TERMINAL ) | ||||||
| usb_transmit( &main_valve_states, | ||||||
| sizeof( main_valve_states ), | ||||||
|
|
@@ -569,6 +574,58 @@ return VALVE_OK; | |||||
| } /* valve_open_fuel_valve */ | ||||||
|
|
||||||
|
|
||||||
| /******************************************************************************* | ||||||
| * * | ||||||
| * PROCEDURE: * | ||||||
| * valve_open_fuel_valve * | ||||||
| * * | ||||||
| * DESCRIPTION: * | ||||||
| * Open the main fuel valve * | ||||||
| * * | ||||||
| *******************************************************************************/ | ||||||
| VALVE_STATUS valve_slow_open_fuel_valve | ||||||
| ( | ||||||
| void | ||||||
| ) | ||||||
| { | ||||||
| /*------------------------------------------------------------------------------ | ||||||
| Local Variables | ||||||
| ------------------------------------------------------------------------------*/ | ||||||
| VALVE_STATUS valve_status; /* Status return codes from valve API */ | ||||||
|
|
||||||
|
|
||||||
| /*------------------------------------------------------------------------------ | ||||||
| Initializations | ||||||
| ------------------------------------------------------------------------------*/ | ||||||
| valve_status = VALVE_OK; | ||||||
|
|
||||||
|
|
||||||
| /*------------------------------------------------------------------------------ | ||||||
| Implementation | ||||||
| ------------------------------------------------------------------------------*/ | ||||||
|
|
||||||
| /* Check if valve is already open */ | ||||||
| if ( fuel_valve_pos == VALVE_OPEN_POS ) | ||||||
| { | ||||||
| return VALVE_OK; | ||||||
| } | ||||||
|
|
||||||
| /* Set the direction */ | ||||||
| valve_status = fuel_driver_set_direction( STEPPER_DRIVER_CW ); | ||||||
| if ( valve_status != VALVE_OK ) | ||||||
| { | ||||||
| return valve_status; | ||||||
| } | ||||||
|
|
||||||
| /* Actuate the valve */ | ||||||
| fuel_valve_opening = true; | ||||||
| HAL_TIM_PWM_Start( &( VALVE_FUEL_TIM ), VALVE_FUEL_TIM_CHANNEL ); | ||||||
| return VALVE_OK; | ||||||
|
Comment on lines
+586
to
+623
|
||||||
| } /* valve_open_fuel_valve */ | ||||||
|
||||||
| } /* valve_open_fuel_valve */ | |
| } /* valve_slow_open_fuel_valve */ |
Copilot
AI
Apr 13, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
dec_lox_encoder() and the encoder-count-based closed-position stop logic are commented out, so lox_valve_pos no longer decrements during closing and the close-stop condition relies solely on valve_get_ox_valve_state(). This removes the encoder position as a fallback safety limit; consider restoring the decrement/update and/or adding a max-steps/timeout safeguard so a photogate failure can’t leave the PWM running indefinitely.
Copilot
AI
Apr 13, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
dec_fuel_encoder() and the encoder-count-based closed-position stop logic are commented out, so fuel_valve_pos no longer decrements during closing and the close-stop condition relies solely on valve_get_fuel_valve_state(). This removes the encoder position as a fallback safety limit; consider restoring the decrement/update and/or adding a max-steps/timeout safeguard so a photogate failure can’t leave the PWM running indefinitely.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
New enum entries
ERROR_FUEL_TIM_INIT_ERRORandERROR_LOX_TIM_INIT_ERRORwere added without the inline comments used by most otherERROR_CODEvalues. Adding brief comments (and keeping formatting consistent with adjacent entries) will make diagnostics/telemetry easier to interpret.