3 Commits

Author SHA1 Message Date
209cbca8ba Remove PWM margin for non-FOC control types
See 2ab0699f1f
2023-04-13 04:31:19 +02:00
1125ab934c Add feedc0de 2 2023-04-09 17:16:38 +02:00
0c3b449a2c All motor configs 2022-10-03 10:20:05 +02:00
3 changed files with 67 additions and 8 deletions

View File

@ -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:

View File

@ -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
#

View File

@ -530,7 +530,11 @@ void updateMotors()
OverrunFlag = true;
constexpr int32_t pwm_res = 64000000 / 2 / PWM_FREQ; // = 2000
constexpr int32_t pwm_margin = 100; /* This margin allows to always have a window in the PWM signal for proper Phase currents measurement */
constexpr int32_t foc_pwm_margin = 100; /* This margin allows to always have a window in the PWM signal for proper Phase currents measurement */
using bobbycar::protocol::ControlType;
const int32_t pwm_margin_l = (left.rtP.z_ctrlTypSel == uint8_t(ControlType::FieldOrientedControl)) ? foc_pwm_margin : 0;
const int32_t pwm_margin_r = (right.rtP.z_ctrlTypSel == uint8_t(ControlType::FieldOrientedControl)) ? foc_pwm_margin : 0;
/* Make sure to stop BOTH motors in case of an error */
@ -575,9 +579,9 @@ void updateMotors()
int wl = left.rtY.DC_phaC;
/* Apply commands */
LEFT_TIM->LEFT_TIM_U = (uint16_t)std::clamp(ul + pwm_res / 2, pwm_margin, pwm_res-pwm_margin);
LEFT_TIM->LEFT_TIM_V = (uint16_t)std::clamp(vl + pwm_res / 2, pwm_margin, pwm_res-pwm_margin);
LEFT_TIM->LEFT_TIM_W = (uint16_t)std::clamp(wl + pwm_res / 2, pwm_margin, pwm_res-pwm_margin);
LEFT_TIM->LEFT_TIM_U = (uint16_t)std::clamp(ul + pwm_res / 2, pwm_margin_l, pwm_res-pwm_margin_l);
LEFT_TIM->LEFT_TIM_V = (uint16_t)std::clamp(vl + pwm_res / 2, pwm_margin_l, pwm_res-pwm_margin_l);
LEFT_TIM->LEFT_TIM_W = (uint16_t)std::clamp(wl + pwm_res / 2, pwm_margin_l, pwm_res-pwm_margin_l);
// =================================================================
@ -612,9 +616,9 @@ void updateMotors()
int wr = right.rtY.DC_phaC;
/* Apply commands */
RIGHT_TIM->RIGHT_TIM_U = (uint16_t)std::clamp(ur + pwm_res / 2, pwm_margin, pwm_res-pwm_margin);
RIGHT_TIM->RIGHT_TIM_V = (uint16_t)std::clamp(vr + pwm_res / 2, pwm_margin, pwm_res-pwm_margin);
RIGHT_TIM->RIGHT_TIM_W = (uint16_t)std::clamp(wr + pwm_res / 2, pwm_margin, pwm_res-pwm_margin);
RIGHT_TIM->RIGHT_TIM_U = (uint16_t)std::clamp(ur + pwm_res / 2, pwm_margin_r, pwm_res-pwm_margin_r);
RIGHT_TIM->RIGHT_TIM_V = (uint16_t)std::clamp(vr + pwm_res / 2, pwm_margin_r, pwm_res-pwm_margin_r);
RIGHT_TIM->RIGHT_TIM_W = (uint16_t)std::clamp(wr + pwm_res / 2, pwm_margin_r, pwm_res-pwm_margin_r);
// =================================================================
/* Indicate task complete */