Skip to content

Commit ac39867

Browse files
committed
feat: initial commit modified from bldc_haptics example
1 parent 86e58bb commit ac39867

15 files changed

+641017
-2
lines changed

.clang-format

Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
---
2+
Language: Cpp
3+
# BasedOnStyle: LLVM
4+
AccessModifierOffset: -2
5+
AlignAfterOpenBracket: Align
6+
AlignConsecutiveAssignments: false
7+
AlignConsecutiveDeclarations: false
8+
AlignEscapedNewlines: Right
9+
AlignOperands: true
10+
AlignTrailingComments: true
11+
AllowAllParametersOfDeclarationOnNextLine: true
12+
AllowShortBlocksOnASingleLine: false
13+
AllowShortCaseLabelsOnASingleLine: false
14+
AllowShortFunctionsOnASingleLine: All
15+
AllowShortIfStatementsOnASingleLine: false
16+
AllowShortLoopsOnASingleLine: false
17+
AlwaysBreakAfterDefinitionReturnType: None
18+
AlwaysBreakAfterReturnType: None
19+
AlwaysBreakBeforeMultilineStrings: false
20+
AlwaysBreakTemplateDeclarations: false
21+
BinPackArguments: true
22+
BinPackParameters: true
23+
BraceWrapping:
24+
AfterClass: false
25+
AfterControlStatement: false
26+
AfterEnum: false
27+
AfterFunction: false
28+
AfterNamespace: false
29+
AfterObjCDeclaration: false
30+
AfterStruct: false
31+
AfterUnion: false
32+
AfterExternBlock: false
33+
BeforeCatch: false
34+
BeforeElse: false
35+
IndentBraces: false
36+
SplitEmptyFunction: true
37+
SplitEmptyRecord: true
38+
SplitEmptyNamespace: true
39+
BreakBeforeBinaryOperators: None
40+
BreakBeforeBraces: Attach
41+
BreakBeforeInheritanceComma: false
42+
BreakBeforeTernaryOperators: true
43+
BreakConstructorInitializersBeforeComma: false
44+
BreakConstructorInitializers: BeforeColon
45+
BreakAfterJavaFieldAnnotations: false
46+
BreakStringLiterals: true
47+
ColumnLimit: 100
48+
CommentPragmas: '^ IWYU pragma:'
49+
CompactNamespaces: false
50+
ConstructorInitializerAllOnOneLineOrOnePerLine: false
51+
ConstructorInitializerIndentWidth: 4
52+
ContinuationIndentWidth: 4
53+
Cpp11BracedListStyle: true
54+
DerivePointerAlignment: false
55+
DisableFormat: false
56+
ExperimentalAutoDetectBinPacking: false
57+
FixNamespaceComments: true
58+
ForEachMacros:
59+
- foreach
60+
- Q_FOREACH
61+
- BOOST_FOREACH
62+
IncludeBlocks: Preserve
63+
IncludeCategories:
64+
- Regex: '^"(llvm|llvm-c|clang|clang-c)/'
65+
Priority: 2
66+
- Regex: '^(<|"(gtest|gmock|isl|json)/)'
67+
Priority: 3
68+
- Regex: '.*'
69+
Priority: 1
70+
IncludeIsMainRegex: '(Test)?$'
71+
IndentCaseLabels: false
72+
IndentPPDirectives: None
73+
IndentWidth: 2
74+
IndentWrappedFunctionNames: false
75+
JavaScriptQuotes: Leave
76+
JavaScriptWrapImports: true
77+
KeepEmptyLinesAtTheStartOfBlocks: true
78+
MacroBlockBegin: ''
79+
MacroBlockEnd: ''
80+
MaxEmptyLinesToKeep: 1
81+
NamespaceIndentation: None
82+
ObjCBlockIndentWidth: 2
83+
ObjCSpaceAfterProperty: false
84+
ObjCSpaceBeforeProtocolList: true
85+
PenaltyBreakAssignment: 2
86+
PenaltyBreakBeforeFirstCallParameter: 19
87+
PenaltyBreakComment: 300
88+
PenaltyBreakFirstLessLess: 120
89+
PenaltyBreakString: 1000
90+
PenaltyExcessCharacter: 1000000
91+
PenaltyReturnTypeOnItsOwnLine: 60
92+
PointerAlignment: Right
93+
RawStringFormats:
94+
- Language: TextProto
95+
Delimiters:
96+
- 'pb'
97+
- 'proto'
98+
BasedOnStyle: google
99+
ReflowComments: true
100+
SortIncludes: true
101+
SortUsingDeclarations: true
102+
SpaceAfterCStyleCast: false
103+
SpaceAfterTemplateKeyword: true
104+
SpaceBeforeAssignmentOperators: true
105+
SpaceBeforeParens: ControlStatements
106+
SpaceInEmptyParentheses: false
107+
SpacesBeforeTrailingComments: 1
108+
SpacesInAngles: false
109+
SpacesInContainerLiterals: true
110+
SpacesInCStyleCastParentheses: false
111+
SpacesInParentheses: false
112+
SpacesInSquareBrackets: false
113+
Standard: Cpp11
114+
TabWidth: 8
115+
UseTab: Never
116+
...
117+

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,3 +30,6 @@
3030
*.exe
3131
*.out
3232
*.app
33+
build/
34+
sdkconfig
35+
sdkconfig.old

.gitmodules

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[submodule "components/espp"]
2+
path = components/espp
3+
url = [email protected]:esp-cpp/espp

.pre-commit-config.yaml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
repos:
2+
- repo: https://github.com/pre-commit/mirrors-clang-format
3+
rev: v14.0.6
4+
hooks:
5+
- id: clang-format
6+
exclude: |
7+
(?x)(
8+
^components/esp-dsp/|
9+
^components/esp_littlefs/|
10+
^components/lvgl/|
11+
^components/state_machine/include/magic_enum.hpp|
12+
^external/alpaca/|
13+
^external/cli/|
14+
^external/csv2/|
15+
^external/fmt/
16+
)
17+
types_or: [c++, c]

CMakeLists.txt

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# The following lines of boilerplate have to be in your project's CMakeLists
2+
# in this exact order for cmake to work correctly
3+
cmake_minimum_required(VERSION 3.5)
4+
5+
include($ENV{IDF_PATH}/tools/cmake/project.cmake)
6+
7+
# add the component directories that we want to use
8+
set(EXTRA_COMPONENT_DIRS
9+
"components/"
10+
"components/espp/components/"
11+
)
12+
13+
set(
14+
COMPONENTS
15+
"main esptool_py filters task monitor mt6701 bldc_motor bldc_driver bldc_haptics"
16+
CACHE STRING
17+
"List of components to include"
18+
)
19+
20+
project(bldc_test_stand)
21+
22+
set(CMAKE_CXX_STANDARD 20)

README.md

Lines changed: 90 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,90 @@
1-
# bldc_test_stand
2-
Test stand (MCAD + code) for running a little gimbal BLDC
1+
# BLDC Motor Test Stand
2+
3+
This project contains the MCAD and source files for a BLDC motor test stand,
4+
designed to enable running various experiments in openloop control, closed loop
5+
control, and user interface / haptics using a small BLDC motor that's commonly
6+
used in camera gimbals.
7+
8+
## Hardware
9+
10+
* TinyS3
11+
* BLDC Motor (I used [these A and B motors](https://www.aliexpress.us/item/3256802907900422.html) from aliexpress)
12+
* MT6701 Magnetic Encoder Breakout (I used [this purple one (color B)](https://www.aliexpress.us/item/3256804851103272.html) from aliexpress)
13+
* TMC6300 BOB
14+
* Mini solderless breadboard
15+
* 3d printed test stand enclosure (.stl and source files in the [mcad](./mcad) directory)
16+
* Benchtop power supply (currently running at 5V 1A so many things should work)
17+
18+
:warning:
19+
> NOTE: you MUST make sure that you run this code with the
20+
> `zero_electrical_offset` value set to 0 (or not provided) at least once
21+
> otherwise the sample will not work and could potentially damage your motor.
22+
23+
### Build and Flash
24+
25+
Build the project and flash it to the board, then run monitor tool to view serial output:
26+
27+
```
28+
idf.py -p PORT flash monitor
29+
```
30+
31+
(Replace PORT with the name of the serial port to use.)
32+
33+
(To exit the serial monitor, type ``Ctrl-]``.)
34+
35+
See the Getting Started Guide for full steps to configure and use ESP-IDF to build projects.
36+
37+
## Output
38+
39+
This code can be re-run (by modifying the code to change the selected
40+
`DetentConfig` from one of the predefined configurations or by making your own)
41+
to produce various behaviors. Additionally, at the end of each demo, it will
42+
play a haptic buzz / click using the motor.
43+
44+
For more information, see the documentation or the original PR:
45+
https://github.com/esp-cpp/espp/pull/60
46+
47+
Some examples:
48+
49+
### coarse values strong detents (best with sound)
50+
51+
https://github.com/esp-cpp/espp/assets/213467/a256b401-6e45-4284-89c7-2dec9a49daa7
52+
53+
### magnetic detents (best with sound)
54+
55+
https://github.com/esp-cpp/espp/assets/213467/ab1ace5c-f967-4cfc-b304-7736fdb35bcb
56+
57+
### On / Off Strong Detents (best with sound)
58+
59+
https://github.com/esp-cpp/espp/assets/213467/038d79b1-7cd9-4af9-b7e8-1b4daf6a363a
60+
61+
### Multi-rev no detents
62+
63+
https://github.com/esp-cpp/espp/assets/213467/2af81edb-67b8-488b-ae7a-3549be36b8cc
64+
65+
## Troubleshooting
66+
67+
Make sure to run the code once with `zero_electrical_offset` set to 0 so that
68+
the motor will go through a calibration / zero offset routine. At the end of
69+
this startup routine it will print the measured zero electrical offset that you
70+
can then provide within the code, at which point it will not need to run the
71+
calibration routine.
72+
73+
You must run this calibration any time you change your hardware configuration
74+
(such as by remounting your motor, magnet, encoder chip).
75+
76+
## Code Breakdown
77+
78+
This example is relatively complex, but builds complex haptic behavior using the
79+
following components:
80+
81+
* `espp::Mt6701`
82+
* `espp::BldcDriver`
83+
* `espp::BldcMotor`
84+
* `espp::BldcHaptics`
85+
* ESP-IDF's `i2c` peripheral driver
86+
87+
You combine the `Mt6701` and `BldcDriver` together when creating the `BldcMotor`
88+
and then simply pass the `BldcMotor` to the `BldcHaptics` component. At that
89+
point, you only have to interface to the `BldcHaptics` to read the input
90+
position or reconfigure the haptics.

components/espp

Submodule espp added at de01b1f

main/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
idf_component_register(SRC_DIRS "."
2+
INCLUDE_DIRS ".")

0 commit comments

Comments
 (0)