/* Robot Controls Generate PWM signals to control motors. By: Alexander Bobkov Date: Dec 21, 2024 built-in LED GPIO: 10 build-in push button GPIO: 3 */ #include #include #include #include "freertos/FreeRTOS.h" #include "freertos/task.h" #include "freertos/queue.h" #include "driver/gpio.h" #include "driver/ledc.h" #include "driver/temperature_sensor.h" //#include "driver/mcpwm.h" #include "esp_log.h" #include "led_strip.h" #include "sdkconfig.h" /* ADC */ #include "rc.h" /* Motors Controls */ #include "motor_controls.h" /* System-wide controls */ #include "controls.h" #include "esp_adc/adc_continuous.h" /* ESP-NOW */ #include #include #include "freertos/semphr.h" #include "freertos/timers.h" #include "nvs_flash.h" #include "esp_random.h" #include "esp_event.h" #include "esp_log.h" #include "esp_crc.h" #include "esp_netif.h" #include "esp_now.h" #include "esp_mac.h" #include "esp_wifi.h" #include "esp_system.h" #include "espnow_config.h" #include "config.h" static const char *TAG = "ESP IDF Robot"; /* Use project configuration menu (idf.py menuconfig) to choose the GPIO to blink, or you can edit the following line and set a number here. */ // Retrieve values from configuration menu #define BLINK_GPIO CONFIG_BLINK_GPIO // 10 GPIO of on-board LED #define PUSH_BTN_GPIO CONFIG_BUTTON_GPIO // 3 GPIO of on-board push-button #define MTR_FL_GPIO 0 //CONFIG_MOTOR_FRONT_LEFT_GPIO // ADC #define ADC_ATTEN ADC_ATTEN_DB_11 #define ADC_BIT_WIDTH SOC_ADC_DIGI_MAX_BITWIDTH #define ADC_UNIT ADC_UNIT_1 #define ADC_CONV_MODE ADC_CONV_BOTH_UNIT// ADC_CONV_SINGLE_UNIT_1 #define ADC_OUTPUT_TYPE ADC_DIGI_OUTPUT_FORMAT_TYPE2 // ESP32C3 #define READ_LEN 1024//256 #define ADC_GET_CHANNEL(p_data) ((p_data)->type2.channel) #define ADC_GET_DATA(p_data) ((p_data)->type2.data) #define PROJ_X (1) // ADC1_CH1; 0 GPIO joystick, x-axis #define PROJ_Y (0) // ADC1_CH0; 1 GPIO joystick, y-axis #define NAV_BTN (8) // 8 GPIO joystick button #define _ADC_UNIT_STR(unit) #unit #define ADC_UNIT_STR(unit) _ADC_UNIT_STR(unit) uint32_t x_avg = 0, y_avg = 0; static TaskHandle_t led_task_handle; static TaskHandle_t s_task_handle; static TaskHandle_t m_task_handle; // Task for controlling motors PWMs static adc_channel_t channel[2] = {ADC_CHANNEL_0, ADC_CHANNEL_1}; static sensors_data_t buf; #define ESP_INTR_FLAG_DEFAULT 0 #define GPIO_INPUT_PIN_SEL ((1ULL<