diff --git a/CHANGELOG b/CHANGELOG index c780fce5..0ac9ee0c 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,3 +1,9 @@ +=== FW 3.53 === +* Limit foc_current_filter_const range to prevent damage due to bad configuration. +* Set default NRF speed to 1 Mbit/s. +* Use lower switching frequency when detecting resistance to reduce deat-time distortion. +* Don't enable temperature compensation in auto detection by default. + === FW 3.52 === * Added support for second revision of HW75/300 with separate UART for NRF51. * Added COMM_TERMINAL_CMD_SYNC, which does not drop commands when busy. diff --git a/Makefile b/Makefile index 57806265..67ff7de7 100644 --- a/Makefile +++ b/Makefile @@ -109,6 +109,7 @@ include applications/applications.mk include nrf/nrf.mk include libcanard/canard.mk include imu/imu.mk +#include blackmagic/blackmagic.mk # Define linker script file here LDSCRIPT= ld_eeprom_emu.ld @@ -157,7 +158,8 @@ CSRC = $(STARTUPSRC) \ $(APPSRC) \ $(NRFSRC) \ $(CANARDSRC) \ - $(IMUSRC) + $(IMUSRC) \ +# $(BLACKMAGICSRC) # C++ sources that can be compiled in ARM or THUMB mode depending on the global # setting. @@ -196,7 +198,8 @@ INCDIR = $(STARTUPINC) $(KERNINC) $(PORTINC) $(OSALINC) \ $(APPINC) \ $(NRFINC) \ $(CANARDINC) \ - $(IMUINC) + $(IMUINC) \ +# $(BLACKMAGICINC) # # Project, sources and paths diff --git a/appconf/appconf_default.h b/appconf/appconf_default.h index 4ac7f29d..1a4676d2 100644 --- a/appconf/appconf_default.h +++ b/appconf/appconf_default.h @@ -218,7 +218,7 @@ // NRF app #ifndef APPCONF_NRF_SPEED -#define APPCONF_NRF_SPEED NRF_SPEED_2M +#define APPCONF_NRF_SPEED NRF_SPEED_1M #endif #ifndef APPCONF_NRF_POWER #define APPCONF_NRF_POWER NRF_POWER_0DBM diff --git a/build_all/410_o_411_o_412/VESC_0005ohm.bin b/build_all/410_o_411_o_412/VESC_0005ohm.bin index c3e78f68..b82872c2 100755 Binary files a/build_all/410_o_411_o_412/VESC_0005ohm.bin and b/build_all/410_o_411_o_412/VESC_0005ohm.bin differ diff --git a/build_all/410_o_411_o_412/VESC_default.bin b/build_all/410_o_411_o_412/VESC_default.bin index 3387916a..07698e32 100755 Binary files a/build_all/410_o_411_o_412/VESC_default.bin and b/build_all/410_o_411_o_412/VESC_default.bin differ diff --git a/build_all/410_o_411_o_412/VESC_default_no_hw_limits.bin b/build_all/410_o_411_o_412/VESC_default_no_hw_limits.bin index eb230d3d..2dda4cad 100755 Binary files a/build_all/410_o_411_o_412/VESC_default_no_hw_limits.bin and b/build_all/410_o_411_o_412/VESC_default_no_hw_limits.bin differ diff --git a/build_all/410_o_411_o_412/VESC_servoout.bin b/build_all/410_o_411_o_412/VESC_servoout.bin index fe060278..b9e2672d 100755 Binary files a/build_all/410_o_411_o_412/VESC_servoout.bin and b/build_all/410_o_411_o_412/VESC_servoout.bin differ diff --git a/build_all/410_o_411_o_412/VESC_ws2811.bin b/build_all/410_o_411_o_412/VESC_ws2811.bin index 9ba0fae1..eb7e6041 100755 Binary files a/build_all/410_o_411_o_412/VESC_ws2811.bin and b/build_all/410_o_411_o_412/VESC_ws2811.bin differ diff --git a/build_all/46_o_47/VESC_0005ohm.bin b/build_all/46_o_47/VESC_0005ohm.bin index 4543768e..7b875913 100755 Binary files a/build_all/46_o_47/VESC_0005ohm.bin and b/build_all/46_o_47/VESC_0005ohm.bin differ diff --git a/build_all/46_o_47/VESC_33k.bin b/build_all/46_o_47/VESC_33k.bin index d8c43fae..41af8c94 100755 Binary files a/build_all/46_o_47/VESC_33k.bin and b/build_all/46_o_47/VESC_33k.bin differ diff --git a/build_all/46_o_47/VESC_default.bin b/build_all/46_o_47/VESC_default.bin index 24b1cc20..95939ec5 100755 Binary files a/build_all/46_o_47/VESC_default.bin and b/build_all/46_o_47/VESC_default.bin differ diff --git a/build_all/46_o_47/VESC_servoout.bin b/build_all/46_o_47/VESC_servoout.bin index ac0925f1..879f4e40 100755 Binary files a/build_all/46_o_47/VESC_servoout.bin and b/build_all/46_o_47/VESC_servoout.bin differ diff --git a/build_all/46_o_47/VESC_ws2811.bin b/build_all/46_o_47/VESC_ws2811.bin index 3049937b..ba3c465b 100755 Binary files a/build_all/46_o_47/VESC_ws2811.bin and b/build_all/46_o_47/VESC_ws2811.bin differ diff --git a/build_all/46_o_47/VESC_ws2811_33k.bin b/build_all/46_o_47/VESC_ws2811_33k.bin index f3e93892..e4d2af88 100755 Binary files a/build_all/46_o_47/VESC_ws2811_33k.bin and b/build_all/46_o_47/VESC_ws2811_33k.bin differ diff --git a/build_all/48/VESC_0005ohm.bin b/build_all/48/VESC_0005ohm.bin index ca33aa10..02cf5c60 100755 Binary files a/build_all/48/VESC_0005ohm.bin and b/build_all/48/VESC_0005ohm.bin differ diff --git a/build_all/48/VESC_default.bin b/build_all/48/VESC_default.bin index 3cfb84b8..9f2b5ce9 100755 Binary files a/build_all/48/VESC_default.bin and b/build_all/48/VESC_default.bin differ diff --git a/build_all/48/VESC_servoout.bin b/build_all/48/VESC_servoout.bin index 240ed186..2c581b5c 100755 Binary files a/build_all/48/VESC_servoout.bin and b/build_all/48/VESC_servoout.bin differ diff --git a/build_all/48/VESC_ws2811.bin b/build_all/48/VESC_ws2811.bin index 8474ec35..e4e047a0 100755 Binary files a/build_all/48/VESC_ws2811.bin and b/build_all/48/VESC_ws2811.bin differ diff --git a/build_all/60/VESC_default.bin b/build_all/60/VESC_default.bin index aa50c19c..3b9dfa88 100755 Binary files a/build_all/60/VESC_default.bin and b/build_all/60/VESC_default.bin differ diff --git a/build_all/60/VESC_default_no_hw_limits.bin b/build_all/60/VESC_default_no_hw_limits.bin index 6bfec917..da8e1740 100755 Binary files a/build_all/60/VESC_default_no_hw_limits.bin and b/build_all/60/VESC_default_no_hw_limits.bin differ diff --git a/build_all/60/VESC_servoout.bin b/build_all/60/VESC_servoout.bin index 36f3cfed..a7f44fff 100755 Binary files a/build_all/60/VESC_servoout.bin and b/build_all/60/VESC_servoout.bin differ diff --git a/build_all/60/VESC_ws2811.bin b/build_all/60/VESC_ws2811.bin index a30f2ee0..c33a2cb0 100755 Binary files a/build_all/60/VESC_ws2811.bin and b/build_all/60/VESC_ws2811.bin differ diff --git a/build_all/75_300/VESC_default.bin b/build_all/75_300/VESC_default.bin index 2bc37b4c..29eb8a60 100755 Binary files a/build_all/75_300/VESC_default.bin and b/build_all/75_300/VESC_default.bin differ diff --git a/build_all/75_300/VESC_default_no_hw_limits.bin b/build_all/75_300/VESC_default_no_hw_limits.bin index 823c6af2..352ffed1 100755 Binary files a/build_all/75_300/VESC_default_no_hw_limits.bin and b/build_all/75_300/VESC_default_no_hw_limits.bin differ diff --git a/build_all/75_300/VESC_servoout.bin b/build_all/75_300/VESC_servoout.bin index 51a1e613..653608da 100755 Binary files a/build_all/75_300/VESC_servoout.bin and b/build_all/75_300/VESC_servoout.bin differ diff --git a/build_all/75_300/VESC_ws2811.bin b/build_all/75_300/VESC_ws2811.bin index 08733223..756c16dc 100755 Binary files a/build_all/75_300/VESC_ws2811.bin and b/build_all/75_300/VESC_ws2811.bin differ diff --git a/build_all/75_300_R2/VESC_default.bin b/build_all/75_300_R2/VESC_default.bin index 854ab315..4c363583 100755 Binary files a/build_all/75_300_R2/VESC_default.bin and b/build_all/75_300_R2/VESC_default.bin differ diff --git a/build_all/75_300_R2/VESC_default_no_hw_limits.bin b/build_all/75_300_R2/VESC_default_no_hw_limits.bin index 63a8c53c..88829b2b 100755 Binary files a/build_all/75_300_R2/VESC_default_no_hw_limits.bin and b/build_all/75_300_R2/VESC_default_no_hw_limits.bin differ diff --git a/build_all/75_300_R2/VESC_servoout.bin b/build_all/75_300_R2/VESC_servoout.bin index 910a0e53..c8513baf 100755 Binary files a/build_all/75_300_R2/VESC_servoout.bin and b/build_all/75_300_R2/VESC_servoout.bin differ diff --git a/build_all/75_300_R2/VESC_ws2811.bin b/build_all/75_300_R2/VESC_ws2811.bin index 47451c3f..6c7048b2 100755 Binary files a/build_all/75_300_R2/VESC_ws2811.bin and b/build_all/75_300_R2/VESC_ws2811.bin differ diff --git a/build_all/DAS_RS/VESC_default.bin b/build_all/DAS_RS/VESC_default.bin index 47523a47..28ed3b06 100755 Binary files a/build_all/DAS_RS/VESC_default.bin and b/build_all/DAS_RS/VESC_default.bin differ diff --git a/build_all/PALTA/VESC_default.bin b/build_all/PALTA/VESC_default.bin index 5f42260b..6ffaa592 100755 Binary files a/build_all/PALTA/VESC_default.bin and b/build_all/PALTA/VESC_default.bin differ diff --git a/commands.c b/commands.c index f956789e..8db62780 100644 --- a/commands.c +++ b/commands.c @@ -1078,6 +1078,9 @@ void commands_apply_mcconf_hw_limits(mc_configuration *mcconf) { utils_truncate_number(&mcconf->l_temp_fet_start, HW_LIM_TEMP_FET); utils_truncate_number(&mcconf->l_temp_fet_end, HW_LIM_TEMP_FET); #endif +#ifdef HW_FOC_CURRENT_FILTER_LIM + utils_truncate_number(&mcconf->foc_current_filter_const, HW_FOC_CURRENT_FILTER_LIM); +#endif #endif } diff --git a/conf_general.c b/conf_general.c index 57e0fbee..af021431 100644 --- a/conf_general.c +++ b/conf_general.c @@ -912,6 +912,7 @@ int conf_general_detect_apply_all_foc(float max_power_loss, mcconf.motor_type = MOTOR_TYPE_FOC; mcconf.foc_sensor_mode = FOC_SENSOR_MODE_SENSORLESS; + mcconf.foc_f_sw = 10000.0; // Lower f_sw => less dead-time distortion mcconf.foc_current_kp = 0.0005; mcconf.foc_current_ki = 1.0; mcconf.l_current_max = MCCONF_L_CURRENT_MAX; @@ -975,6 +976,12 @@ int conf_general_detect_apply_all_foc(float max_power_loss, float i_max = sqrtf(max_power_loss / r); utils_truncate_number(&i_max, HW_LIM_CURRENT); + // Increase switching frequency for flux linkage measurement + // as dead-time distortion has less effect at higher modulation. + // Having a smooth rotation is more important. + mcconf.foc_f_sw = 20000.0; + mc_interface_set_configuration(&mcconf); + float lambda = 0.0; int res = conf_general_measure_flux_linkage_openloop(i_max / 2.5, 0.3, 1800, r, &lambda); @@ -1005,12 +1012,14 @@ int conf_general_detect_apply_all_foc(float max_power_loss, mcconf_old.foc_observer_gain = gain * 1e6; // Temperature compensation - if (mc_interface_temp_motor_filtered() > 0.0) { - mcconf_old.foc_temp_comp = true; - mcconf_old.foc_temp_comp_base_temp = mc_interface_temp_motor_filtered(); - } else { - mcconf_old.foc_temp_comp = false; - } + // Skip temperature compensation for now, as it seems to make + // things worse on some setups. +// if (mc_interface_temp_motor_filtered() > 0.0) { +// mcconf_old.foc_temp_comp = true; +// mcconf_old.foc_temp_comp_base_temp = mc_interface_temp_motor_filtered(); +// } else { +// mcconf_old.foc_temp_comp = false; +// } } else { result = -10; } diff --git a/conf_general.h b/conf_general.h index 8f551d5e..80950266 100644 --- a/conf_general.h +++ b/conf_general.h @@ -22,7 +22,7 @@ // Firmware version #define FW_VERSION_MAJOR 3 -#define FW_VERSION_MINOR 52 +#define FW_VERSION_MINOR 53 #include "datatypes.h" @@ -138,6 +138,7 @@ */ //#define APP_CUSTOM_TO_USE "app_rotary_led.c" //#define APPCONF_APP_TO_USE APP_CUSTOM +//#define MCCONF_FOC_F_SW 5000 /* * Enable CAN-bus diff --git a/hwconf/hw.h b/hwconf/hw.h index 1431cea1..9be9d9ab 100644 --- a/hwconf/hw.h +++ b/hwconf/hw.h @@ -175,6 +175,10 @@ #define HW_LIM_FOC_CTRL_LOOP_FREQ 3000.0, 30000.0 #endif +#ifndef HW_FOC_CURRENT_FILTER_LIM +#define HW_FOC_CURRENT_FILTER_LIM 0.05, 1.0 +#endif + // Functions void hw_init_gpio(void); void hw_setup_adc_channels(void); diff --git a/main.c b/main.c index 7e201b75..6d37b3bf 100644 --- a/main.c +++ b/main.c @@ -1,5 +1,5 @@ /* - Copyright 2016 Benjamin Vedder benjamin@vedder.se + Copyright 2016 - 2019 Benjamin Vedder benjamin@vedder.se This file is part of the VESC firmware. @@ -51,7 +51,8 @@ #include "imu.h" /* - * Timers used: + * HW resources used: + * * TIM1: mcpwm * TIM5: timer * TIM8: mcpwm @@ -68,8 +69,6 @@ */ // Private variables - - static THD_WORKING_AREA(periodic_thread_wa, 1024); static THD_WORKING_AREA(timer_thread_wa, 128); @@ -106,20 +105,20 @@ static THD_FUNCTION(periodic_thread, arg) { disp_pos_mode display_mode = commands_get_disp_pos_mode(); switch (display_mode) { - case DISP_POS_MODE_ENCODER: - commands_send_rotor_pos(encoder_read_deg()); - break; + case DISP_POS_MODE_ENCODER: + commands_send_rotor_pos(encoder_read_deg()); + break; - case DISP_POS_MODE_PID_POS: - commands_send_rotor_pos(mc_interface_get_pid_pos_now()); - break; + case DISP_POS_MODE_PID_POS: + commands_send_rotor_pos(mc_interface_get_pid_pos_now()); + break; - case DISP_POS_MODE_PID_POS_ERROR: - commands_send_rotor_pos(utils_angle_difference(mc_interface_get_pid_pos_set(), mc_interface_get_pid_pos_now())); - break; + case DISP_POS_MODE_PID_POS_ERROR: + commands_send_rotor_pos(utils_angle_difference(mc_interface_get_pid_pos_set(), mc_interface_get_pid_pos_now())); + break; - default: - break; + default: + break; } if (mc_interface_get_configuration()->motor_type == MOTOR_TYPE_FOC) { @@ -134,30 +133,10 @@ static THD_FUNCTION(periodic_thread, arg) { default: break; - } + } } chThdSleepMilliseconds(10); - -// chThdSleepMilliseconds(40); -// volatile const mc_configuration *conf = mc_interface_get_configuration(); -// float vq = mcpwm_foc_get_vq(); -// float iq = mc_interface_get_tot_current_directional(); -// float linkage = conf->foc_motor_flux_linkage; -// float speed = ((2.0 * M_PI) / 60.0) * mc_interface_get_rpm(); -// -// if (iq < -6.0) { -// float res = vq / (linkage * speed * iq); -// res *= 2.0 / 3.0; -// static float res_filtered = 0.0; -// UTILS_LP_FAST(res_filtered, res, 0.02); -// commands_printf("Res: %.4f", (double)res_filtered); -// } - -// chThdSleepMilliseconds(40); -// commands_printf("Max: %.2f Min: %.2f", -// (double)mc_interface_get_configuration()->lo_current_motor_max_now, -// (double)mc_interface_get_configuration()->lo_current_motor_min_now); } } @@ -173,12 +152,13 @@ static THD_FUNCTION(timer_thread, arg) { } } -/* When assertions enabled halve PWM frequency. The control loop ISR runs 40% slower */ +// When assertions enabled halve PWM frequency. The control loop ISR runs 40% slower void assert_failed(uint8_t* file, uint32_t line) { commands_printf("Wrong parameters value: file %s on line %d\r\n", file, line); mc_interface_release_motor(); - while(1) + while(1) { chThdSleepMilliseconds(1); + } } int main(void) { @@ -317,9 +297,5 @@ int main(void) { for(;;) { chThdSleepMilliseconds(10); - - if (encoder_is_configured()) { - // comm_can_set_pos(0, encoder_read_deg()); - } } } diff --git a/nrf/nrf_driver.c b/nrf/nrf_driver.c index 46beec41..468d68d0 100644 --- a/nrf/nrf_driver.c +++ b/nrf/nrf_driver.c @@ -155,7 +155,7 @@ void nrf_driver_start_pairing(int ms) { conf.retries = 3; conf.retry_delay = NRF_RETR_DELAY_1000US; conf.send_crc_ack = true; - conf.speed = NRF_SPEED_250K; + conf.speed = NRF_SPEED_1M; rfhelp_update_conf(&conf); } @@ -472,7 +472,7 @@ void nrf_driver_process_packet(unsigned char *buf, unsigned char len) { appconf.app_nrf_conf.retries = 3; appconf.app_nrf_conf.retry_delay = NRF_RETR_DELAY_1000US; appconf.app_nrf_conf.send_crc_ack = true; - appconf.app_nrf_conf.speed = NRF_SPEED_250K; + appconf.app_nrf_conf.speed = NRF_SPEED_1M; if (ext_nrf) { unsigned char data[5];