diff --git a/.eide/bc2d-pos.arm.options.gcc.json b/.eide/bc2d-pos.arm.options.gcc.json new file mode 100644 index 0000000..961a577 --- /dev/null +++ b/.eide/bc2d-pos.arm.options.gcc.json @@ -0,0 +1,29 @@ +{ + "version": 5, + "beforeBuildTasks": [], + "afterBuildTasks": [], + "global": { + "$float-abi-type": "softfp", + "output-debug-info": "enable", + "misc-control": "--specs=nosys.specs --specs=nano.specs" + }, + "c/cpp-compiler": { + "language-c": "c11", + "language-cpp": "c++11", + "optimization": "level-debug", + "warnings": "all-warnings", + "one-elf-section-per-function": true, + "one-elf-section-per-data": true, + "C_FLAGS": "", + "CXX_FLAGS": "" + }, + "asm-compiler": { + "ASM_FLAGS": "" + }, + "linker": { + "output-format": "elf", + "remove-unused-input-sections": true, + "LD_FLAGS": "", + "LIB_FLAGS": "-lm" + } +} \ No newline at end of file diff --git a/.eide/bc2d-pos.files.options.yml b/.eide/bc2d-pos.files.options.yml new file mode 100644 index 0000000..2486c4f --- /dev/null +++ b/.eide/bc2d-pos.files.options.yml @@ -0,0 +1,31 @@ +########################################################################################## +# Append Compiler Options For Source Files +# +# syntax: +# : +# +# examples: +# 'main.cpp': --cpp11 -Og ... +# 'src/*.c': -gnu -O2 ... +# 'src/lib/**/*.cpp': --cpp11 -Os ... +# '!Application/*.c': -O0 +# '**/*.c': -O2 -gnu ... +# +# For more syntax, please refer to: https://www.npmjs.com/package/micromatch +# +########################################################################################## + +version: '1.0' + +# +# for source files with filesystem paths +# +files: +# './test/**/*.c': --c99 + +# +# for source files with virtual paths +# +virtualPathFiles: +# 'virtual_folder/**/*.c': --c99 + diff --git a/.eide/bc2d.arm.options.v5.json b/.eide/bc2d.arm.options.v5.json deleted file mode 100644 index 1e7f380..0000000 --- a/.eide/bc2d.arm.options.v5.json +++ /dev/null @@ -1,24 +0,0 @@ -{ - "version": 4, - "beforeBuildTasks": [], - "afterBuildTasks": [], - "global": { - "use-microLIB": true, - "output-debug-info": "enable" - }, - "c/cpp-compiler": { - "optimization": "level-0", - "one-elf-section-per-function": true, - "c99-mode": true, - "C_FLAGS": "--diag_suppress=1 --diag_suppress=1295", - "CXX_FLAGS": "--diag_suppress=1 --diag_suppress=1295", - "warnings": "all-warnings" - }, - "asm-compiler": {}, - "linker": { - "output-format": "elf", - "xo-base": "", - "ro-base": "0x08000000", - "rw-base": "0x20000000" - } -} \ No newline at end of file diff --git a/.eide/eide.json b/.eide/eide.json index 7b61839..fb9bcd6 100644 --- a/.eide/eide.json +++ b/.eide/eide.json @@ -1,5 +1,5 @@ { - "name": "BC2D", + "name": "BC2D-POS", "type": "ARM", "dependenceList": [], "srcDirs": [ @@ -89,7 +89,7 @@ "uid": "9d909db3024271625a98879e53e2d396" }, "targets": { - "BC2D": { + "BC2D-POS": { "excludeList": [], "toolchain": "GCC", "compileConfig": { @@ -131,7 +131,6 @@ "libraries/cmsis/cm4/device_support", "project/inc", ".cmsis/include", - "project/MDK_V5/RTE/_BC2D", ".eide/deps", "3rd-part/dwt_delay", "3rd-part/PID-Library", diff --git a/.vscode/settings.json b/.vscode/settings.json index 0b84e1d..a5ec91f 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,3 +1,3 @@ { - "sonarlint.pathToCompileCommands": "${workspaceFolder}\\build\\BC2D\\compile_commands.json" + "sonarlint.pathToCompileCommands": "${workspaceFolder}\\build\\BC2D-POS\\compile_commands.json" } \ No newline at end of file diff --git a/BC2D.ATWP b/BC2D-POS.ATWP similarity index 91% rename from BC2D.ATWP rename to BC2D-POS.ATWP index f17d0ca..5ae32a0 100644 --- a/BC2D.ATWP +++ b/BC2D-POS.ATWP @@ -54,6 +54,13 @@ + + + + + + + @@ -66,7 +73,7 @@ - + @@ -134,8 +141,8 @@ - BC2D - C:/Users/ForgotDoge/Desktop/BC2024/firmware + BC2D-POS + C:/Users/evan/Desktop/BC2024 MDK_V5 true 0x200 diff --git a/BC2D.code-workspace b/BC2D-POS.code-workspace similarity index 91% rename from BC2D.code-workspace rename to BC2D-POS.code-workspace index 0829fea..a414cf3 100644 --- a/BC2D.code-workspace +++ b/BC2D-POS.code-workspace @@ -30,7 +30,7 @@ "titleBar.activeBackground": "#1D18AE", "titleBar.activeForeground": "#FAFAFE" }, - "EIDE.OpenOCD.ExePath": "D:/Program Files (x86)/at32_OpenOCD_V2.0.2/bin/openocd.exe", + "EIDE.OpenOCD.ExePath": "C:/toolchains/openocd-arterytek/bin/openocd.exe", "cortex-debug.variableUseNaturalFormat": true }, "extensions": { diff --git a/app/by_motion.c b/app/by_motion.c index 49613cc..f6e01a5 100644 --- a/app/by_motion.c +++ b/app/by_motion.c @@ -16,7 +16,7 @@ uint8_t motion_enable_flag; void by_motion_set_pwm_m1(int32_t pwm_duty) { - pwm_duty = clip_s32(pwm_duty, -449, 449); // 不可以拉满哦 + pwm_duty = clip_s32(pwm_duty, -440, 440); // 不可以拉满哦 pwm_duty += 499; // 互补 pwm 输出,499 为中值 @@ -25,7 +25,7 @@ void by_motion_set_pwm_m1(int32_t pwm_duty) void by_motion_set_pwm_m2(int32_t pwm_duty) { - pwm_duty = clip_s32(pwm_duty, -449, 449); // 不可以拉满哦 + pwm_duty = clip_s32(pwm_duty, -440, 440); // 不可以拉满哦 pwm_duty += 499; // 互补 pwm 输出,499 为中值 @@ -36,7 +36,7 @@ int16_t by_motion_get_speed_m1(void) { #define alpha (0.1f) static float last_speed = 0.0f; - param_m1.real_speed = alpha * last_speed + (1.0f - alpha) * (float)(-1 * (int16_t)tmr_counter_value_get(TMR2)); + param_m1.real_speed = alpha * last_speed + (1.0f - alpha) * (float)(+1 * (int16_t)tmr_counter_value_get(TMR2)); last_speed = param_m1.real_speed; tmr_counter_value_set(TMR2, 0); return (int16_t)param_m1.real_speed; @@ -100,13 +100,13 @@ void by_motion_run(void) { if (motion_enable_flag) { by_motion_get_speed_m1(); - by_motion_get_speed_m2(); + // by_motion_get_speed_m2(); PID_Compute(&pid_m1); - PID_Compute(&pid_m2); + // PID_Compute(&pid_m2); by_motion_set_pwm_m1((int32_t)param_m1.out_pwm); - by_motion_set_pwm_m2((int32_t)param_m2.out_pwm); + // by_motion_set_pwm_m2((int32_t)param_m2.out_pwm); } } diff --git a/app/by_motion.h b/app/by_motion.h index fdf4fe0..c8e43ef 100644 --- a/app/by_motion.h +++ b/app/by_motion.h @@ -12,9 +12,9 @@ typedef struct by_motor_param { float out_pwm; } by_motor_param; -#define BY_MOTION_DEFAULT_KP_M1 (5.0f) -#define BY_MOTION_DEFAULT_KI_M1 (100.0f) -#define BY_MOTION_DEFAULT_KD_M1 (0.0f) +#define BY_MOTION_DEFAULT_KP_M1 (10.0f) +#define BY_MOTION_DEFAULT_KI_M1 (80.0f) +#define BY_MOTION_DEFAULT_KD_M1 (0.08f) #define BY_MOTION_DEFAULT_KP_M2 (5.0f) #define BY_MOTION_DEFAULT_KI_M2 (100.0f) #define BY_MOTION_DEFAULT_KD_M2 (0.0f) diff --git a/project/inc/at32f413_wk_config.h b/project/inc/at32f413_wk_config.h index 4c017e2..f490149 100644 --- a/project/inc/at32f413_wk_config.h +++ b/project/inc/at32f413_wk_config.h @@ -55,6 +55,65 @@ extern "C" { /* add user code end exported macro */ +/* add user code begin dma define */ +/* user can only modify the dma define value */ +//#define DMA1_CHANNEL1_BUFFER_SIZE 0 +//#define DMA1_CHANNEL1_MEMORY_BASE_ADDR 0 +//#define DMA1_CHANNEL1_PERIPHERAL_BASE_ADDR 0 + +//#define DMA1_CHANNEL2_BUFFER_SIZE 0 +//#define DMA1_CHANNEL2_MEMORY_BASE_ADDR 0 +//#define DMA1_CHANNEL2_PERIPHERAL_BASE_ADDR 0 + +//#define DMA1_CHANNEL3_BUFFER_SIZE 0 +//#define DMA1_CHANNEL3_MEMORY_BASE_ADDR 0 +//#define DMA1_CHANNEL3_PERIPHERAL_BASE_ADDR 0 + +//#define DMA1_CHANNEL4_BUFFER_SIZE 0 +//#define DMA1_CHANNEL4_MEMORY_BASE_ADDR 0 +//#define DMA1_CHANNEL4_PERIPHERAL_BASE_ADDR 0 + +//#define DMA1_CHANNEL5_BUFFER_SIZE 0 +//#define DMA1_CHANNEL5_MEMORY_BASE_ADDR 0 +//#define DMA1_CHANNEL5_PERIPHERAL_BASE_ADDR 0 + +//#define DMA1_CHANNEL6_BUFFER_SIZE 0 +//#define DMA1_CHANNEL6_MEMORY_BASE_ADDR 0 +//#define DMA1_CHANNEL6_PERIPHERAL_BASE_ADDR 0 + +//#define DMA1_CHANNEL7_BUFFER_SIZE 0 +//#define DMA1_CHANNEL7_MEMORY_BASE_ADDR 0 +//#define DMA1_CHANNEL7_PERIPHERAL_BASE_ADDR 0 + +//#define DMA2_CHANNEL1_BUFFER_SIZE 0 +//#define DMA2_CHANNEL1_MEMORY_BASE_ADDR 0 +//#define DMA2_CHANNEL1_PERIPHERAL_BASE_ADDR 0 + +//#define DMA2_CHANNEL2_BUFFER_SIZE 0 +//#define DMA2_CHANNEL2_MEMORY_BASE_ADDR 0 +//#define DMA2_CHANNEL2_PERIPHERAL_BASE_ADDR 0 + +//#define DMA2_CHANNEL3_BUFFER_SIZE 0 +//#define DMA2_CHANNEL3_MEMORY_BASE_ADDR 0 +//#define DMA2_CHANNEL3_PERIPHERAL_BASE_ADDR 0 + +//#define DMA2_CHANNEL4_BUFFER_SIZE 0 +//#define DMA2_CHANNEL4_MEMORY_BASE_ADDR 0 +//#define DMA2_CHANNEL4_PERIPHERAL_BASE_ADDR 0 + +//#define DMA2_CHANNEL5_BUFFER_SIZE 0 +//#define DMA2_CHANNEL5_MEMORY_BASE_ADDR 0 +//#define DMA2_CHANNEL5_PERIPHERAL_BASE_ADDR 0 + +//#define DMA2_CHANNEL6_BUFFER_SIZE 0 +//#define DMA2_CHANNEL6_MEMORY_BASE_ADDR 0 +//#define DMA2_CHANNEL6_PERIPHERAL_BASE_ADDR 0 + +//#define DMA2_CHANNEL7_BUFFER_SIZE 0 +//#define DMA2_CHANNEL7_MEMORY_BASE_ADDR 0 +//#define DMA2_CHANNEL7_PERIPHERAL_BASE_ADDR 0 +/* add user code end dma define */ + /* exported functions ------------------------------------------------------- */ /* system clock config. */ void wk_system_clock_config(void); diff --git a/project/src/at32f413_wk_config.c b/project/src/at32f413_wk_config.c index 5f0a3c0..a3efcd6 100644 --- a/project/src/at32f413_wk_config.c +++ b/project/src/at32f413_wk_config.c @@ -461,16 +461,16 @@ void wk_tmr2_init(void) tmr_input_struct.input_channel_select = TMR_SELECT_CHANNEL_1; tmr_input_struct.input_mapped_select = TMR_CC_CHANNEL_MAPPED_DIRECT; tmr_input_struct.input_polarity_select = TMR_INPUT_RISING_EDGE; - tmr_input_struct.input_filter_value = 0; + tmr_input_struct.input_filter_value = 7; tmr_input_channel_init(TMR2, &tmr_input_struct, TMR_CHANNEL_INPUT_DIV_1); tmr_input_struct.input_channel_select = TMR_SELECT_CHANNEL_2; tmr_input_struct.input_mapped_select = TMR_CC_CHANNEL_MAPPED_DIRECT; tmr_input_struct.input_polarity_select = TMR_INPUT_RISING_EDGE; - tmr_input_struct.input_filter_value = 0; + tmr_input_struct.input_filter_value = 7; tmr_input_channel_init(TMR2, &tmr_input_struct, TMR_CHANNEL_INPUT_DIV_1); - tmr_encoder_mode_config(TMR2, TMR_ENCODER_MODE_A, TMR_INPUT_RISING_EDGE, TMR_INPUT_RISING_EDGE); + tmr_encoder_mode_config(TMR2, TMR_ENCODER_MODE_B, TMR_INPUT_RISING_EDGE, TMR_INPUT_RISING_EDGE); tmr_counter_enable(TMR2, TRUE); @@ -564,7 +564,7 @@ void wk_tmr4_init(void) /* add user code end tmr4_init 1 */ /* configure counter settings */ - tmr_base_init(TMR4, 1999, 999); + tmr_base_init(TMR4, 1999, 1999); tmr_cnt_dir_set(TMR4, TMR_COUNT_UP); tmr_clock_source_div_set(TMR4, TMR_CLOCK_DIV1); tmr_period_buffer_enable(TMR4, FALSE); diff --git a/project/src/main.c b/project/src/main.c index bc72ac5..6feb0b4 100644 --- a/project/src/main.c +++ b/project/src/main.c @@ -68,10 +68,10 @@ /* add user code end 0 */ /** - * @brief main function. - * @param none - * @retval none - */ + * @brief main function. + * @param none + * @retval none + */ int main(void) { /* add user code begin 1 */ @@ -124,8 +124,12 @@ int main(void) LOGI("init done"); /* add user code end 2 */ - while (1) { + while(1) + { /* add user code begin 3 */ + // lwprintf("pwm value: %f\r\n", param_m1.out_pwm); + // lwprintf("mot speed: %f\r\n", param_m1.real_speed); + lwprintf("%f,%f,%f\r\n", param_m1.real_speed, param_m1.target_speed, param_m1.out_pwm); /* add user code end 3 */ } }