Skip to content

Commit 9521291

Browse files
committed
Merge branch 'dev_fw_5_03' into dev
2 parents c9febf9 + 4c029e3 commit 9521291

25 files changed

+1479
-407
lines changed

CHANGELOG

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,14 @@
1+
=== FW 5.03 <dev> ===
2+
* Fixed inductance measurement bug.
3+
* Speed tracker windup protection.
4+
* Phase filter support.
5+
* Phase voltage offset calibration.
6+
* Better current offset calibration.
7+
* Added power switch commands.
8+
* Synchronize observer state when running in open loop.
9+
* Force oberver state magnitude above 50% of flux linkage. This prevents the motor from getting stuck and 'screaming'.
10+
* Observer global convergence update. Helps tracking the motor through 0 speed.
11+
112
=== FW 5.02 ===
213
* IMU calibration improvement.
314
* Added COMM_GET_MCCONF_TEMP command.

comm_can.c

Lines changed: 52 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ static can_status_msg_5 stat_msgs_5[CAN_STATUS_MSGS_TO_STORE];
7979
static io_board_adc_values io_board_adc_1_4[CAN_STATUS_MSGS_TO_STORE];
8080
static io_board_adc_values io_board_adc_5_8[CAN_STATUS_MSGS_TO_STORE];
8181
static io_board_digial_inputs io_board_digital_in[CAN_STATUS_MSGS_TO_STORE];
82+
static psw_status psw_stat[CAN_STATUS_MSGS_TO_STORE];
8283
static unsigned int detect_all_foc_res_index = 0;
8384
static int8_t detect_all_foc_res[50];
8485

@@ -120,6 +121,8 @@ void comm_can_init(void) {
120121
io_board_adc_1_4[i].id = -1;
121122
io_board_adc_5_8[i].id = -1;
122123
io_board_digital_in[i].id = -1;
124+
125+
psw_stat[i].id = -1;
123126
}
124127

125128
#if CAN_ENABLE
@@ -911,6 +914,35 @@ void comm_can_io_board_set_output_pwm(int id, int channel, float duty) {
911914
buffer, send_index, true);
912915
}
913916

917+
psw_status *comm_can_get_psw_status_index(int index) {
918+
if (index < CAN_STATUS_MSGS_TO_STORE) {
919+
return &psw_stat[index];
920+
} else {
921+
return 0;
922+
}
923+
}
924+
925+
psw_status *comm_can_get_psw_status_id(int id) {
926+
for (int i = 0;i < CAN_STATUS_MSGS_TO_STORE;i++) {
927+
if (psw_stat[i].id == id) {
928+
return &psw_stat[i];
929+
}
930+
}
931+
932+
return 0;
933+
}
934+
935+
void comm_can_psw_switch(int id, bool is_on, bool plot) {
936+
int32_t send_index = 0;
937+
uint8_t buffer[8];
938+
939+
buffer[send_index++] = is_on ? 1 : 0;
940+
buffer[send_index++] = plot ? 1 : 0;
941+
942+
comm_can_transmit_eid_replace(id | ((uint32_t)CAN_PACKET_PSW_SWITCH << 8),
943+
buffer, send_index, true);
944+
}
945+
914946
CANRxFrame *comm_can_get_rx_frame(void) {
915947
#if CAN_ENABLE
916948
chMtxLock(&can_rx_mtx);
@@ -1599,7 +1631,26 @@ static void decode_msg(uint32_t eid, uint8_t *data8, int len, bool is_replaced)
15991631
}
16001632
}
16011633
break;
1602-
break;
1634+
1635+
case CAN_PACKET_PSW_STAT: {
1636+
for (int i = 0;i < CAN_STATUS_MSGS_TO_STORE;i++) {
1637+
psw_status *msg = &psw_stat[i];
1638+
if (msg->id == id || msg->id == -1) {
1639+
ind = 0;
1640+
msg->id = id;
1641+
msg->rx_time = chVTGetSystemTime();
1642+
1643+
msg->v_in = buffer_get_float16(data8, 10.0, &ind);
1644+
msg->v_out = buffer_get_float16(data8, 10.0, &ind);
1645+
msg->temp = buffer_get_float16(data8, 10.0, &ind);
1646+
msg->is_out_on = (data8[ind] >> 0) & 1;
1647+
msg->is_pch_on = (data8[ind] >> 1) & 1;
1648+
msg->is_dsc_on = (data8[ind] >> 2) & 1;
1649+
ind++;
1650+
break;
1651+
}
1652+
}
1653+
} break;
16031654

16041655
default:
16051656
break;

comm_can.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,10 @@ io_board_digial_inputs *comm_can_get_io_board_digital_in_id(int id);
7676
void comm_can_io_board_set_output_digital(int id, int channel, bool on);
7777
void comm_can_io_board_set_output_pwm(int id, int channel, float duty);
7878

79+
psw_status *comm_can_get_psw_status_index(int index);
80+
psw_status *comm_can_get_psw_status_id(int id);
81+
void comm_can_psw_switch(int id, bool is_on, bool plot);
82+
7983
CANRxFrame *comm_can_get_rx_frame(void);
8084

8185
#endif /* COMM_CAN_H_ */

commands.c

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,12 @@ void commands_process_packet(unsigned char *data, unsigned int len,
212212

213213
send_buffer[ind++] = 0; // No custom config
214214

215+
#ifdef HW_HAS_PHASE_FILTERS
216+
send_buffer[ind++] = 1;
217+
#else
218+
send_buffer[ind++] = 0;
219+
#endif
220+
215221
fw_version_sent_cnt++;
216222

217223
reply_func(send_buffer, ind);
@@ -452,6 +458,7 @@ void commands_process_packet(unsigned char *data, unsigned int len,
452458
} break;
453459

454460
case COMM_SET_MCCONF: {
461+
#ifndef HW_MCCONF_READ_ONLY
455462
mc_configuration *mcconf = mempools_alloc_mcconf();
456463
*mcconf = *mc_interface_get_configuration();
457464

@@ -484,6 +491,7 @@ void commands_process_packet(unsigned char *data, unsigned int len,
484491
}
485492

486493
mempools_free_mcconf(mcconf);
494+
#endif
487495
} break;
488496

489497
case COMM_GET_MCCONF:
@@ -501,6 +509,7 @@ void commands_process_packet(unsigned char *data, unsigned int len,
501509
} break;
502510

503511
case COMM_SET_APPCONF: {
512+
#ifndef HW_APPCONF_READ_ONLY
504513
app_configuration *appconf = mempools_alloc_appconf();
505514
*appconf = *app_get_configuration();
506515

@@ -526,6 +535,7 @@ void commands_process_packet(unsigned char *data, unsigned int len,
526535
}
527536

528537
mempools_free_appconf(appconf);
538+
#endif
529539
} break;
530540

531541
case COMM_GET_APPCONF:
@@ -1179,6 +1189,56 @@ void commands_process_packet(unsigned char *data, unsigned int len,
11791189
break;
11801190
}
11811191

1192+
// Power switch
1193+
case COMM_PSW_GET_STATUS: {
1194+
int32_t ind = 0;
1195+
bool by_id = data[ind++];
1196+
int id_ind = buffer_get_int16(data, &ind);
1197+
1198+
int psws_num = 0;
1199+
for (int i = 0;i < CAN_STATUS_MSGS_TO_STORE;i++) {
1200+
psw_status *stat = comm_can_get_psw_status_index(i);
1201+
if (stat->id >= 0) {
1202+
psws_num++;
1203+
} else {
1204+
break;
1205+
}
1206+
}
1207+
1208+
psw_status *stat = 0;
1209+
if (by_id) {
1210+
stat = comm_can_get_psw_status_id(id_ind);
1211+
} else if (id_ind < psws_num) {
1212+
stat = comm_can_get_psw_status_index(id_ind);
1213+
}
1214+
1215+
if (stat) {
1216+
ind = 0;
1217+
uint8_t send_buffer[70];
1218+
1219+
send_buffer[ind++] = packet_id;
1220+
buffer_append_int16(send_buffer, stat->id, &ind);
1221+
buffer_append_int16(send_buffer, psws_num, &ind);
1222+
buffer_append_float32_auto(send_buffer, UTILS_AGE_S(stat->rx_time), &ind);
1223+
buffer_append_float32_auto(send_buffer, stat->v_in, &ind);
1224+
buffer_append_float32_auto(send_buffer, stat->v_out, &ind);
1225+
buffer_append_float32_auto(send_buffer, stat->temp, &ind);
1226+
send_buffer[ind++] = stat->is_out_on;
1227+
send_buffer[ind++] = stat->is_pch_on;
1228+
send_buffer[ind++] = stat->is_dsc_on;
1229+
1230+
reply_func(send_buffer, ind);
1231+
}
1232+
} break;
1233+
1234+
case COMM_PSW_SWITCH: {
1235+
int32_t ind = 0;
1236+
int id = buffer_get_int16(data, &ind);
1237+
bool is_on = data[ind++];
1238+
bool plot = data[ind++];
1239+
comm_can_psw_switch(id, is_on, plot);
1240+
} break;
1241+
11821242
// Blocking commands. Only one of them runs at any given time, in their
11831243
// own thread. If other blocking commands come before the previous one has
11841244
// finished, they are discarded.

conf_general.c

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
Copyright 2016 - 2019 Benjamin Vedder benjamin@vedder.se
2+
Copyright 2016 - 2021 Benjamin Vedder benjamin@vedder.se
33
44
This file is part of the VESC firmware.
55
@@ -1165,8 +1165,8 @@ void conf_general_calc_apply_foc_cc_kp_ki_gain(mc_configuration *mcconf, float t
11651165
float bw = 1.0 / (tc * 1e-6);
11661166
float kp = l * bw;
11671167
float ki = r * bw;
1168-
float gain = 1.0e-3 / (lambda * lambda);
1169-
// float gain = (0.00001 / r) / (lambda * lambda); // Old method
1168+
float gain = 1.0e-3 / SQ(lambda);
1169+
// float gain = (0.00001 / r) / SQ(lambda); // Old method
11701170

11711171
mcconf->foc_current_kp = kp;
11721172
mcconf->foc_current_ki = ki;
@@ -1519,6 +1519,14 @@ int conf_general_detect_apply_all_foc(float max_power_loss,
15191519
mcconf_old->foc_motor_r = r;
15201520
mcconf_old->foc_motor_l = l;
15211521
mcconf_old->foc_motor_flux_linkage = lambda;
1522+
1523+
if (mc_interface_temp_motor_filtered() > -10) {
1524+
mcconf_old->foc_temp_comp_base_temp = mc_interface_temp_motor_filtered();
1525+
#ifdef HW_HAS_PHASE_FILTERS
1526+
mcconf_old->foc_temp_comp = true;
1527+
#endif
1528+
}
1529+
15221530
conf_general_calc_apply_foc_cc_kp_ki_gain(mcconf_old, 1000);
15231531
mc_interface_set_configuration(mcconf_old);
15241532

@@ -1531,12 +1539,18 @@ int conf_general_detect_apply_all_foc(float max_power_loss,
15311539
mcconf_old_second->foc_motor_flux_linkage = linkage_args.linkage;
15321540
conf_general_calc_apply_foc_cc_kp_ki_gain(mcconf_old_second, 1000);
15331541
mc_interface_select_motor_thread(2);
1542+
1543+
if (mc_interface_temp_motor_filtered() > -10) {
1544+
mcconf_old_second->foc_temp_comp_base_temp = mc_interface_temp_motor_filtered();
1545+
#ifdef HW_HAS_PHASE_FILTERS
1546+
mcconf_old_second->foc_temp_comp = true;
1547+
#endif
1548+
}
1549+
15341550
mc_interface_set_configuration(mcconf_old_second);
15351551
mc_interface_select_motor_thread(1);
15361552
#endif
15371553

1538-
// TODO: optionally apply temperature compensation here.
1539-
15401554
wait_motor_stop(10000);
15411555

15421556
#ifdef HW_HAS_DUAL_MOTORS

conf_general.h

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
#define FW_VERSION_MAJOR 5
2525
#define FW_VERSION_MINOR 03
2626
// Set to 0 for building a release and iterate during beta test builds
27-
#define FW_TEST_VERSION_NUMBER 2
27+
#define FW_TEST_VERSION_NUMBER 5
2828

2929
#include "datatypes.h"
3030

@@ -74,8 +74,8 @@
7474
//#define HW60_IS_MK4
7575
#define HW60_IS_MK5
7676

77-
#define HW_SOURCE "hw_60.c"
78-
#define HW_HEADER "hw_60.h"
77+
//#define HW_SOURCE "hw_60.c"
78+
//#define HW_HEADER "hw_60.h"
7979

8080
//#define HW_SOURCE "hw_r2.c"
8181
//#define HW_HEADER "hw_r2.h"
@@ -123,8 +123,8 @@
123123
//#define HW_SOURCE "hw_binar_v1.c"
124124
//#define HW_HEADER "hw_binar_v1.h"
125125

126-
//#define HW_SOURCE "hw_hd60.c"
127-
//#define HW_HEADER "hw_hd60.h"
126+
#define HW_SOURCE "hw_hd60.c"
127+
#define HW_HEADER "hw_hd60.h"
128128

129129
//#define HW_SOURCE "hw_hd75.c"
130130
//#define HW_HEADER "hw_hd75.h"
@@ -170,6 +170,9 @@
170170
//#define HW_SOURCE "hw_Little_FOCer.c"
171171
//#define HW_HEADER "hw_Little_FOCer.h"
172172

173+
//#define HW_SOURCE "hw_100_500.c"
174+
//#define HW_HEADER "hw_100_500.h"
175+
173176
#endif
174177

175178
#ifndef HW_SOURCE

0 commit comments

Comments
 (0)