forked from espressif/esp-idf
Merge branch 'bugfix/step_motor_example_check_curve_step' into 'master'
stepper motor example: check curve_step for stepper motor encoder Closes IDFGH-8824 See merge request espressif/esp-idf!21318
This commit is contained in:
@@ -76,8 +76,9 @@ esp_err_t rmt_new_stepper_motor_curve_encoder(const stepper_motor_curve_encoder_
|
||||
bool is_accel_curve = config->start_freq_hz < config->end_freq_hz;
|
||||
|
||||
// prepare the curve table, in RMT symbol format
|
||||
uint32_t curve_step = 0;
|
||||
if (is_accel_curve) {
|
||||
uint32_t curve_step = (config->end_freq_hz - config->start_freq_hz) / (config->sample_points - 1);
|
||||
curve_step = (config->end_freq_hz - config->start_freq_hz) / (config->sample_points - 1);
|
||||
for (uint32_t i = 0; i < config->sample_points; i++) {
|
||||
smooth_freq = convert_to_smooth_freq(config->start_freq_hz, config->end_freq_hz, config->start_freq_hz + curve_step * i);
|
||||
symbol_duration = config->resolution / smooth_freq / 2;
|
||||
@@ -87,7 +88,7 @@ esp_err_t rmt_new_stepper_motor_curve_encoder(const stepper_motor_curve_encoder_
|
||||
step_encoder->curve_table[i].duration1 = symbol_duration;
|
||||
}
|
||||
} else {
|
||||
uint32_t curve_step = (config->start_freq_hz - config->end_freq_hz) / (config->sample_points - 1);
|
||||
curve_step = (config->start_freq_hz - config->end_freq_hz) / (config->sample_points - 1);
|
||||
for (uint32_t i = 0; i < config->sample_points; i++) {
|
||||
smooth_freq = convert_to_smooth_freq(config->end_freq_hz, config->start_freq_hz, config->end_freq_hz + curve_step * i);
|
||||
symbol_duration = config->resolution / smooth_freq / 2;
|
||||
@@ -97,6 +98,7 @@ esp_err_t rmt_new_stepper_motor_curve_encoder(const stepper_motor_curve_encoder_
|
||||
step_encoder->curve_table[config->sample_points - i - 1].duration1 = symbol_duration;
|
||||
}
|
||||
}
|
||||
ESP_GOTO_ON_FALSE(curve_step > 0, ESP_ERR_INVALID_ARG, err, TAG, "|end_freq_hz - start_freq_hz| can't be smaller than sample_points");
|
||||
|
||||
step_encoder->sample_points = config->sample_points;
|
||||
step_encoder->flags.is_accel_curve = is_accel_curve;
|
||||
|
@@ -17,7 +17,7 @@ extern "C" {
|
||||
*/
|
||||
typedef struct {
|
||||
uint32_t resolution; // Encoder resolution, in Hz
|
||||
uint32_t sample_points; // Sample points used for deceleration phase
|
||||
uint32_t sample_points; // Sample points used for deceleration phase. Note: |end_freq_hz - start_freq_hz| >= sample_points
|
||||
uint32_t start_freq_hz; // Start frequency on the curve, in Hz
|
||||
uint32_t end_freq_hz; // End frequency on the curve, in Hz
|
||||
} stepper_motor_curve_encoder_config_t;
|
||||
|
Reference in New Issue
Block a user