Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

arch: refactor the espFoC on top of the Zephyr RTOS #10

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 1 addition & 38 deletions .github/workflows/espfoc_flow.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: Build
on: push
jobs:
build:
name: Test compiling
name: Test compiling
runs-on: ubuntu-latest
steps:
- name: Checkout
Expand Down Expand Up @@ -45,40 +45,3 @@ jobs:
path: idf
submodules: recursive
ref: master

- name: Build Samples
run: |
./idf/install.sh
. ./idf/export.sh
pushd examples/simple_velocity
idf.py set-target esp32
idf.py build
popd
pushd examples/simple_motor_tester
idf.py set-target esp32
idf.py build
popd
pushd examples/simple_servo
idf.py set-target esp32
idf.py build
popd
pushd examples/speed_control
idf.py set-target esp32
idf.py build
popd
pushd examples/simple_velocity
idf.py set-target esp32s3
idf.py build
popd
pushd examples/simple_motor_tester
idf.py set-target esp32s3
idf.py build
popd
pushd examples/simple_servo
idf.py set-target esp32s3
idf.py build
popd
pushd examples/speed_control
idf.py set-target esp32s3
idf.py build
popd
3 changes: 0 additions & 3 deletions .gitmodules

This file was deleted.

15 changes: 0 additions & 15 deletions CMakeLists.txt

This file was deleted.

45 changes: 0 additions & 45 deletions Kconfig

This file was deleted.

2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
The MIT License (MIT)
=====================

Copyright © `2021` `Felipe Neves`
Copyright © `2023` `Felipe Neves`

Permission is hereby granted, free of charge, to any person
obtaining a copy of this software and associated documentation
Expand Down
59 changes: 34 additions & 25 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,45 +1,54 @@
# espFoC: Vector FoC controller for PMSM motors for ESP-IDF
# espFoC: Vector FoC controller for PMSM motors for ESP32 SoCs

![Build](https://github.com/uLipe/espFoC/workflows/Build/badge.svg)
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)

espFoC is a simple implementation of voltage mode, vector controller intended to be used with permanent-magnet synchronous motors (PMSM), and general brushless motors. This component was developed to be used with the ESP-IDF
espressif framework.
espFoC is a simple implementation of voltage mode, vector controller intended to be used with permanent-magnet synchronous motors (PMSM), and general brushless motors for ESP32S3 Espressif SoC, other SoC from espressif might be supported but the primary requirement is to be a dual
core variant. espFoC started as a library for motor control, but it suffered a goal change, and now it is intended to create a programmable
BLDC (FoC based) motor control-IC, the dual core capabillity splits the controller into application side and motor control core side
the former is intended for user to write it own application or exchange packets with external controller via CAN-Bus, the later is
100% focused on perform motor control algorithm achieving better control bandwidth. Up two axis are supported in this new variant, refer the
simplified architecture below:
![espFoC Simplified Architecture](/doc/images/arch.png)

## Features:

* Voltage mode control, control a PMSM like a DC motor!;
* Position and Speed closed-loop control;
* Single-precision Floating point implementation;
* Sample inverter driver based on esp32 LEDC PWM (easy to wire!);
* Sample rotor position driver based on as5600 encoder (very popular!);
* FoC engine runs sychronized at inverter PWM rate;
* Scope function for debugging using Better Serial Plot
* Easy to wire motor using common drivers and I2C encoders out there!
* Uses ESP32 AMP solution for Zephyr RTOS to split execution;
* App CPU runs the motor control firmware;
* Pro CPU runs communication and exposes a thread for user application;
* Interaction between the firmwares are doing by a custom IPC protocol;
* Planned support for UART and CAN communication;

## Limitations:
* Support for esp32 and esp32s3 only;
* Requires and rotor position sensor, for example, incremental encoder.

* Support only for espressif SoC that are dual-core and have FPU;
* Once sensored support, requires an I2C magnetic encoder sensor.

## Getting started:
* Just clone this project on most convenient folder;
* Inside of your IDF project CMakeLists.txt set or add the path of this component to EXTRA_COMPONENT_DIRS for example: `set(EXTRA_COMPONENT_DIRS "path/to/this/component/")`
* For batteries included getting started, refer the examples folder.
* Inside of any of examples just build: `$ idf.py build flash`


* Just clone this project on most convenient folder then:

```
$ west build -palways -besp32s3_devkitm/esp32s3/procpu --sysbuild /path/to/espFoC/app
```

* To flash:
```
$ west flash
```

## Typical wiring:

* espFoC is intended to run on ESP32 board plus a motor driver;
* The current driver supports 3-PWM output suited to: L6230, DRV83xx and others;
* The suggested wiring for quick get started is shown below:
* The suggested wiring for quick get started is shown below:
![Wiring](/doc/images/wiring.png)


## Debug with Better Serial Plot:
* Install Better Serial Plot from here: https://hackaday.io/project/181686-better-serial-plotter
* In menuconfing enable the option: `CONFIG_ESP_FOC_SCOPE`
* Download the firmware for your target board;
* Open the Better Serial Port and select the port and baud rate of your board;
* The data should arrive automatically.

## Support:

If you find some trouble, open an issue, and if you are enjoying the project
give it a star or submir a PR. Also, you can try reaching me at:
[email protected]
give it a star or submir a PR. Also, you can try reaching me at:
21 changes: 21 additions & 0 deletions app/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# SPDX-License-Identifier: Apache-2.0

cmake_minimum_required(VERSION 3.20.0)

set(REMOTE_ZEPHYR_DIR ${CMAKE_CURRENT_BINARY_DIR}/../espfoc_motor_remote/zephyr)

find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
project(espfoc_app)

set(MOTOR_CONTROL_SRC ${APPLICATION_SOURCE_DIR}/../common)
set(MOTOR_CONTROL_INC ${APPLICATION_SOURCE_DIR}/../common/include)

FILE(GLOB ipc ${MOTOR_CONTROL_SRC}/ipc/*.c)
target_sources(app PRIVATE espfoc_app/esp_foc_app_shell.c
espfoc_app/esp_foc_main.c
espfoc_app/esp_foc_user.c
espfoc_app/esp_foc_motor_control_firmware_pilot.c
${ipc})

target_include_directories(app PRIVATE ${MOTOR_CONTROL_INC})

7 changes: 7 additions & 0 deletions app/Kconfig.sysbuild
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
source "share/sysbuild/Kconfig"

config ESP_FOC_REMOTE_BOARD
string
default "esp32_devkitc_wrover/esp32/appcpu" if $(BOARD) = "esp32_devkitc_wroom"
default "esp32_devkitc_wroom/esp32/appcpu" if $(BOARD) = "esp32_devkitc_wroom"
default "esp32s3_devkitm/esp32s3/appcpu" if $(BOARD) = "esp32s3_devkitm"
97 changes: 97 additions & 0 deletions app/boards/esp32s3_devkitm_procpu.overlay
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
/*
* Copyright (c) 2023 Felipe Neves <[email protected]>
*
* SPDX-License-Identifier: Apache-2.0
*/

#include <zephyr/dt-bindings/pwm/pwm.h>

/ {
chosen {
zephyr,console = &uart0;
zephyr,shell-uart = &uart0;
/*
* shared memory reserved for the inter-processor communication
*/
zephyr,ipc_shm = &shm0;
zephyr,ipc = &ipm0;
};
};

&pinctrl {
ledc0_default: ledc0_default {
group1 {
pinmux = <LEDC_CH0_GPIO0>,
<LEDC_CH1_GPIO1>,
<LEDC_CH2_GPIO2>;
output-enable;
};
};
};

&ipm0 {
status = "okay";
};

&timer0 {
status = "okay";
};

&timer1 {
status = "okay";
};

&timer2 {
status = "okay";
};

&timer3 {
status = "okay";
};

&i2c0 {
clock-frequency = <I2C_BITRATE_FAST>;
pinctrl-0 = <&i2c0_default>;
pinctrl-names = "default";
status = "okay";

angle_sensor0: as5600@36 {
compatible = "ams,as5600";
status = "okay";
reg = <0x36>;
};
};

&i2c1 {
clock-frequency = <I2C_BITRATE_FAST>;
pinctrl-0 = <&i2c1_default>;
pinctrl-names = "default";
status = "okay";

angle_sensor1: as5600@36 {
compatible = "ams,as5600";
status = "okay";
reg = <0x36>;
};
};

&ledc0 {
pinctrl-0 = <&ledc0_default>;
pinctrl-names = "default";
status = "okay";

#address-cells = <1>;
#size-cells = <0>;
channel0@0 {
reg = <0x0>;
timer = <0>;
};
channel1@1 {
reg = <0x1>;
timer = <0>;
};
channel2@2 {
reg = <0x2>;
timer = <1>;
};
};
Loading
Loading