Compare commits
14 Commits
led_fet_br
...
master
Author | SHA1 | Date | |
---|---|---|---|
cd69f0b894 | |||
323db30bc1 | |||
1125ab934c | |||
0c3b449a2c | |||
cae4a46d18 | |||
fea59a5004 | |||
bf1b2f34bd | |||
8d755d42e7 | |||
e361066e0b | |||
c8f29ccb9f | |||
f01a34c109 | |||
b307e1bc79 | |||
3a872bcd58 | |||
fa0c149352 |
12
.github/workflows/workflow.yml
vendored
12
.github/workflows/workflow.yml
vendored
@ -15,7 +15,7 @@ jobs:
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
config: [motortest, motortest_peter, feedcode-front, feedcode-back, greyhash]
|
||||
config: [motortest, motortest_peter, feedcode-front, feedcode-back, greyhash, pcbv2_front, pcbv2_back, pcbv2_test, commander_v2_front, commander_v2_back]
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
with:
|
||||
@ -28,16 +28,6 @@ jobs:
|
||||
|
||||
- name: Build
|
||||
id: build
|
||||
continue-on-error: true
|
||||
run: |
|
||||
cmake -DCMAKE_BUILD_TYPE=Release .
|
||||
make -j$(nproc) ${{ matrix.config }}
|
||||
|
||||
# github artifacts
|
||||
- name: Upload logs if failed
|
||||
if: ${{ steps.build.outcome == 'failure' }}
|
||||
uses: actions/upload-artifact@v2.2.4
|
||||
with:
|
||||
path: |
|
||||
./CMakeFiles/CMakeOutput.log
|
||||
./CMakeFiles/CMakeError.log
|
||||
|
22
.gitignore
vendored
22
.gitignore
vendored
@ -3,8 +3,20 @@ CMakeCache.txt
|
||||
CMakeFiles
|
||||
Makefile
|
||||
cmake_install.cmake
|
||||
*.bin
|
||||
*.hex
|
||||
*.elf
|
||||
*.a
|
||||
*.map
|
||||
|
||||
build/
|
||||
|
||||
# VS Code
|
||||
.vscode/
|
||||
.cache/
|
||||
|
||||
# Jetbrains
|
||||
.idea/
|
||||
cmake-build-*/
|
||||
|
||||
# other
|
||||
hover.map
|
||||
libemanuel_foc_model.a
|
||||
libstm32_hal.a
|
||||
/*.bin
|
||||
/*elf
|
||||
|
257
CMakeLists.txt
257
CMakeLists.txt
@ -11,7 +11,7 @@ SET(CMAKE_SYSTEM_NAME Generic)
|
||||
set(COMMON_FLAGS "-mcpu=cortex-m3 -mthumb -Wall -fdata-sections -ffunction-sections")
|
||||
set(CMAKE_ASM_FLAGS "${COMMON_FLAGS} -x assembler-with-cpp")
|
||||
set(CMAKE_C_FLAGS "${COMMON_FLAGS}")
|
||||
set(CMAKE_CXX_FLAGS "${COMMON_FLAGS}")
|
||||
set(CMAKE_CXX_FLAGS "${COMMON_FLAGS} -Wno-volatile")
|
||||
|
||||
set(CMAKE_C_STANDARD 11)
|
||||
set(CMAKE_CXX_STANDARD 20)
|
||||
@ -174,6 +174,61 @@ add_custom_command(OUTPUT feedcode-back.bin COMMAND arm-none-eabi-objcopy -O bin
|
||||
add_custom_target(feedcode-back ALL SOURCES feedcode-back.hex feedcode-back.bin)
|
||||
add_custom_target(flash-feedcode-back COMMAND st-flash --reset write feedcode-back.bin 0x8000000 SOURCES feedcode-back.bin DEPENDS feedcode-back.bin)
|
||||
|
||||
|
||||
#
|
||||
# feedc0de 2 front
|
||||
#
|
||||
add_executable(feedcode2-front.elf config.h defines.h main.cpp)
|
||||
target_link_libraries(feedcode2-front.elf stm32_hal emanuel_foc_model bobbycar-protocol)
|
||||
target_compile_options(feedcode2-front.elf PRIVATE
|
||||
# -DMOTOR_TEST
|
||||
-DFEATURE_IGNORE_OTHER_MOTOR
|
||||
-DLEFT_HALL_ABC
|
||||
-DRIGHT_HALL_ABC
|
||||
# -DPWM_FREQ_12KHZ
|
||||
# -DFEATURE_BUTTON
|
||||
-DPETERS_PLATINE
|
||||
# -DHUART2
|
||||
# -DHUART3
|
||||
# -DFEATURE_SERIAL_CONTROL
|
||||
# -DFEATURE_SERIAL_FEEDBACK
|
||||
# -DLOG_TO_SERIAL
|
||||
-DFEATURE_CAN
|
||||
# -DCAN_LOG_UNKNOWN_ADDR
|
||||
# -DIS_BACK
|
||||
)
|
||||
add_custom_command(OUTPUT feedcode2-front.hex COMMAND arm-none-eabi-objcopy -O ihex feedcode2-front.elf feedcode2-front.hex DEPENDS feedcode2-front.elf)
|
||||
add_custom_command(OUTPUT feedcode2-front.bin COMMAND arm-none-eabi-objcopy -O binary -S feedcode2-front.elf feedcode2-front.bin DEPENDS feedcode2-front.elf)
|
||||
add_custom_target(feedcode2-front ALL SOURCES feedcode2-front.hex feedcode2-front.bin)
|
||||
add_custom_target(flash-feedcode2-front COMMAND st-flash --reset write feedcode2-front.bin 0x8000000 SOURCES feedcode2-front.bin DEPENDS feedcode2-front.bin)
|
||||
|
||||
#
|
||||
# feedc0de 2 back
|
||||
#
|
||||
add_executable(feedcode2-back.elf config.h defines.h main.cpp)
|
||||
target_link_libraries(feedcode2-back.elf stm32_hal emanuel_foc_model bobbycar-protocol)
|
||||
target_compile_options(feedcode2-back.elf PRIVATE
|
||||
# -DMOTOR_TEST
|
||||
-DFEATURE_IGNORE_OTHER_MOTOR
|
||||
-DLEFT_HALL_ACB
|
||||
-DRIGHT_HALL_ACB
|
||||
# -DPWM_FREQ_12KHZ
|
||||
# -DFEATURE_BUTTON
|
||||
-DPETERS_PLATINE
|
||||
# -DHUART2
|
||||
# -DHUART3
|
||||
# -DFEATURE_SERIAL_CONTROL
|
||||
# -DFEATURE_SERIAL_FEEDBACK
|
||||
# -DLOG_TO_SERIAL
|
||||
-DFEATURE_CAN
|
||||
# -DCAN_LOG_UNKNOWN_ADDR
|
||||
-DIS_BACK
|
||||
)
|
||||
add_custom_command(OUTPUT feedcode2-back.hex COMMAND arm-none-eabi-objcopy -O ihex feedcode2-back.elf feedcode2-back.hex DEPENDS feedcode2-back.elf)
|
||||
add_custom_command(OUTPUT feedcode2-back.bin COMMAND arm-none-eabi-objcopy -O binary -S feedcode2-back.elf feedcode2-back.bin DEPENDS feedcode2-back.elf)
|
||||
add_custom_target(feedcode2-back ALL SOURCES feedcode2-back.hex feedcode2-back.bin)
|
||||
add_custom_target(flash-feedcode2-back COMMAND st-flash --reset write feedcode2-back.bin 0x8000000 SOURCES feedcode2-back.bin DEPENDS feedcode2-back.bin)
|
||||
|
||||
#
|
||||
# greyhash
|
||||
#
|
||||
@ -200,8 +255,208 @@ add_custom_command(OUTPUT greyhash.bin COMMAND arm-none-eabi-objcopy -O binary -
|
||||
add_custom_target(greyhash ALL SOURCES greyhash.hex greyhash.bin)
|
||||
add_custom_target(flash-greyhash COMMAND st-flash --reset write greyhash.bin 0x8000000 SOURCES greyhash.bin DEPENDS greyhash.bin)
|
||||
|
||||
#
|
||||
# peters platine v2 front
|
||||
#
|
||||
add_executable(pcbv2_front.elf config.h defines.h main.cpp)
|
||||
target_link_libraries(pcbv2_front.elf stm32_hal emanuel_foc_model bobbycar-protocol)
|
||||
target_compile_options(pcbv2_front.elf PRIVATE
|
||||
# -DMOTOR_TEST
|
||||
-DFEATURE_IGNORE_OTHER_MOTOR
|
||||
# -DHALL_BCA
|
||||
# -DPWM_FREQ_12KHZ
|
||||
# -DFEATURE_BUTTON
|
||||
-DPETERS_PLATINE
|
||||
# -DHUART2
|
||||
# -DHUART3
|
||||
# -DFEATURE_SERIAL_CONTROL
|
||||
# -DFEATURE_SERIAL_FEEDBACK
|
||||
# -DLOG_TO_SERIAL
|
||||
-DFEATURE_CAN
|
||||
# -DCAN_LOG_UNKNOWN_ADDR
|
||||
# -DIS_BACK
|
||||
-DAMPERE2BIT_CONV=28
|
||||
)
|
||||
add_custom_command(OUTPUT pcbv2_front.hex COMMAND arm-none-eabi-objcopy -O ihex pcbv2_front.elf pcbv2_front.hex DEPENDS pcbv2_front.elf)
|
||||
add_custom_command(OUTPUT pcbv2_front.bin COMMAND arm-none-eabi-objcopy -O binary -S pcbv2_front.elf pcbv2_front.bin DEPENDS pcbv2_front.elf)
|
||||
add_custom_target(pcbv2_front ALL SOURCES pcbv2_front.hex pcbv2_front.bin)
|
||||
add_custom_target(flash-pcbv2_front COMMAND st-flash --reset write pcbv2_front.bin 0x8000000 SOURCES pcbv2_front.bin DEPENDS pcbv2_front.bin)
|
||||
|
||||
#
|
||||
# peters platine v2 back
|
||||
#
|
||||
add_executable(pcbv2_back.elf config.h defines.h main.cpp)
|
||||
target_link_libraries(pcbv2_back.elf stm32_hal emanuel_foc_model bobbycar-protocol)
|
||||
target_compile_options(pcbv2_back.elf PRIVATE
|
||||
# -DMOTOR_TEST
|
||||
-DFEATURE_IGNORE_OTHER_MOTOR
|
||||
# -DHALL_BCA
|
||||
# -DPWM_FREQ_12KHZ
|
||||
# -DFEATURE_BUTTON
|
||||
-DPETERS_PLATINE
|
||||
# -DHUART2
|
||||
# -DHUART3
|
||||
# -DFEATURE_SERIAL_CONTROL
|
||||
# -DFEATURE_SERIAL_FEEDBACK
|
||||
# -DLOG_TO_SERIAL
|
||||
-DFEATURE_CAN
|
||||
# -DCAN_LOG_UNKNOWN_ADDR
|
||||
-DIS_BACK
|
||||
-DAMPERE2BIT_CONV=28
|
||||
)
|
||||
add_custom_command(OUTPUT pcbv2_back.hex COMMAND arm-none-eabi-objcopy -O ihex pcbv2_back.elf pcbv2_back.hex DEPENDS pcbv2_back.elf)
|
||||
add_custom_command(OUTPUT pcbv2_back.bin COMMAND arm-none-eabi-objcopy -O binary -S pcbv2_back.elf pcbv2_back.bin DEPENDS pcbv2_back.elf)
|
||||
add_custom_target(pcbv2_back ALL SOURCES pcbv2_back.hex pcbv2_back.bin)
|
||||
add_custom_target(flash-pcbv2_back COMMAND st-flash --reset write pcbv2_back.bin 0x8000000 SOURCES pcbv2_back.bin DEPENDS pcbv2_back.bin)
|
||||
|
||||
#
|
||||
# peters platine v2 motortest
|
||||
#
|
||||
add_executable(pcbv2_test.elf config.h defines.h main.cpp)
|
||||
target_link_libraries(pcbv2_test.elf stm32_hal emanuel_foc_model bobbycar-protocol)
|
||||
target_compile_options(pcbv2_test.elf PRIVATE
|
||||
-DMOTOR_TEST
|
||||
-DFEATURE_IGNORE_OTHER_MOTOR
|
||||
# -DHALL_BCA
|
||||
# -DPWM_FREQ_12KHZ
|
||||
# -DFEATURE_BUTTON
|
||||
-DPETERS_PLATINE
|
||||
# -DHUART2
|
||||
# -DHUART3
|
||||
# -DFEATURE_SERIAL_CONTROL
|
||||
# -DFEATURE_SERIAL_FEEDBACK
|
||||
# -DLOG_TO_SERIAL
|
||||
# -DFEATURE_CAN
|
||||
# -DCAN_LOG_UNKNOWN_ADDR
|
||||
# -DIS_BACK
|
||||
-DAMPERE2BIT_CONV=28
|
||||
-DLEFT_HALL_ABC
|
||||
#-DLEFT_HALL_ACB
|
||||
#-DLEFT_HALL_BAC
|
||||
#-DLEFT_HALL_BCA
|
||||
#-DLEFT_HALL_CAB
|
||||
#-DLEFT_HALL_CBA
|
||||
|
||||
-DRIGHT_HALL_ABC
|
||||
#-DRIGHT_HALL_ACB
|
||||
#-DRIGHT_HALL_BAC
|
||||
#-DRIGHT_HALL_BCA
|
||||
#-DRIGHT_HALL_CAB
|
||||
#-DRIGHT_HALL_CBA
|
||||
|
||||
#-DFEATURE_BETTER_FOC_CONFIG
|
||||
#-DLEFT_PHASE_MEAS_AB
|
||||
#-DLEFT_PHASE_MEAS_AC
|
||||
#-DLEFT_PHASE_MEAS_BC
|
||||
|
||||
#-DRIGHT_PHASE_MEAS_AB
|
||||
#-DRIGHT_PHASE_MEAS_AC
|
||||
#-DRIGHT_PHASE_MEAS_BC
|
||||
)
|
||||
add_custom_command(OUTPUT pcbv2_test.hex COMMAND arm-none-eabi-objcopy -O ihex pcbv2_test.elf pcbv2_test.hex DEPENDS pcbv2_test.elf)
|
||||
add_custom_command(OUTPUT pcbv2_test.bin COMMAND arm-none-eabi-objcopy -O binary -S pcbv2_test.elf pcbv2_test.bin DEPENDS pcbv2_test.elf)
|
||||
add_custom_target(pcbv2_test ALL SOURCES pcbv2_test.hex pcbv2_test.bin)
|
||||
add_custom_target(flash-pcbv2_test COMMAND st-flash --reset write pcbv2_test.bin 0x8000000 SOURCES pcbv2_test.bin DEPENDS pcbv2_test.bin)
|
||||
|
||||
|
||||
#
|
||||
# commander v2 front
|
||||
#
|
||||
add_executable(commander_v2_front.elf config.h defines.h main.cpp)
|
||||
target_link_libraries(commander_v2_front.elf stm32_hal emanuel_foc_model bobbycar-protocol)
|
||||
target_compile_options(commander_v2_front.elf PRIVATE
|
||||
#-DMOTOR_TEST
|
||||
-DFEATURE_IGNORE_OTHER_MOTOR
|
||||
# -DHALL_BCA
|
||||
# -DPWM_FREQ_12KHZ
|
||||
# -DFEATURE_BUTTON
|
||||
-DPETERS_PLATINE
|
||||
# -DHUART2
|
||||
# -DHUART3
|
||||
# -DFEATURE_SERIAL_CONTROL
|
||||
# -DFEATURE_SERIAL_FEEDBACK
|
||||
# -DLOG_TO_SERIAL
|
||||
-DFEATURE_CAN
|
||||
# -DCAN_LOG_UNKNOWN_ADDR
|
||||
# -DIS_BACK
|
||||
#-DAMPERE2BIT_CONV=28
|
||||
-DLEFT_HALL_ABC
|
||||
#-DLEFT_HALL_ACB
|
||||
#-DLEFT_HALL_BAC
|
||||
#-DLEFT_HALL_BCA
|
||||
#-DLEFT_HALL_CAB
|
||||
#-DLEFT_HALL_CBA
|
||||
|
||||
-DRIGHT_HALL_ABC
|
||||
#-DRIGHT_HALL_ACB
|
||||
#-DRIGHT_HALL_BAC
|
||||
#-DRIGHT_HALL_BCA
|
||||
#-DRIGHT_HALL_CAB
|
||||
#-DRIGHT_HALL_CBA
|
||||
|
||||
#-DFEATURE_BETTER_FOC_CONFIG
|
||||
#-DLEFT_PHASE_MEAS_AB
|
||||
#-DLEFT_PHASE_MEAS_AC
|
||||
#-DLEFT_PHASE_MEAS_BC
|
||||
|
||||
#-DRIGHT_PHASE_MEAS_AB
|
||||
#-DRIGHT_PHASE_MEAS_AC
|
||||
#-DRIGHT_PHASE_MEAS_BC
|
||||
)
|
||||
add_custom_command(OUTPUT commander_v2_front.hex COMMAND arm-none-eabi-objcopy -O ihex commander_v2_front.elf commander_v2_front.hex DEPENDS commander_v2_front.elf)
|
||||
add_custom_command(OUTPUT commander_v2_front.bin COMMAND arm-none-eabi-objcopy -O binary -S commander_v2_front.elf commander_v2_front.bin DEPENDS commander_v2_front.elf)
|
||||
add_custom_target(commander_v2_front ALL SOURCES commander_v2_front.hex commander_v2_front.bin)
|
||||
add_custom_target(flash-commander_v2_front COMMAND st-flash --reset write commander_v2_front.bin 0x8000000 SOURCES commander_v2_front.bin DEPENDS commander_v2_front.bin)
|
||||
|
||||
|
||||
#
|
||||
# commander v2 back
|
||||
#
|
||||
add_executable(commander_v2_back.elf config.h defines.h main.cpp)
|
||||
target_link_libraries(commander_v2_back.elf stm32_hal emanuel_foc_model bobbycar-protocol)
|
||||
target_compile_options(commander_v2_back.elf PRIVATE
|
||||
#-DMOTOR_TEST
|
||||
-DFEATURE_IGNORE_OTHER_MOTOR
|
||||
# -DHALL_BCA
|
||||
# -DPWM_FREQ_12KHZ
|
||||
# -DFEATURE_BUTTON
|
||||
-DPETERS_PLATINE
|
||||
# -DHUART2
|
||||
# -DHUART3
|
||||
# -DFEATURE_SERIAL_CONTROL
|
||||
# -DFEATURE_SERIAL_FEEDBACK
|
||||
# -DLOG_TO_SERIAL
|
||||
-DFEATURE_CAN
|
||||
# -DCAN_LOG_UNKNOWN_ADDR
|
||||
-DIS_BACK
|
||||
#-DAMPERE2BIT_CONV=28
|
||||
-DLEFT_HALL_ABC
|
||||
#-DLEFT_HALL_ACB
|
||||
#-DLEFT_HALL_BAC
|
||||
#-DLEFT_HALL_BCA
|
||||
#-DLEFT_HALL_CAB
|
||||
#-DLEFT_HALL_CBA
|
||||
|
||||
-DRIGHT_HALL_ABC
|
||||
#-DRIGHT_HALL_ACB
|
||||
#-DRIGHT_HALL_BAC
|
||||
#-DRIGHT_HALL_BCA
|
||||
#-DRIGHT_HALL_CAB
|
||||
#-DRIGHT_HALL_CBA
|
||||
|
||||
#-DFEATURE_BETTER_FOC_CONFIG
|
||||
#-DLEFT_PHASE_MEAS_AB
|
||||
#-DLEFT_PHASE_MEAS_AC
|
||||
#-DLEFT_PHASE_MEAS_BC
|
||||
|
||||
#-DRIGHT_PHASE_MEAS_AB
|
||||
#-DRIGHT_PHASE_MEAS_AC
|
||||
#-DRIGHT_PHASE_MEAS_BC
|
||||
)
|
||||
add_custom_command(OUTPUT commander_v2_back.hex COMMAND arm-none-eabi-objcopy -O ihex commander_v2_back.elf commander_v2_back.hex DEPENDS commander_v2_back.elf)
|
||||
add_custom_command(OUTPUT commander_v2_back.bin COMMAND arm-none-eabi-objcopy -O binary -S commander_v2_back.elf commander_v2_back.bin DEPENDS commander_v2_back.elf)
|
||||
add_custom_target(commander_v2_back ALL SOURCES commander_v2_back.hex commander_v2_back.bin)
|
||||
add_custom_target(flash-commander_v2_back COMMAND st-flash --reset write commander_v2_back.bin 0x8000000 SOURCES commander_v2_back.bin DEPENDS commander_v2_back.bin)
|
||||
|
||||
|
||||
# util targets
|
||||
|
17
config.h
17
config.h
@ -6,7 +6,10 @@
|
||||
#define PWM_FREQ 16000 // PWM frequency in Hz
|
||||
#endif
|
||||
#define DEAD_TIME 48 // PWM deadtime
|
||||
#define A2BIT_CONV 50 // A to bit for current conversion on ADC. Example: 1 A = 50, 2 A = 100, etc
|
||||
|
||||
#ifndef AMPERE2BIT_CONV
|
||||
#define AMPERE2BIT_CONV 50 // Ampere to bit for current conversion on ADC. Example: 1 A = 50, 2 A = 100, etc
|
||||
#endif
|
||||
|
||||
// ADC conversion time definitions
|
||||
#define ADC_CONV_TIME_1C5 (14) //Total ADC clock cycles / conversion = ( 1.5+12.5)
|
||||
@ -41,8 +44,8 @@
|
||||
* Then you can verify voltage on value 6 (to get calibrated voltage multiplied by 100).
|
||||
*/
|
||||
#define BAT_FILT_COEF 655 // battery voltage filter coefficient in fixed-point. coef_fixedPoint = coef_floatingPoint * 2^16. In this case 655 = 0.01 * 2^16
|
||||
#define BAT_CALIB_REAL_VOLTAGE 4800 // input voltage measured by multimeter (multiplied by 100). For example 43.00 V * 100 = 4300
|
||||
#define BAT_CALIB_ADC 1845 // adc-value measured by mainboard (value nr 5 on UART debug output)
|
||||
#define BAT_CALIB_REAL_VOLTAGE 3970 // input voltage measured by multimeter (multiplied by 100). For example 43.00 V * 100 = 4300
|
||||
#define BAT_CALIB_ADC 1492 // adc-value measured by mainboard (value nr 5 on UART debug output)
|
||||
|
||||
#define BAT_CELLS 12 // battery number of cells. Normal Hoverboard battery: 10s
|
||||
|
||||
@ -54,10 +57,10 @@
|
||||
* Enable warning and/or poweroff and make and flash firmware.
|
||||
*/
|
||||
#define TEMP_FILT_COEF 655 // temperature filter coefficient in fixed-point. coef_fixedPoint = coef_floatingPoint * 2^16. In this case 655 = 0.01 * 2^16
|
||||
#define TEMP_CAL_LOW_ADC 1593 // temperature 1: ADC value
|
||||
#define TEMP_CAL_LOW_DEG_C 400 // temperature 1: measured temperature [°C * 10]. Here 40.0 °C
|
||||
#define TEMP_CAL_HIGH_ADC 1463 // temperature 2: ADC value
|
||||
#define TEMP_CAL_HIGH_DEG_C 623 // temperature 2: measured temperature [°C * 10]. Here 62.3 °C
|
||||
#define TEMP_CAL_LOW_ADC 1655 // temperature 1: ADC value
|
||||
#define TEMP_CAL_LOW_DEG_C 358 // temperature 1: measured temperature [°C * 10]. Here 35.8 °C
|
||||
#define TEMP_CAL_HIGH_ADC 1588 // temperature 2: ADC value
|
||||
#define TEMP_CAL_HIGH_DEG_C 489 // temperature 2: measured temperature [°C * 10]. Here 48.9 °C
|
||||
|
||||
|
||||
// ############################### INPUT ###############################
|
||||
|
41
defines.h
41
defines.h
@ -24,57 +24,63 @@
|
||||
|
||||
#ifdef PETERS_PLATINE
|
||||
|
||||
#ifdef HALL_CAB
|
||||
#ifdef LEFT_HALL_CAB
|
||||
#define LEFT_HALL_U_PIN GPIO_PIN_11
|
||||
#define LEFT_HALL_V_PIN GPIO_PIN_12
|
||||
#define LEFT_HALL_W_PIN GPIO_PIN_10
|
||||
#elif HALL_CBA
|
||||
#elif LEFT_HALL_CBA
|
||||
#define LEFT_HALL_U_PIN GPIO_PIN_11
|
||||
#define LEFT_HALL_V_PIN GPIO_PIN_10
|
||||
#define LEFT_HALL_W_PIN GPIO_PIN_12
|
||||
#elif HALL_BAC
|
||||
#elif LEFT_HALL_BAC
|
||||
#define LEFT_HALL_U_PIN GPIO_PIN_10
|
||||
#define LEFT_HALL_V_PIN GPIO_PIN_12
|
||||
#define LEFT_HALL_W_PIN GPIO_PIN_11
|
||||
#elif HALL_BCA
|
||||
#elif LEFT_HALL_BCA
|
||||
#define LEFT_HALL_U_PIN GPIO_PIN_10
|
||||
#define LEFT_HALL_V_PIN GPIO_PIN_11
|
||||
#define LEFT_HALL_W_PIN GPIO_PIN_12
|
||||
#elif HALL_ABC
|
||||
#elif LEFT_HALL_ABC
|
||||
#define LEFT_HALL_U_PIN GPIO_PIN_12
|
||||
#define LEFT_HALL_V_PIN GPIO_PIN_10
|
||||
#define LEFT_HALL_W_PIN GPIO_PIN_11
|
||||
#else //HALL_ACB
|
||||
#else //LEFT_HALL_ACB
|
||||
#ifndef LEFT_HALL_ACB
|
||||
#warning "No left Hall configuration defined, using default ACB"
|
||||
#endif
|
||||
#define LEFT_HALL_U_PIN GPIO_PIN_12
|
||||
#define LEFT_HALL_V_PIN GPIO_PIN_11
|
||||
#define LEFT_HALL_W_PIN GPIO_PIN_10
|
||||
#endif
|
||||
|
||||
#define LEFT_HALL_U_PORT GPIOC
|
||||
#define LEFT_HALL_V_PORT GPIOC
|
||||
#define LEFT_HALL_W_PORT GPIOC
|
||||
#define LEFT_HALL_U_PORT GPIOC
|
||||
#define LEFT_HALL_V_PORT GPIOC
|
||||
#define LEFT_HALL_W_PORT GPIOC
|
||||
|
||||
#ifdef HALL_CAB
|
||||
#ifdef RIGHT_HALL_CAB
|
||||
#define RIGHT_HALL_U_PIN GPIO_PIN_6
|
||||
#define RIGHT_HALL_V_PIN GPIO_PIN_5
|
||||
#define RIGHT_HALL_W_PIN GPIO_PIN_7
|
||||
#elif HALL_CBA
|
||||
#elif RIGHT_HALL_CBA
|
||||
#define RIGHT_HALL_U_PIN GPIO_PIN_6
|
||||
#define RIGHT_HALL_V_PIN GPIO_PIN_7
|
||||
#define RIGHT_HALL_W_PIN GPIO_PIN_5
|
||||
#elif HALL_BAC
|
||||
#elif RIGHT_HALL_BAC
|
||||
#define RIGHT_HALL_U_PIN GPIO_PIN_7
|
||||
#define RIGHT_HALL_V_PIN GPIO_PIN_5
|
||||
#define RIGHT_HALL_W_PIN GPIO_PIN_6
|
||||
#elif HALL_BCA
|
||||
#elif RIGHT_HALL_BCA
|
||||
#define RIGHT_HALL_U_PIN GPIO_PIN_7
|
||||
#define RIGHT_HALL_V_PIN GPIO_PIN_6
|
||||
#define RIGHT_HALL_W_PIN GPIO_PIN_5
|
||||
#elif HALL_ABC
|
||||
#elif RIGHT_HALL_ABC
|
||||
#define RIGHT_HALL_U_PIN GPIO_PIN_5
|
||||
#define RIGHT_HALL_V_PIN GPIO_PIN_7
|
||||
#define RIGHT_HALL_W_PIN GPIO_PIN_6
|
||||
#else //HALL_ACB
|
||||
#else //RIGHT_HALL_ACB
|
||||
#ifndef RIGHT_HALL_ACB
|
||||
#warning "No right Hall configuration defined, using default ACB"
|
||||
#endif
|
||||
#define RIGHT_HALL_U_PIN GPIO_PIN_5
|
||||
#define RIGHT_HALL_V_PIN GPIO_PIN_6
|
||||
#define RIGHT_HALL_W_PIN GPIO_PIN_7
|
||||
@ -83,7 +89,7 @@
|
||||
#define RIGHT_HALL_U_PORT GPIOB
|
||||
#define RIGHT_HALL_V_PORT GPIOB
|
||||
#define RIGHT_HALL_W_PORT GPIOB
|
||||
#else
|
||||
#else // defined(PETERS_PLATINE)
|
||||
#ifdef HALL_BCA
|
||||
#define LEFT_HALL_U_PIN GPIO_PIN_7
|
||||
#define LEFT_HALL_V_PIN GPIO_PIN_6
|
||||
@ -185,9 +191,6 @@
|
||||
#define LED_PIN GPIO_PIN_2
|
||||
#define LED_PORT GPIOB
|
||||
|
||||
#define LIGHT_PIN GPIO_PIN_3
|
||||
#define LIGHT_PORT GPIOB
|
||||
|
||||
#define BUZZER_PIN GPIO_PIN_4
|
||||
#define BUZZER_PORT GPIOA
|
||||
|
||||
|
66
main.cpp
66
main.cpp
@ -24,6 +24,7 @@
|
||||
#include <algorithm>
|
||||
#include <atomic>
|
||||
#include <bit>
|
||||
#include <cstdint>
|
||||
#include <cstring>
|
||||
|
||||
#include "stm32f1xx_hal.h"
|
||||
@ -317,6 +318,7 @@ int main()
|
||||
|
||||
enum { CurrentMeasAB, CurrentMeasBC, CurrentMeasAC };
|
||||
|
||||
#ifndef FEATURE_BETTER_FOC_CONFIG
|
||||
#ifdef PETERS_PLATINE
|
||||
left.rtP.z_selPhaCurMeasABC = CurrentMeasBC;
|
||||
#else
|
||||
@ -324,6 +326,23 @@ int main()
|
||||
#endif
|
||||
|
||||
right.rtP.z_selPhaCurMeasABC = CurrentMeasBC;
|
||||
#else
|
||||
#ifdef LEFT_PHASE_MEAS_AB
|
||||
left.rtP.z_selPhaCurMeasABC = CurrentMeasAB;
|
||||
#elif LEFT_PHASE_MEAS_BC
|
||||
left.rtP.z_selPhaCurMeasABC = CurrentMeasBC;
|
||||
#else
|
||||
left.rtP.z_selPhaCurMeasABC = CurrentMeasAC;
|
||||
#endif
|
||||
|
||||
#ifdef RIGHT_PHASE_MEAS_AB
|
||||
right.rtP.z_selPhaCurMeasABC = CurrentMeasAB;
|
||||
#elif RIGHT_PHASE_MEAS_BC
|
||||
right.rtP.z_selPhaCurMeasABC = CurrentMeasBC;
|
||||
#else
|
||||
right.rtP.z_selPhaCurMeasABC = CurrentMeasAC;
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
|
||||
applyDefaultSettings();
|
||||
@ -477,11 +496,11 @@ void updateMotors()
|
||||
#endif
|
||||
int16_t curR_DC = (int16_t)(offsetdcr - adc_buffer.dcr);
|
||||
|
||||
const bool chopL = std::abs(curL_DC) > (left.iDcMax.load() * A2BIT_CONV);
|
||||
const bool chopL = std::abs(curL_DC) > (left.iDcMax.load() * AMPERE2BIT_CONV);
|
||||
if (chopL)
|
||||
left.chops++;
|
||||
|
||||
const bool chopR = std::abs(curR_DC) > (right.iDcMax.load() * A2BIT_CONV);
|
||||
const bool chopR = std::abs(curR_DC) > (right.iDcMax.load() * AMPERE2BIT_CONV);
|
||||
if (chopR)
|
||||
right.chops++;
|
||||
|
||||
@ -1050,10 +1069,6 @@ void MX_GPIO_Init()
|
||||
|
||||
GPIO_InitStruct.Pin = LED_PIN;
|
||||
HAL_GPIO_Init(LED_PORT, &GPIO_InitStruct);
|
||||
|
||||
GPIO_InitStruct.Pin = LIGHT_PIN;
|
||||
HAL_GPIO_Init(LIGHT_PORT, &GPIO_InitStruct);
|
||||
__HAL_AFIO_REMAP_SWJ_NOJTAG();
|
||||
|
||||
GPIO_InitStruct.Pin = BUZZER_PIN;
|
||||
HAL_GPIO_Init(BUZZER_PORT, &GPIO_InitStruct);
|
||||
@ -1396,7 +1411,6 @@ void communicationTimeout()
|
||||
buzzer.pattern = 1;
|
||||
|
||||
HAL_GPIO_WritePin(LED_PORT, LED_PIN, GPIO_PIN_RESET);
|
||||
HAL_GPIO_WritePin(LIGHT_PORT, LIGHT_PIN, GPIO_PIN_RESET);
|
||||
}
|
||||
|
||||
#ifdef MOTOR_TEST
|
||||
@ -1409,21 +1423,21 @@ void doMotorTest()
|
||||
left.enable = true;
|
||||
left.rtU.r_inpTgt = pwm;
|
||||
left.rtP.z_ctrlTypSel = uint8_t(ControlType::FieldOrientedControl);
|
||||
left.rtU.z_ctrlModReq = uint8_t(ControlMode::Torque);
|
||||
left.rtP.i_max = (2 * A2BIT_CONV) << 4;
|
||||
left.rtU.z_ctrlModReq = uint8_t(ControlMode::Voltage);
|
||||
left.rtP.i_max = (2 * AMPERE2BIT_CONV) << 4;
|
||||
left.iDcMax = 8;
|
||||
left.rtP.n_max = 1000 << 4;
|
||||
left.rtP.id_fieldWeakMax = (0 * A2BIT_CONV) << 4;
|
||||
left.rtP.id_fieldWeakMax = (0 * AMPERE2BIT_CONV) << 4;
|
||||
left.rtP.a_phaAdvMax = 40 << 4;
|
||||
|
||||
right.enable = true;
|
||||
right.rtU.r_inpTgt = -pwm;
|
||||
right.rtP.z_ctrlTypSel = uint8_t(ControlType::FieldOrientedControl);
|
||||
right.rtU.z_ctrlModReq = uint8_t(ControlMode::Torque);
|
||||
right.rtP.i_max = (2 * A2BIT_CONV) << 4;
|
||||
right.rtU.z_ctrlModReq = uint8_t(ControlMode::Voltage);
|
||||
right.rtP.i_max = (2 * AMPERE2BIT_CONV) << 4;
|
||||
right.iDcMax = 8;
|
||||
right.rtP.n_max = 1000 << 4;
|
||||
right.rtP.id_fieldWeakMax = (0 * A2BIT_CONV) << 4;
|
||||
right.rtP.id_fieldWeakMax = (0 * AMPERE2BIT_CONV) << 4;
|
||||
right.rtP.a_phaAdvMax = 40 << 4;
|
||||
|
||||
constexpr auto pwmMax = 400;
|
||||
@ -1476,9 +1490,9 @@ void parseCommand()
|
||||
left.iDcMax = command.left.iDcMax;
|
||||
|
||||
left.rtP.z_ctrlTypSel = uint8_t(command.left.ctrlTyp);
|
||||
left.rtP.i_max = (int16_t(command.left.iMotMax) * A2BIT_CONV) << 4;
|
||||
left.rtP.i_max = (int16_t(command.left.iMotMax) * AMPERE2BIT_CONV) << 4;
|
||||
left.rtP.n_max = command.left.nMotMax << 4;
|
||||
left.rtP.id_fieldWeakMax = (int16_t(command.left.fieldWeakMax) * A2BIT_CONV) << 4;
|
||||
left.rtP.id_fieldWeakMax = (int16_t(command.left.fieldWeakMax) * AMPERE2BIT_CONV) << 4;
|
||||
left.rtP.a_phaAdvMax = command.left.phaseAdvMax << 4;
|
||||
left.rtU.z_ctrlModReq = uint8_t(command.left.ctrlMod);
|
||||
left.rtU.r_inpTgt = command.left.pwm;
|
||||
@ -1486,9 +1500,9 @@ void parseCommand()
|
||||
right.iDcMax = command.right.iDcMax;
|
||||
|
||||
right.rtP.z_ctrlTypSel = uint8_t(command.right.ctrlTyp);
|
||||
right.rtP.i_max = (int16_t(command.right.iMotMax) * A2BIT_CONV) << 4; // fixdt(1,16,4)
|
||||
right.rtP.i_max = (int16_t(command.right.iMotMax) * AMPERE2BIT_CONV) << 4; // fixdt(1,16,4)
|
||||
right.rtP.n_max = command.right.nMotMax << 4; // fixdt(1,16,4)
|
||||
right.rtP.id_fieldWeakMax = (int16_t(command.right.fieldWeakMax) * A2BIT_CONV) << 4; // fixdt(1,16,4)
|
||||
right.rtP.id_fieldWeakMax = (int16_t(command.right.fieldWeakMax) * AMPERE2BIT_CONV) << 4; // fixdt(1,16,4)
|
||||
right.rtP.a_phaAdvMax = command.right.phaseAdvMax << 4; // fixdt(1,16,4)
|
||||
right.rtU.z_ctrlModReq = uint8_t(command.right.ctrlMod);
|
||||
right.rtU.r_inpTgt = command.right.pwm;
|
||||
@ -1502,7 +1516,6 @@ void parseCommand()
|
||||
#endif
|
||||
|
||||
HAL_GPIO_WritePin(LED_PORT, LED_PIN, command.led ? GPIO_PIN_RESET : GPIO_PIN_SET);
|
||||
HAL_GPIO_WritePin(LIGHT_PORT, LIGHT_PIN, command.led ? GPIO_PIN_SET : GPIO_PIN_RESET);
|
||||
|
||||
command.start = Command::INVALID_HEADER; // Change the Start Frame for timeout detection in the next cycle
|
||||
timeoutCntSerial = 0; // Reset the timeout counter
|
||||
@ -1630,16 +1643,16 @@ void applyIncomingCanMessage()
|
||||
case MotorController<isBackBoard, true> ::Command::CtrlTyp: right.rtP.z_ctrlTypSel = *((uint8_t*)buf); break;
|
||||
case MotorController<isBackBoard, false>::Command::CtrlMod: left .rtU.z_ctrlModReq = *((uint8_t*)buf); break;
|
||||
case MotorController<isBackBoard, true> ::Command::CtrlMod: right.rtU.z_ctrlModReq = *((uint8_t*)buf); break;
|
||||
case MotorController<isBackBoard, false>::Command::IMotMax: left .rtP.i_max = (int16_t(*((uint8_t*)buf)) * A2BIT_CONV) << 4; break;
|
||||
case MotorController<isBackBoard, true> ::Command::IMotMax: right.rtP.i_max = (int16_t(*((uint8_t*)buf)) * A2BIT_CONV) << 4; break;
|
||||
case MotorController<isBackBoard, false>::Command::IMotMax: left .rtP.i_max = (int16_t(*((uint8_t*)buf)) * AMPERE2BIT_CONV) << 4; break;
|
||||
case MotorController<isBackBoard, true> ::Command::IMotMax: right.rtP.i_max = (int16_t(*((uint8_t*)buf)) * AMPERE2BIT_CONV) << 4; break;
|
||||
case MotorController<isBackBoard, false>::Command::IDcMax: left .iDcMax = *((uint8_t*)buf); break;
|
||||
case MotorController<isBackBoard, true> ::Command::IDcMax: right.iDcMax = *((uint8_t*)buf); break;
|
||||
case MotorController<isBackBoard, false>::Command::NMotMax: left .rtP.n_max = *((uint16_t*)buf) << 4; break;
|
||||
case MotorController<isBackBoard, true> ::Command::NMotMax: right.rtP.n_max = *((uint16_t*)buf) << 4; break;
|
||||
case MotorController<isBackBoard, false>::Command::FieldWeakMax: left .rtP.id_fieldWeakMax = (int16_t(*((uint8_t*)buf)) * A2BIT_CONV) << 4; break;
|
||||
case MotorController<isBackBoard, true> ::Command::FieldWeakMax: right.rtP.id_fieldWeakMax = (int16_t(*((uint8_t*)buf)) * A2BIT_CONV) << 4; break;
|
||||
case MotorController<isBackBoard, false>::Command::PhaseAdvMax: left .rtP.a_phaAdvMax = *((uint16_t*)buf) << 4; break;
|
||||
case MotorController<isBackBoard, true> ::Command::PhaseAdvMax: right.rtP.a_phaAdvMax = *((uint16_t*)buf) << 4; break;
|
||||
case MotorController<isBackBoard, false>::Command::FieldWeakMax: left .rtP.id_fieldWeakMax = (int16_t(*((uint8_t*)buf)) * AMPERE2BIT_CONV) << 4; break;
|
||||
case MotorController<isBackBoard, true> ::Command::FieldWeakMax: right.rtP.id_fieldWeakMax = (int16_t(*((uint8_t*)buf)) * AMPERE2BIT_CONV) << 4; break;
|
||||
case MotorController<isBackBoard, false>::Command::PhaseAdvMax: left .rtP.a_phaAdvMax = ((uint16_t)*((uint8_t*)buf)) << 4; break;
|
||||
case MotorController<isBackBoard, true> ::Command::PhaseAdvMax: right.rtP.a_phaAdvMax = ((uint16_t)*((uint8_t*)buf)) << 4; break;
|
||||
case MotorController<isBackBoard, false>::Command::CruiseCtrlEna: left .rtP.b_cruiseCtrlEna = *((bool*)buf); break;
|
||||
case MotorController<isBackBoard, true> ::Command::CruiseCtrlEna: right.rtP.b_cruiseCtrlEna = *((bool*)buf); break;
|
||||
case MotorController<isBackBoard, false>::Command::CruiseMotTgt: left .rtP.n_cruiseMotTgt = *((int16_T*)buf); break;
|
||||
@ -1651,7 +1664,6 @@ void applyIncomingCanMessage()
|
||||
case MotorController<isBackBoard, false>::Command::Led:
|
||||
case MotorController<isBackBoard, true> ::Command::Led:
|
||||
HAL_GPIO_WritePin(LED_PORT, LED_PIN, *((bool*)buf) ? GPIO_PIN_SET : GPIO_PIN_RESET);
|
||||
HAL_GPIO_WritePin(LIGHT_PORT, LIGHT_PIN, *((bool*)buf) ? GPIO_PIN_SET : GPIO_PIN_RESET);
|
||||
break;
|
||||
case MotorController<isBackBoard, false>::Command::Poweroff:
|
||||
case MotorController<isBackBoard, true>::Command::Poweroff:
|
||||
@ -1822,10 +1834,10 @@ void applyDefaultSettings()
|
||||
motor.rtU.r_inpTgt = 0;
|
||||
motor.rtP.z_ctrlTypSel = uint8_t(ControlType::FieldOrientedControl);
|
||||
motor.rtU.z_ctrlModReq = uint8_t(ControlMode::OpenMode);
|
||||
motor.rtP.i_max = (5 * A2BIT_CONV) << 4;
|
||||
motor.rtP.i_max = (5 * AMPERE2BIT_CONV) << 4;
|
||||
motor.iDcMax = 7;
|
||||
motor.rtP.n_max = 1000 << 4;
|
||||
motor.rtP.id_fieldWeakMax = (1 * A2BIT_CONV) << 4;
|
||||
motor.rtP.id_fieldWeakMax = (1 * AMPERE2BIT_CONV) << 4;
|
||||
motor.rtP.a_phaAdvMax = 40 << 4;
|
||||
motor.rtP.b_cruiseCtrlEna = false;
|
||||
motor.rtP.n_cruiseMotTgt = 0;
|
||||
|
Reference in New Issue
Block a user