Skip to content

Commit 5d385c0

Browse files
committed
Added UAVCAN raw RPM command
1 parent 36c333c commit 5d385c0

File tree

4 files changed

+16
-5
lines changed

4 files changed

+16
-5
lines changed

confgenerator.c

+5-2
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,7 @@ int32_t confgenerator_serialize_appconf(uint8_t *buffer, const app_configuration
204204
buffer[ind++] = conf->can_mode;
205205
buffer[ind++] = (uint8_t)conf->uavcan_esc_index;
206206
buffer[ind++] = conf->uavcan_raw_mode;
207+
buffer_append_float32_auto(buffer, conf->uavcan_raw_rpm_max, &ind);
207208
buffer[ind++] = conf->servo_out_enable;
208209
buffer[ind++] = conf->kill_sw_mode;
209210
buffer[ind++] = conf->app_to_use;
@@ -223,7 +224,7 @@ int32_t confgenerator_serialize_appconf(uint8_t *buffer, const app_configuration
223224
buffer[ind++] = conf->app_ppm_conf.multi_esc;
224225
buffer[ind++] = conf->app_ppm_conf.tc;
225226
buffer_append_float32_auto(buffer, conf->app_ppm_conf.tc_max_diff, &ind);
226-
buffer_append_float32_auto(buffer, conf->app_ppm_conf.max_erpm_for_dir, &ind);
227+
buffer_append_float16(buffer, conf->app_ppm_conf.max_erpm_for_dir, 1, &ind);
227228
buffer_append_float32_auto(buffer, conf->app_ppm_conf.smart_rev_max_duty, &ind);
228229
buffer_append_float32_auto(buffer, conf->app_ppm_conf.smart_rev_ramp_time, &ind);
229230
buffer[ind++] = conf->app_adc_conf.ctrl_type;
@@ -574,6 +575,7 @@ bool confgenerator_deserialize_appconf(const uint8_t *buffer, app_configuration
574575
conf->can_mode = buffer[ind++];
575576
conf->uavcan_esc_index = buffer[ind++];
576577
conf->uavcan_raw_mode = buffer[ind++];
578+
conf->uavcan_raw_rpm_max = buffer_get_float32_auto(buffer, &ind);
577579
conf->servo_out_enable = buffer[ind++];
578580
conf->kill_sw_mode = buffer[ind++];
579581
conf->app_to_use = buffer[ind++];
@@ -593,7 +595,7 @@ bool confgenerator_deserialize_appconf(const uint8_t *buffer, app_configuration
593595
conf->app_ppm_conf.multi_esc = buffer[ind++];
594596
conf->app_ppm_conf.tc = buffer[ind++];
595597
conf->app_ppm_conf.tc_max_diff = buffer_get_float32_auto(buffer, &ind);
596-
conf->app_ppm_conf.max_erpm_for_dir = buffer_get_float32_auto(buffer, &ind);
598+
conf->app_ppm_conf.max_erpm_for_dir = buffer_get_float16(buffer, 1, &ind);
597599
conf->app_ppm_conf.smart_rev_max_duty = buffer_get_float32_auto(buffer, &ind);
598600
conf->app_ppm_conf.smart_rev_ramp_time = buffer_get_float32_auto(buffer, &ind);
599601
conf->app_adc_conf.ctrl_type = buffer[ind++];
@@ -928,6 +930,7 @@ void confgenerator_set_defaults_appconf(app_configuration *conf) {
928930
conf->can_mode = APPCONF_CAN_MODE;
929931
conf->uavcan_esc_index = APPCONF_UAVCAN_ESC_INDEX;
930932
conf->uavcan_raw_mode = APPCONF_UAVCAN_RAW_MODE;
933+
conf->uavcan_raw_rpm_max = APPCONF_UAVCAN_RAW_RPM_MAX;
931934
conf->servo_out_enable = APPCONF_SERVO_OUT_ENABLE;
932935
conf->kill_sw_mode = APPCONF_KILL_SW_MODE;
933936
conf->app_to_use = APPCONF_APP_TO_USE;

confgenerator.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
// Constants
1111
#define MCCONF_SIGNATURE 2686986464
12-
#define APPCONF_SIGNATURE 763356168
12+
#define APPCONF_SIGNATURE 3733512279
1313

1414
// Functions
1515
int32_t confgenerator_serialize_mcconf(uint8_t *buffer, const mc_configuration *conf);

datatypes.h

+3-1
Original file line numberDiff line numberDiff line change
@@ -854,7 +854,8 @@ typedef enum {
854854
typedef enum {
855855
UAVCAN_RAW_MODE_CURRENT = 0,
856856
UAVCAN_RAW_MODE_CURRENT_NO_REV_BRAKE,
857-
UAVCAN_RAW_MODE_DUTY
857+
UAVCAN_RAW_MODE_DUTY,
858+
UAVCAN_RAW_MODE_RPM
858859
} UAVCAN_RAW_MODE;
859860

860861
typedef enum {
@@ -883,6 +884,7 @@ typedef struct {
883884
CAN_MODE can_mode;
884885
uint8_t uavcan_esc_index;
885886
UAVCAN_RAW_MODE uavcan_raw_mode;
887+
float uavcan_raw_rpm_max;
886888

887889
// Application to use
888890
app_use app_to_use;

libcanard/canard_driver.c

+7-1
Original file line numberDiff line numberDiff line change
@@ -510,7 +510,9 @@ static void handle_esc_raw_command(CanardInstance* ins, CanardRxTransfer* transf
510510
if (cmd.cmd.len > app_get_configuration()->uavcan_esc_index) {
511511
float raw_val = ((float)cmd.cmd.data[app_get_configuration()->uavcan_esc_index]) / 8192.0;
512512

513-
switch (app_get_configuration()->uavcan_raw_mode) {
513+
volatile const app_configuration *conf = app_get_configuration();
514+
515+
switch (conf->uavcan_raw_mode) {
514516
case UAVCAN_RAW_MODE_CURRENT:
515517
mc_interface_set_current_rel(raw_val);
516518
break;
@@ -527,6 +529,10 @@ static void handle_esc_raw_command(CanardInstance* ins, CanardRxTransfer* transf
527529
mc_interface_set_duty(raw_val);
528530
break;
529531

532+
case UAVCAN_RAW_MODE_RPM:
533+
mc_interface_set_pid_speed(raw_val * conf->uavcan_raw_rpm_max);
534+
break;
535+
530536
default:
531537
break;
532538
}

0 commit comments

Comments
 (0)