From b75f3130ff5e0dd69bcb7e253e7d00a779df5271 Mon Sep 17 00:00:00 2001 From: Oskar Weigl Date: Mon, 18 Sep 2017 21:16:49 -0700 Subject: [PATCH] start hw version define split --- .vscode/settings.json | 19 ------------------- Inc/main.h | 3 +++ Makefile | 7 +++++++ MotorControl/low_level.c | 33 ++++++++++++++++++--------------- 4 files changed, 28 insertions(+), 34 deletions(-) diff --git a/.vscode/settings.json b/.vscode/settings.json index 528798a1..3c85c084 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,22 +1,3 @@ { - "files.associations": { - "stm32f4xx_hal.h": "c", - "spi.h": "c", - "gpio.h": "c", - "type_traits": "cpp", - "utility": "c", - "low_level.h": "cpp", - "motor.h": "cpp", - "math.h": "c", - "encoder.h": "cpp", - "xutility": "c", - "usb_commands.h": "cpp", - "sensorless.h": "cpp", - "usbd_cdc_if.h": "c", - "drv8301.h": "c", - "adc.h": "c", - "configuration.h": "cpp", - "utils.h": "cpp" - }, "C_Cpp.clang_format_style": "{ BasedOnStyle: Google, IndentWidth: 4, ColumnLimit: 0 }" } \ No newline at end of file diff --git a/Inc/main.h b/Inc/main.h index 50fd3061..b5ac30ab 100644 --- a/Inc/main.h +++ b/Inc/main.h @@ -52,6 +52,9 @@ /* USER CODE BEGIN Includes */ +#define HW_VERSION_MAJOR 3 +#define HW_VERSION_MINOR 3 + /* USER CODE END Includes */ /* Private define ------------------------------------------------------------*/ diff --git a/Makefile b/Makefile index 2412327b..f11b2b2d 100644 --- a/Makefile +++ b/Makefile @@ -86,6 +86,7 @@ ASM_SOURCES = \ # binaries ####################################### CC = arm-none-eabi-gcc +CXX = arm-none-eabi-g++ AS = arm-none-eabi-gcc -x assembler-with-cpp CP = arm-none-eabi-objcopy AR = arm-none-eabi-ar @@ -116,11 +117,14 @@ C_INCLUDES += -IMotorControl # compile gcc flags ASFLAGS = -mthumb -mcpu=cortex-m4 -mfpu=fpv4-sp-d16 -mfloat-abi=hard $(AS_DEFS) $(AS_INCLUDES) $(OPT) -Wall -fdata-sections -ffunction-sections CFLAGS = -mthumb -mcpu=cortex-m4 -mfpu=fpv4-sp-d16 -mfloat-abi=hard $(C_DEFS) $(C_INCLUDES) $(OPT) -Wall -fdata-sections -ffunction-sections +CXXFLAGS = -mthumb -mcpu=cortex-m4 -mfpu=fpv4-sp-d16 -mfloat-abi=hard $(C_DEFS) $(C_INCLUDES) $(OPT) -Wall -fdata-sections -ffunction-sections ifeq ($(DEBUG), 1) CFLAGS += -g -gdwarf-2 +CXXFLAGS += -g -gdwarf-2 endif # Generate dependency information CFLAGS += -std=c99 -MD -MP -MF .dep/$(@F).d +CXXFLAGS += -std=c++14 -MD -MP -MF .dep/$(@F).d ####################################### # LDFLAGS @@ -141,6 +145,9 @@ all: $(BUILD_DIR)/$(TARGET).elf $(BUILD_DIR)/$(TARGET).hex $(BUILD_DIR)/$(TARGET # list of objects OBJECTS = $(addprefix $(BUILD_DIR)/,$(notdir $(C_SOURCES:.c=.o))) vpath %.c $(sort $(dir $(C_SOURCES))) +# list of C++ objects +OBJECTS += $(addprefix $(BUILD_DIR)/,$(notdir $(CPP_SOURCES:.cpp=.o))) +vpath %.cpp $(sort $(dir $(CPP_SOURCES))) # list of ASM program objects OBJECTS += $(addprefix $(BUILD_DIR)/,$(notdir $(ASM_SOURCES:.s=.o))) vpath %.s $(sort $(dir $(ASM_SOURCES))) diff --git a/MotorControl/low_level.c b/MotorControl/low_level.c index 785cd4fa..a0827a91 100755 --- a/MotorControl/low_level.c +++ b/MotorControl/low_level.c @@ -41,20 +41,20 @@ static float elec_rad_per_enc = POLE_PAIRS * 2 * M_PI * (1.0f / (float)ENCODER_C // TODO: For nice encapsulation, consider not having the motor objects public Motor_t motors[] = { { // M0 - .control_mode = CTRL_MODE_VELOCITY_CONTROL, //see: Motor_control_mode_t + .control_mode = CTRL_MODE_POSITION_CONTROL, //see: Motor_control_mode_t .enable_step_dir = false, //auto enabled after calibration .counts_per_step = 2.0f, .error = ERROR_NO_ERROR, .pos_setpoint = 0.0f, .pos_gain = 20.0f, // [(counts/s) / counts] - // .vel_setpoint = 40000.0f, - .vel_setpoint = 800.0f, - // .vel_gain = 15.0f / 10000.0f, // [A/(counts/s)] - .vel_gain = 15.0f / 200.0f, // [A/(rad/s)] - // .vel_integrator_gain = 10.0f / 10000.0f, // [A/(counts/s * s)] - .vel_integrator_gain = 0.0f, // [A/(rad/s * s)] + .vel_setpoint = 0.0f, + // .vel_setpoint = 800.0f, + .vel_gain = 15.0f / 10000.0f, // [A/(counts/s)] + // .vel_gain = 15.0f / 200.0f, // [A/(rad/s)] + .vel_integrator_gain = 10.0f / 10000.0f, // [A/(counts/s * s)] + // .vel_integrator_gain = 0.0f, // [A/(rad/s * s)] .vel_integrator_current = 0.0f, // [A] - .vel_limit = 80000.0f, // [counts/s] + .vel_limit = 20000.0f, // [counts/s] .current_setpoint = 0.0f, // [A] .calibration_current = 10.0f, // [A] .phase_inductance = 0.0f, // to be set by measure_phase_inductance @@ -84,7 +84,7 @@ Motor_t motors[] = { .shunt_conductance = 1.0f/0.0005f, //[S] .phase_current_rev_gain = 0.0f, // to be set by DRV8301_setup .current_control = { - // .current_lim = 75.0f, //[A] // Note: consistent with 40v/v gain + // .current_lim = 75.0f, //[A] // Note: consistent with 40v/v gain, TODO: auto limit from gain settings .current_lim = 10.0f, //[A] .p_gain = 0.0f, // [V/A] should be auto set after resistance and inductance measurement .i_gain = 0.0f, // [V/As] should be auto set after resistance and inductance measurement @@ -94,9 +94,9 @@ Motor_t motors[] = { .final_v_alpha = 0.0f, .final_v_beta = 0.0f, }, - // .rotor_mode = ROTOR_MODE_ENCODER, + // .rotor_mode = ROTOR_MODE_SENSORLESS, // .rotor_mode = ROTOR_MODE_RUN_ENCODER_TEST_SENSORLESS, - .rotor_mode = ROTOR_MODE_SENSORLESS, + .rotor_mode = ROTOR_MODE_ENCODER, .encoder = { .encoder_timer = &htim3, .encoder_offset = 0, @@ -127,7 +127,7 @@ Motor_t motors[] = { .timing_log = {0}, }, { // M1 - .control_mode = CTRL_MODE_VELOCITY_CONTROL, //see: Motor_control_mode_t + .control_mode = CTRL_MODE_POSITION_CONTROL, //see: Motor_control_mode_t .enable_step_dir = false, //auto enabled after calibration .counts_per_step = 2.0f, .error = ERROR_NO_ERROR, @@ -144,8 +144,8 @@ Motor_t motors[] = { .phase_resistance = 0.0f, // to be set by measure_phase_resistance .motor_thread = 0, .thread_ready = false, - .enable_control = false, - .do_calibration = false, + .enable_control = true, + .do_calibration = true, .calibration_ok = false, .motor_timer = &htim8, .next_timings = {TIM_1_8_PERIOD_CLOCKS/2, TIM_1_8_PERIOD_CLOCKS/2, TIM_1_8_PERIOD_CLOCKS/2}, @@ -167,7 +167,7 @@ Motor_t motors[] = { .shunt_conductance = 1.0f/0.0005f, //[S] .phase_current_rev_gain = 0.0f, // to be set by DRV8301_setup .current_control = { - // .current_lim = 75.0f, //[A] // Note: consistent with 40v/v gain + // .current_lim = 75.0f, //[A] // Note: consistent with 40v/v gain, TODO: auto limit from gain settings .current_lim = 10.0f, //[A] .p_gain = 0.0f, // [V/A] should be auto set after resistance and inductance measurement .i_gain = 0.0f, // [V/As] should be auto set after resistance and inductance measurement @@ -200,6 +200,9 @@ Motor_t motors[] = { .V_alpha_beta_memory = {0.0f, 0.0f}, // [V] .pm_flux_linkage = 1.58e-3f, // [V / (rad/s)] { 5.51328895422 / ( * ) } .estimator_good = false, + .spin_up_current = 10.0f, // [A] + .spin_up_acceleration = 400.0f, // [rad/s^2] + .spin_up_target_vel = 400.0f, // [rad/s] }, .timing_log_index = 0, .timing_log = {0}