feat: Adjust valve obstacle detection thresholds
Reduced the current thresholds for obstacle detection during valve opening and closing from 500mA to 200mA. This makes the obstacle detection more sensitive. refactor: Simplify valve_work_handler logic Refactored the function to directly call when an obstacle is detected or the valve reaches its end position. This removes redundant code and improves the clarity of the control flow. Signed-off-by: Eduard Iten <eduard@iten.pro>
This commit is contained in:
parent
66cdc3ae27
commit
fc0add8583
|
|
@ -17,8 +17,8 @@
|
||||||
#define VALVE_CHANNEL_CLOSE 1
|
#define VALVE_CHANNEL_CLOSE 1
|
||||||
#define VALVE_ENDPOSITION_CHECK_INTERVAL K_MSEC(100)
|
#define VALVE_ENDPOSITION_CHECK_INTERVAL K_MSEC(100)
|
||||||
|
|
||||||
#define VALVE_OBSTACLE_THRESHOLD_OPEN_MA 500
|
#define VALVE_OBSTACLE_THRESHOLD_OPEN_MA 200
|
||||||
#define VALVE_OBSTACLE_THRESHOLD_CLOSE_MA 500
|
#define VALVE_OBSTACLE_THRESHOLD_CLOSE_MA 200
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Represents the static state of the valve (open or closed).
|
* @brief Represents the static state of the valve (open or closed).
|
||||||
|
|
|
||||||
|
|
@ -54,7 +54,7 @@ static void valve_work_handler(struct k_work *work)
|
||||||
current_ma);
|
current_ma);
|
||||||
current_movement = VALVE_MOVEMENT_ERROR;
|
current_movement = VALVE_MOVEMENT_ERROR;
|
||||||
valve_stop();
|
valve_stop();
|
||||||
goto work_handler_cleanup;
|
return;
|
||||||
} else if (current_ma > end_current_threshold_open_ma) {
|
} else if (current_ma > end_current_threshold_open_ma) {
|
||||||
k_work_schedule(&valve_work, VALVE_ENDPOSITION_CHECK_INTERVAL);
|
k_work_schedule(&valve_work, VALVE_ENDPOSITION_CHECK_INTERVAL);
|
||||||
return;
|
return;
|
||||||
|
|
@ -69,7 +69,7 @@ static void valve_work_handler(struct k_work *work)
|
||||||
current_ma);
|
current_ma);
|
||||||
current_movement = VALVE_MOVEMENT_ERROR;
|
current_movement = VALVE_MOVEMENT_ERROR;
|
||||||
valve_stop();
|
valve_stop();
|
||||||
goto work_handler_cleanup;
|
return;
|
||||||
} else if (current_ma > end_current_threshold_close_ma) {
|
} else if (current_ma > end_current_threshold_close_ma) {
|
||||||
k_work_schedule(&valve_work, VALVE_ENDPOSITION_CHECK_INTERVAL);
|
k_work_schedule(&valve_work, VALVE_ENDPOSITION_CHECK_INTERVAL);
|
||||||
return;
|
return;
|
||||||
|
|
@ -79,12 +79,7 @@ static void valve_work_handler(struct k_work *work)
|
||||||
}
|
}
|
||||||
current_movement = VALVE_MOVEMENT_IDLE;
|
current_movement = VALVE_MOVEMENT_IDLE;
|
||||||
|
|
||||||
work_handler_cleanup:
|
valve_stop();
|
||||||
// Reset the movement timer
|
|
||||||
k_timer_stop(&movement_timer);
|
|
||||||
|
|
||||||
vnd7050aj_set_output_state(vnd7050aj_dev, VALVE_CHANNEL_OPEN, false);
|
|
||||||
vnd7050aj_set_output_state(vnd7050aj_dev, VALVE_CHANNEL_CLOSE, false);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -147,9 +142,9 @@ void valve_open(void)
|
||||||
vnd7050aj_reset_fault(vnd7050aj_dev);
|
vnd7050aj_reset_fault(vnd7050aj_dev);
|
||||||
vnd7050aj_set_output_state(vnd7050aj_dev, VALVE_CHANNEL_CLOSE, false);
|
vnd7050aj_set_output_state(vnd7050aj_dev, VALVE_CHANNEL_CLOSE, false);
|
||||||
vnd7050aj_set_output_state(vnd7050aj_dev, VALVE_CHANNEL_OPEN, true);
|
vnd7050aj_set_output_state(vnd7050aj_dev, VALVE_CHANNEL_OPEN, true);
|
||||||
current_state = VALVE_STATE_OPEN;
|
current_state =
|
||||||
current_movement = VALVE_MOVEMENT_OPENING; /* Security: assume valve open as
|
VALVE_STATE_OPEN; /* Security: assume valve open as soon as it starts opening */
|
||||||
soons as it starts opening */
|
current_movement = VALVE_MOVEMENT_OPENING;
|
||||||
if (max_opening_time_s > 0) {
|
if (max_opening_time_s > 0) {
|
||||||
k_timer_start(&movement_timer, K_SECONDS(max_opening_time_s), K_NO_WAIT);
|
k_timer_start(&movement_timer, K_SECONDS(max_opening_time_s), K_NO_WAIT);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue