Skip to content

Commit 80b5e70

Browse files
committed
Fixed bug introduced in PR and calculate motor current from magnitude of both axes
1 parent 0b6ccb1 commit 80b5e70

File tree

2 files changed

+9
-8
lines changed

2 files changed

+9
-8
lines changed

CHANGELOG

+1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
* Added bm_reset terminal command.
1313
* Added bm support for STM32F30x and STM32L47x.
1414
* App Balance updates. See https://github.com/vedderb/bldc/pull/193
15+
* Motor current now based on magnitude of both axes.
1516

1617
=== FW 5.01 ===
1718
* Fixed PPM bug in previous release.

mcpwm_foc.c

+8-8
Original file line numberDiff line numberDiff line change
@@ -1084,22 +1084,20 @@ bool mcpwm_foc_is_using_encoder(void) {
10841084
float mcpwm_foc_get_tot_current_motor(bool is_second_motor) {
10851085
#ifdef HW_HAS_DUAL_MOTORS
10861086
volatile motor_all_state_t *motor = is_second_motor ? &m_motor_2 : &m_motor_1;
1087-
return SIGN(motor->m_motor_state.vq) * motor->m_motor_state.iq;
1087+
return SIGN(motor->m_motor_state.vq * motor->m_motor_state.iq) * motor->m_motor_state.i_abs;
10881088
#else
10891089
(void)is_second_motor;
1090-
return SIGN(m_motor_1.m_motor_state.vq) * m_motor_1.m_motor_state.iq;
1090+
return SIGN(m_motor_1.m_motor_state.vq * m_motor_1.m_motor_state.iq) * m_motor_1.m_motor_state.i_abs;
10911091
#endif
10921092
}
10931093

10941094
float mcpwm_foc_get_tot_current_filtered_motor(bool is_second_motor) {
10951095
#ifdef HW_HAS_DUAL_MOTORS
10961096
volatile motor_all_state_t *motor = is_second_motor ? &m_motor_2 : &m_motor_1;
1097-
return SIGN(motor->m_motor_state.vq) *
1098-
sqrtf( SQ(motor->m_motor_state.iq_filter) + SQ(motor->m_motor_state.id_filter) );
1097+
return SIGN(motor->m_motor_state.vq * motor->m_motor_state.iq_filter) * motor->m_motor_state.i_abs_filter;
10991098
#else
11001099
(void)is_second_motor;
1101-
return SIGN(m_motor_1.m_motor_state.vq) *
1102-
sqrtf( SQ(m_motor_1.m_motor_state.iq_filter) + SQ(m_motor_1.m_motor_state.id_filter) );
1100+
return SIGN(m_motor_1.m_motor_state.vq * m_motor_1.m_motor_state.iq_filter) * m_motor_1.m_motor_state.i_abs_filter;
11031101
#endif
11041102
}
11051103

@@ -1185,7 +1183,8 @@ float mcpwm_foc_get_rpm_faster(void) {
11851183
* The motor current.
11861184
*/
11871185
float mcpwm_foc_get_tot_current(void) {
1188-
return SIGN(motor_now()->m_motor_state.vq) * motor_now()->m_motor_state.iq;
1186+
volatile motor_all_state_t *motor = motor_now();
1187+
return SIGN(motor->m_motor_state.vq * motor->m_motor_state.iq) * motor->m_motor_state.i_abs;
11891188
}
11901189

11911190
/**
@@ -1197,7 +1196,8 @@ float mcpwm_foc_get_tot_current(void) {
11971196
* The filtered motor current.
11981197
*/
11991198
float mcpwm_foc_get_tot_current_filtered(void) {
1200-
return SIGN(motor_now()->m_motor_state.vq) * motor_now()->m_motor_state.iq_filter;
1199+
volatile motor_all_state_t *motor = motor_now();
1200+
return SIGN(motor->m_motor_state.vq * motor->m_motor_state.iq_filter) * motor->m_motor_state.i_abs_filter;
12011201
}
12021202

12031203
/**

0 commit comments

Comments
 (0)