Skip to content

Commit

Permalink
Send foc can detect result back to sender even if some other interfac…
Browse files Browse the repository at this point in the history
…e communicates in-between
  • Loading branch information
vedderb committed Nov 22, 2022
1 parent 297e3ad commit 1e7da25
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 8 deletions.
2 changes: 1 addition & 1 deletion comm/commands.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
12 changes: 9 additions & 3 deletions conf_general.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
}

Expand All @@ -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);
}

Expand Down
6 changes: 4 additions & 2 deletions conf_general.h
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -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_ */
2 changes: 1 addition & 1 deletion lispBM/lispif_vesc_extensions.c
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}

Expand Down
2 changes: 1 addition & 1 deletion terminal.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down

0 comments on commit 1e7da25

Please sign in to comment.