feat: Implement obstacle detection for valve movement
Implement obstacle detection for valve movement that stops the motor if the current exceeds a predefined threshold during opening or closing.
- :
- Added new defines and with a default value of 500 mA.
- :
- Modified function to compare the measured current with the new obstacle thresholds.
- If the threshold is exceeded, the valve movement is stopped and the status is set to .
Signed-off-by: Your Name <your.email@example.com>
This commit is contained in:
parent
3de42a46c2
commit
76d0d0647c
|
|
@ -17,6 +17,9 @@
|
||||||
#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_CLOSE_MA 500
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Represents the static state of the valve (open or closed).
|
* @brief Represents the static state of the valve (open or closed).
|
||||||
*/
|
*/
|
||||||
|
|
|
||||||
|
|
@ -47,14 +47,28 @@ static void valve_work_handler(struct k_work *work)
|
||||||
|
|
||||||
if (current_movement == VALVE_MOVEMENT_OPENING) {
|
if (current_movement == VALVE_MOVEMENT_OPENING) {
|
||||||
vnd7050aj_read_load_current(vnd7050aj_dev, VALVE_CHANNEL_OPEN, ¤t_ma);
|
vnd7050aj_read_load_current(vnd7050aj_dev, VALVE_CHANNEL_OPEN, ¤t_ma);
|
||||||
if (current_ma > end_current_threshold_open_ma) {
|
if (current_ma > VALVE_OBSTACLE_THRESHOLD_OPEN_MA) {
|
||||||
|
LOG_ERR(
|
||||||
|
"Obstacle detected during opening (current: %d mA), stopping motor.",
|
||||||
|
current_ma);
|
||||||
|
current_movement = VALVE_MOVEMENT_ERROR;
|
||||||
|
valve_stop();
|
||||||
|
return;
|
||||||
|
} 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;
|
||||||
}
|
}
|
||||||
LOG_INF("Valve finished opening");
|
LOG_INF("Valve finished opening");
|
||||||
} else if (current_movement == VALVE_MOVEMENT_CLOSING) {
|
} else if (current_movement == VALVE_MOVEMENT_CLOSING) {
|
||||||
vnd7050aj_read_load_current(vnd7050aj_dev, VALVE_CHANNEL_CLOSE, ¤t_ma);
|
vnd7050aj_read_load_current(vnd7050aj_dev, VALVE_CHANNEL_CLOSE, ¤t_ma);
|
||||||
if (current_ma > end_current_threshold_close_ma) {
|
if (current_ma > VALVE_OBSTACLE_THRESHOLD_CLOSE_MA) {
|
||||||
|
LOG_ERR(
|
||||||
|
"Obstacle detected during closing (current: %d mA), stopping motor.",
|
||||||
|
current_ma);
|
||||||
|
current_movement = VALVE_MOVEMENT_ERROR;
|
||||||
|
valve_stop();
|
||||||
|
return;
|
||||||
|
} 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;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue