Merge remote-tracking branch 'origin/master'

This commit is contained in:
Jakub Tomczak 2022-01-27 10:28:16 +01:00
commit 6a9bd07c72
81 changed files with 222 additions and 175 deletions

View File

@ -1,6 +1,7 @@
=== FW 6.00 <dev> ===
* Added stack checks.
* Release motor fix when cc_min_current is 0.
* Added support for NTC and PTC temperature sensors with custom resisrance and base temperature.
=== FW 5.03 ===
* Fixed inductance measurement bug.

View File

@ -14,7 +14,7 @@
#define SPEED_STEP 0.05
#define SPEED_MAX 1.00
#define SPEED_MIN 0.20
#define SPEED_MIN 0.10
#define SPEED_OFF 0.00
//private variables
@ -60,6 +60,9 @@ void app_custom_start(void) {
// Start the dv thread
chThdCreateStatic(dpv_thread_wa, sizeof(dpv_thread_wa), NORMALPRIO, dpv_thread, NULL);
hw_start_i2c();
app_uartcomm_start(UART_PORT_COMM_HEADER);
app_uartcomm_start(UART_PORT_BUILTIN);
chSysLock();
chVTSetI(&dpv_vt, MS2ST(1), update, NULL);
chSysUnlock();
@ -122,7 +125,6 @@ static THD_FUNCTION(dpv_thread, arg) {
static systime_t last_time = 0;
static float motorSpeed_val_ramp = 0.0;
float ramp_time;
if ( ! palReadPad(HW_HALL_TRIGGER_GPIO, HW_HALL_TRIGGER_PIN)) {
motorSpeed=targetSpeed;
} else {
@ -138,9 +140,9 @@ static THD_FUNCTION(dpv_thread, arg) {
last_time = chVTGetSystemTimeX();
motorSpeed = motorSpeed_val_ramp;
}
mc_interface_set_duty(utils_map(motorSpeed, 0, 1.0, 0, mcconf->l_max_duty));
//mc_interface_set_pid_speed(motorSpeed*mcconf->l_max_erpm);
chThdSleepMilliseconds(10);
mc_interface_set_duty(motorSpeed*mcconf->l_max_duty);
chThdSleepMilliseconds(5);
// Reset the timeout
timeout_reset();
}

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -24,7 +24,7 @@
#define FW_VERSION_MAJOR 6
#define FW_VERSION_MINOR 00
// Set to 0 for building a release and iterate during beta test builds
#define FW_TEST_VERSION_NUMBER 2
#define FW_TEST_VERSION_NUMBER 4
#include "datatypes.h"

View File

@ -170,6 +170,8 @@ int32_t confgenerator_serialize_mcconf(uint8_t *buffer, const mc_configuration *
buffer[ind++] = conf->m_out_aux_mode;
buffer[ind++] = conf->m_motor_temp_sens_type;
buffer_append_float32_auto(buffer, conf->m_ptc_motor_coeff, &ind);
buffer_append_float16(buffer, conf->m_ntcx_ptcx_res, 0.1, &ind);
buffer_append_float16(buffer, conf->m_ntcx_ptcx_temp_base, 10, &ind);
buffer[ind++] = (uint8_t)conf->m_hall_extra_samples;
buffer[ind++] = (uint8_t)conf->si_motor_poles;
buffer_append_float32_auto(buffer, conf->si_gear_ratio, &ind);
@ -539,6 +541,8 @@ bool confgenerator_deserialize_mcconf(const uint8_t *buffer, mc_configuration *c
conf->m_out_aux_mode = buffer[ind++];
conf->m_motor_temp_sens_type = buffer[ind++];
conf->m_ptc_motor_coeff = buffer_get_float32_auto(buffer, &ind);
conf->m_ntcx_ptcx_res = buffer_get_float16(buffer, 0.1, &ind);
conf->m_ntcx_ptcx_temp_base = buffer_get_float16(buffer, 10, &ind);
conf->m_hall_extra_samples = buffer[ind++];
conf->si_motor_poles = buffer[ind++];
conf->si_gear_ratio = buffer_get_float32_auto(buffer, &ind);
@ -904,6 +908,8 @@ void confgenerator_set_defaults_mcconf(mc_configuration *conf) {
conf->m_out_aux_mode = MCCONF_M_OUT_AUX_MODE;
conf->m_motor_temp_sens_type = MCCONF_M_MOTOR_TEMP_SENS_TYPE;
conf->m_ptc_motor_coeff = MCCONF_M_PTC_MOTOR_COEFF;
conf->m_ntcx_ptcx_res = MCCONF_M_NTCX_PTCX_RES;
conf->m_ntcx_ptcx_temp_base = MCCONF_M_NTCX_PTCX_BASE_TEMP;
conf->m_hall_extra_samples = MCCONF_M_HALL_EXTRA_SAMPLES;
conf->si_motor_poles = MCCONF_SI_MOTOR_POLES;
conf->si_gear_ratio = MCCONF_SI_GEAR_RATIO;

View File

@ -8,7 +8,7 @@
#include <stdbool.h>
// Constants
#define MCCONF_SIGNATURE 2525666056
#define MCCONF_SIGNATURE 1018325777
#define APPCONF_SIGNATURE 3733512279
// Functions

View File

@ -86,7 +86,9 @@ typedef enum {
TEMP_SENSOR_PTC_1K_100C,
TEMP_SENSOR_KTY83_122,
TEMP_SENSOR_NTC_100K_25C,
TEMP_SENSOR_KTY84_130
TEMP_SENSOR_KTY84_130,
TEMP_SENSOR_NTCX,
TEMP_SENSOR_PTCX
} temp_sensor_type;
// General purpose drive output mode
@ -480,6 +482,8 @@ typedef struct {
temp_sensor_type m_motor_temp_sens_type;
float m_ptc_motor_coeff;
int m_hall_extra_samples;
float m_ntcx_ptcx_temp_base;
float m_ntcx_ptcx_res;
// Setup info
uint8_t si_motor_poles;
float si_gear_ratio;

View File

@ -231,6 +231,12 @@
#ifndef AUX_OFF
#define AUX_OFF()
#endif
#ifndef AUX2_ON
#define AUX2_ON()
#endif
#ifndef AUX2_OFF
#define AUX2_OFF()
#endif
#ifndef PHASE_FILTER_ON
#define PHASE_FILTER_ON()
@ -444,8 +450,8 @@
#ifndef PTC_TEMP_MOTOR
#if defined(NTC_RES_MOTOR) && defined(ADC_IND_TEMP_MOTOR)
#define PTC_TEMP_MOTOR(res, con, tbase) (((NTC_RES_MOTOR(ADC_Value[ADC_IND_TEMP_MOTOR]) - res) / res) * 100 / con + tbase)
#define PTC_TEMP_MOTOR_2(res, con, tbase) (((NTC_RES_MOTOR(ADC_Value[ADC_IND_TEMP_MOTOR_2]) - res) / res) * 100 / con + tbase)
#define PTC_TEMP_MOTOR(res, con, tbase) (((NTC_RES_MOTOR(ADC_Value[ADC_IND_TEMP_MOTOR]) - (res)) / (res)) * 100 / (con) + (tbase))
#define PTC_TEMP_MOTOR_2(res, con, tbase) (((NTC_RES_MOTOR(ADC_Value[ADC_IND_TEMP_MOTOR_2]) - (res)) / (res)) * 100 / (con) + (tbase))
#else
#define PTC_TEMP_MOTOR(res, con, tbase) 0.0
#define PTC_TEMP_MOTOR_2(res, con, tbase) 0.0
@ -458,7 +464,17 @@
#define NTC100K_TEMP_MOTOR_2(beta) (1.0 / ((logf(NTC_RES_MOTOR(ADC_Value[ADC_IND_TEMP_MOTOR_2]) / 100000.0) / beta) + (1.0 / 298.15)) - 273.15)
#else
#define NTC100K_TEMP_MOTOR(beta) 0.0
#define NTC100K_TEMP_MOTOR2(beta) 0.0
#define NTC100K_TEMP_MOTOR_2(beta) 0.0
#endif
#endif
#ifndef NTCX_TEMP_MOTOR
#if defined(NTC_RES_MOTOR) && defined(ADC_IND_TEMP_MOTOR)
#define NTCX_TEMP_MOTOR(res, beta, tbase) (1.0 / ((logf(NTC_RES_MOTOR(ADC_Value[ADC_IND_TEMP_MOTOR]) / (res)) / (beta)) + (1.0 / (273.15 + (tbase)))) - 273.15)
#define NTCX_TEMP_MOTOR_2(res, beta, tbase) (1.0 / ((logf(NTC_RES_MOTOR(ADC_Value[ADC_IND_TEMP_MOTOR_2]) / (res)) / (beta)) + (1.0 / (273.15 + (tbase)))) - 273.15)
#else
#define NTCX_TEMP_MOTOR(res, beta, tbase) 0.0
#define NTCX_TEMP_MOTOR_2(res, beta, tbase) 0.0
#endif
#endif

View File

@ -88,11 +88,15 @@ void hw_init_gpio(void) {
CURRENT_FILTER_OFF();
// AUX pin
// AUX pins
AUX_OFF();
palSetPadMode(AUX_GPIO, AUX_PIN,
PAL_MODE_OUTPUT_PUSHPULL |
PAL_STM32_OSPEED_HIGHEST);
AUX2_OFF();
palSetPadMode(AUX2_GPIO, AUX2_PIN,
PAL_MODE_OUTPUT_PUSHPULL |
PAL_STM32_OSPEED_HIGHEST);
// Sensor port voltage
SENSOR_PORT_3V3();

View File

@ -20,7 +20,7 @@
#ifndef HW_60V2_ALVA_H_
#define HW_60V2_ALVA_H_
#define HW_NAME "ALVA60"
#define HW_NAME "60v2_alva"
#define ALVA_V0_PPM
//#define ALVA_V0_ABI_ENC
@ -55,6 +55,10 @@
#define AUX_PIN 12
#define AUX_ON() palSetPad(AUX_GPIO, AUX_PIN)
#define AUX_OFF() palClearPad(AUX_GPIO, AUX_PIN)
#define AUX2_GPIO GPIOC
#define AUX2_PIN 13
#define AUX2_ON() palSetPad(AUX2_GPIO, AUX2_PIN)
#define AUX2_OFF() palClearPad(AUX2_GPIO, AUX2_PIN)
#define CURRENT_FILTER_GPIO GPIOD
#define CURRENT_FILTER_PIN 2

View File

@ -36,9 +36,8 @@
#include "lora/lora.h"
#endif
// Threads
THD_FUNCTION(mag_thread, arg);
static THD_WORKING_AREA(mag_thread_wa, 256);
static THD_WORKING_AREA(mag_thread_wa, 512);
static bool mag_thread_running = false;
// Variables
@ -56,7 +55,6 @@ static const I2CConfig i2cfg = {
STD_DUTY_CYCLE
};
void hw_init_gpio(void) {
// GPIO clock enable
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA, ENABLE);
@ -144,8 +142,6 @@ void hw_init_gpio(void) {
0,
terminal_cmd_doublepulse);
#endif
//start uart for log
//app_uartcomm_start(UART_PORT_COMM_HEADER);
}
void hw_setup_adc_channels(void) {
@ -221,7 +217,6 @@ void hw_start_i2c(void) {
PAL_STM32_OTYPE_OPENDRAIN |
PAL_STM32_OSPEED_MID1 |
PAL_STM32_PUDR_PULLUP);
i2cStart(&HW_I2C_DEV, &i2cfg);
i2c_running = true;
}
@ -260,7 +255,6 @@ void hw_try_restore_i2c(void) {
PAL_STM32_OTYPE_OPENDRAIN |
PAL_STM32_OSPEED_MID1 |
PAL_STM32_PUDR_PULLUP);
palSetPad(HW_I2C_SCL_PORT, HW_I2C_SCL_PIN);
palSetPad(HW_I2C_SDA_PORT, HW_I2C_SDA_PIN);

View File

@ -25,7 +25,7 @@
// HW properties
#define HW_HAS_3_SHUNTS
#define HW_HAS_PHASE_SHUNTS
//#define HW_HAS_PHASE_FILTERS
#define HW_HAS_PHASE_FILTERS
#define INVERTED_SHUNT_POLARITY
#define HW_HAS_NO_CAN
#define HW_HAS_LORA
@ -151,13 +151,13 @@
#define HW_UART_RX_PORT GPIOB
#define HW_UART_RX_PIN 11
//#define HW_UART_P_BAUD 115200
//#define HW_UART_P_DEV SD4
//#define HW_UART_P_GPIO_AF GPIO_AF_UART4
//#define HW_UART_P_TX_PORT GPIOC
//#define HW_UART_P_TX_PIN 10
//#define HW_UART_P_RX_PORT GPIOC
//#define HW_UART_P_RX_PIN 11
#define HW_UART_P_BAUD 115200
#define HW_UART_P_DEV SD4
#define HW_UART_P_GPIO_AF GPIO_AF_UART4
#define HW_UART_P_TX_PORT GPIOC
#define HW_UART_P_TX_PIN 10
#define HW_UART_P_RX_PORT GPIOC
#define HW_UART_P_RX_PIN 11
// ICU Peripheral for servo decoding
#define HW_USE_SERVO_TIM4
@ -225,16 +225,16 @@
#ifdef HW_HAS_LORA
#define HW_LORA_SPI_DEV SPID1
#define HW_LORA_SPI_GPIO_AF GPIO_AF_SPI1
#define HW_LORA_SPI_PORT_NSS GPIOA
#define HW_LORA_SPI_PIN_NSS 4
#define HW_LORA_SPI_PORT_SCK GPIOA
#define HW_LORA_SPI_PIN_SCK 5
#define HW_LORA_SPI_PORT_MOSI GPIOA
#define HW_LORA_SPI_PIN_MOSI 7
#define HW_LORA_SPI_PORT_MISO GPIOA
#define HW_LORA_SPI_PIN_MISO 6
#define HW_LORA_SPI_PORT_DIO0 GPIOC
#define HW_LORA_SPI_PIN_DIO0 5
#define HW_LORA_SPI_PORT_NSS GPIOB
#define HW_LORA_SPI_PIN_NSS 3
#define HW_LORA_SPI_PORT_SCK GPIOB
#define HW_LORA_SPI_PIN_SCK 6
#define HW_LORA_SPI_PORT_MOSI GPIOB
#define HW_LORA_SPI_PIN_MOSI 4
#define HW_LORA_SPI_PORT_MISO GPIOB
#define HW_LORA_SPI_PIN_MISO 5
#define HW_LORA_SPI_PORT_DIO0 GPIOB
#define HW_LORA_SPI_PIN_DIO0 12
#define HW_LORA_SPI_PORT_RESET GPIOB
#define HW_LORA_SPI_PIN_RESET 2
#endif
@ -252,14 +252,14 @@
// Override dead time. See the stm32f4 reference manual for calculating this value.
#define HW_DEAD_TIME_NSEC 660.0
#define HW_DEAD_TIME_NSEC 360.0
// Default setting overrides
#ifndef MCCONF_L_MIN_VOLTAGE
#define MCCONF_L_MIN_VOLTAGE 12.0 // Minimum input voltage
#endif
#ifndef MCCONF_L_MAX_VOLTAGE
#define MCCONF_L_MAX_VOLTAGE 50.0 // Maximum input voltage
#define MCCONF_L_MAX_VOLTAGE 57.0 // Maximum input voltage
#endif
#ifndef MCCONF_DEFAULT_MOTOR_TYPE
#define MCCONF_DEFAULT_MOTOR_TYPE MOTOR_TYPE_FOC
@ -284,7 +284,7 @@
#define HW_LIM_CURRENT -120.0, 120.0
#define HW_LIM_CURRENT_IN -120.0, 120.0
#define HW_LIM_CURRENT_ABS 0.0, 160.0
#define HW_LIM_VIN 12.0, 50.0
#define HW_LIM_VIN 12.0, 60.0
#define HW_LIM_ERPM -200e3, 200e3
#define HW_LIM_DUTY_MIN 0.0, 0.1
#define HW_LIM_DUTY_MAX 0.0, 0.99

View File

@ -247,6 +247,30 @@ static lbm_value ext_secs_since(lbm_value *args, lbm_uint argn) {
return lbm_enc_F(UTILS_AGE_S(lbm_dec_as_u(args[0])));
}
static lbm_value ext_set_aux(lbm_value *args, lbm_uint argn) {
CHECK_ARGN_NUMBER(2);
int port = lbm_dec_as_u(args[0]);
bool on = lbm_dec_as_u(args[1]);
if (port == 1) {
if (on) {
AUX_ON();
} else {
AUX_OFF();
}
return lbm_enc_sym(SYM_TRUE);
} else if (port == 2) {
if (on) {
AUX2_ON();
} else {
AUX2_OFF();
}
return lbm_enc_sym(SYM_TRUE);
}
return lbm_enc_sym(SYM_EERROR);
}
// Motor set commands
static lbm_value ext_set_current(lbm_value *args, lbm_uint argn) {
@ -476,6 +500,7 @@ void lispif_load_vesc_extensions(void) {
lbm_add_extension("get-adc", ext_get_adc);
lbm_add_extension("systime", ext_systime);
lbm_add_extension("secs-since", ext_secs_since);
lbm_add_extension("set-aux", ext_set_aux);
// Motor set commands
lbm_add_extension("set-current", ext_set_current);

View File

@ -51,7 +51,8 @@ Item {
// mLogReader.openLogFile("example_control_servo_from_duty.lisp")
// mLogReader.openLogFile("example_print_bms_data.lisp")
// mLogReader.openLogFile("example_can_pos_follow.lisp")
mLogReader.openLogFile("example_speed_test.lisp")
// mLogReader.openLogFile("example_speed_test.lisp")
mLogReader.openLogFile("example_aux.lisp")
//
// mLogReader.openLogFile("test_math.lisp")

View File

@ -0,0 +1,17 @@
(define set-auxtime (lambda (port state time)
(progn
(set-aux port state)
(define aux-now (list port state time))
(yield (* 1000 time))
)))
(let ((f (lambda ()
(progn
(set-auxtime 1 1 1500)
(set-auxtime 1 0 500)
(set-auxtime 2 1 1500)
(set-auxtime 2 0 500)
(yield 1000000)
(f)
)))) (f))

View File

@ -6,6 +6,7 @@
(canset-pos 124 (get-encoder))
(define canc (canget-current-dir 124))
(set-servo (- 0.5 (* 0.02 canc)))
(set-brake (* 0.5 canc))
(timeout-reset)
(yield 2000)
(f)

View File

@ -143,6 +143,57 @@ static thread_t *fault_stop_tp;
static THD_WORKING_AREA(stat_thread_wa, 512);
static THD_FUNCTION(stat_thread, arg);
static void init_sensor_port(volatile mc_configuration *conf) {
switch (conf->m_sensor_port_mode) {
case SENSOR_PORT_MODE_ABI:
SENSOR_PORT_5V();
encoder_init_abi(conf->m_encoder_counts);
break;
case SENSOR_PORT_MODE_AS5047_SPI:
SENSOR_PORT_3V3();
encoder_init_as5047p_spi();
break;
case SENSOR_PORT_MODE_MT6816_SPI:
SENSOR_PORT_5V();
encoder_init_mt6816_spi();
break;
case SENSOR_PORT_MODE_AD2S1205:
SENSOR_PORT_5V();
encoder_init_ad2s1205_spi();
break;
case SENSOR_PORT_MODE_SINCOS:
SENSOR_PORT_5V();
encoder_init_sincos(conf->foc_encoder_sin_gain, conf->foc_encoder_sin_offset,
conf->foc_encoder_cos_gain, conf->foc_encoder_cos_offset,
conf->foc_encoder_sincos_filter_constant);
break;
case SENSOR_PORT_MODE_TS5700N8501:
case SENSOR_PORT_MODE_TS5700N8501_MULTITURN: {
SENSOR_PORT_5V();
app_configuration *appconf = mempools_alloc_appconf();
conf_general_read_app_configuration(appconf);
if (appconf->app_to_use == APP_ADC ||
appconf->app_to_use == APP_UART ||
appconf->app_to_use == APP_PPM_UART ||
appconf->app_to_use == APP_ADC_UART) {
appconf->app_to_use = APP_NONE;
conf_general_store_app_configuration(appconf);
}
mempools_free_appconf(appconf);
encoder_init_ts5700n8501();
} break;
default:
SENSOR_PORT_5V();
break;
}
}
void mc_interface_init(void) {
memset((void*)&m_motor_1, 0, sizeof(motor_if_state_t));
#ifdef HW_HAS_DUAL_MOTORS
@ -207,60 +258,7 @@ void mc_interface_init(void) {
#endif
mc_interface_select_motor_thread(motor_old);
// Initialize encoder
ENCSINCOS_config_t sincos_config;
switch (motor_now()->m_conf.m_sensor_port_mode) {
case SENSOR_PORT_MODE_ABI:
SENSOR_PORT_3V3();
encoder_set_counts(motor_now()->m_conf.m_encoder_counts);
encoder_init(ENCODER_TYPE_ABI);
break;
case SENSOR_PORT_MODE_AS5047_SPI:
SENSOR_PORT_3V3();
encoder_init(ENCODER_TYPE_AS504x);
break;
case SENSOR_PORT_MODE_MT6816_SPI:
encoder_init(ENCODER_TYPE_MT6816);
break;
case SENSOR_PORT_MODE_AD2S1205:
encoder_init(ENCODER_TYPE_AD2S1205_SPI);
break;
case SENSOR_PORT_MODE_SINCOS:
sincos_config.s_gain = motor_now()->m_conf.foc_encoder_sin_gain;
sincos_config.s_offset = motor_now()->m_conf.foc_encoder_sin_offset;
sincos_config.c_gain = motor_now()->m_conf.foc_encoder_cos_gain;
sincos_config.c_offset = motor_now()->m_conf.foc_encoder_cos_offset;
sincos_config.filter_constant = motor_now()->m_conf.foc_encoder_sincos_filter_constant;
encoder_sincos_conf_set(&sincos_config);
encoder_init(ENCODER_TYPE_SINCOS);
break;
case SENSOR_PORT_MODE_TS5700N8501:
//TODO: integrate with encoder/encoders
case SENSOR_PORT_MODE_TS5700N8501_MULTITURN: {
app_configuration *appconf = mempools_alloc_appconf();
conf_general_read_app_configuration(appconf);
if (appconf->app_to_use == APP_ADC ||
appconf->app_to_use == APP_UART ||
appconf->app_to_use == APP_PPM_UART ||
appconf->app_to_use == APP_ADC_UART) {
appconf->app_to_use = APP_NONE;
conf_general_store_app_configuration(appconf);
}
mempools_free_appconf(appconf);
encoder_init(ENCODER_TYPE_TS5700N8501);
} break;
default:
SENSOR_PORT_5V();
break;
}
init_sensor_port(&motor_now()->m_conf);
// Initialize selected implementation
switch (motor_now()->m_conf.motor_type) {
@ -352,57 +350,7 @@ void mc_interface_set_configuration(mc_configuration *configuration) {
ENCSINCOS_config_t sincos_config;
encoder_deinit();
switch (configuration->m_sensor_port_mode) {
case SENSOR_PORT_MODE_ABI:
SENSOR_PORT_3V3();
encoder_set_counts(configuration->m_encoder_counts);
encoder_init(ENCODER_TYPE_ABI);
break;
case SENSOR_PORT_MODE_AS5047_SPI:
SENSOR_PORT_3V3();
encoder_init(ENCODER_TYPE_AS504x);
break;
case SENSOR_PORT_MODE_MT6816_SPI:
encoder_init(ENCODER_TYPE_MT6816);
break;
case SENSOR_PORT_MODE_AD2S1205:
encoder_init(ENCODER_TYPE_AD2S1205_SPI);
break;
case SENSOR_PORT_MODE_SINCOS:
sincos_config.s_gain = motor->m_conf.foc_encoder_sin_gain;
sincos_config.s_offset = motor->m_conf.foc_encoder_sin_offset;
sincos_config.c_gain = motor->m_conf.foc_encoder_cos_gain;
sincos_config.c_offset = motor->m_conf.foc_encoder_cos_offset;
sincos_config.filter_constant = motor->m_conf.foc_encoder_sincos_filter_constant;
encoder_sincos_conf_set(&sincos_config);
encoder_init(ENCODER_TYPE_SINCOS);
break;
case SENSOR_PORT_MODE_TS5700N8501:
case SENSOR_PORT_MODE_TS5700N8501_MULTITURN: {
app_configuration *appconf = mempools_alloc_appconf();
*appconf = *app_get_configuration();
if (appconf->app_to_use == APP_ADC ||
appconf->app_to_use == APP_UART ||
appconf->app_to_use == APP_PPM_UART ||
appconf->app_to_use == APP_ADC_UART) {
appconf->app_to_use = APP_NONE;
conf_general_store_app_configuration(appconf);
app_set_configuration(appconf);
}
mempools_free_appconf(appconf);
encoder_init(ENCODER_TYPE_TS5700N8501);
} break;
default:
SENSOR_PORT_5V();
break;
}
init_sensor_port(configuration);
}
if (configuration->m_sensor_port_mode == SENSOR_PORT_MODE_ABI) {
@ -2163,6 +2111,16 @@ static void update_override_limits(volatile motor_if_state_t *motor, volatile mc
temp_motor = -7.82531699e-12 * res * res * res * res + 6.34445902e-8 * res * res * res -
0.00020119157 * res * res + 0.407683016 * res - 161.357536;
} break;
case TEMP_SENSOR_NTCX:
temp_motor = is_motor_1 ? NTCX_TEMP_MOTOR(conf->m_ntcx_ptcx_res, conf->m_ntc_motor_beta, conf->m_ntcx_ptcx_temp_base) :
NTCX_TEMP_MOTOR_2(conf->m_ntcx_ptcx_res, conf->m_ntc_motor_beta, conf->m_ntcx_ptcx_temp_base);
break;
case TEMP_SENSOR_PTCX:
temp_motor = is_motor_1 ? PTC_TEMP_MOTOR(conf->m_ntcx_ptcx_res, conf->m_ptc_motor_coeff, conf->m_ntcx_ptcx_temp_base) :
PTC_TEMP_MOTOR_2(conf->m_ntcx_ptcx_res, conf->m_ptc_motor_coeff, conf->m_ntcx_ptcx_temp_base);
break;
}
// If the reading is messed up (by e.g. reading 0 on the ADC and dividing by 0) we avoid putting an

View File

@ -524,6 +524,12 @@
#ifndef MCCONF_M_PTC_MOTOR_COEFF
#define MCCONF_M_PTC_MOTOR_COEFF 0.61 // %/K coefficient for motor PTC sensor
#endif
#ifndef MCCONF_M_NTCX_PTCX_RES
#define MCCONF_M_NTCX_PTCX_RES 10000.0 // Custom NTC/PTC resistance
#endif
#ifndef MCCONF_M_NTCX_PTCX_BASE_TEMP
#define MCCONF_M_NTCX_PTCX_BASE_TEMP 25.0 // Custom NTC/PTC base temperature
#endif
#ifndef MCCONF_M_HALL_EXTRA_SAMPLES
#define MCCONF_M_HALL_EXTRA_SAMPLES 1 // Extra samples for filtering when reading hall sensors
#endif

View File

@ -1564,7 +1564,7 @@ void mcpwm_foc_encoder_detect(float current, bool print, float *offset, float *r
// Inverted and ratio
chThdSleepMilliseconds(1000);
const int it_rat = 20;
const int it_rat = 30;
float s_sum = 0.0;
float c_sum = 0.0;
float first = motor->m_phase_now_encoder;
@ -1579,6 +1579,7 @@ void mcpwm_foc_encoder_detect(float current, bool print, float *offset, float *r
}
utils_norm_angle_rad((float*)&motor->m_phase_now_override);
chThdSleepMilliseconds(300);
timeout_reset();
float diff = utils_angle_difference_rad(motor->m_phase_now_encoder, phase_old);
float s, c;
@ -1587,7 +1588,7 @@ void mcpwm_foc_encoder_detect(float current, bool print, float *offset, float *r
c_sum += c;
if (print) {
commands_printf("%.2f", (double)RAD2DEG_f(diff));
commands_printf("Diff: %.2f", (double)RAD2DEG_f(diff));
}
if (i > 3 && fabsf(utils_angle_difference_rad(motor->m_phase_now_encoder, first)) < fabsf(diff / 2.0)) {
@ -1607,6 +1608,7 @@ void mcpwm_foc_encoder_detect(float current, bool print, float *offset, float *r
}
utils_norm_angle_rad((float*)&motor->m_phase_now_override);
chThdSleepMilliseconds(300);
timeout_reset();
float diff = utils_angle_difference_rad(phase_old, motor->m_phase_now_encoder);
float s, c;
@ -1615,7 +1617,7 @@ void mcpwm_foc_encoder_detect(float current, bool print, float *offset, float *r
c_sum += c;
if (print) {
commands_printf("%.2f", (double)RAD2DEG_f(diff));
commands_printf("Diff: %.2f", (double)RAD2DEG_f(diff));
}
if (i > 3 && fabsf(utils_angle_difference_rad(motor->m_phase_now_encoder, first)) < fabsf(diff / 2.0)) {
@ -1632,6 +1634,7 @@ void mcpwm_foc_encoder_detect(float current, bool print, float *offset, float *r
if (print) {
commands_printf("Inversion and ratio detected");
commands_printf("Ratio: %.2f", (double)*ratio);
}
// Rotate
@ -1659,6 +1662,7 @@ void mcpwm_foc_encoder_detect(float current, bool print, float *offset, float *r
}
chThdSleepMilliseconds(100);
timeout_reset();
float angle_diff = utils_angle_difference_rad(motor->m_phase_now_encoder, motor->m_phase_now_override);
float s, c;
@ -1667,7 +1671,7 @@ void mcpwm_foc_encoder_detect(float current, bool print, float *offset, float *r
c_sum += c;
if (print) {
commands_printf("%.2f", (double)RAD2DEG_f(angle_diff));
commands_printf("Ovr: %.2f/%.2f Diff: %.2f", (double)override, (double)(it_ofs * step), (double)RAD2DEG_f(angle_diff));
}
}
@ -1681,6 +1685,7 @@ void mcpwm_foc_encoder_detect(float current, bool print, float *offset, float *r
}
chThdSleepMilliseconds(100);
timeout_reset();
float angle_diff = utils_angle_difference_rad(motor->m_phase_now_encoder, motor->m_phase_now_override);
float s, c;
@ -1689,7 +1694,7 @@ void mcpwm_foc_encoder_detect(float current, bool print, float *offset, float *r
c_sum += c;
if (print) {
commands_printf("%.2f", (double)RAD2DEG_f(angle_diff));
commands_printf("Ovr: %.2f/%.2f Diff: %.2f", (double)override, (double)(it_ofs * step), (double)RAD2DEG_f(angle_diff));
}
}

View File

@ -445,7 +445,6 @@ void terminal_process_string(char *str) {
mcconf->motor_type = MOTOR_TYPE_FOC;
mc_interface_set_configuration(mcconf);
const float res = (3.0 / 2.0) * mcconf->foc_motor_r;
// Disable timeout
systime_t tout = timeout_get_timeout_msec();
@ -485,7 +484,7 @@ void terminal_process_string(char *str) {
rpm_avg /= samples;
iq_avg /= samples;
float linkage = (vq_avg - res * iq_avg) / RPM2RADPS_f(rpm_avg);
float linkage = (vq_avg - mcconf->foc_motor_r * iq_avg) / RPM2RADPS_f(rpm_avg);
commands_printf("Flux linkage: %.7f\n", (double)linkage);
} else {
@ -936,6 +935,10 @@ void terminal_process_string(char *str) {
encoder_resolver_loss_of_signal_error_cnt(),
(double)encoder_resolver_loss_of_signal_error_rate() * (double)100.0);
}
if (mcconf->m_sensor_port_mode == SENSOR_PORT_MODE_ABI) {
commands_printf("Index found: %d\n", encoder_index_found());
}
} else if (strcmp(argv[0], "encoder_clear_errors") == 0) {
encoder_reset_errors();
commands_printf("Done!\n");