From 0517164e429687fd43b099d4073dc90aab074eb3 Mon Sep 17 00:00:00 2001
From: bmy <2583236812@qq.com>
Date: Sun, 2 Jun 2024 17:01:35 +0800
Subject: [PATCH] =?UTF-8?q?feat:=20=E6=8E=A5=E5=8F=A3=E6=9B=B4=E6=96=B0?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
BC1C.ATWP | 20 ++++-
BC1C.code-workspace | 4 +-
app/by_messy.c | 74 ++++++++++++++-
project/inc/at32f403a_407_wk_config.h | 59 ++++++++++++
project/src/at32f403a_407_int.c | 124 +++++++++++++-------------
project/src/at32f403a_407_wk_config.c | 4 +-
project/src/main.c | 14 +--
7 files changed, 227 insertions(+), 72 deletions(-)
diff --git a/BC1C.ATWP b/BC1C.ATWP
index e82e475..6dabddf 100644
--- a/BC1C.ATWP
+++ b/BC1C.ATWP
@@ -155,6 +155,24 @@
0;0;0
0;0;0
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
0
8.000000
@@ -214,7 +232,7 @@
BC1C
- C:/Users/ForgotDoge/Desktop/BC2024/firmware
+ C:/Users/evan/Desktop/BC2024
MDK_V5
true
0x200
diff --git a/BC1C.code-workspace b/BC1C.code-workspace
index 38de214..8ab9dfc 100644
--- a/BC1C.code-workspace
+++ b/BC1C.code-workspace
@@ -25,13 +25,13 @@
"editor.tabSize": 4,
"editor.autoIndent": "advanced"
},
- "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",
"workbench.colorCustomizations": {
"activityBar.background": "#4B2301",
"titleBar.activeBackground": "#693002",
"titleBar.activeForeground": "#FFF9F4"
},
- "cortex-debug.variableUseNaturalFormat": true
+ "cortex-debug.variableUseNaturalFormat": false
},
"extensions": {
}
diff --git a/app/by_messy.c b/app/by_messy.c
index 2d05343..2944a64 100644
--- a/app/by_messy.c
+++ b/app/by_messy.c
@@ -3,6 +3,7 @@
#include "lwprintf.h"
#include "by_frame.h"
#include "by_motion.h"
+#include "by_can.h"
void by_messy_init(void)
{
@@ -12,6 +13,9 @@ void by_messy_init(void)
void by_messy_loop(void)
{
uint8_t cmd = 0;
+ uint8_t buff_t_u8[8] = {0};
+ uint16_t buff_t_u16[4] = {0};
+ float buff_t_f[2] = {0};
uint32_t buff[BY_FRAME_DATA_NUM] = {0};
if (!by_frame_parse(&cmd, buff)) {
@@ -57,16 +61,82 @@ void by_messy_loop(void)
case 0x41: // 设置转台 x 轴复位
by_frame_send(cmd, buff); // 正确接收后直接返回原文
+ buff_t_u8[0] = 0;
+ buff_t_u8[1] = 1; // 复位模式下速度设置无效
+ buff_t_f[0] = 0.0;
+ memcpy(&buff_t_u8[2], &buff_t_f[0], sizeof(buff_t_f[0]));
+ by_can_send_stdd(0x008, buff_t_u8, 1, 100);
break;
case 0x42: // 设置转台 z 轴复位
by_frame_send(cmd, buff); // 正确接收后直接返回原文
+ buff_t_u8[0] = 0;
+ buff_t_u8[1] = 5; // 设置复位速度 5
+ by_can_send_stdd(0x008, buff_t_u8, 1, 100);
break;
-
case 0x43: // 设置转台末端执行器复位
by_frame_send(cmd, buff); // 正确接收后直接返回原文
+ buff_t_u8[0] = 0;
+ by_can_send_stdd(0x009, buff_t_u8, 1, 100);
+ break;
+ case 0x44: // 设置x轴位置 (增量)
+ by_frame_send(cmd, buff);
+ buff_t_u8[0] = 1; // 增量模式
+ buff_t_u8[1] = buff[0]; // 拷贝设置速度
+ memcpy(&buff_t_u8[2], &buff[1], sizeof(float)); // 拷贝设置距离
+ by_can_send_stdd(0x006, buff_t_u8, 8, 100);
+ break;
+ case 0x46: // 设置z轴位置 (增量)
+ by_frame_send(cmd, buff);
+ buff_t_u8[0] = 1; // 增量模式
+ buff_t_u8[1] = buff[0]; // 拷贝设置速度
+ memcpy(&buff_t_u8[2], &buff[1], sizeof(float)); // 拷贝设置距离
+ by_can_send_stdd(0x008, buff_t_u8, 8, 100);
+ break;
+ case 0x47: // 设置x轴位置 (绝对)
+ by_frame_send(cmd, buff);
+ buff_t_u8[0] = 0; // 位置模式
+ buff_t_u8[1] = buff[0]; // 拷贝设置速度
+ memcpy(&buff_t_u8[2], &buff[1], sizeof(float)); // 拷贝设置距离
+ by_can_send_stdd(0x006, buff_t_u8, 8, 100);
+ break;
+ case 0x49: // 设置z轴位置 (绝对)
+ by_frame_send(cmd, buff);
+ buff_t_u8[0] = 0; // 增量模式
+ buff_t_u8[1] = buff[0]; // 拷贝设置速度
+ memcpy(&buff_t_u8[2], &buff[1], sizeof(float)); // 拷贝设置距离
+ by_can_send_stdd(0x008, buff_t_u8, 8, 100);
+ break;
+ case 0x50: // 设置夹爪摇臂角度
+ by_frame_send(cmd, buff);
+ memcpy(buff_t_f, buff, sizeof(float));
+ buff_t_u16[0] = (int16_t)(buff_t_f[0]);
+ by_can_send_stdd(0x009, (uint8_t *)&buff_t_u16, 2, 100);
+ break;
+ case 0x51: // 设置夹爪角度
+ by_frame_send(cmd, buff);
+ memcpy(buff_t_f, buff, sizeof(float));
+ buff_t_u16[0] = (int16_t)(buff_t_f[0]);
+ by_can_send_stdd(0x00A, (uint8_t *)&buff_t_u16, 2, 100);
+ break;
+ case 0x52: // 设置摄像头角度
+ by_frame_send(cmd, buff);
+ memcpy(buff_t_f, buff, sizeof(float));
+ buff_t_u16[0] = (int16_t)(buff_t_f[0]);
+ by_can_send_stdd(0x00B, (uint8_t *)&buff_t_u16, 2, 100);
+ break;
+ case 0x53: // 设置顶端抓取机构角度
+ by_frame_send(cmd, buff);
+ memcpy(buff_t_f, buff, sizeof(float));
+ buff_t_u16[0] = (int16_t)(buff_t_f[0]);
+ by_can_send_stdd(0x00C, (uint8_t *)&buff_t_u16, 2, 100);
+ break;
+ case 0x54: // 设置托盘角度
+ by_frame_send(cmd, buff);
+ memcpy(buff_t_f, buff, sizeof(float));
+ buff_t_u16[0] = (int16_t)(buff_t_f[0]);
+ by_can_send_stdd(0x00D, (uint8_t *)&buff_t_u16, 2, 100);
break;
-
default:
break;
}
diff --git a/project/inc/at32f403a_407_wk_config.h b/project/inc/at32f403a_407_wk_config.h
index b112ff5..de91330 100644
--- a/project/inc/at32f403a_407_wk_config.h
+++ b/project/inc/at32f403a_407_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/at32f403a_407_int.c b/project/src/at32f403a_407_int.c
index ca6e2f7..b7733ad 100644
--- a/project/src/at32f403a_407_int.c
+++ b/project/src/at32f403a_407_int.c
@@ -70,10 +70,10 @@
/* add user code end external variables */
/**
- * @brief this function handles nmi exception.
- * @param none
- * @retval none
- */
+ * @brief this function handles nmi exception.
+ * @param none
+ * @retval none
+ */
void NMI_Handler(void)
{
/* add user code begin NonMaskableInt_IRQ 0 */
@@ -86,17 +86,18 @@ void NMI_Handler(void)
}
/**
- * @brief this function handles hard fault exception.
- * @param none
- * @retval none
- */
+ * @brief this function handles hard fault exception.
+ * @param none
+ * @retval none
+ */
void HardFault_Handler(void)
{
/* add user code begin HardFault_IRQ 0 */
/* add user code end HardFault_IRQ 0 */
/* go to infinite loop when hard fault exception occurs */
- while (1) {
+ while (1)
+ {
/* add user code begin W1_HardFault_IRQ 0 */
/* add user code end W1_HardFault_IRQ 0 */
@@ -104,17 +105,18 @@ void HardFault_Handler(void)
}
/**
- * @brief this function handles memory manage exception.
- * @param none
- * @retval none
- */
+ * @brief this function handles memory manage exception.
+ * @param none
+ * @retval none
+ */
void MemManage_Handler(void)
{
/* add user code begin MemoryManagement_IRQ 0 */
/* add user code end MemoryManagement_IRQ 0 */
/* go to infinite loop when memory manage exception occurs */
- while (1) {
+ while (1)
+ {
/* add user code begin W1_MemoryManagement_IRQ 0 */
/* add user code end W1_MemoryManagement_IRQ 0 */
@@ -122,17 +124,18 @@ void MemManage_Handler(void)
}
/**
- * @brief this function handles bus fault exception.
- * @param none
- * @retval none
- */
+ * @brief this function handles bus fault exception.
+ * @param none
+ * @retval none
+ */
void BusFault_Handler(void)
{
/* add user code begin BusFault_IRQ 0 */
/* add user code end BusFault_IRQ 0 */
/* go to infinite loop when bus fault exception occurs */
- while (1) {
+ while (1)
+ {
/* add user code begin W1_BusFault_IRQ 0 */
/* add user code end W1_BusFault_IRQ 0 */
@@ -140,17 +143,18 @@ void BusFault_Handler(void)
}
/**
- * @brief this function handles usage fault exception.
- * @param none
- * @retval none
- */
+ * @brief this function handles usage fault exception.
+ * @param none
+ * @retval none
+ */
void UsageFault_Handler(void)
{
/* add user code begin UsageFault_IRQ 0 */
/* add user code end UsageFault_IRQ 0 */
/* go to infinite loop when usage fault exception occurs */
- while (1) {
+ while (1)
+ {
/* add user code begin W1_UsageFault_IRQ 0 */
/* add user code end W1_UsageFault_IRQ 0 */
@@ -158,10 +162,10 @@ void UsageFault_Handler(void)
}
/**
- * @brief this function handles svcall exception.
- * @param none
- * @retval none
- */
+ * @brief this function handles svcall exception.
+ * @param none
+ * @retval none
+ */
void SVC_Handler(void)
{
/* add user code begin SVCall_IRQ 0 */
@@ -173,10 +177,10 @@ void SVC_Handler(void)
}
/**
- * @brief this function handles debug monitor exception.
- * @param none
- * @retval none
- */
+ * @brief this function handles debug monitor exception.
+ * @param none
+ * @retval none
+ */
void DebugMon_Handler(void)
{
/* add user code begin DebugMonitor_IRQ 0 */
@@ -188,10 +192,10 @@ void DebugMon_Handler(void)
}
/**
- * @brief this function handles pendsv_handler exception.
- * @param none
- * @retval none
- */
+ * @brief this function handles pendsv_handler exception.
+ * @param none
+ * @retval none
+ */
void PendSV_Handler(void)
{
/* add user code begin PendSV_IRQ 0 */
@@ -203,10 +207,10 @@ void PendSV_Handler(void)
}
/**
- * @brief this function handles USB Low Priority or CAN1 RX0 handler.
- * @param none
- * @retval none
- */
+ * @brief this function handles USB Low Priority or CAN1 RX0 handler.
+ * @param none
+ * @retval none
+ */
void USBFS_L_CAN1_RX0_IRQHandler(void)
{
/* add user code begin USBFS_L_CAN1_RX0_IRQ 0 */
@@ -223,10 +227,10 @@ void USBFS_L_CAN1_RX0_IRQHandler(void)
}
/**
- * @brief this function handles USART1 handler.
- * @param none
- * @retval none
- */
+ * @brief this function handles USART1 handler.
+ * @param none
+ * @retval none
+ */
void USART1_IRQHandler(void)
{
/* add user code begin USART1_IRQ 0 */
@@ -241,10 +245,10 @@ void USART1_IRQHandler(void)
}
/**
- * @brief this function handles USART2 handler.
- * @param none
- * @retval none
- */
+ * @brief this function handles USART2 handler.
+ * @param none
+ * @retval none
+ */
void USART2_IRQHandler(void)
{
/* add user code begin USART2_IRQ 0 */
@@ -262,10 +266,10 @@ void USART2_IRQHandler(void)
}
/**
- * @brief this function handles USART3 handler.
- * @param none
- * @retval none
- */
+ * @brief this function handles USART3 handler.
+ * @param none
+ * @retval none
+ */
void USART3_IRQHandler(void)
{
/* add user code begin USART3_IRQ 0 */
@@ -281,10 +285,10 @@ void USART3_IRQHandler(void)
}
/**
- * @brief this function handles TMR6 handler.
- * @param none
- * @retval none
- */
+ * @brief this function handles TMR6 handler.
+ * @param none
+ * @retval none
+ */
void TMR6_GLOBAL_IRQHandler(void)
{
/* add user code begin TMR6_GLOBAL_IRQ 0 */
@@ -299,10 +303,10 @@ void TMR6_GLOBAL_IRQHandler(void)
}
/**
- * @brief this function handles CAN2 RX0 handler.
- * @param none
- * @retval none
- */
+ * @brief this function handles CAN2 RX0 handler.
+ * @param none
+ * @retval none
+ */
void CAN2_RX0_IRQHandler(void)
{
/* add user code begin CAN2_RX0_IRQ 0 */
diff --git a/project/src/at32f403a_407_wk_config.c b/project/src/at32f403a_407_wk_config.c
index bb7fa65..a22c9bd 100644
--- a/project/src/at32f403a_407_wk_config.c
+++ b/project/src/at32f403a_407_wk_config.c
@@ -268,9 +268,9 @@ void wk_gpio_config(void)
gpio_init(GPIOB, &gpio_init_struct);
/* gpio output config */
- gpio_bits_reset(GPIOC, GPIO_PINS_0 | GPIO_PINS_1 | GPIO_PINS_2 | GPIO_PINS_3);
+ gpio_bits_set(GPIOC, GPIO_PINS_0 | GPIO_PINS_1 | GPIO_PINS_2 | GPIO_PINS_3);
- gpio_init_struct.gpio_drive_strength = GPIO_DRIVE_STRENGTH_MODERATE;
+ gpio_init_struct.gpio_drive_strength = GPIO_DRIVE_STRENGTH_STRONGER;
gpio_init_struct.gpio_out_type = GPIO_OUTPUT_PUSH_PULL;
gpio_init_struct.gpio_mode = GPIO_MODE_OUTPUT;
gpio_init_struct.gpio_pins = GPIO_PINS_0 | GPIO_PINS_1 | GPIO_PINS_2 | GPIO_PINS_3;
diff --git a/project/src/main.c b/project/src/main.c
index 96cae07..43e05aa 100644
--- a/project/src/main.c
+++ b/project/src/main.c
@@ -69,10 +69,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 */
@@ -152,8 +152,12 @@ int main(void)
/* add user code end 2 */
- while (1) {
+ while(1)
+ {
/* add user code begin 3 */
+ // gpio_bits_write(GPIOC, GPIO_PINS_3, !gpio_output_data_bit_read(GPIOC, GPIO_PINS_3));
+ // gpio_bits_write(GPIOC, GPIO_PINS_2, !gpio_output_data_bit_read(GPIOC, GPIO_PINS_2));
+ // DWT_Delay(1000000);
by_messy_loop();
by_motion_loop();
/* add user code end 3 */