Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
3522aef
feat(bldc_haptics): initial bldc_haptics component
finger563 May 25, 2023
04aa8ab
feat(bldc_haptics): remove empty src
finger563 May 25, 2023
e6ee866
feat(pid): udpate API
finger563 May 26, 2023
1c18925
chore(math): add maybe_unused to suppress compiler warning
finger563 May 26, 2023
ae25fb9
doc: update
finger563 May 26, 2023
f66034f
ci: update
finger563 May 26, 2023
f47e192
removed unneeded file
finger563 May 26, 2023
208ddcf
feat(bldc_driver): add fault
finger563 May 27, 2023
a76c066
feat(bldc_motor): update example
finger563 May 27, 2023
cdd3bd9
example(bldc_motor): update to use logger
finger563 May 27, 2023
550a203
example(bldc_haptics): update
finger563 May 27, 2023
dde3d42
feat(bldc_haptics): allow pid config
finger563 May 29, 2023
abfe080
feat(bldc_motor): refactor types
finger563 May 31, 2023
59e8acf
feat(bldc_haptics): updated interface
finger563 May 31, 2023
4ec09be
doc(rtsp): update
finger563 May 31, 2023
a56542a
doc(ftp): update
finger563 May 31, 2023
65f3ff7
feat(bldc_haptics): updated haptics
finger563 Jun 1, 2023
d5f41ca
doc
finger563 Jun 1, 2023
671d80f
doc: update
finger563 Jun 1, 2023
682ca04
doc: rebuild
finger563 Jun 1, 2023
e162a78
feat(haptics): update api
finger563 Jun 2, 2023
b52a513
example(haptics): update
finger563 Jun 2, 2023
114392e
update to use new logger
finger563 Jun 2, 2023
1e1d2c3
merge main
finger563 Jun 2, 2023
a874795
feat(bldc_motor): accept 0 targets in the move() command
finger563 Jun 2, 2023
58c45bb
feat(bldc_haptics): better behavior
finger563 Jun 2, 2023
ffaaad5
feat(bldc_motor): minor update
finger563 Jun 3, 2023
b71ab12
feat(bldc_haptics): working haptics example
finger563 Jun 3, 2023
8fb55f1
doc: rebuild
finger563 Jun 3, 2023
886d5e3
feat(bldc_haptics): update example
finger563 Jun 3, 2023
e3beb88
doc: rebuild
finger563 Jun 3, 2023
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
2 changes: 2 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ jobs:
target: esp32s3
- path: 'components/aw9523/example'
target: esp32
- path: 'components/bldc_haptics/example'
target: esp32s3
- path: 'components/bldc_motor/example'
target: esp32s3
- path: 'components/controller/example'
Expand Down
47 changes: 45 additions & 2 deletions components/bldc_driver/include/bldc_driver.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ class BldcDriver {
int gpio_c_h; /**< Phase C high side gpio. */
int gpio_c_l; /**< Phase C low side gpio. */
int gpio_enable{-1}; /**< Enable pin for the BLDC driver (if any). */
int gpio_fault{-1}; /**< Fault pin for the BLDC driver (if any). */
float power_supply_voltage; /**< Voltage of the power supply. */
float limit_voltage{-1}; /**< What voltage the motor should be limited to. Less than 0 means no
limit. Will be clamped to power supply voltage. */
Expand All @@ -50,7 +51,7 @@ class BldcDriver {
: gpio_ah_((gpio_num_t)config.gpio_a_h), gpio_al_((gpio_num_t)config.gpio_a_l),
gpio_bh_((gpio_num_t)config.gpio_b_h), gpio_bl_((gpio_num_t)config.gpio_b_l),
gpio_ch_((gpio_num_t)config.gpio_c_h), gpio_cl_((gpio_num_t)config.gpio_c_l),
gpio_en_(config.gpio_enable), dead_zone_(config.dead_zone),
gpio_en_(config.gpio_enable), gpio_fault_(config.gpio_fault), dead_zone_(config.dead_zone),
logger_({.tag = "BLDC Driver", .level = config.log_level}) {
configure_power(config.power_supply_voltage, config.limit_voltage);
init(config);
Expand Down Expand Up @@ -87,8 +88,30 @@ class BldcDriver {
// set force level to 0 (gate off), and hold it
mcpwm_generator_set_force_level(g, 0, true);
}
gpio_set_level((gpio_num_t)gpio_en_, 0);
enabled_ = false;
std::lock_guard<std::mutex> lock(en_mutex_);
if (gpio_en_ >= 0) {
gpio_set_level((gpio_num_t)gpio_en_, 0);
}
}

/**
* @brief Check if the driver is enabled.
* @return True if the driver is enabled, false otherwise.
*/
bool is_enabled() const { return enabled_; }

/**
* @brief Check if the driver is faulted.
* @note If no fault pin was provided, this will always return false.
* @return True if the driver is faulted, false otherwise.
*/
bool is_faulted() {
std::lock_guard<std::mutex> lock(fault_mutex_);
if (gpio_fault_ < 0) {
return false;
}
return gpio_get_level((gpio_num_t)gpio_fault_) == 1;
}

/**
Expand Down Expand Up @@ -195,6 +218,7 @@ class BldcDriver {
protected:
void init(const Config &config) {
configure_enable_gpio();
configure_fault_gpio();
configure_timer();
configure_operators();
configure_comparators();
Expand All @@ -208,6 +232,7 @@ class BldcDriver {
}

void configure_enable_gpio() {
std::lock_guard<std::mutex> lock(en_mutex_);
if (gpio_en_ < 0) {
return;
}
Expand All @@ -220,6 +245,21 @@ class BldcDriver {
gpio_set_level((gpio_num_t)gpio_en_, 0);
}

void configure_fault_gpio() {
std::lock_guard<std::mutex> lock(fault_mutex_);
if (gpio_fault_ < 0) {
return;
}
logger_.info("Configure fault pin");
gpio_config_t drv_fault_config;
memset(&drv_fault_config, 0, sizeof(drv_fault_config));
drv_fault_config.pin_bit_mask = 1ULL << gpio_fault_;
drv_fault_config.mode = GPIO_MODE_INPUT;
drv_fault_config.pull_up_en = GPIO_PULLUP_DISABLE;
drv_fault_config.pull_down_en = GPIO_PULLDOWN_ENABLE;
ESP_ERROR_CHECK(gpio_config(&drv_fault_config));
}

void configure_timer() {
logger_.info("Create MCPWM timer");
mcpwm_timer_config_t timer_config;
Expand Down Expand Up @@ -307,7 +347,10 @@ class BldcDriver {
gpio_num_t gpio_bl_;
gpio_num_t gpio_ch_;
gpio_num_t gpio_cl_;
std::mutex en_mutex_;
int gpio_en_;
std::mutex fault_mutex_;
int gpio_fault_;
std::atomic<float> power_supply_voltage_;
std::atomic<float> limit_voltage_;
float dead_zone_;
Expand Down
4 changes: 4 additions & 0 deletions components/bldc_haptics/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
idf_component_register(
INCLUDE_DIRS "include"
REQUIRES logger math pid task bldc_motor
)
21 changes: 21 additions & 0 deletions components/bldc_haptics/example/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# The following lines of boilerplate have to be in your project's CMakeLists
# in this exact order for cmake to work correctly
cmake_minimum_required(VERSION 3.5)

include($ENV{IDF_PATH}/tools/cmake/project.cmake)

# add the component directories that we want to use
set(EXTRA_COMPONENT_DIRS
"../../../components/"
)

set(
COMPONENTS
"main esptool_py filters task monitor mt6701 bldc_motor bldc_driver bldc_haptics"
CACHE STRING
"List of components to include"
)

project(bldc_motor_example)

set(CMAKE_CXX_STANDARD 20)
67 changes: 67 additions & 0 deletions components/bldc_haptics/example/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
_Note that this is a template for an ESP-IDF example README.md file. When using this template, replace all these emphasised placeholders with example-specific content._

| Supported Targets | _Supported target, e.g. ESP32_ | _Another supported target, e.g. ESP32-S3_ |
| ----------------- | ------------------------------ | ----------------------------------------- |

_If the example supports all targets supported by ESP-IDF then the table can be omitted_
# _Example Title_

(See the README.md file in the upper level 'examples' directory for more information about examples.)

_What is this example? What does it do?_

_What features of ESP-IDF does it use?_

_What could someone create based on this example? ie applications/use cases/etc_

_If there are any acronyms or Espressif-only words used here, explain them or mention where in the datasheet/TRM this information can be found._

## How to use example

### Hardware Required

_If possible, example should be able to run on any commonly available ESP32 development board. Otherwise, describe what specific hardware should be used._

_If any other items (server, BLE device, app, second chip, whatever) are needed, mention them here. Include links if applicable. Explain how to set them up._

### Configure the project

```
idf.py menuconfig
```

* _If there is any project configuration that the user must set for this example, mention this here._

### Build and Flash

Build the project and flash it to the board, then run monitor tool to view serial output:

```
idf.py -p PORT flash monitor
```

(Replace PORT with the name of the serial port to use.)

(To exit the serial monitor, type ``Ctrl-]``.)

See the Getting Started Guide for full steps to configure and use ESP-IDF to build projects.

## Example Output

_Include an example of the console output from the running example, here:_

```
Use this style for pasting the log.
```

_If the user is supposed to interact with the example at this point (read/write GATT attribute, send HTTP request, press button, etc. then mention it here)_

_For examples where ESP32 is connected with some other hardware, include a table or schematics with connection details._

## Troubleshooting

_If there are any likely problems or errors which many users might encounter, mention them here. Remove this section for very simple examples where nothing is likely to go wrong._

## Example Breakdown

_If the example source code is lengthy, complex, or cannot be easily understood, use this section to break down and explain the source code. This can be done by breaking down the execution path step by step, or explaining what each major function/task/source file does. Add sub titles if necessary. Remove this section for very simple examples where the source code is self explanatory._
2 changes: 2 additions & 0 deletions components/bldc_haptics/example/main/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
idf_component_register(SRC_DIRS "."
INCLUDE_DIRS ".")
Loading