First phase filter and offset calibration attempt

This commit is contained in:
Benjamin Vedder 2021-02-28 20:36:02 +01:00
parent 5099d2c7f0
commit 8900c41c34
16 changed files with 820 additions and 402 deletions

View File

@ -1,3 +1,14 @@
=== FW 5.03 <dev> ===
* Fixed inductance measurement bug.
* Speed tracker windup protection.
* Phase filter support.
* Phase voltage offset calibration.
* Better current offset calibration.
* Added power switch commands.
* Synchronize observer state when running in open loop.
* Force oberver state magnitude above 50% of flux linkage. This prevents the motor from getting stuck and 'screaming'.
* Observer global convergence update. Helps tracking the motor through 0 speed.
=== FW 5.02 ===
* IMU calibration improvement.
* Added COMM_GET_MCCONF_TEMP command.

View File

@ -1,5 +1,5 @@
/*
Copyright 2016 - 2019 Benjamin Vedder benjamin@vedder.se
Copyright 2016 - 2021 Benjamin Vedder benjamin@vedder.se
This file is part of the VESC firmware.
@ -1165,8 +1165,8 @@ void conf_general_calc_apply_foc_cc_kp_ki_gain(mc_configuration *mcconf, float t
float bw = 1.0 / (tc * 1e-6);
float kp = l * bw;
float ki = r * bw;
float gain = 1.0e-3 / (lambda * lambda);
// float gain = (0.00001 / r) / (lambda * lambda); // Old method
float gain = 1.0e-3 / SQ(lambda);
// float gain = (0.00001 / r) / SQ(lambda); // Old method
mcconf->foc_current_kp = kp;
mcconf->foc_current_ki = ki;
@ -1519,6 +1519,14 @@ int conf_general_detect_apply_all_foc(float max_power_loss,
mcconf_old->foc_motor_r = r;
mcconf_old->foc_motor_l = l;
mcconf_old->foc_motor_flux_linkage = lambda;
if (mc_interface_temp_motor_filtered() > -10) {
mcconf_old->foc_temp_comp_base_temp = mc_interface_temp_motor_filtered();
#ifdef HW_HAS_PHASE_FILTERS
mcconf_old->foc_temp_comp = true;
#endif
}
conf_general_calc_apply_foc_cc_kp_ki_gain(mcconf_old, 1000);
mc_interface_set_configuration(mcconf_old);
@ -1531,12 +1539,18 @@ int conf_general_detect_apply_all_foc(float max_power_loss,
mcconf_old_second->foc_motor_flux_linkage = linkage_args.linkage;
conf_general_calc_apply_foc_cc_kp_ki_gain(mcconf_old_second, 1000);
mc_interface_select_motor_thread(2);
if (mc_interface_temp_motor_filtered() > -10) {
mcconf_old_second->foc_temp_comp_base_temp = mc_interface_temp_motor_filtered();
#ifdef HW_HAS_PHASE_FILTERS
mcconf_old_second->foc_temp_comp = true;
#endif
}
mc_interface_set_configuration(mcconf_old_second);
mc_interface_select_motor_thread(1);
#endif
// TODO: optionally apply temperature compensation here.
wait_motor_stop(10000);
#ifdef HW_HAS_DUAL_MOTORS

View File

@ -24,7 +24,7 @@
#define FW_VERSION_MAJOR 5
#define FW_VERSION_MINOR 03
// Set to 0 for building a release and iterate during beta test builds
#define FW_TEST_VERSION_NUMBER 2
#define FW_TEST_VERSION_NUMBER 5
#include "datatypes.h"
@ -74,8 +74,8 @@
//#define HW60_IS_MK4
#define HW60_IS_MK5
#define HW_SOURCE "hw_60.c"
#define HW_HEADER "hw_60.h"
//#define HW_SOURCE "hw_60.c"
//#define HW_HEADER "hw_60.h"
//#define HW_SOURCE "hw_r2.c"
//#define HW_HEADER "hw_r2.h"
@ -123,8 +123,8 @@
//#define HW_SOURCE "hw_binar_v1.c"
//#define HW_HEADER "hw_binar_v1.h"
//#define HW_SOURCE "hw_hd60.c"
//#define HW_HEADER "hw_hd60.h"
#define HW_SOURCE "hw_hd60.c"
#define HW_HEADER "hw_hd60.h"
//#define HW_SOURCE "hw_hd75.c"
//#define HW_HEADER "hw_hd75.h"
@ -166,6 +166,9 @@
//#define HW_SOURCE "hw_Little_FOCer.c"
//#define HW_HEADER "hw_Little_FOCer.h"
//#define HW_SOURCE "hw_100_500.c"
//#define HW_HEADER "hw_100_500.h"
#endif
#ifndef HW_SOURCE

View File

@ -20,7 +20,7 @@ int32_t confgenerator_serialize_mcconf(uint8_t *buffer, const mc_configuration *
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);
buffer_append_float32_auto(buffer, conf->l_erpm_start, &ind);
buffer_append_float16(buffer, conf->l_erpm_start, 10000, &ind);
buffer_append_float32_auto(buffer, conf->l_max_erpm_fbrake, &ind);
buffer_append_float32_auto(buffer, conf->l_max_erpm_fbrake_cc, &ind);
buffer_append_float32_auto(buffer, conf->l_min_vin, &ind);
@ -28,23 +28,23 @@ int32_t confgenerator_serialize_mcconf(uint8_t *buffer, const mc_configuration *
buffer_append_float32_auto(buffer, conf->l_battery_cut_start, &ind);
buffer_append_float32_auto(buffer, conf->l_battery_cut_end, &ind);
buffer[ind++] = conf->l_slow_abs_current;
buffer_append_float32_auto(buffer, conf->l_temp_fet_start, &ind);
buffer_append_float32_auto(buffer, conf->l_temp_fet_end, &ind);
buffer_append_float32_auto(buffer, conf->l_temp_motor_start, &ind);
buffer_append_float32_auto(buffer, conf->l_temp_motor_end, &ind);
buffer_append_float32_auto(buffer, conf->l_temp_accel_dec, &ind);
buffer_append_float32_auto(buffer, conf->l_min_duty, &ind);
buffer_append_float32_auto(buffer, conf->l_max_duty, &ind);
buffer_append_float16(buffer, conf->l_temp_fet_start, 10, &ind);
buffer_append_float16(buffer, conf->l_temp_fet_end, 10, &ind);
buffer_append_float16(buffer, conf->l_temp_motor_start, 10, &ind);
buffer_append_float16(buffer, conf->l_temp_motor_end, 10, &ind);
buffer_append_float16(buffer, conf->l_temp_accel_dec, 10000, &ind);
buffer_append_float16(buffer, conf->l_min_duty, 10000, &ind);
buffer_append_float16(buffer, conf->l_max_duty, 10000, &ind);
buffer_append_float32_auto(buffer, conf->l_watt_max, &ind);
buffer_append_float32_auto(buffer, conf->l_watt_min, &ind);
buffer_append_float32_auto(buffer, conf->l_current_max_scale, &ind);
buffer_append_float32_auto(buffer, conf->l_current_min_scale, &ind);
buffer_append_float32_auto(buffer, conf->l_duty_start, &ind);
buffer_append_float16(buffer, conf->l_current_max_scale, 10000, &ind);
buffer_append_float16(buffer, conf->l_current_min_scale, 10000, &ind);
buffer_append_float16(buffer, conf->l_duty_start, 10000, &ind);
buffer_append_float32_auto(buffer, conf->sl_min_erpm, &ind);
buffer_append_float32_auto(buffer, conf->sl_min_erpm_cycle_int_limit, &ind);
buffer_append_float32_auto(buffer, conf->sl_max_fullbreak_current_dir_change, &ind);
buffer_append_float32_auto(buffer, conf->sl_cycle_int_limit, &ind);
buffer_append_float32_auto(buffer, conf->sl_phase_advance_at_br, &ind);
buffer_append_float16(buffer, conf->sl_cycle_int_limit, 10, &ind);
buffer_append_float16(buffer, conf->sl_phase_advance_at_br, 10000, &ind);
buffer_append_float32_auto(buffer, conf->sl_cycle_int_rpm_br, &ind);
buffer_append_float32_auto(buffer, conf->sl_bemf_coupling_k, &ind);
buffer[ind++] = (uint8_t)conf->hall_table[0];
@ -102,7 +102,7 @@ int32_t confgenerator_serialize_mcconf(uint8_t *buffer, const mc_configuration *
buffer_append_float16(buffer, conf->foc_sat_comp, 1000, &ind);
buffer[ind++] = conf->foc_temp_comp;
buffer_append_float16(buffer, conf->foc_temp_comp_base_temp, 100, &ind);
buffer_append_float32_auto(buffer, conf->foc_current_filter_const, &ind);
buffer_append_float16(buffer, conf->foc_current_filter_const, 10000, &ind);
buffer[ind++] = conf->foc_cc_decoupling;
buffer[ind++] = conf->foc_observer_type;
buffer_append_float32_auto(buffer, conf->foc_hfi_voltage_start, &ind);
@ -112,15 +112,27 @@ int32_t confgenerator_serialize_mcconf(uint8_t *buffer, const mc_configuration *
buffer_append_uint16(buffer, conf->foc_hfi_start_samples, &ind);
buffer_append_float32_auto(buffer, conf->foc_hfi_obs_ovr_sec, &ind);
buffer[ind++] = conf->foc_hfi_samples;
buffer[ind++] = conf->foc_offsets_measured;
buffer_append_float32_auto(buffer, conf->foc_offsets_current[0], &ind);
buffer_append_float32_auto(buffer, conf->foc_offsets_current[1], &ind);
buffer_append_float32_auto(buffer, conf->foc_offsets_current[2], &ind);
buffer_append_float16(buffer, conf->foc_offsets_voltage[0], 10000, &ind);
buffer_append_float16(buffer, conf->foc_offsets_voltage[1], 10000, &ind);
buffer_append_float16(buffer, conf->foc_offsets_voltage[2], 10000, &ind);
buffer_append_float16(buffer, conf->foc_offsets_voltage_undriven[0], 10000, &ind);
buffer_append_float16(buffer, conf->foc_offsets_voltage_undriven[1], 10000, &ind);
buffer_append_float16(buffer, conf->foc_offsets_voltage_undriven[2], 10000, &ind);
buffer[ind++] = conf->foc_phase_filter_enable;
buffer_append_float32_auto(buffer, conf->foc_phase_filter_max_erpm, &ind);
buffer_append_int16(buffer, conf->gpd_buffer_notify_left, &ind);
buffer_append_int16(buffer, conf->gpd_buffer_interpol, &ind);
buffer_append_float32_auto(buffer, conf->gpd_current_filter_const, &ind);
buffer_append_float16(buffer, conf->gpd_current_filter_const, 10000, &ind);
buffer_append_float32_auto(buffer, conf->gpd_current_kp, &ind);
buffer_append_float32_auto(buffer, conf->gpd_current_ki, &ind);
buffer_append_float32_auto(buffer, conf->s_pid_kp, &ind);
buffer_append_float32_auto(buffer, conf->s_pid_ki, &ind);
buffer_append_float32_auto(buffer, conf->s_pid_kd, &ind);
buffer_append_float32_auto(buffer, conf->s_pid_kd_filter, &ind);
buffer_append_float16(buffer, conf->s_pid_kd_filter, 10000, &ind);
buffer_append_float32_auto(buffer, conf->s_pid_min_erpm, &ind);
buffer[ind++] = conf->s_pid_allow_braking;
buffer_append_float32_auto(buffer, conf->s_pid_ramp_erpms_s, &ind);
@ -341,7 +353,7 @@ bool confgenerator_deserialize_mcconf(const uint8_t *buffer, mc_configuration *c
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);
conf->l_erpm_start = buffer_get_float32_auto(buffer, &ind);
conf->l_erpm_start = buffer_get_float16(buffer, 10000, &ind);
conf->l_max_erpm_fbrake = buffer_get_float32_auto(buffer, &ind);
conf->l_max_erpm_fbrake_cc = buffer_get_float32_auto(buffer, &ind);
conf->l_min_vin = buffer_get_float32_auto(buffer, &ind);
@ -349,23 +361,23 @@ bool confgenerator_deserialize_mcconf(const uint8_t *buffer, mc_configuration *c
conf->l_battery_cut_start = buffer_get_float32_auto(buffer, &ind);
conf->l_battery_cut_end = buffer_get_float32_auto(buffer, &ind);
conf->l_slow_abs_current = buffer[ind++];
conf->l_temp_fet_start = buffer_get_float32_auto(buffer, &ind);
conf->l_temp_fet_end = buffer_get_float32_auto(buffer, &ind);
conf->l_temp_motor_start = buffer_get_float32_auto(buffer, &ind);
conf->l_temp_motor_end = buffer_get_float32_auto(buffer, &ind);
conf->l_temp_accel_dec = buffer_get_float32_auto(buffer, &ind);
conf->l_min_duty = buffer_get_float32_auto(buffer, &ind);
conf->l_max_duty = buffer_get_float32_auto(buffer, &ind);
conf->l_temp_fet_start = buffer_get_float16(buffer, 10, &ind);
conf->l_temp_fet_end = buffer_get_float16(buffer, 10, &ind);
conf->l_temp_motor_start = buffer_get_float16(buffer, 10, &ind);
conf->l_temp_motor_end = buffer_get_float16(buffer, 10, &ind);
conf->l_temp_accel_dec = buffer_get_float16(buffer, 10000, &ind);
conf->l_min_duty = buffer_get_float16(buffer, 10000, &ind);
conf->l_max_duty = buffer_get_float16(buffer, 10000, &ind);
conf->l_watt_max = buffer_get_float32_auto(buffer, &ind);
conf->l_watt_min = buffer_get_float32_auto(buffer, &ind);
conf->l_current_max_scale = buffer_get_float32_auto(buffer, &ind);
conf->l_current_min_scale = buffer_get_float32_auto(buffer, &ind);
conf->l_duty_start = buffer_get_float32_auto(buffer, &ind);
conf->l_current_max_scale = buffer_get_float16(buffer, 10000, &ind);
conf->l_current_min_scale = buffer_get_float16(buffer, 10000, &ind);
conf->l_duty_start = buffer_get_float16(buffer, 10000, &ind);
conf->sl_min_erpm = buffer_get_float32_auto(buffer, &ind);
conf->sl_min_erpm_cycle_int_limit = buffer_get_float32_auto(buffer, &ind);
conf->sl_max_fullbreak_current_dir_change = buffer_get_float32_auto(buffer, &ind);
conf->sl_cycle_int_limit = buffer_get_float32_auto(buffer, &ind);
conf->sl_phase_advance_at_br = buffer_get_float32_auto(buffer, &ind);
conf->sl_cycle_int_limit = buffer_get_float16(buffer, 10, &ind);
conf->sl_phase_advance_at_br = buffer_get_float16(buffer, 10000, &ind);
conf->sl_cycle_int_rpm_br = buffer_get_float32_auto(buffer, &ind);
conf->sl_bemf_coupling_k = buffer_get_float32_auto(buffer, &ind);
conf->hall_table[0] = (int8_t)buffer[ind++];
@ -423,7 +435,7 @@ bool confgenerator_deserialize_mcconf(const uint8_t *buffer, mc_configuration *c
conf->foc_sat_comp = buffer_get_float16(buffer, 1000, &ind);
conf->foc_temp_comp = buffer[ind++];
conf->foc_temp_comp_base_temp = buffer_get_float16(buffer, 100, &ind);
conf->foc_current_filter_const = buffer_get_float32_auto(buffer, &ind);
conf->foc_current_filter_const = buffer_get_float16(buffer, 10000, &ind);
conf->foc_cc_decoupling = buffer[ind++];
conf->foc_observer_type = buffer[ind++];
conf->foc_hfi_voltage_start = buffer_get_float32_auto(buffer, &ind);
@ -433,15 +445,27 @@ bool confgenerator_deserialize_mcconf(const uint8_t *buffer, mc_configuration *c
conf->foc_hfi_start_samples = buffer_get_uint16(buffer, &ind);
conf->foc_hfi_obs_ovr_sec = buffer_get_float32_auto(buffer, &ind);
conf->foc_hfi_samples = buffer[ind++];
conf->foc_offsets_measured = buffer[ind++];
conf->foc_offsets_current[0] = buffer_get_float32_auto(buffer, &ind);
conf->foc_offsets_current[1] = buffer_get_float32_auto(buffer, &ind);
conf->foc_offsets_current[2] = buffer_get_float32_auto(buffer, &ind);
conf->foc_offsets_voltage[0] = buffer_get_float16(buffer, 10000, &ind);
conf->foc_offsets_voltage[1] = buffer_get_float16(buffer, 10000, &ind);
conf->foc_offsets_voltage[2] = buffer_get_float16(buffer, 10000, &ind);
conf->foc_offsets_voltage_undriven[0] = buffer_get_float16(buffer, 10000, &ind);
conf->foc_offsets_voltage_undriven[1] = buffer_get_float16(buffer, 10000, &ind);
conf->foc_offsets_voltage_undriven[2] = buffer_get_float16(buffer, 10000, &ind);
conf->foc_phase_filter_enable = buffer[ind++];
conf->foc_phase_filter_max_erpm = buffer_get_float32_auto(buffer, &ind);
conf->gpd_buffer_notify_left = buffer_get_int16(buffer, &ind);
conf->gpd_buffer_interpol = buffer_get_int16(buffer, &ind);
conf->gpd_current_filter_const = buffer_get_float32_auto(buffer, &ind);
conf->gpd_current_filter_const = buffer_get_float16(buffer, 10000, &ind);
conf->gpd_current_kp = buffer_get_float32_auto(buffer, &ind);
conf->gpd_current_ki = buffer_get_float32_auto(buffer, &ind);
conf->s_pid_kp = buffer_get_float32_auto(buffer, &ind);
conf->s_pid_ki = buffer_get_float32_auto(buffer, &ind);
conf->s_pid_kd = buffer_get_float32_auto(buffer, &ind);
conf->s_pid_kd_filter = buffer_get_float32_auto(buffer, &ind);
conf->s_pid_kd_filter = buffer_get_float16(buffer, 10000, &ind);
conf->s_pid_min_erpm = buffer_get_float32_auto(buffer, &ind);
conf->s_pid_allow_braking = buffer[ind++];
conf->s_pid_ramp_erpms_s = buffer_get_float32_auto(buffer, &ind);
@ -750,6 +774,18 @@ void confgenerator_set_defaults_mcconf(mc_configuration *conf) {
conf->foc_hfi_start_samples = MCCONF_FOC_HFI_START_SAMPLES;
conf->foc_hfi_obs_ovr_sec = MCCONF_FOC_HFI_OBS_OVR_SEC;
conf->foc_hfi_samples = MCCONF_FOC_HFI_SAMPLES;
conf->foc_offsets_measured = MCCONF_FOC_OFFSETS_MEASURED;
conf->foc_offsets_current[0] = MCCONF_FOC_OFFSETS_CURRENT_0;
conf->foc_offsets_current[1] = MCCONF_FOC_OFFSETS_CURRENT_1;
conf->foc_offsets_current[2] = MCCONF_FOC_OFFSETS_CURRENT_2;
conf->foc_offsets_voltage[0] = MCCONF_FOC_OFFSETS_VOLTAGE_0;
conf->foc_offsets_voltage[1] = MCCONF_FOC_OFFSETS_VOLTAGE_1;
conf->foc_offsets_voltage[2] = MCCONF_FOC_OFFSETS_VOLTAGE_2;
conf->foc_offsets_voltage_undriven[0] = MCCONF_FOC_OFFSETS_VOLTAGE_UNDRIVEN_0;
conf->foc_offsets_voltage_undriven[1] = MCCONF_FOC_OFFSETS_VOLTAGE_UNDRIVEN_1;
conf->foc_offsets_voltage_undriven[2] = MCCONF_FOC_OFFSETS_VOLTAGE_UNDRIVEN_2;
conf->foc_phase_filter_enable = MCCONF_FOC_PHASE_FILTER_ENABLE;
conf->foc_phase_filter_max_erpm = MCCONF_FOC_PHASE_FILTER_MAX_ERPM;
conf->gpd_buffer_notify_left = MCCONF_GPD_BUFFER_NOTIFY_LEFT;
conf->gpd_buffer_interpol = MCCONF_GPD_BUFFER_INTERPOL;
conf->gpd_current_filter_const = MCCONF_GPD_CURRENT_FILTER_CONST;

View File

@ -8,7 +8,7 @@
#include <stdbool.h>
// Constants
#define MCCONF_SIGNATURE 2211848314
#define MCCONF_SIGNATURE 4091050000
#define APPCONF_SIGNATURE 3264926020
// Functions

View File

@ -25,6 +25,7 @@
// HW properties
#define HW_HAS_3_SHUNTS
#define INVERTED_SHUNT_POLARITY
#define HW_HAS_PHASE_FILTERS
// Macros
#define LED_GREEN_GPIO GPIOB

View File

@ -59,6 +59,7 @@
#define CURRENT_FILTER_OFF() palClearPad(GPIOD, 2)
#ifdef HW60_IS_MK5
#define HW_HAS_PHASE_FILTERS
#define PHASE_FILTER_GPIO GPIOC
#define PHASE_FILTER_PIN 13
#define PHASE_FILTER_ON() palSetPad(PHASE_FILTER_GPIO, PHASE_FILTER_PIN)

View File

@ -31,7 +31,7 @@
// HW properties
#define HW_HAS_3_SHUNTS
#define HW_HAS_PHASE_SHUNTS
//#define HW_HAS_PHASE_FILTERS
#define HW_HAS_PHASE_FILTERS
// Macros
#ifdef HW75_300_VEDDER_FIRST_PCB

View File

@ -27,6 +27,7 @@
// HW properties
#define HW_HAS_DRV8323S
#define HW_HAS_3_SHUNTS
#define HW_HAS_PHASE_FILTERS
// Macros
#define ENABLE_GATE() palSetPad(GPIOB, 5)

View File

@ -51,7 +51,7 @@
// Global variables
volatile uint16_t ADC_Value[HW_ADC_CHANNELS + HW_ADC_CHANNELS_EXTRA];
volatile int ADC_curr_norm_value[6];
volatile float ADC_curr_norm_value[6];
typedef struct {
volatile mc_configuration m_conf;
@ -2192,9 +2192,9 @@ static void run_timer_tasks(volatile motor_if_state_t *motor) {
}
// TODO: Implement for BLDC and GPDRIVE
if(motor->m_conf.motor_type == MOTOR_TYPE_FOC) {
int curr0_offset;
int curr1_offset;
int curr2_offset;
float curr0_offset;
float curr1_offset;
float curr2_offset;
#ifdef HW_HAS_DUAL_MOTORS
mcpwm_foc_get_current_offsets(&curr0_offset, &curr1_offset, &curr2_offset, motor == &m_motor_2);
@ -2208,14 +2208,14 @@ static void run_timer_tasks(volatile motor_if_state_t *motor) {
#define MIDDLE_ADC 2048
#endif
if (abs(curr0_offset - MIDDLE_ADC) > HW_MAX_CURRENT_OFFSET) {
if (fabsf(curr0_offset - MIDDLE_ADC) > HW_MAX_CURRENT_OFFSET) {
mc_interface_fault_stop(FAULT_CODE_HIGH_OFFSET_CURRENT_SENSOR_1, !is_motor_1, false);
}
if (abs(curr1_offset - MIDDLE_ADC) > HW_MAX_CURRENT_OFFSET) {
if (fabsf(curr1_offset - MIDDLE_ADC) > HW_MAX_CURRENT_OFFSET) {
mc_interface_fault_stop(FAULT_CODE_HIGH_OFFSET_CURRENT_SENSOR_2, !is_motor_1, false);
}
#ifdef HW_HAS_3_SHUNTS
if (abs(curr2_offset - MIDDLE_ADC) > HW_MAX_CURRENT_OFFSET) {
if (fabsf(curr2_offset - MIDDLE_ADC) > HW_MAX_CURRENT_OFFSET) {
mc_interface_fault_stop(FAULT_CODE_HIGH_OFFSET_CURRENT_SENSOR_3, !is_motor_1, false);
}
#endif

View File

@ -102,7 +102,7 @@ void mc_interface_adc_inj_int_handler(void);
// External variables
extern volatile uint16_t ADC_Value[];
extern volatile int ADC_curr_norm_value[];
extern volatile float ADC_curr_norm_value[];
// Common fixed parameters
#ifndef HW_DEAD_TIME_NSEC

View File

@ -137,7 +137,7 @@
#define MCCONF_S_PID_ALLOW_BRAKING true // Allow braking in speed control mode
#endif
#ifndef MCCONF_S_PID_RAMP_ERPMS_S
#define MCCONF_S_PID_RAMP_ERPMS_S -1.0 // Default Speed Input Ramp
#define MCCONF_S_PID_RAMP_ERPMS_S 25000.0 // Speed input ramping, in ERPM/s
#endif
// Position PID parameters
@ -377,6 +377,42 @@
#ifndef MCCONF_FOC_HFI_SAMPLES
#define MCCONF_FOC_HFI_SAMPLES HFI_SAMPLES_16 // Samples per motor revolution for HFI
#endif
#ifndef MCCONF_FOC_OFFSETS_MEASURED
#define MCCONF_FOC_OFFSETS_MEASURED false // Offsets have been measured
#endif
#ifndef MCCONF_FOC_OFFSETS_CURRENT_0
#define MCCONF_FOC_OFFSETS_CURRENT_0 2048.0 // Current 0 offset
#endif
#ifndef MCCONF_FOC_OFFSETS_CURRENT_1
#define MCCONF_FOC_OFFSETS_CURRENT_1 2048.0 // Current 1 offset
#endif
#ifndef MCCONF_FOC_OFFSETS_CURRENT_2
#define MCCONF_FOC_OFFSETS_CURRENT_2 2048.0 // Current 2 offset
#endif
#ifndef MCCONF_FOC_OFFSETS_VOLTAGE_0
#define MCCONF_FOC_OFFSETS_VOLTAGE_0 0.0 // Voltage 0 offset
#endif
#ifndef MCCONF_FOC_OFFSETS_VOLTAGE_1
#define MCCONF_FOC_OFFSETS_VOLTAGE_1 0.0 // Voltage 1 offset
#endif
#ifndef MCCONF_FOC_OFFSETS_VOLTAGE_2
#define MCCONF_FOC_OFFSETS_VOLTAGE_2 0.0 // Voltage 2 offset
#endif
#ifndef MCCONF_FOC_OFFSETS_VOLTAGE_UNDRIVEN_0
#define MCCONF_FOC_OFFSETS_VOLTAGE_UNDRIVEN_0 0.0 // Voltage undriven 0 offset
#endif
#ifndef MCCONF_FOC_OFFSETS_VOLTAGE_UNDRIVEN_1
#define MCCONF_FOC_OFFSETS_VOLTAGE_UNDRIVEN_1 0.0 // Voltage undriven 1 offset
#endif
#ifndef MCCONF_FOC_OFFSETS_VOLTAGE_UNDRIVEN_2
#define MCCONF_FOC_OFFSETS_VOLTAGE_UNDRIVEN_2 0.0 // Voltage undriven 2 offset
#endif
#ifndef MCCONF_FOC_PHASE_FILTER_ENABLE
#define MCCONF_FOC_PHASE_FILTER_ENABLE true // Use phase voltage filters when available
#endif
#ifndef MCCONF_FOC_PHASE_FILTER_MAX_ERPM
#define MCCONF_FOC_PHASE_FILTER_MAX_ERPM 10000.0 // Use phase filter up to this ERPM
#endif
// GPD
#ifndef MCCONF_GPD_BUFFER_NOTIFY_LEFT

File diff suppressed because it is too large Load Diff

View File

@ -79,17 +79,28 @@ float mcpwm_foc_measure_inductance(float duty, int samples, float *curr, float *
float mcpwm_foc_measure_inductance_current(float curr_goal, int samples, float *curr, float *ld_lq_diff);
bool mcpwm_foc_measure_res_ind(float *res, float *ind);
bool mcpwm_foc_hall_detect(float current, uint8_t *hall_table);
void mcpwm_foc_dc_cal(void);
void mcpwm_foc_print_state(void);
float mcpwm_foc_get_last_adc_isr_duration(void);
void mcpwm_foc_get_current_offsets(
volatile int *curr0_offset,
volatile int *curr1_offset,
volatile int *curr2_offset,
volatile float *curr0_offset,
volatile float *curr1_offset,
volatile float *curr2_offset,
bool is_second_motor);
void mcpwm_foc_set_current_offsets(
volatile int curr0_offset,
volatile int curr1_offset,
volatile int curr2_offset);
volatile float curr0_offset,
volatile float curr1_offset,
volatile float curr2_offset);
void mcpwm_foc_get_voltage_offsets(
float *v0_offset,
float *v1_offset,
float *v2_offset,
bool is_second_motor);
void mcpwm_foc_get_voltage_offsets_undriven(
float *v0_offset,
float *v1_offset,
float *v2_offset,
bool is_second_motor);
float mcpwm_foc_get_ts(void);
bool mcpwm_foc_is_using_encoder(void);

View File

@ -1,5 +1,5 @@
/*
Copyright 2016 - 2020 Benjamin Vedder benjamin@vedder.se
Copyright 2016 - 2021 Benjamin Vedder benjamin@vedder.se
This file is part of the VESC firmware.
@ -527,6 +527,12 @@ void terminal_process_string(char *str) {
} else if (strcmp(argv[0], "foc_state") == 0) {
mcpwm_foc_print_state();
commands_printf(" ");
} else if (strcmp(argv[0], "foc_dc_cal") == 0) {
commands_printf("Performing DC offset calibration...");
mcpwm_foc_dc_cal();
conf_general_store_mc_configuration((mc_configuration*)mc_interface_get_configuration(),
mc_interface_get_motor_thread() == 2);
commands_printf("Done!\n");
} else if (strcmp(argv[0], "hw_status") == 0) {
commands_printf("Firmware: %d.%d", FW_VERSION_MAJOR, FW_VERSION_MINOR);
#ifdef HW_NAME
@ -538,15 +544,31 @@ void terminal_process_string(char *str) {
STM32_UUID_8[8], STM32_UUID_8[9], STM32_UUID_8[10], STM32_UUID_8[11]);
commands_printf("Permanent NRF found: %s", conf_general_permanent_nrf_found ? "Yes" : "No");
int curr0_offset;
int curr1_offset;
int curr2_offset;
float curr0_offset;
float curr1_offset;
float curr2_offset;
mcpwm_foc_get_current_offsets(&curr0_offset, &curr1_offset, &curr2_offset,
mc_interface_get_motor_thread() == 2);
commands_printf("FOC Current Offsets: %d %d %d",
curr0_offset, curr1_offset, curr2_offset);
commands_printf("FOC Current Offsets: %.2f %.2f %.2f",
(double)curr0_offset, (double)curr1_offset, (double)curr2_offset);
float v0_offset;
float v1_offset;
float v2_offset;
mcpwm_foc_get_voltage_offsets(&v0_offset, &v1_offset, &v2_offset,
mc_interface_get_motor_thread() == 2);
commands_printf("FOC Voltage Offsets: %.4f %.4f %.4f",
(double)v0_offset, (double)v1_offset, (double)v2_offset);
mcpwm_foc_get_voltage_offsets_undriven(&v0_offset, &v1_offset, &v2_offset,
mc_interface_get_motor_thread() == 2);
commands_printf("FOC Voltage Offsets Undriven: %.4f %.4f %.4f",
(double)v0_offset, (double)v1_offset, (double)v2_offset);
#ifdef COMM_USE_USB
commands_printf("USB config events: %d", comm_usb_serial_configured_cnt());
@ -1134,6 +1156,9 @@ void terminal_process_string(char *str) {
commands_printf("foc_state");
commands_printf(" Print some FOC state variables.");
commands_printf("foc_dc_cal");
commands_printf(" Calibrate current and voltage DC offsets.");
commands_printf("hw_status");
commands_printf(" Print some hardware status information.");

View File

@ -63,9 +63,9 @@ typedef struct{
}virtual_motor_t;
static volatile virtual_motor_t virtual_motor;
static volatile int m_curr0_offset_backup;
static volatile int m_curr1_offset_backup;
static volatile int m_curr2_offset_backup;
static volatile float m_curr0_offset_backup;
static volatile float m_curr1_offset_backup;
static volatile float m_curr2_offset_backup;
static volatile mc_configuration *m_conf;
//private functions