Skip to content

Commit

Permalink
Added filter for the mapped input current limit
Browse files Browse the repository at this point in the history
  • Loading branch information
vedderb committed Jun 23, 2023
1 parent a380ea8 commit e3d7e86
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 4 deletions.
3 changes: 3 additions & 0 deletions confgenerator.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ int32_t confgenerator_serialize_mcconf(uint8_t *buffer, const mc_configuration *
buffer_append_float32_auto(buffer, conf->l_in_current_max, &ind);
buffer_append_float32_auto(buffer, conf->l_in_current_min, &ind);
buffer_append_float16(buffer, conf->l_in_current_map_start, 10000, &ind);
buffer_append_float16(buffer, conf->l_in_current_map_filter, 10000, &ind);
buffer_append_float32_auto(buffer, conf->l_abs_current_max, &ind);
buffer_append_float32_auto(buffer, conf->l_min_erpm, &ind);
buffer_append_float32_auto(buffer, conf->l_max_erpm, &ind);
Expand Down Expand Up @@ -352,6 +353,7 @@ bool confgenerator_deserialize_mcconf(const uint8_t *buffer, mc_configuration *c
conf->l_in_current_max = buffer_get_float32_auto(buffer, &ind);
conf->l_in_current_min = buffer_get_float32_auto(buffer, &ind);
conf->l_in_current_map_start = buffer_get_float16(buffer, 10000, &ind);
conf->l_in_current_map_filter = buffer_get_float16(buffer, 10000, &ind);
conf->l_abs_current_max = buffer_get_float32_auto(buffer, &ind);
conf->l_min_erpm = buffer_get_float32_auto(buffer, &ind);
conf->l_max_erpm = buffer_get_float32_auto(buffer, &ind);
Expand Down Expand Up @@ -681,6 +683,7 @@ void confgenerator_set_defaults_mcconf(mc_configuration *conf) {
conf->l_in_current_max = MCCONF_L_IN_CURRENT_MAX;
conf->l_in_current_min = MCCONF_L_IN_CURRENT_MIN;
conf->l_in_current_map_start = MCCONF_L_IN_CURRENT_MAP_START;
conf->l_in_current_map_filter = MCCONF_L_IN_CURRENT_MAP_FILTER;
conf->l_abs_current_max = MCCONF_L_MAX_ABS_CURRENT;
conf->l_min_erpm = MCCONF_L_RPM_MIN;
conf->l_max_erpm = MCCONF_L_RPM_MAX;
Expand Down
2 changes: 1 addition & 1 deletion confgenerator.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#include <stdbool.h>

// Constants
#define MCCONF_SIGNATURE 1910543301
#define MCCONF_SIGNATURE 4054209897
#define APPCONF_SIGNATURE 2099347128

// Functions
Expand Down
1 change: 1 addition & 0 deletions datatypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,7 @@ typedef struct {
float l_in_current_max;
float l_in_current_min;
float l_in_current_map_start;
float l_in_current_map_filter;
float l_abs_current_max;
float l_min_erpm;
float l_max_erpm;
Expand Down
9 changes: 6 additions & 3 deletions motor/mc_interface.c
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ typedef struct {
float m_input_voltage_filtered;
float m_input_voltage_filtered_slower;
float m_temp_override;
float m_i_in_filter;

// Backup data counters
uint64_t m_odometer_last;
Expand Down Expand Up @@ -1904,6 +1905,9 @@ void mc_interface_mc_timer_isr(bool is_second_motor) {
abs_current_filtered = current_filtered;
}

// Additional input current filter for the mapped current limit
UTILS_LP_FAST(motor->m_i_in_filter, current_in_filtered, motor->m_conf.l_in_current_map_filter);

if (state == MC_STATE_RUNNING) {
motor->m_cycles_running++;
} else {
Expand Down Expand Up @@ -2436,9 +2440,8 @@ static void update_override_limits(volatile motor_if_state_t *motor, volatile mc
// input current from id and iq.

float lo_max_i_in = l_current_max_tmp;
float i_in = mc_interface_get_tot_current_in();
if (i_in > 0.0 && conf->l_in_current_map_start < 0.98) {
float frac = i_in / conf->lo_in_current_max;
if (motor->m_i_in_filter > 0.0 && conf->l_in_current_map_start < 0.98) {
float frac = motor->m_i_in_filter / conf->lo_in_current_max;
if (frac > conf->l_in_current_map_start) {
lo_max_i_in = utils_map(frac, conf->l_in_current_map_start,
1.0, l_current_max_tmp, 0.0);
Expand Down
3 changes: 3 additions & 0 deletions motor/mcconf_default.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@
#ifndef MCCONF_L_IN_CURRENT_MAP_START
#define MCCONF_L_IN_CURRENT_MAP_START 1.0 // Input current to Q axis current limit map start
#endif
#ifndef MCCONF_L_IN_CURRENT_MAP_FILTER
#define MCCONF_L_IN_CURRENT_MAP_FILTER 0.1 // Input current filter for the mapped limit
#endif
#ifndef MCCONF_L_MAX_ABS_CURRENT
#define MCCONF_L_MAX_ABS_CURRENT 130.0 // The maximum absolute current above which a fault is generated
#endif
Expand Down

0 comments on commit e3d7e86

Please sign in to comment.