ESP-IDF 配置 SimpleFOC 项目

创建 ESP-IDF 项目
使用VSCode创建第一个ESP-IDF项目_vscode串口监视器在哪-CSDN博客

idf.py create-project motor_test

进入项目文件夹

cd motor_test

设置 freertos 时钟频率

创建项目后执行 idf.py menuconfig设置(Top) → Component config → FreeRTOS → Kernel (100) configTICK_RATE_HZ1000 (为了使用 arduino 组件)

添加 arduino-esp32 到 components

使用命令进行安装

idf.py add-dependency "espressif/arduino-esp32^3.0.2"

或者手动进行安装

a. 下载 arduino-esp32 ,需要注意 esp-idf 和 arduino-esp32 的版本对照关系
b. 在项目根目录创建 components 文件夹

mkdir -p components
cd components

c. 将下载的 arduino-esp32 放到components 文件夹后,执行 idf.py menuconfig更新设置。

添加 SimpleFOC 组件

idf.py add-dependency "espressif/esp_simplefoc"

执行 idf.py menuconfig更新设置。

修改项目为可执行 C++ 代码

a. 修改源文件为 .cpp 后缀(motor_test.cpp),并修改源码为导出 C 接口

#include <stdio.h>
#include <stdlib.h>
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "esp_simplefoc.h"
#include "driver/gpio.h"

#if CONFIG_SOC_MCPWM_SUPPORTED
#define USING_MCPWM
#endif

#define PWMA_GPIO GPIO_NUM_5
#define PWMB_GPIO GPIO_NUM_18
#define PWMC_GPIO GPIO_NUM_19
#define ENABLE_GPIO GPIO_NUM_21

BLDCMotor motor = BLDCMotor(7);
BLDCDriver3PWM driver = BLDCDriver3PWM(PWMA_GPIO, PWMB_GPIO, PWMC_GPIO, ENABLE_GPIO);

// 目标变量
float target_velocity = 0.5;

// 串口指令设置
Commander command = Commander(Serial);
void doTarget(char *cmd)
{
   
    command.scalar(&target_velocity, cmd);
}

extern "C" void app_main(void)
{
   
    Serial.begin(115200);

    driver.voltage_power_supply = 9;
    driver.init();

    motor.linkDriver(&driver);
    motor.voltage_limit = 9;   // [V]
    motor.velocity_limit = 30; // [rad/s]

    // 开环控制
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值