uploaded 4 months ago
Espressif's additions to SimpleFOC

readme

[![Component Registry](https://components.espressif.com/components/espressif/esp_simplefoc/badge.svg)](https://components.espressif.com/components/espressif/esp_simplefoc)

## ESP-IDF SimpleFOC Component
 
Features:

1. Support voltage control.
2. Support Host computer control.
3. Support multiple motor control, up to 4, support manual selection of the drive mode or by the system.
4. Compatible with SimpleFOC examples.
5. Use IQMath to greatly accelerate Foc operations.


### Usage Considerations
1. The configTICK_RATE_HZ of Freertos must be set to 1000. If it is not set, a motor exception may occur.

### License
esp_simplefoc is licensed under the Apache License, see license.txt for more information.

changelog

# ChangeLog

## v0.1.1 - 2023-12-4
### Enhancements:
* FOC:
    * Change angle sensor driver with c++.

## v0.1.0 - 2023-11-4
### Enhancements:
* FOC:
    * Support chip whitch without mcpwm driver.

## V0.0.3 - 2023-8-16
### Enhancements:
* FOC:
    * Fix int type to uart_port_t type conversion.

## V0.0.2 - 2023-7-13
### Enhancements:
* FOC:
    * Remove the arduino-foc submodule and replace it with a component dependency.
    * Modify the Driver class of Arduino-FOC to support manual selection of pwm driver mode. If no PWM driver mode is specified, the system automatically applies for PWM driver.
    * Synchronize changes to test_apps.

## V0.0.1 - 2023-6-27
### Enhancements:
* FOC:
    * Add ESP-IDF driver for Arduino-FOC.
    * Fix mcpwm driver for esp-simplefoc.
    * Compatible with SimpleFOC Studio host computer.


readme of foc_openloop_control example

                                        
                                        # Application example of ESP SIMPLEFOC openloop speed control

This example demonstrates how to develop a motor openloop speed control program using the `esp_simplefoc` component on a series of ESP32 chips. 
The specific functions of the demonstration are as follows:

- Openloop control of motor speed

## How to use the example

### Hardware requirement

1. Hardware connection:
    * for ESP32-S3 chips, the serial port is connected to the default RXD0 and TXD0. If you need to use other serial ports, you need to modify the corresponding uart_num, RXD and TXD in the initialization part of the serial port. 
    * the sample motor has a pole pair of 14 and a rated voltage of 12V.
    * the example MOS predrive uses EG2133, and connects LIN with HIN, using 3PWM driver.
    * the example hardware schematic: [single bldc](https://dl.espressif.com/AE/esp-iot-solution/docs/foc_hardware_single_bldc.pdf)
    > debugging parameters need to be modified for different types of motors and hardware. **make sure to debug under the correct parameters and beware of anomalies.**

### Compile and write

1. Enter the `foc_openloop_control` directory:

    ```linux
    cd ./esp-iot-solution/examples/motor/foc_openloop_control
    ```

2. Use the `idf.py` tool to set the compiler chip, and then compile and download it. The instructions are:

    ```linux
    # Set compiler chip
    idf.py idf.py set-target esp32s3

    # Compile and download
    idf.py -p PORT build flash
    ```

    Please replace `PORT` with the port number currently in use

### Example output

The following is the openloop control log:

```log
I (27) boot: ESP-IDF v5.2-dev-1113-g28c643a56d 2nd stage bootloader
I (27) boot: compile time Jul 19 2023 11:12:44
I (28) boot: Multicore bootloader
I (32) boot: chip revision: v0.1
I (36) boot.esp32s3: Boot SPI Speed : 80MHz
I (40) boot.esp32s3: SPI Mode       : DIO
I (45) boot.esp32s3: SPI Flash Size : 2MB
I (50) boot: Enabling RNG early entropy source...
I (55) boot: Partition Table:
I (59) boot: ## Label            Usage          Type ST Offset   Length
I (66) boot:  0 nvs              WiFi data        01 02 00009000 00006000
I (74) boot:  1 phy_init         RF data          01 01 0000f000 00001000
I (81) boot:  2 factory          factory app      00 00 00010000 00100000
I (88) boot: End of partition table
I (93) esp_image: segment 0: paddr=00010020 vaddr=3c030020 size=0f220h ( 61984) map
I (112) esp_image: segment 1: paddr=0001f248 vaddr=3fc92700 size=00dd0h (  3536) load
I (113) esp_image: segment 2: paddr=00020020 vaddr=42000020 size=21428h (136232) map
I (142) esp_image: segment 3: paddr=00041450 vaddr=3fc934d0 size=01bdch (  7132) load
I (144) esp_image: segment 4: paddr=00043034 vaddr=40374000 size=0e690h ( 59024) load
I (167) boot: Loaded app from partition at offset 0x10000
I (167) boot: Disabling RNG early entropy source...
I (179) cpu_start: Multicore app
I (179) cpu_start: Pro cpu up.
I (179) cpu_start: Starting app cpu, entry point is 0x403752ac
0x403752ac: call_start_cpu1 at /home/yanke/esp/esp-idf/components/esp_system/port/cpu_start.c:154

I (0) cpu_start: App cpu up.
I (197) cpu_start: Pro cpu start user code
I (197) cpu_start: cpu freq: 240000000 Hz
I (197) cpu_start: Application information:
I (200) cpu_start: Project name:     foc_openloop_control
I (207) cpu_start: App version:      d580537b
I (212) cpu_start: Compile time:     Jul 19 2023 11:12:38
I (218) cpu_start: ELF file SHA256:  4515fda00...
I (223) cpu_start: ESP-IDF:          v5.2-dev-1113-g28c643a56d
I (230) cpu_start: Min chip rev:     v0.0
I (234) cpu_start: Max chip rev:     v0.99 
I (239) cpu_start: Chip rev:         v0.1
I (244) heap_init: Initializing. RAM available for dynamic allocation:
I (251) heap_init: At 3FC961C8 len 00053548 (333 KiB): DRAM
I (257) heap_init: At 3FCE9710 len 00005724 (21 KiB): STACK/DRAM
I (264) heap_init: At 3FCF0000 len 00008000 (32 KiB): DRAM
I (270) heap_init: At 600FE010 len 00001FD8 (7 KiB): RTCRAM
I (277) spi_flash: detected chip: gd
I (281) spi_flash: flash io: dio
W (284) spi_flash: Detected size(16384k) larger than the size in the binary image header(2048k). Using the size in the binary image header.
I (298) sleep: Configure to isolate all GPIO pins in sleep state
I (305) sleep: Enable automatic switching of GPIO sleep configuration
I (312) app_start: Starting scheduler on CPU0
I (317) app_start: Start)�I (331) gpio: GPIO[17]| InputEn: 0| OutputEn: 1| OpenDrain: 0| Pullup: 0| Pulldown: 0| Intr:0 
I (332) gpio: GPIO[16]| InputEn: 0| OutputEn: 1| OpenDrain: 0| Pullup: 0| Pulldown: 0| Intr:0 
I (339) gpio: GPIO[15]| InputEn: 0| OutputEn: 1| OpenDrain: 0| Pullup: 0| Pulldown: 0| Intr:0 
MCPWM Group: 0 is idle
Auto. Current Driver uses Mcpwm GroupId:0
I (354) gpio: GPIO[17]| InputEn: 0| OutputEn: 1| OpenDrain: 0| Pullup: 1| Pulldown: 0| Intr:0 
I (363) gpio: GPIO[16]| InputEn: 0| OutputEn: 1| OpenDrain: 0| Pullup: 1| Pulldown: 0| Intr:0 
I (373) gpio: GPIO[15]| InputEn: 0| OutputEn: 1| OpenDrain: 0| Pullup: 1| Pulldown: 0| Intr:0 
MOT: Init
MOT: Enable driver.
```
                                    

readme of foc_velocity_control example

                                        
                                        # Application example of ESP SIMPLEFOC Speed Control

This example demonstrates how to develop a motor speed control program using the `esp_ speed control component on an ESP32 series chip. 
The specific functions of the demonstration are as follows: 

- Motor speed closed loop. 
- Serial port instruction to control motor speed

## How to use the example

### Hardware requirement

1. Hardware connection:
    * for ESP32-S3 chips, the serial port is connected to the default RXD0 and TXD0. If you need to use other serial ports, you need to modify the corresponding uart_num, RXD and TXD in the initialization part of the serial port. 
    * the sample motor has a pole pair of 14 and a rated voltage of 12V.
    * the example MOS predrive uses EG2133, and connects LIN with HIN, using 3PWM driver.
    * the example angle sensor uses AS5600. If you use other angle sensors, you need to manually enter the initialization and angle reading functions into GenericSensor.
    * the example hardware schematic: [single bldc](https://dl.espressif.com/AE/esp-iot-solution/docs/foc_hardware_single_bldc.pdf)
    > debugging parameters need to be modified for different types of motors and hardware. **make sure to debug under the correct parameters and beware of anomalies.**

### Compile and write

1. Enter the `foc_velocity_ control` directory:

    ```linux
    cd ./esp-iot-solution/examples/motor/foc_velocity_control
    ```

2. Use the `idf.py` tool to set the compiler chip, and then compile and download it. The instructions are:

    ```linux
    # Set compiler chip
    idf.py idf.py set-target esp32s3

    # Compile and download
    idf.py -p PORT build flash
    ```

    Please replace `PORT` with the port number currently in use

### Example output

The following is the speed control log:

```log
 Usage          Type ST Offset   Length
I (66) boot:  0 nvs              WiFi data        01 02 00009000 00006000
I (74) boot:  1 phy_init         RF data          01 01 0000f000 00001000
I (81) boot:  2 factory          factory app      00 00 00010000 00100000
I (88) boot: End of partition table
I (93) esp_image: segment 0: paddr=00010020 vaddr=3c030020 size=0fc00h ( 64512) map
I (113) esp_image: segment 1: paddr=0001fc28 vaddr=3fc92f00 size=003f0h (  1008) load
I (113) esp_image: segment 2: paddr=00020020 vaddr=42000020 size=24d48h (150856) map
I (145) esp_image: segment 3: paddr=00044d70 vaddr=3fc932f0 size=025dch (  9692) load
I (148) esp_image: segment 4: paddr=00047354 vaddr=40374000 size=0ee18h ( 60952) load
I (171) boot: Loaded app from partition at offset 0x10000
I (171) boot: Disabling RNG early entropy source...
I (182) cpu_start: Multicore app
I (183) cpu_start: Pro cpu up.
I (183) cpu_start: Starting app cpu, entry point is 0x403752d4
I (0) cpu_start: App cpu up.
I (201) cpu_start: Pro cpu start user code
I (201) cpu_start: cpu freq: 240000000 Hz
I (201) cpu_start: Application information:
I (204) cpu_start: Project name:     foc_example
I (209) cpu_start: App version:      d580537b
I (214) cpu_start: Compile time:     Jul 19 2023 10:20:23
I (221) cpu_start: ELF file SHA256:  686b47738...
I (226) cpu_start: ESP-IDF:          v5.2-dev-1113-g28c643a56d
I (232) cpu_start: Min chip rev:     v0.0
I (237) cpu_start: Max chip rev:     v0.99 
I (242) cpu_start: Chip rev:         v0.1
I (247) heap_init: Initializing. RAM available for dynamic allocation:
I (254) heap_init: At 3FC96AF8 len 00052C18 (331 KiB): DRAM
I (260) heap_init: At 3FCE9710 len 00005724 (21 KiB): STACK/DRAM
I (267) heap_init: At 3FCF0000 len 00008000 (32 KiB): DRAM
I (273) heap_init: At 600FE010 len 00001FD8 (7 KiB): RTCRAM
I (280) spi_flash: detected chip: gd
I (283) spi_flash: flash io: dio
W (287) spi_flash: Detected size(16384k) larger than the size in the binary image header(2048k). Using the size in the binary image header.
I (301) sleep: Configure to isolate all GPIO pins in sleep state
I (307) sleep: Enable automatic switching of GPIO sleep configuration
I (315) app_start: Starting scheduler on CPU0
I (319) app_start: StartY�I (345) gpio: GPIO[17]| InputEn: 0| OutputEn: 1| OpenDrain: 0| Pullup: 0| Pulldown: 0| Intr:0 
I (345) gpio: GPIO[16]| InputEn: 0| OutputEn: 1| OpenDrain: 0| Pullup: 0| Pulldown: 0| Intr:0 
I (352) gpio: GPIO[15]| InputEn: 0| OutputEn: 1| OpenDrain: 0| Pullup: 0| Pulldown: 0| Intr:0 
MCPWM Group: 0 is idle
Auto. Current Driver uses Mcpwm GroupId:0
I (368) gpio: GPIO[17]| InputEn: 0| OutputEn: 1| OpenDrain: 0| Pullup: 1| Pulldown: 0| Intr:0 
I (377) gpio: GPIO[16]| InputEn: 0| OutputEn: 1| OpenDrain: 0| Pullup: 1| Pulldown: 0| Intr:0 
I (386) gpio: GPIO[15]| InputEn: 0| OutputEn: 1| OpenDrain: 0| Pullup: 1| Pulldown: 0| Intr:0 
MOT: Monitor enabled!
MOT: Init
MOT: Enable driver.
MOT: Align sensor.
MOT: sensor_direction==CW
MOT: PP check: OK!
MOT: Zero elec. angle: 4.49
MOT: No current sense.
MOT: Ready.

T2.0
2.000
```
                                    

Links

License: Apache-2.0

To add this component to your project, run:

idf.py add-dependency "espressif/esp_simplefoc^0.1.1"

or download archive

Dependencies

  • espressif/arduino-foc >=2.3.0~3
  • espressif/iqmath ^1.11.0
  • ESP-IDF >=5.0
  • Examples:

    foc_openloop_control

    more details

    To create a project from this example, run:

    idf.py create-project-from-example "espressif/esp_simplefoc^0.1.1:foc_openloop_control"

    or download archive

    foc_velocity_control

    more details

    To create a project from this example, run:

    idf.py create-project-from-example "espressif/esp_simplefoc^0.1.1:foc_velocity_control"

    or download archive

    Stats

    • Downloaded in total
      Downloaded in total 67 times
    • Downloaded this version
      This version: 49 times

    Badge

    espressif/esp_simplefoc version: 0.1.1
    |