diff --git a/main/Kconfig.projbuild b/main/Kconfig.projbuild index c54c4d2..270e9a3 100644 --- a/main/Kconfig.projbuild +++ b/main/Kconfig.projbuild @@ -1,19 +1,33 @@ menu "Example Configuration" - choice EXAMPLE_HARDWARE - prompt "Hardware" - default EXAMPLE_HARDWARE_MOTORGO_MINI - help - Select the hardware to run this example on. + choice EXAMPLE_HARDWARE + prompt "Hardware" + default EXAMPLE_HARDWARE_MOTORGO_MINI + help + Select the hardware to run this example on. - config EXAMPLE_HARDWARE_MOTORGO_MINI - depends on IDF_TARGET_ESP32S3 - bool "MotorGo Mini" + config EXAMPLE_HARDWARE_MOTORGO_MINI + depends on IDF_TARGET_ESP32S3 + bool "MotorGo Mini" - config EXAMPLE_HARDWARE_TEST_STAND - depends on IDF_TARGET_ESP32S3 - bool "BLDC Motor Test Stand (TinyS3)" + config EXAMPLE_HARDWARE_TEST_STAND + depends on IDF_TARGET_ESP32S3 + bool "BLDC Motor Test Stand (TinyS3)" - endchoice + endchoice + + choice EXAMPLE_BLDC_MOTOR + prompt "Which BLDC motor to control" + default EXAMPLE_BLDC_MOTOR_1 + depends on EXAMPLE_HARDWARE_MOTORGO_MINI + help + Select the BLDC motor to control. This is only used for the MotorGo Mini hardware, which has two motors. + + config EXAMPLE_BLDC_MOTOR_1 + bool "Motor 1" + config EXAMPLE_BLDC_MOTOR_2 + bool "Motor 2" + + endchoice endmenu diff --git a/main/main.cpp b/main/main.cpp index 0978a84..d576497 100644 --- a/main/main.cpp +++ b/main/main.cpp @@ -19,9 +19,38 @@ extern "C" void app_main(void) { logger.info("Using MotorGo Mini hardware configuration"); // we don't want to init both motors, so we'll pass in auto_init=false auto &motorgo_mini = espp::MotorGoMini::get(); - auto motor1_config = motorgo_mini.default_motor1_config; - motorgo_mini.init_motor_channel_1(motor1_config); + +#if CONFIG_EXAMPLE_BLDC_MOTOR_1 +#pragma message("Using MotorGo Mini Motor 1") + logger.info("Configuring Motor 1"); + auto motor_config = motorgo_mini.default_motor1_config; +#elif CONFIG_EXAMPLE_BLDC_MOTOR_2 +#pragma message("Using MotorGo Mini Motor 2") + logger.info("Configuring Motor 2"); + auto motor_config = motorgo_mini.default_motor2_config; +#else +#error "No motor selected" +#endif + + // velocity PID config: + motor_config.velocity_pid_config.kp = 0.010f; + motor_config.velocity_pid_config.ki = 0.100f; + motor_config.velocity_pid_config.kd = 0.000f; + // angle PID config: + motor_config.angle_pid_config.kp = 5.000f; + motor_config.angle_pid_config.ki = 1.000f; + motor_config.angle_pid_config.kd = 0.000f; + +#if CONFIG_EXAMPLE_BLDC_MOTOR_1 + motorgo_mini.init_motor_channel_1(motor_config); auto motor = motorgo_mini.motor1(); +#elif CONFIG_EXAMPLE_BLDC_MOTOR_2 + motorgo_mini.init_motor_channel_2(motor_config); + auto motor = motorgo_mini.motor2(); +#else +#error "No motor selected" +#endif + using BldcHaptics = espp::BldcHaptics; #elif CONFIG_EXAMPLE_HARDWARE_TEST_STAND #pragma message("Using TinyS3 Test Stand hardware configuration")