Send foc can detect result back to sender even if some other interface communicates in-between

This commit is contained in:
Benjamin Vedder 2022-11-22 18:18:38 +01:00
parent 297e3ad434
commit 1e7da25160
5 changed files with 16 additions and 8 deletions

View File

@ -2229,7 +2229,7 @@ static THD_FUNCTION(blocking_thread, arg) {
float sl_erpm = buffer_get_float32(data, 1e3, &ind);
int res = conf_general_detect_apply_all_foc_can(detect_can, max_power_loss,
min_current_in, max_current_in, openloop_rpm, sl_erpm);
min_current_in, max_current_in, openloop_rpm, sl_erpm, send_func_blocking);
ind = 0;
send_buffer[ind++] = COMM_DETECT_APPLY_ALL_FOC;

View File

@ -2002,13 +2002,19 @@ int conf_general_detect_apply_all_foc(float max_power_loss,
* @param sl_erpm
* FOC ERPM above which sensorless should be used in sensored modes. 0 means leave it unchanged.
*
* @param reply_func
* Send the motor and app config using this function pointer. If it is null the last function
* from commands will be used.
*
* @return
* Same as conf_general_detect_apply_all_foc, and
* -50: CAN detection timed out
* -51: CAN detection failed
*/
int conf_general_detect_apply_all_foc_can(bool detect_can, float max_power_loss,
float min_current_in, float max_current_in, float openloop_rpm, float sl_erpm) {
float min_current_in, float max_current_in,
float openloop_rpm, float sl_erpm,
void(*reply_func)(unsigned char* data, unsigned int len)) {
int motor_last = mc_interface_get_motor_thread();
mc_interface_select_motor_thread(1);
@ -2126,7 +2132,7 @@ int conf_general_detect_apply_all_foc_can(bool detect_can, float max_power_loss,
appconf->can_status_msgs_r1 = 0b00001111;
conf_general_store_app_configuration(appconf);
app_set_configuration(appconf);
commands_send_appconf(COMM_GET_APPCONF, appconf, 0);
commands_send_appconf(COMM_GET_APPCONF, appconf, reply_func);
chThdSleepMilliseconds(1000);
}
@ -2139,7 +2145,7 @@ int conf_general_detect_apply_all_foc_can(bool detect_can, float max_power_loss,
mc_interface_select_motor_thread(1);
*mcconf = *mc_interface_get_configuration();
#endif
commands_send_mcconf(COMM_GET_MCCONF, mcconf, 0);
commands_send_mcconf(COMM_GET_MCCONF, mcconf, reply_func);
chThdSleepMilliseconds(1000);
}

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 81
#define FW_TEST_VERSION_NUMBER 82
#include "datatypes.h"
@ -189,7 +189,9 @@ void conf_general_calc_apply_foc_cc_kp_ki_gain(mc_configuration *mcconf, float t
int conf_general_detect_apply_all_foc(float max_power_loss,
bool store_mcconf_on_success, bool send_mcconf_on_success);
int conf_general_detect_apply_all_foc_can(bool detect_can, float max_power_loss,
float min_current_in, float max_current_in, float openloop_rpm, float sl_erpm);
float min_current_in, float max_current_in,
float openloop_rpm, float sl_erpm,
void(*reply_func)(unsigned char* data, unsigned int len));
#endif /* CONF_GENERAL_H_ */

View File

@ -3399,7 +3399,7 @@ typedef struct {
static void detect_task(void *arg) {
detect_args *a = (detect_args*)arg;
int res = conf_general_detect_apply_all_foc_can(a->detect_can, a->max_power_loss,
a->min_current_in, a->max_current_in, a->openloop_rpm, a->sl_erpm);
a->min_current_in, a->max_current_in, a->openloop_rpm, a->sl_erpm, NULL);
lbm_unblock_ctx(a->id, lbm_enc_i(res));
}

View File

@ -879,7 +879,7 @@ void terminal_process_string(char *str) {
commands_printf("Running detection...");
if (max_power_loss > 0.0) {
int res = conf_general_detect_apply_all_foc_can(true, max_power_loss, 0.0, 0.0, 0.0, 0.0);
int res = conf_general_detect_apply_all_foc_can(true, max_power_loss, 0.0, 0.0, 0.0, 0.0, NULL);
commands_printf("Res: %d", res);