Skip to content

Commit

Permalink
Merge branch 'freewheel' into vesc_comp
Browse files Browse the repository at this point in the history
  • Loading branch information
Netzpfuscher committed Feb 2, 2022
2 parents 4a8542c + 97ea172 commit c1d1093
Show file tree
Hide file tree
Showing 21 changed files with 810 additions and 277 deletions.
4 changes: 2 additions & 2 deletions common_files/inc/drive_parameters.h
Original file line number Diff line number Diff line change
Expand Up @@ -149,8 +149,8 @@
/****************************** ADDITIONAL FEATURES **********************/
#define FW_VOLTAGE_REF 985 /*!<Vs reference, tenth
of a percent */
#define FW_KP_GAIN 6000 /*!< Default Kp gain */
#define FW_KI_GAIN 10000 /*!< Default Ki gain */
#define FW_KP_GAIN 2000 /*!< Default Kp gain */
#define FW_KI_GAIN 5000 /*!< Default Ki gain */
#define FW_KPDIV 32768
/*!< Kp gain divisor.If FULL_MISRA_C_COMPLIANCY
is not defined the divisor is implemented through
Expand Down
21 changes: 18 additions & 3 deletions common_files/inc/mcconf_default.h
Original file line number Diff line number Diff line change
Expand Up @@ -255,13 +255,13 @@
#define MCCONF_FOC_PLL_KI 30000.0
#endif
#ifndef MCCONF_FOC_MOTOR_L
#define MCCONF_FOC_MOTOR_L 0.000010
#define MCCONF_FOC_MOTOR_L 0.0001
#endif
#ifndef MCCONF_FOC_MOTOR_R
#define MCCONF_FOC_MOTOR_R 0.015
#define MCCONF_FOC_MOTOR_R 0.1
#endif
#ifndef MCCONF_FOC_MOTOR_FLUX_LINKAGE
#define MCCONF_FOC_MOTOR_FLUX_LINKAGE 0.0012
#define MCCONF_FOC_MOTOR_FLUX_LINKAGE 0.012
#endif
#ifndef MCCONF_FOC_MOTOR_LD_LQ_DIFF
#define MCCONF_FOC_MOTOR_LD_LQ_DIFF 0.0
Expand Down Expand Up @@ -377,6 +377,21 @@
#ifndef MCCONF_FOC_HFI_SAMPLES
#define MCCONF_FOC_HFI_SAMPLES HFI_SAMPLES_16 // Samples per motor revolution for HFI
#endif
#ifndef MCCONF_FOC_MTPA_MODE
#define MCCONF_FOC_MTPA_MODE MTPA_MODE_OFF // Maximum torque per amp (MTPA) algorithm mode
#endif
#ifndef MCCONF_FOC_FW_CURRENT_MAX
#define MCCONF_FOC_FW_CURRENT_MAX 0.0 // Maximum field weakening current
#endif
#ifndef MCCONF_FOC_FW_DUTY_START
#define MCCONF_FOC_FW_DUTY_START 0.9 // Start field weakening at this fraction of max duty cycle
#endif
#ifndef MCCONF_FOC_FW_RAMP_TIME
#define MCCONF_FOC_FW_RAMP_TIME 0.2 // Ramp time for field weakening current
#endif
#ifndef MCCONF_FOC_FW_Q_CURRENT_FACTOR
#define MCCONF_FOC_FW_Q_CURRENT_FACTOR 0.02 // Factor of the FW-current to feed to the Q-axis to slow motor down when setting 0 current
#endif

// GPD
#ifndef MCCONF_GPD_BUFFER_NOTIFY_LEFT
Expand Down
10 changes: 9 additions & 1 deletion common_files/inc/product.h
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@
#endif
/****************************************************************************/

#define KMH_NO_LIMIT 1337
#define PRODUCT_FIRMWARE_VERSION 0x0001
#define VESC_TOOL_ENABLE 1
#define AUTO_RESET_FAULT 1
Expand All @@ -116,7 +117,14 @@
#define BATTERY_SUPPORT_LEAD 1
#define ABS_OVR_CURRENT_TRIP_MS 2.0
#define MIN_DUTY_FOR_PWM_FREEWHEEL 80
#define CURRENT_DISPLAY_OFFSET 60 //in cnts
#define CURRENT_DISPLAY_OFFSET 80 //in cnts

#define MODE_SLOW_CURR 0.5
#define MODE_DRIVE_CURR 0.8
#define MODE_SPORT_CURR 1.0
#define MODE_SLOW_SPEED 10
#define MODE_DRIVE_SPEED 25
#define MODE_SPORT_SPEED KMH_NO_LIMIT

#define BATTERY_VOLTAGE_GAIN ((VOLTAGE_DIVIDER_GAIN * ADC_GAIN) * 512.0)
#define CURRENT_FACTOR_A ((32767.0*RSHUNT*AMPLIFICATION_GAIN)/(3.3/2))
Expand Down
8 changes: 8 additions & 0 deletions common_files/inc/task_LED.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,15 @@

extern osThreadId_t task_LED_handle;

typedef enum {
BRAKE_LIGHT_ON,
BRAKE_LIGHT_OFF
}en_brake;

void task_LED_init();
void task_LED_set_brake_light(en_brake mode);




#endif /* TASK_LED_H_ */
Expand Down
22 changes: 19 additions & 3 deletions common_files/src/VescCommand.c
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ void commands_send_appconf(COMM_PACKET_ID packet_id, app_configuration *appconf,
commands_printf(phandle, "Malloc failed send appconf)");
return;
}
memset(send_buffer,0,512 + PACKET_HEADER);
uint8_t * buffer = send_buffer + PACKET_HEADER;
buffer[0] = packet_id;
int32_t len = confgenerator_serialize_appconf(&buffer[1], appconf);
Expand Down Expand Up @@ -256,7 +257,7 @@ void commands_process_packet(unsigned char *data, unsigned int len,
switch (packet_id) {
case COMM_FW_VERSION: {
int32_t ind = 0;
uint8_t send_buffer[PACKET_SIZE(50)];
uint8_t send_buffer[PACKET_SIZE(60)];
uint8_t * buffer = send_buffer + PACKET_HEADER;
buffer[ind++] = COMM_FW_VERSION;
buffer[ind++] = FW_VERSION_MAJOR;
Expand All @@ -273,6 +274,9 @@ void commands_process_packet(unsigned char *data, unsigned int len,
buffer[ind++] = HW_TYPE_VESC;

buffer[ind++] = 0; // No custom config
buffer[ind++] = 0; //No phase filters
buffer[ind++] = 0;
buffer[ind++] = 0;

fw_version_sent_cnt++;

Expand Down Expand Up @@ -392,6 +396,12 @@ void commands_process_packet(unsigned char *data, unsigned int len,
if (mask & ((uint32_t)1 << 20)) {
buffer_append_float32(buffer, VescToSTM_get_Vq(), 1e3, &ind);
}
if (mask & ((uint32_t)1 << 21)) {
uint8_t status = 0;
status |= VescToSTM_get_timeout_state();
//status |= timeout_kill_sw_active() << 1;
buffer[ind++] = status;
}

reply_func(send_buffer, ind, phandle);
} break;
Expand Down Expand Up @@ -701,7 +711,7 @@ void commands_process_packet(unsigned char *data, unsigned int len,
val.wh_charge_tot = 0;
val.wh_tot = 0;

float wh_batt_left = 0.0;
float wh_batt_left = 1.0;
float battery_level = VescToSTM_get_battery_level(&wh_batt_left);

int32_t ind = 0;
Expand Down Expand Up @@ -769,7 +779,7 @@ void commands_process_packet(unsigned char *data, unsigned int len,
}
if (mask & ((uint32_t)1 << 17)) {
uint8_t current_controller_id = app_get_configuration()->controller_id;
send_buffer[ind++] = current_controller_id;
buffer[ind++] = current_controller_id;
}
if (mask & ((uint32_t)1 << 18)) {
buffer[ind++] = val.num_vescs;
Expand All @@ -780,6 +790,10 @@ void commands_process_packet(unsigned char *data, unsigned int len,
if (mask & ((uint32_t)1 << 20)) {
buffer_append_uint32(buffer, VescToSTM_get_odometer(), &ind);
}
if (mask & ((uint32_t)1 << 21)) {
//buffer_append_uint32(send_buffer, chVTGetSystemTimeX() / (CH_CFG_ST_FREQUENCY / 1000), &ind);
buffer_append_uint32(buffer, xTaskGetTickCount()/2, &ind);
}

reply_func(send_buffer, ind, phandle);
} break;
Expand Down Expand Up @@ -983,6 +997,8 @@ void commands_process_packet(unsigned char *data, unsigned int len,
mcconf->l_battery_cut_start = start;
mcconf->l_battery_cut_end = end;

VescToSTM_set_battery_cut(start, end);

/*if (store) {
conf_general_store_mc_configuration(mcconf,
mc_interface_get_motor_thread() == 2);
Expand Down
111 changes: 102 additions & 9 deletions common_files/src/VescDatatypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,24 @@ typedef struct {
} bms_soc_soh_temp_stat;
*/

typedef enum {
PID_RATE_25_HZ = 0,
PID_RATE_50_HZ,
PID_RATE_100_HZ,
PID_RATE_250_HZ,
PID_RATE_500_HZ,
PID_RATE_1000_HZ,
PID_RATE_2500_HZ,
PID_RATE_5000_HZ,
PID_RATE_10000_HZ,
} PID_RATE;

typedef enum {
MTPA_MODE_OFF = 0,
MTPA_MODE_IQ_TARGET,
MTPA_MODE_IQ_MEASURED
} MTPA_MODE;

typedef struct {
// Limits
float l_current_max;
Expand Down Expand Up @@ -304,6 +322,8 @@ typedef struct {
// Overridden limits (Computed during runtime)
float lo_current_max;
float lo_current_min;
float lo_current_max_scale;
float lo_current_min_scale;
float lo_in_current_max;
float lo_in_current_min;
float lo_current_motor_max_now;
Expand Down Expand Up @@ -334,7 +354,7 @@ typedef struct {
float foc_current_ki;
float foc_f_sw;
float foc_dt_us;
float foc_encoder_offset;
// float foc_encoder_offset;
// bool foc_encoder_inverted;
// float foc_encoder_ratio;
// float foc_encoder_sin_offset;
Expand All @@ -348,6 +368,7 @@ typedef struct {
float foc_motor_flux_linkage;
float foc_observer_gain;
float foc_observer_gain_slow;
float foc_observer_offset;
float foc_pll_kp;
float foc_pll_ki;
float foc_duty_dowmramp_kp;
Expand All @@ -372,13 +393,25 @@ typedef struct {
float foc_current_filter_const;
mc_foc_cc_decoupling_mode foc_cc_decoupling;
mc_foc_observer_type foc_observer_type;
// float foc_hfi_voltage_start;
// float foc_hfi_voltage_run;
// float foc_hfi_voltage_max;
// float foc_sl_erpm_hfi;
// uint16_t foc_hfi_start_samples;
// float foc_hfi_obs_ovr_sec;
// uint8_t foc_hfi_samples;
float foc_hfi_voltage_start;
float foc_hfi_voltage_run;
float foc_hfi_voltage_max;
float foc_sl_erpm_hfi;
uint16_t foc_hfi_start_samples;
float foc_hfi_obs_ovr_sec;
foc_hfi_samples foc_hfi_samples;
bool foc_offsets_cal_on_boot;
float foc_offsets_current[3];
float foc_offsets_voltage[3];
float foc_offsets_voltage_undriven[3];
bool foc_phase_filter_enable;
float foc_phase_filter_max_erpm;
MTPA_MODE foc_mtpa_mode;
// Field Weakening
float foc_fw_current_max;
float foc_fw_duty_start;
float foc_fw_ramp_time;
float foc_fw_q_current_factor;

// GPDrive
// int gpd_buffer_notify_left;
Expand All @@ -387,6 +420,8 @@ typedef struct {
// float gpd_current_kp;
// float gpd_current_ki;

PID_RATE sp_pid_loop_rate;

// Speed PID
float s_pid_kp;
float s_pid_ki;
Expand Down Expand Up @@ -426,14 +461,21 @@ 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;
float si_wheel_diameter;
BATTERY_TYPE si_battery_type;
int si_battery_cells;
float si_battery_ah;
float si_motor_nl_current;

bool override_limits;
uint16_t modes_kmh_limits[3];
float modes_curr_scale[3];

// BMS Configuration
// bms_config bms;

Expand Down Expand Up @@ -464,6 +506,12 @@ typedef enum {
THR_EXP_POLY
} thr_exp_mode;

typedef enum {
SAFE_START_DISABLED = 0,
SAFE_START_REGULAR,
SAFE_START_NO_FAULT
} SAFE_START_MODE;

// PPM control types
typedef enum {
PPM_CTRL_TYPE_NONE = 0,
Expand Down Expand Up @@ -530,6 +578,14 @@ typedef enum {
PAS_SENSOR_TYPE_QUADRATURE = 0
} pas_sensor_type;

typedef enum {
KILL_SW_MODE_DISABLED = 0,
KILL_SW_MODE_PPM_LOW,
KILL_SW_MODE_PPM_HIGH,
KILL_SW_MODE_ADC2_LOW,
KILL_SW_MODE_ADC2_HIGH
} KILL_SW_MODE;

typedef struct {
adc_control_type ctrl_type;
float hyst;
Expand All @@ -539,7 +595,7 @@ typedef struct {
float voltage2_start;
float voltage2_end;
bool use_filter;
bool safe_start;
SAFE_START_MODE safe_start;
bool cc_button_inverted;
bool rev_button_inverted;
bool voltage_inverted;
Expand Down Expand Up @@ -770,11 +826,14 @@ typedef struct {
bool pairing_done;
bool permanent_uart_enabled;
SHUTDOWN_MODE shutdown_mode;
bool servo_out_enable;
KILL_SW_MODE kill_sw_mode;

// CAN modes
CAN_MODE can_mode;
uint8_t uavcan_esc_index;
UAVCAN_RAW_MODE uavcan_raw_mode;
float uavcan_raw_rpm_max;

// Application to use
app_use app_to_use;
Expand Down Expand Up @@ -807,6 +866,7 @@ typedef struct {
uint16_t crc;
} app_configuration;

// Communication commands
// Communication commands
typedef enum {
COMM_FW_VERSION = 0,
Expand Down Expand Up @@ -927,6 +987,39 @@ typedef enum {
COMM_ERASE_BOOTLOADER_ALL_CAN_HW,

COMM_SET_ODOMETER,

// Power switch commands
COMM_PSW_GET_STATUS,
COMM_PSW_SWITCH,

COMM_BMS_FWD_CAN_RX,
COMM_BMS_HW_DATA,
COMM_GET_BATTERY_CUT,
COMM_BM_HALT_REQ,
COMM_GET_QML_UI_HW,
COMM_GET_QML_UI_APP,
COMM_CUSTOM_HW_DATA,
COMM_QMLUI_ERASE,
COMM_QMLUI_WRITE,

// IO Board
COMM_IO_BOARD_GET_ALL,
COMM_IO_BOARD_SET_PWM,
COMM_IO_BOARD_SET_DIGITAL,

COMM_BM_MEM_WRITE,
COMM_BMS_BLNC_SELFTEST,
COMM_GET_EXT_HUM_TMP,
COMM_GET_STATS,
COMM_RESET_STATS,

// Lisp
COMM_LISP_READ_CODE,
COMM_LISP_WRITE_CODE,
COMM_LISP_ERASE_CODE,
COMM_LISP_SET_RUNNING,
COMM_LISP_GET_STATS,
COMM_LISP_PRINT
} COMM_PACKET_ID;

// CAN commands
Expand Down
Loading

0 comments on commit c1d1093

Please sign in to comment.