修改了电机控制盒初始化,上电后暂不进行校准

This commit is contained in:
CSBOOK\44744
2026-06-26 00:03:43 +08:00
parent 82eae93513
commit 61762b98fb
6 changed files with 54 additions and 83 deletions
@@ -16,7 +16,9 @@ static const char *TAG = "domain_cal";
#define DOMAIN_CALIBRATION_TIMEOUT_MS 20000
#define DOMAIN_CALIBRATION_STEP_TIMEOUT_MS 1500
#define DOMAIN_CALIBRATION_RELEASE_SWEEP_DEG 45.0f
#define DOMAIN_TURNTABLE_LIMIT_SEARCH_MAX_DEG 330.0f
#define DOMAIN_TURNTABLE_LIMIT_TO_HOME_DEG 180.0f
#define DOMAIN_TURNTABLE_HOME_ANGLE_DEG 0.0f
static float clamp_positive_default(float value, float default_value)
{
@@ -108,51 +110,6 @@ static esp_err_t calibration_rotate_and_track(float delta, int rotate_speed_us,
return domain_apply_rotation_delta(delta);
}
static esp_err_t calibration_release_active_switch(const domain_direction_calibration_t *calibration,
float step_angle,
float search_direction,
int rotate_speed_us,
TickType_t start_tick,
TickType_t timeout_ticks)
{
float release_sweep_limit = clamp_positive_default(DOMAIN_CALIBRATION_RELEASE_SWEEP_DEG,
step_angle);
float released_sweep = 0.0f;
float release_delta = -search_direction * step_angle;
while (released_sweep < release_sweep_limit) {
if (!is_calibration_switch_active(calibration)) {
ESP_LOGI(TAG, "Calibration switch released after %.1f deg", released_sweep);
return ESP_OK;
}
if (calibration_timeout_reached(start_tick, timeout_ticks)) {
return ESP_ERR_TIMEOUT;
}
int step_timeout_ms = calibration_step_timeout_ms(start_tick, timeout_ticks);
esp_err_t err = calibration_rotate_and_track(release_delta, rotate_speed_us, step_timeout_ms);
if (err != ESP_OK) {
return err;
}
released_sweep += step_angle;
if (!calibration_settle(calibration, start_tick, timeout_ticks)) {
return ESP_ERR_TIMEOUT;
}
}
if (is_calibration_switch_active(calibration)) {
ESP_LOGW(TAG,
"Calibration switch stayed active after %.1f deg release sweep",
released_sweep);
return ESP_ERR_INVALID_STATE;
}
ESP_LOGI(TAG, "Calibration switch released after %.1f deg", released_sweep);
return ESP_OK;
}
esp_err_t domain_calibrate_with_timeout(const domain_direction_calibration_t *config, int timeout_ms)
{
int effective_timeout_ms = timeout_ms > 0 ? timeout_ms : DOMAIN_CALIBRATION_TIMEOUT_MS;
@@ -190,37 +147,44 @@ esp_err_t domain_calibrate_with_timeout(const domain_direction_calibration_t *co
}
float step_angle = clamp_positive_default(calibration.step_angle_deg, 5.0f);
float max_sweep = clamp_positive_default(calibration.max_sweep_deg, 360.0f);
float configured_max_sweep = clamp_positive_default(calibration.max_sweep_deg,
DOMAIN_TURNTABLE_LIMIT_SEARCH_MAX_DEG);
float max_sweep = configured_max_sweep > DOMAIN_TURNTABLE_LIMIT_SEARCH_MAX_DEG ?
DOMAIN_TURNTABLE_LIMIT_SEARCH_MAX_DEG :
configured_max_sweep;
float total_sweep = 0.0f;
float direction = calibration.search_clockwise ? 1.0f : -1.0f;
int rotate_speed_us = domain_get_rotate_speed_us();
ESP_LOGI(TAG,
"Calibration start step=%.1f sweep=%.1f search=%s",
"Limit calibration start step=%.1f sweep=%.1f search=%s",
step_angle,
max_sweep,
calibration.search_clockwise ? "clockwise" : "counterclockwise");
if (is_calibration_switch_active(&calibration)) {
ESP_LOGI(TAG, "Calibration switch active at start, releasing before homing");
err = calibration_release_active_switch(&calibration,
step_angle,
direction,
rotate_speed_us,
start_tick,
timeout_ticks);
ESP_LOGI(TAG, "Limit switch active at start; treating current position as 6 o'clock");
int return_timeout_ms = calibration_step_timeout_ms(start_tick, timeout_ticks);
err = calibration_rotate_and_track(-direction * DOMAIN_TURNTABLE_LIMIT_TO_HOME_DEG,
rotate_speed_us,
return_timeout_ms);
if (err != ESP_OK) {
domain_runtime_stepper_power_off();
domain_direction_unlock_state();
return err;
}
domain_set_current_angle(DOMAIN_TURNTABLE_HOME_ANGLE_DEG);
domain_runtime_stepper_power_off();
domain_direction_unlock_state();
ESP_LOGI(TAG, "Turntable home reached from active limit switch");
return ESP_OK;
}
while (total_sweep < max_sweep) {
if (calibration_timeout_reached(start_tick, timeout_ticks)) {
domain_runtime_stepper_power_off();
domain_direction_unlock_state();
ESP_LOGW(TAG, "Calibration timed out after %.1f deg search", total_sweep);
ESP_LOGW(TAG, "Limit calibration timed out after %.1f deg search", total_sweep);
return ESP_ERR_TIMEOUT;
}
@@ -237,21 +201,31 @@ esp_err_t domain_calibrate_with_timeout(const domain_direction_calibration_t *co
if (!calibration_settle(&calibration, start_tick, timeout_ticks)) {
domain_runtime_stepper_power_off();
domain_direction_unlock_state();
ESP_LOGW(TAG, "Calibration timed out during settle after %.1f deg search", total_sweep);
ESP_LOGW(TAG, "Limit calibration timed out during settle after %.1f deg search", total_sweep);
return ESP_ERR_TIMEOUT;
}
if (is_calibration_switch_active(&calibration)) {
domain_set_current_angle(calibration.calibration_angle);
ESP_LOGI(TAG, "Limit switch detected after %.1f deg; current position is 6 o'clock", total_sweep);
int return_timeout_ms = calibration_step_timeout_ms(start_tick, timeout_ticks);
err = calibration_rotate_and_track(-direction * DOMAIN_TURNTABLE_LIMIT_TO_HOME_DEG,
rotate_speed_us,
return_timeout_ms);
if (err != ESP_OK) {
domain_runtime_stepper_power_off();
domain_direction_unlock_state();
return err;
}
domain_set_current_angle(DOMAIN_TURNTABLE_HOME_ANGLE_DEG);
domain_runtime_stepper_power_off();
domain_direction_unlock_state();
ESP_LOGI(TAG, "Calibration switch detected after %.1f deg", total_sweep);
ESP_LOGI(TAG, "Turntable home reached after limit calibration");
return ESP_OK;
}
}
domain_runtime_stepper_power_off();
domain_direction_unlock_state();
ESP_LOGW(TAG, "Calibration sweep exhausted after %.1f deg", total_sweep);
ESP_LOGW(TAG, "Limit switch not found after %.1f deg search", total_sweep);
return ESP_ERR_TIMEOUT;
}
@@ -19,9 +19,9 @@ static const char *TAG = "domain";
#define DOMAIN_ROTATE_TIMEOUT_MS 8000
#define DOMAIN_STATE_LOCK_TIMEOUT_MS 2000
#define DOMAIN_DEFAULT_CALIBRATION_ENABLED 1
#define DOMAIN_DEFAULT_CALIBRATION_ANGLE_DEG 180.0f
#define DOMAIN_DEFAULT_CALIBRATION_ANGLE_DEG 0.0f
#define DOMAIN_DEFAULT_CALIBRATION_STEP_ANGLE_DEG 5.0f
#define DOMAIN_DEFAULT_CALIBRATION_MAX_SWEEP_DEG 360.0f
#define DOMAIN_DEFAULT_CALIBRATION_MAX_SWEEP_DEG 330.0f
#define DOMAIN_DEFAULT_CALIBRATION_SEARCH_CLOCKWISE 1
#define DOMAIN_DEFAULT_CALIBRATION_SETTLE_DELAY_MS 10