From 6d731dd9d2fde2bd5d74cb111b5576eb159066ac Mon Sep 17 00:00:00 2001 From: Alexander B Date: Wed, 25 Jun 2025 02:41:28 -0400 Subject: [PATCH] adc --- ESP-IDF_Robot/main/rc.h | 44 ++++++++++++++++++++++++++++++++++++++++- 1 file changed, 43 insertions(+), 1 deletion(-) diff --git a/ESP-IDF_Robot/main/rc.h b/ESP-IDF_Robot/main/rc.h index 292613400..3a0be5f8b 100644 --- a/ESP-IDF_Robot/main/rc.h +++ b/ESP-IDF_Robot/main/rc.h @@ -70,7 +70,7 @@ static int check_motor_pcm(int x) { // Update PWM based on received values static void update_pwm (int rc_x, int rc_y) { - + //m.motor1_rpm_pcm = check_motor_pcm(rescale_raw_val(x)); x = check_motor_pcm(rescale_raw_val(rc_x)); y = check_motor_pcm(rescale_raw_val(rc_y)); @@ -130,6 +130,48 @@ static void update_pwm (int rc_x, int rc_y) { m.motor3_rpm_pcm = 0; m.motor4_rpm_pcm = 0; }*/ + if ((x > 0) && (y > 0 && y < 500)) { + //ESP_LOGW("ESP-NOW", "FORWARD"); + // Both sides rotate in forward direction. + m.motor1_rpm_pcm = x; // left, forward + m.motor2_rpm_pcm = x; // right, forward + m.motor3_rpm_pcm = 0; + m.motor4_rpm_pcm = 0; + } + else if ((x < 0) && (y > 0 && y < 500)) { + //else if ((x > 0 && x < 500) && (y < -200)) { + //ESP_LOGW("ESP-NOW", "REVERSE"); + // Both sides rotate in reverse direction. + m.motor1_rpm_pcm = 0; + m.motor2_rpm_pcm = 0; + m.motor3_rpm_pcm = -x; + m.motor4_rpm_pcm = -x; + } + else if ((x > 0 && x < 500) && (y < 200)) { + //else if ((y < 0 && y > -200) && (x < -1000)) { + //ESP_LOGW("ESP-NOW", "LEFT"); + // Left side rotates in forward direction, right side rotates in reverse direction. + m.motor1_rpm_pcm = -y; + m.motor2_rpm_pcm = 0; + m.motor3_rpm_pcm = -y; + m.motor4_rpm_pcm = 0; + } + else if ((x > 0 && x < 500) && (y > 600)) { + //else if ((y < 0 && y > -200) && (x > 1000)) { + //ESP_LOGW("ESP-NOW", "RIGHT"); + // Right side rotates in forward direction, left side rotates in reverse direction. + m.motor1_rpm_pcm = 0; + m.motor2_rpm_pcm = y; + m.motor3_rpm_pcm = 0; + m.motor4_rpm_pcm = y; + } + else { + //ESP_LOGW("ESP-NOW", "STAND STILL"); + m.motor1_rpm_pcm = 0; + m.motor2_rpm_pcm = 0; + m.motor3_rpm_pcm = 0; + m.motor4_rpm_pcm = 0; + } ledc_set_duty(MTR_MODE, MTR_FRONT_LEFT, m.motor1_rpm_pcm); ledc_update_duty(MTR_MODE, MTR_FRONT_LEFT); ledc_set_duty(MTR_MODE, MTR_FRONT_RIGHT, m.motor2_rpm_pcm);