|
|
@ -51,7 +51,7 @@ void IOClass::InitMotors() { |
|
|
|
ERROR_CHECK(mcpwm_gpio_init(MCPWM_UNIT, MCPWM1A, MOTOR_RIGHT_PWM)); |
|
|
|
ERROR_CHECK(mcpwm_gpio_init(MCPWM_UNIT, MCPWM1A, MOTOR_RIGHT_PWM)); |
|
|
|
|
|
|
|
|
|
|
|
mcpwm_config_t mcpwm_config; |
|
|
|
mcpwm_config_t mcpwm_config; |
|
|
|
mcpwm_config.frequency = 20000; // 20khz
|
|
|
|
mcpwm_config.frequency = 10000; // 20khz
|
|
|
|
mcpwm_config.cmpr_a = 0; |
|
|
|
mcpwm_config.cmpr_a = 0; |
|
|
|
mcpwm_config.cmpr_b = 0; |
|
|
|
mcpwm_config.cmpr_b = 0; |
|
|
|
mcpwm_config.counter_mode = MCPWM_UP_DOWN_COUNTER; // for symmetric pwm
|
|
|
|
mcpwm_config.counter_mode = MCPWM_UP_DOWN_COUNTER; // for symmetric pwm
|
|
|
@ -68,12 +68,12 @@ void IOClass::ReadInputs(Inputs &inputs) { |
|
|
|
void IOClass::WriteOutputs(const Outputs &outputs) { |
|
|
|
void IOClass::WriteOutputs(const Outputs &outputs) { |
|
|
|
esp_err_t ret; |
|
|
|
esp_err_t ret; |
|
|
|
ret = mcpwm_set_duty(MCPWM_UNIT, MCPWM_TIMER_0, MCPWM_OPR_A, |
|
|
|
ret = mcpwm_set_duty(MCPWM_UNIT, MCPWM_TIMER_0, MCPWM_OPR_A, |
|
|
|
fabsf(outputs.left_motor * 100.0)); |
|
|
|
fabsf(outputs.left_motor * 100.0f)); |
|
|
|
ERROR_CHECK(ret); |
|
|
|
ERROR_CHECK(ret); |
|
|
|
ret = mcpwm_start(MCPWM_UNIT, MCPWM_TIMER_0); |
|
|
|
ret = mcpwm_start(MCPWM_UNIT, MCPWM_TIMER_0); |
|
|
|
ERROR_CHECK(ret); |
|
|
|
ERROR_CHECK(ret); |
|
|
|
ret = mcpwm_set_duty(MCPWM_UNIT, MCPWM_TIMER_1, MCPWM_OPR_A, |
|
|
|
ret = mcpwm_set_duty(MCPWM_UNIT, MCPWM_TIMER_1, MCPWM_OPR_A, |
|
|
|
fabsf(outputs.right_motor * 100.0)); |
|
|
|
fabsf(outputs.right_motor * 100.0f)); |
|
|
|
ERROR_CHECK(ret); |
|
|
|
ERROR_CHECK(ret); |
|
|
|
ret = mcpwm_start(MCPWM_UNIT, MCPWM_TIMER_1); |
|
|
|
ret = mcpwm_start(MCPWM_UNIT, MCPWM_TIMER_1); |
|
|
|
ERROR_CHECK(ret); |
|
|
|
ERROR_CHECK(ret); |
|
|
|