diff --git a/MDK-ARM/R2.uvoptx b/MDK-ARM/R2.uvoptx index a44139d..7424a0e 100644 --- a/MDK-ARM/R2.uvoptx +++ b/MDK-ARM/R2.uvoptx @@ -1117,8 +1117,8 @@ 0 0 0 - ..\User\task\dr16_task.c - dr16_task.c + ..\User\task\up_task.c + up_task.c 0 0 @@ -1129,20 +1129,8 @@ 0 0 0 - ..\User\task\r12ds_task.c - r12ds_task.c - 0 - 0 - - - 8 - 73 - 1 - 0 - 0 - 0 - ..\User\task\up_task.c - up_task.c + ..\User\task\rc_task.c + rc_task.c 0 0 @@ -1156,7 +1144,7 @@ 0 9 - 74 + 73 1 0 0 @@ -1168,7 +1156,7 @@ 9 - 75 + 74 1 0 0 @@ -1180,7 +1168,7 @@ 9 - 76 + 75 1 0 0 @@ -1192,7 +1180,7 @@ 9 - 77 + 76 1 0 0 @@ -1204,7 +1192,7 @@ 9 - 78 + 77 1 0 0 @@ -1216,7 +1204,7 @@ 9 - 79 + 78 1 0 0 @@ -1236,7 +1224,7 @@ 0 10 - 80 + 79 1 0 0 @@ -1248,7 +1236,7 @@ 10 - 81 + 80 1 0 0 @@ -1260,7 +1248,7 @@ 10 - 82 + 81 1 0 0 @@ -1272,7 +1260,7 @@ 10 - 83 + 82 1 0 0 @@ -1284,7 +1272,7 @@ 10 - 84 + 83 1 0 0 @@ -1296,31 +1284,7 @@ 10 - 85 - 1 - 0 - 0 - 0 - ..\User\device\dr16.c - dr16.c - 0 - 0 - - - 10 - 86 - 1 - 0 - 0 - 0 - ..\User\device\r12ds.c - r12ds.c - 0 - 0 - - - 10 - 87 + 84 1 0 0 @@ -1330,17 +1294,29 @@ 0 0 + + 10 + 85 + 1 + 0 + 0 + 0 + ..\User\device\rc.c + rc.c + 0 + 0 + Application/User/USB_DEVICE/App - 0 + 1 0 0 0 11 - 88 + 86 1 0 0 @@ -1352,7 +1328,7 @@ 11 - 89 + 87 1 0 0 @@ -1364,7 +1340,7 @@ 11 - 90 + 88 1 0 0 @@ -1378,13 +1354,13 @@ Application/User/USB_DEVICE/Target - 0 + 1 0 0 0 12 - 91 + 89 1 0 0 @@ -1398,13 +1374,13 @@ Middlewares/USB_Device_Library - 0 + 1 0 0 0 13 - 92 + 90 1 0 0 @@ -1416,7 +1392,7 @@ 13 - 93 + 91 1 0 0 @@ -1428,7 +1404,7 @@ 13 - 94 + 92 1 0 0 @@ -1440,7 +1416,7 @@ 13 - 95 + 93 1 0 0 diff --git a/MDK-ARM/R2.uvprojx b/MDK-ARM/R2.uvprojx index f9d4bc2..ee3c96d 100644 --- a/MDK-ARM/R2.uvprojx +++ b/MDK-ARM/R2.uvprojx @@ -1228,21 +1228,16 @@ 1 ..\User\task\error_detect_task.c - - dr16_task.c - 1 - ..\User\task\dr16_task.c - - - r12ds_task.c - 1 - ..\User\task\r12ds_task.c - up_task.c 1 ..\User\task\up_task.c + + rc_task.c + 1 + ..\User\task\rc_task.c + @@ -1308,21 +1303,16 @@ 1 ..\User\device\vofa.c - - dr16.c - 1 - ..\User\device\dr16.c - - - r12ds.c - 1 - ..\User\device\r12ds.c - GO_M8010_6_Driver.c 1 ..\User\device\GO_M8010_6_Driver.c + + rc.c + 1 + ..\User\device\rc.c + diff --git a/MDK-ARM/R2/R2.axf b/MDK-ARM/R2/R2.axf index 4b82759..c6c22e5 100644 Binary files a/MDK-ARM/R2/R2.axf and b/MDK-ARM/R2/R2.axf differ diff --git a/User/bsp/bsp_usart.h b/User/bsp/bsp_usart.h index cef04b6..4974127 100644 --- a/User/bsp/bsp_usart.h +++ b/User/bsp/bsp_usart.h @@ -7,7 +7,6 @@ #define SBUS_RX_BUF_NUM 50u - #define RC_FRAME_LENGTH 25u typedef enum { diff --git a/User/device/LD_remote.c b/User/device/LD_remote.c deleted file mode 100644 index 14c70bf..0000000 --- a/User/device/LD_remote.c +++ /dev/null @@ -1,31 +0,0 @@ -#include "LD_remote.h" -#include - -#include "bsp_usart.h" -#include "error_detect.h" - -static uint8_t sbus_rx_buf_new[SBUS_RX_BUF_NUM]; // SBUS 数据缓冲区 -static RC_Ctrl_New_t rc_ctrl_new; // SBUS 数据结构 - -/* SBUS 数据解析 */ -static void sbus_to_rc_new(volatile const uint8_t *sbus_buf) { - if (sbus_buf == NULL) return; - - rc_ctrl_new.ch[0] = (sbus_buf[1] | (sbus_buf[2] << 8)) & 0x07FF; - rc_ctrl_new.ch[1] = ((sbus_buf[2] >> 3) | (sbus_buf[3] << 5)) & 0x07FF; - rc_ctrl_new.ch[2] = ((sbus_buf[3] >> 6) | (sbus_buf[4] << 2) | (sbus_buf[5] << 10)) & 0x07FF; - rc_ctrl_new.ch[3] = ((sbus_buf[5] >> 1) | (sbus_buf[6] << 7)) & 0x07FF; - - rc_ctrl_new.sw[0] = ((sbus_buf[6] >> 4) | (sbus_buf[7] << 4)) & 0x07FF; - rc_ctrl_new.sw[1] = ((sbus_buf[7] >> 7) | (sbus_buf[8] << 1) | (sbus_buf[9] << 9)) & 0x07FF; -} - -/* 初始化函数 */ -void RC_New_Init(void) { - HAL_UARTEx_ReceiveToIdle_DMA(&huart3, sbus_rx_buf_new, SBUS_RX_BUF_NUM); -} - -/* 获取数据指针 */ -const RC_Ctrl_New_t* RC_New_GetData(void) { - return &rc_ctrl_new; -} \ No newline at end of file diff --git a/User/device/LD_remote.h b/User/device/LD_remote.h deleted file mode 100644 index 5ee6770..0000000 --- a/User/device/LD_remote.h +++ /dev/null @@ -1,21 +0,0 @@ -#ifndef LD_H -#define LD_H -#include "user_math.h" - - -#include "main.h" - -/* SBUS ݽṹ */ -typedef struct { - int16_t ch[4]; // 4 ͨ - int16_t sw[8]; // 8 -} RC_Ctrl_New_t; - -/* */ -void RC_New_Init(void); -const RC_Ctrl_New_t* RC_New_GetData(void); - - - -#endif - diff --git a/User/device/motor_control.c b/User/device/motor_control.c deleted file mode 100644 index 560da9f..0000000 --- a/User/device/motor_control.c +++ /dev/null @@ -1,7 +0,0 @@ -#include "motor_control.h" -#include "pid.h" -#include "user_math.h" -#include "device\device.h" -#include "can_use.h" - - diff --git a/User/device/motor_control.h b/User/device/motor_control.h deleted file mode 100644 index 2bf0589..0000000 --- a/User/device/motor_control.h +++ /dev/null @@ -1,23 +0,0 @@ -#ifndef _MOTOR_CONTROL_H_ -#define _MOTOR_CONTROL_H_ - -#include "struct_typedef.h" -#include "pid.h" - -/*󽮵*/ -typedef struct -{ - uint16_t ecd; - int16_t speed_rpm; - int16_t given_current; - uint16_t temperate; - int16_t last_ecd; - int16_t round_cnt; - int16_t total_angle; - uint16_t offset_ecd; - uint32_t msg_cnt; -} DJmotor_measure_t; - - - -#endif \ No newline at end of file diff --git a/User/device/r12ds.c b/User/device/r12ds.c deleted file mode 100644 index e5bbe97..0000000 --- a/User/device/r12ds.c +++ /dev/null @@ -1,192 +0,0 @@ -/* - 乐迪r12ds遥控器。 - 需要根据实际的遥控器通道修改解析的函数 该遥控器采用sbus 用的uart3 - -*/ - - -/* Includes ----------------------------------------------------------------- */ -#include "r12ds.h" -#include "main.h" -#include "error_detect.h" -#include -#include "cmd.h" -#include "user_math.h" - -#ifdef r12ds_t -extern UART_HandleTypeDef huart3; -extern DMA_HandleTypeDef hdma_usart3_rx; - - - -osThreadId_t thread_alert; - -int buf0ready =0; /*不起作用*/ -int buf1ready =0; - -/* Private function -------------------------------------------------------- */ -static void R12DS_IdleCallback(void) { - static uint16_t this_time_rx_len = 0; - if( (hdma_usart3_rx.Instance->CR & DMA_SxCR_CT) == RESET) - { - //current memory buffer used is memory0 - - //disable dma to change dma register - __HAL_DMA_DISABLE(&hdma_usart3_rx); - - //get received data length, length = set_data_length - remain_length - this_time_rx_len = SBUS_RX_BUF_NUM - hdma_usart3_rx.Instance->NDTR; - - //reset set_data_length - hdma_usart3_rx.Instance->NDTR = SBUS_RX_BUF_NUM; - - //change memory0 to memory1 - hdma_usart3_rx.Instance->CR |= DMA_SxCR_CT; - - //enable dma - __HAL_DMA_ENABLE(&hdma_usart3_rx); - - //1 frame length is correct data - if(this_time_rx_len == RC_FRAME_LENGTH) - { -// osThreadFlagsSet(thread_alert,SIGNAL_R12DS_BUF0_REDY); - buf0ready = 1; -// detect_hook(R12DS_TOE); - } - } - else - { - __HAL_DMA_DISABLE(&hdma_usart3_rx); - - this_time_rx_len = SBUS_RX_BUF_NUM - hdma_usart3_rx.Instance->NDTR; - - hdma_usart3_rx.Instance->NDTR = SBUS_RX_BUF_NUM; - - //change memory1 to memory0 - DMA1_Stream1->CR &= ~(DMA_SxCR_CT); - - __HAL_DMA_ENABLE(&hdma_usart3_rx); - - if(this_time_rx_len == RC_FRAME_LENGTH) - { -// osThreadFlagsSet(thread_alert,SIGNAL_R12DS_BUF1_REDY); - buf1ready = 1; -// detect_hook(R12DS_TOE); - } - } -} - -/* Exported functions ------------------------------------------------------- */ - - -int8_t R12ds_DMA_Init(uint8_t *rx1_buf, uint8_t *rx2_buf, uint16_t dma_buf_num) -{ - if((thread_alert = osThreadGetId()) == NULL ) return DEVICE_ERR_NULL; - //enable the dma transfer for the receiver request - SET_BIT(huart3.Instance->CR3, USART_CR3_DMAR); - - //enable idle interrupt - __HAL_UART_ENABLE_IT(&huart3, UART_IT_IDLE); - - //disable dma, to change the dma register - __HAL_DMA_DISABLE(&hdma_usart3_rx); - - //disable dma again but why? - //what's the condition? - while(hdma_usart3_rx.Instance->CR & DMA_SxCR_EN) - { - __HAL_DMA_DISABLE(&hdma_usart3_rx); - } - - //?? - hdma_usart3_rx.Instance->PAR = (uint32_t) & (USART3->DR); - - //memory buffer 1 - hdma_usart3_rx.Instance->M0AR = (uint32_t)(rx1_buf); - - //momory buffer 2 - hdma_usart3_rx.Instance->M1AR = (uint32_t)(rx2_buf); - - //data length - hdma_usart3_rx.Instance->NDTR = dma_buf_num; - - //enable double memory buffer - SET_BIT(hdma_usart3_rx.Instance->CR, DMA_SxCR_DBM); - - - //enable dma - __HAL_DMA_ENABLE(&hdma_usart3_rx); - - BSP_UART_RegisterCallback(BSP_UART_REMOTE, BSP_UART_IDLE_LINE_CB, - R12DS_IdleCallback); - - return 1; -} - - - -int8_t sbus_to_rc(volatile const uint8_t *sbus_buf, CMD_RC_t *rc_ctrl) -{ - if (sbus_buf == NULL || rc_ctrl == NULL) - { - return 0; - } - - - rc_ctrl->ch_x = (sbus_buf[1] | (sbus_buf[2] << 8)) & 0x07ff; //Channel 1 x - rc_ctrl->ch_y = ((sbus_buf[2] >> 3) | (sbus_buf[3] << 5)) & 0x07ff; //Channel 2 mul - rc_ctrl->mul= ((sbus_buf[3] >> 6) | (sbus_buf[4] << 2) | //Channel 3 y - (sbus_buf[5] << 10)) &0x07ff; - rc_ctrl->ch_w = ((sbus_buf[5] >> 1) | (sbus_buf[6] << 7)) & 0x07ff; //Channel 4 w - - rc_ctrl->key[0] = ((int16_t)sbus_buf[6] >> 4 | ((int16_t)sbus_buf[7] << 4 )) & 0x07FF; //Channel 5 - rc_ctrl->key[1] = ((int16_t)sbus_buf[7] >> 7 | ((int16_t)sbus_buf[8] << 1 ) | (int16_t)sbus_buf[9] << 9 ) & 0x07FF; //Channel 6 - rc_ctrl->key[2] = ((int16_t)sbus_buf[9] >> 2 | ((int16_t)sbus_buf[10] << 6 )) & 0x07FF;; //Channel 7 - rc_ctrl->key[3] = ((int16_t)sbus_buf[10] >> 5 | ((int16_t)sbus_buf[11] << 3 )) & 0x07FF; //Channel 8 - rc_ctrl->key[4] = ((int16_t)sbus_buf[12] << 0 | ((int16_t)sbus_buf[13] << 8 )) & 0x07FF; //Channel 9 - rc_ctrl->key[5] = ((int16_t)sbus_buf[13] >> 3 | ((int16_t)sbus_buf[14] << 5 )) & 0x07FF; //Channel 10 - rc_ctrl->key[6] = ((int16_t)sbus_buf[14] >> 6 | ((int16_t)sbus_buf[15] << 2 ) | (int16_t)sbus_buf[16] << 10 ) & 0x07FF; //Channel 11 - rc_ctrl->key[7] = ((int16_t)sbus_buf[16] >> 1 | ((int16_t)sbus_buf[17] << 7 )) & 0x07FF; //Channel 12 - - rc_ctrl->ch_y -= RC_CH_VALUE_OFFSET; - rc_ctrl->ch_x -= RC_CH_VALUE_OFFSET; - rc_ctrl->mul -= RC_CH_VALUE_OFFSET; - rc_ctrl->ch_w -= RC_CH_VALUE_OFFSET; - - - - rc_ctrl->ch_y -= 4; //y(-694,693) - rc_ctrl->ch_x += 3; //x(-693,694) - rc_ctrl->mul = rc_ctrl->mul; //m(-518,843) - rc_ctrl->ch_w += 4; //w(-694,693) - - rc_ctrl->key[2] = map_fp32(rc_ctrl->key[2],306,1694,1694,306); - rc_ctrl->key[3] = map_fp32(rc_ctrl->key[3],306,1694,1694,306); - rc_ctrl->ch_x = map_fp32(rc_ctrl->ch_x,700,-800,-700,700); //x - rc_ctrl->ch_y = map_fp32(rc_ctrl->ch_y,-900,796,700,-700); //y - rc_ctrl->mul = map_fp32(rc_ctrl->mul,-632,901,25,0); //m - rc_ctrl->ch_w = map_fp32(rc_ctrl->ch_w,-820,780,-700,700); - rc_ctrl->ch_w = 0.5f*(rc_ctrl->ch_w); - rc_ctrl->ch_x = -0.5f*(rc_ctrl->ch_x); - rc_ctrl->ch_y = 0.5f*(rc_ctrl->ch_y); -// -//̀死区(-5,5) - if(rc_ctrl->ch_y>-15&&rc_ctrl->ch_y<15) rc_ctrl->ch_y=0; - if(rc_ctrl->ch_x>-15&&rc_ctrl->ch_x<15) rc_ctrl->ch_x=0; - if(rc_ctrl->mul>=0&&rc_ctrl->mul<=3) rc_ctrl->mul=0; - if(rc_ctrl->ch_w>-15&&rc_ctrl->ch_w<15) rc_ctrl->ch_w=0; - - - if( (((int16_t)sbus_buf[16] >> 1 | ((int16_t)sbus_buf[17] << 7 )) & 0x07FF )<380) rc_ctrl->offline =1; //遥控器掉线 - else rc_ctrl->offline =0; - - - return 0; -} - - - - - -#endif - diff --git a/User/device/r12ds.h b/User/device/r12ds.h deleted file mode 100644 index 111c3bc..0000000 --- a/User/device/r12ds.h +++ /dev/null @@ -1,29 +0,0 @@ -#ifndef _R12DS_H -#define _R12DS_H - -#include -#include "device.h" -#include "bsp_usart.h" -#include "cmd.h" - - -#ifdef r12ds_t - -#define RC_FRAME_LENGTH 25u - - -#define RC_CH_VALUE_OFFSET ((uint16_t)1024) - - - -int8_t R12ds_DMA_Init(uint8_t *rx1_buf, uint8_t *rx2_buf, uint16_t dma_buf_num); - -int8_t sbus_to_rc(volatile const uint8_t *sbus_buf,CMD_RC_t *rc_ctrl); - - - - - -#endif - -#endif diff --git a/User/device/dr16.c b/User/device/rc.c similarity index 89% rename from User/device/dr16.c rename to User/device/rc.c index 9e4394f..026c486 100644 --- a/User/device/dr16.c +++ b/User/device/rc.c @@ -4,7 +4,7 @@ */ /* Includes ----------------------------------------------------------------- */ -#include "dr16.h" +#include "rc.h" #include @@ -72,14 +72,14 @@ int8_t LD_ParseRaw( RC_ctrl_t *rc_ctrl) (cbuf[5] << 10)) &0x07ff; rc_ctrl->ch[3] = ((cbuf[5] >> 1) | (cbuf[6] << 7)) & 0x07ff; //!< Channel 3 - rc_ctrl->sw[0] = ((int16_t)cbuf[6] >> 4 | ((int16_t)cbuf[7] << 4 )) & 0x07FF; //!< Switch left - rc_ctrl->sw[1] = ((int16_t)cbuf[7] >> 7 | ((int16_t)cbuf[8] << 1 ) | (int16_t)cbuf[9] << 9 ) & 0x07FF; //!< Switch right - rc_ctrl->sw[2] = ((int16_t)cbuf[9] >> 2 | ((int16_t)cbuf[10] << 6 )) & 0x07FF;; //!< Mouse X axis - rc_ctrl->sw[3] = ((int16_t)cbuf[10] >> 5 | ((int16_t)cbuf[11] << 3 )) & 0x07FF; //!< Mouse Y axis - rc_ctrl->sw[4] = ((int16_t)cbuf[12] << 0 | ((int16_t)cbuf[13] << 8 )) & 0x07FF; //!< Mouse Z axis - rc_ctrl->sw[5] = ((int16_t)cbuf[13] >> 3 | ((int16_t)cbuf[14] << 5 )) & 0x07FF; //!< Mouse Left Is Press ? - rc_ctrl->sw[6] = ((int16_t)cbuf[14] >> 6 | ((int16_t)cbuf[15] << 2 ) | (int16_t)cbuf[16] << 10 ) & 0x07FF; //!< Mouse Right Is Press ? - rc_ctrl->sw[7] = ((int16_t)cbuf[16] >> 1 | ((int16_t)cbuf[17] << 7 )) & 0x07FF; //!< KeyBoard value + rc_ctrl->sw[0] = ((int16_t)cbuf[6] >> 4 | ((int16_t)cbuf[7] << 4 )) & 0x07FF; + rc_ctrl->sw[1] = ((int16_t)cbuf[7] >> 7 | ((int16_t)cbuf[8] << 1 ) | (int16_t)cbuf[9] << 9 ) & 0x07FF; + rc_ctrl->sw[2] = ((int16_t)cbuf[9] >> 2 | ((int16_t)cbuf[10] << 6 )) & 0x07FF;; + rc_ctrl->sw[3] = ((int16_t)cbuf[10] >> 5 | ((int16_t)cbuf[11] << 3 )) & 0x07FF; + rc_ctrl->sw[4] = ((int16_t)cbuf[12] << 0 | ((int16_t)cbuf[13] << 8 )) & 0x07FF; + rc_ctrl->sw[5] = ((int16_t)cbuf[13] >> 3 | ((int16_t)cbuf[14] << 5 )) & 0x07FF; + rc_ctrl->sw[6] = ((int16_t)cbuf[14] >> 6 | ((int16_t)cbuf[15] << 2 ) | (int16_t)cbuf[16] << 10 ) & 0x07FF; + rc_ctrl->sw[7] = ((int16_t)cbuf[16] >> 1 | ((int16_t)cbuf[17] << 7 )) & 0x07FF; rc_ctrl->ch[0] -= RC_CH_VALUE_MID; rc_ctrl->ch[1] -= RC_CH_VALUE_MID; @@ -114,11 +114,12 @@ int8_t LD_ParseRaw( RC_ctrl_t *rc_ctrl) rc_ctrl->map_ch[3]=expo_map(rc_ctrl->map_ch[3],0.7f); //死区(-30,30) - if(rc_ctrl->map_ch[0]>-0.05&&rc_ctrl->map_ch[0]<0.05) rc_ctrl->map_ch[0]=0; - if(rc_ctrl->map_ch[1]>-0.05&&rc_ctrl->map_ch[1]<0.05) rc_ctrl->map_ch[1]=0; - if(rc_ctrl->map_ch[2]>-0.05&&rc_ctrl->map_ch[2]<0.05) rc_ctrl->map_ch[2]=0; - if(rc_ctrl->map_ch[3]>-0.05&&rc_ctrl->map_ch[3]<0.05) rc_ctrl->map_ch[3]=0; - + if(rc_ctrl->map_ch[0]>-0.05f&&rc_ctrl->map_ch[0]<0.05f) rc_ctrl->map_ch[0]=0; + if(rc_ctrl->map_ch[1]>-0.05f&&rc_ctrl->map_ch[1]<0.05f) rc_ctrl->map_ch[1]=0; + if(rc_ctrl->map_ch[2]>-0.05f&&rc_ctrl->map_ch[2]<0.05f) rc_ctrl->map_ch[2]=0; + if(rc_ctrl->map_ch[3]>-0.05f&&rc_ctrl->map_ch[3]<0.05f) rc_ctrl->map_ch[3]=0; + return 1; + } /*dr16数据解析+校验 */ static bool DR16_DataCorrupted(const DR16_t *dr16) { @@ -207,4 +208,4 @@ int8_t DR16_HandleOffline(const DR16_t *dr16, CMD_RC_t *rc) { (void)dr16; memset(rc, 0, sizeof(*rc)); return 0; -} \ No newline at end of file +} diff --git a/User/device/dr16.h b/User/device/rc.h similarity index 92% rename from User/device/dr16.h rename to User/device/rc.h index 037c81f..f39fe24 100644 --- a/User/device/dr16.h +++ b/User/device/rc.h @@ -1,9 +1,9 @@ -#ifndef DR16_h -#define DR16_h +#ifndef RC_h +#define RC_h /* Includes ----------------------------------------------------------------- */ #include - +#include "bsp_usart.h" #include "cmd.h" #include "user_math.h" #include "device.h" @@ -34,9 +34,9 @@ typedef struct { -#define SBUS_RX_BUF_NUM 25u +//#define SBUS_RX_BUF_NUM 25u -#define RC_FRAME_LENGTH 18u +//#define RC_FRAME_LENGTH 18u diff --git a/User/device/remote_control.c b/User/device/remote_control.c deleted file mode 100644 index aa5e3ed..0000000 --- a/User/device/remote_control.c +++ /dev/null @@ -1,185 +0,0 @@ -/** - ****************************(C) COPYRIGHT 2019 DJI**************************** - * @file remote_control.c/h - * @brief ңңͨSBUSЭ鴫䣬DMA䷽ʽԼCPU - * ԴôڿжͬʱṩһЩDMA - * ķʽ֤Ȳεȶԡ - * @note ͨжfreeRTOS - * @history - * Version Date Author Modification - * V1.0.0 Dec-01-2019 RM 1. - * - @verbatim - ============================================================================== - - ============================================================================== - @endverbatim - ****************************(C) COPYRIGHT 2019 DJI**************************** - */ - -#include "remote_control.h" -#include "main.h" - - -extern UART_HandleTypeDef huart3; -extern DMA_HandleTypeDef hdma_usart3_rx; - -static void sbus_to_rc(volatile const uint8_t *sbus_buf, RC_ctrl_t *rc_ctrl); - -RC_ctrl_t rc_ctrl; -static uint8_t sbus_rx_buf[2][RC_FRAME_LENGTH]; -uint8_t remote_ready = 0;//ң׼ - -void remote_control_init(void) -{ - RC_init(sbus_rx_buf[0], sbus_rx_buf[1], RC_FRAME_LENGTH); -} - - -//ж -void USART3_IRQHandler(void) -{ - //have received data ??? - if(huart3.Instance->SR & UART_FLAG_RXNE) - { - __HAL_UART_CLEAR_FEFLAG(&huart3); - } - else if(USART3->SR & UART_FLAG_IDLE) - { - - static uint16_t this_time_rx_len = 0; - __HAL_UART_CLEAR_PEFLAG(&huart3); - - if( (hdma_usart3_rx.Instance->CR & DMA_SxCR_CT) == RESET) - { - //current memory buffer used is memory0 - - //disable dma to change dma register - __HAL_DMA_DISABLE(&hdma_usart3_rx); - - //get received data length, length = set_data_length - remain_length - this_time_rx_len = SBUS_RX_BUF_NUM - hdma_usart3_rx.Instance->NDTR; - - //reset set_data_length - hdma_usart3_rx.Instance->NDTR = SBUS_RX_BUF_NUM; - - //change memory0 to memory1 - hdma_usart3_rx.Instance->CR |= DMA_SxCR_CT; - - //enable dma - __HAL_DMA_ENABLE(&hdma_usart3_rx); - - //1 frame length is correct data - if(this_time_rx_len == RC_FRAME_LENGTH) - { - sbus_to_rc(sbus_rx_buf[0], &rc_ctrl); - } - } - else - { - __HAL_DMA_DISABLE(&hdma_usart3_rx); - - this_time_rx_len = SBUS_RX_BUF_NUM - hdma_usart3_rx.Instance->NDTR; - - hdma_usart3_rx.Instance->NDTR = SBUS_RX_BUF_NUM; - - //change memory1 to memory0 - DMA1_Stream1->CR &= ~(DMA_SxCR_CT); - - __HAL_DMA_ENABLE(&hdma_usart3_rx); - - if(this_time_rx_len == RC_FRAME_LENGTH) - { - sbus_to_rc(sbus_rx_buf[1], &rc_ctrl); - } - } - } -} - -static void sbus_to_rc(volatile const uint8_t *sbus_buf, RC_ctrl_t *rc_ctrl) -{ - if (sbus_buf == NULL || rc_ctrl == NULL) - { - return; - } - - rc_ctrl->ch[1] = (sbus_buf[1] | (sbus_buf[2] << 8)) & 0x07ff; //Channel 1 - rc_ctrl->ch[2] = ((sbus_buf[2] >> 3) | (sbus_buf[3] << 5)) & 0x07ff; //Channel 2 - rc_ctrl->ch[0] = ((sbus_buf[3] >> 6) | (sbus_buf[4] << 2) | //Channel 3 - (sbus_buf[5] << 10)) &0x07ff; - rc_ctrl->ch[3] = ((sbus_buf[5] >> 1) | (sbus_buf[6] << 7)) & 0x07ff; //Channel 4 - - rc_ctrl->sw[0] = ((int16_t)sbus_buf[6] >> 4 | ((int16_t)sbus_buf[7] << 4 )) & 0x07FF; //Channel 5 - rc_ctrl->sw[1] = ((int16_t)sbus_buf[7] >> 7 | ((int16_t)sbus_buf[8] << 1 ) | (int16_t)sbus_buf[9] << 9 ) & 0x07FF; //Channel 6 - rc_ctrl->sw[2] = ((int16_t)sbus_buf[9] >> 2 | ((int16_t)sbus_buf[10] << 6 )) & 0x07FF;; //Channel 7 - rc_ctrl->sw[3] = ((int16_t)sbus_buf[10] >> 5 | ((int16_t)sbus_buf[11] << 3 )) & 0x07FF; //Channel 8 - rc_ctrl->sw[4] = ((int16_t)sbus_buf[12] << 0 | ((int16_t)sbus_buf[13] << 8 )) & 0x07FF; //Channel 9 - rc_ctrl->sw[5] = ((int16_t)sbus_buf[13] >> 3 | ((int16_t)sbus_buf[14] << 5 )) & 0x07FF; //Channel 10 - rc_ctrl->sw[6] = ((int16_t)sbus_buf[14] >> 6 | ((int16_t)sbus_buf[15] << 2 ) | (int16_t)sbus_buf[16] << 10 ) & 0x07FF; //Channel 11 - rc_ctrl->sw[7] = ((int16_t)sbus_buf[16] >> 1 | ((int16_t)sbus_buf[17] << 7 )) & 0x07FF; //Channel 12 - - rc_ctrl->ch[0] -= RC_CH_VALUE_OFFSET; - rc_ctrl->ch[1] -= RC_CH_VALUE_OFFSET; - rc_ctrl->ch[2] -= RC_CH_VALUE_OFFSET; - rc_ctrl->ch[3] -= RC_CH_VALUE_OFFSET; - - -// //ң - rc_ctrl->ch[0] += 20; //y(-694,693) - rc_ctrl->ch[1] += 20; //x(-693,694) - rc_ctrl->ch[2] = -rc_ctrl->ch[2]+144; //m(-518,843) - rc_ctrl->ch[3] += 4; //w(-694,693) - - rc_ctrl->sw[2] = map(rc_ctrl->sw[2],306,1694,1694,306); - rc_ctrl->sw[3] = map(rc_ctrl->sw[3],306,1694,1694,306); -// rc_ctrl->ch[1] = map(rc_ctrl->ch[1],656,-656,-700,700); //x - rc_ctrl->ch[0] = map(rc_ctrl->ch[0],-800,796,700,-700); //y - rc_ctrl->ch[2] = map(rc_ctrl->ch[2],-632,901,25,0); //m - rc_ctrl->ch[3] = map(rc_ctrl->ch[3],-820,780,-700,700); - rc_ctrl->ch[3] = 0.5*(rc_ctrl->ch[3]); - rc_ctrl->ch[1] = 0.5*(rc_ctrl->ch[1]); - rc_ctrl->ch[0] = 0.5*(rc_ctrl->ch[0]); -// - //(-30,30) - if(rc_ctrl->ch[0]>-14&&rc_ctrl->ch[0]<10) rc_ctrl->ch[0]=0; - if(rc_ctrl->ch[1]>-30&&rc_ctrl->ch[1]<20) rc_ctrl->ch[1]=0; - if(rc_ctrl->ch[2]>=0&&rc_ctrl->ch[2]<=3) rc_ctrl->ch[2]=0; - if(rc_ctrl->ch[3]>-22&&rc_ctrl->ch[3]<22) rc_ctrl->ch[3]=0; - - remote_ready = 1; -} - - - -int map(int x, int in_min, int in_max, int out_min, int out_max) //ӳ亯 -{ - return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min; -} - - -/* - - - - -306 306 - sw[] sw[7] -1694 1694 - -306 306 -sw[6] sw[4] -1694 1694 - -306 306 306 306 -sw[0] sw[2] sw[1]:306-1694 sw[5]:306-1694 sw[]1000 sw[3] -1694 1694 1694 1694 - 710 - 688 1425 - | | - | | - 54 -616------ch[3]770 -354---------ch[0] 339 0 - | | - | | - ch[2] ch[1] - _699 38 -*/ diff --git a/User/device/remote_control.h b/User/device/remote_control.h deleted file mode 100644 index 5971266..0000000 --- a/User/device/remote_control.h +++ /dev/null @@ -1,42 +0,0 @@ -/** - ****************************(C) COPYRIGHT 2016 DJI**************************** - * @file remote_control.c/h - * @brief ңңͨSBUSЭ鴫䣬DMA䷽ʽԼCPU - * ԴôڿжͬʱṩһЩDMA - * ķʽ֤Ȳεȶԡ - * @note - * @history - * Version Date Author Modification - * V1.0.0 Dec-26-2018 RM 1. - * - @verbatim - ============================================================================== - - ============================================================================== - @endverbatim - ****************************(C) COPYRIGHT 2016 DJI**************************** - */ -#ifndef REMOTE_CONTROL_H -#define REMOTE_CONTROL_H -#include "struct_typedef.h" -#include "bsp_rc.h" - -#define SBUS_RX_BUF_NUM 50u - -#define RC_FRAME_LENGTH 25u - -#define RC_CH_VALUE_OFFSET ((uint16_t)1024) - -typedef struct -{ - int16_t ch[4]; - int16_t sw[8]; - -}__attribute__((packed)) RC_ctrl_t; - -extern void remote_control_init(void); -static void sbus_to_rc(volatile const uint8_t *sbus_buf, RC_ctrl_t *rc_ctrl); -int map(int x, int in_min, int in_max, int out_min, int out_max); //ӳ亯 - - -#endif diff --git a/User/task/error_detect_task.c b/User/task/error_detect_task.c index f8e8992..8ace272 100644 --- a/User/task/error_detect_task.c +++ b/User/task/error_detect_task.c @@ -51,7 +51,6 @@ */ #include "error_detect.h" #include "user_task.h" -#include "r12ds.h" #include "nuc.h" /** * @brief init error_list, assign offline_time, online_time, priority. diff --git a/User/task/init.c b/User/task/init.c index 7300d1a..e63b787 100644 --- a/User/task/init.c +++ b/User/task/init.c @@ -35,10 +35,8 @@ void Task_Init(void *argument) { osThreadNew(Task_AttiEsti, NULL, &attr_atti_esti); task_runtime.thread.chassis = osThreadNew(Task_Chassis, NULL, &attr_chassis); -// task_runtime.thread.r12ds = -// osThreadNew(Task_r12ds,NULL,&attr_r12ds); - task_runtime.thread.dr16 = - osThreadNew(Task_dr16,NULL,&attr_dr16); + task_runtime.thread.rc = + osThreadNew(Task_rc,NULL,&attr_rc); task_runtime.thread.can = osThreadNew(Task_can,NULL,&attr_can); diff --git a/User/task/r12ds_task.c b/User/task/r12ds_task.c deleted file mode 100644 index 3e5aa3a..0000000 --- a/User/task/r12ds_task.c +++ /dev/null @@ -1,82 +0,0 @@ -#include "r12ds.h" -#include "cmsis_os.h" -#include "user_task.h" -#include - - -#ifdef r12ds_t - -#ifdef DEBUG - -CMD_RC_t cmd_rc; - -uint8_t sbus_rx_buf[2][RC_FRAME_LENGTH]; - -#else - -static CMD_RC_t cmd_rc; - -#endif - - - -CMD_RC_t *R12ds_DataGet(){ - return &cmd_rc; -} - - -void R12ds_HandleOffline(void) { - CMD_RC_t *rc; - rc = R12ds_DataGet(); - memset(rc, 0, sizeof(rc->ch_x) + sizeof(rc->mul) + sizeof(rc->ch_y) + sizeof(rc->ch_w) + sizeof(rc->key)); -} - -#endif - -void Task_r12ds(void *argument) -{ - (void)argument; - - - const uint32_t delay_tick = osKernelGetTickFreq() / TASK_FREQ_R12DS; -#ifdef r12ds_t - - R12ds_DMA_Init(sbus_rx_buf[0],sbus_rx_buf[1],50); -#endif - - uint32_t tick = osKernelGetTickCount(); - - - while (1) - { - -#ifdef r12ds_t - -#ifdef DEBUG - - task_runtime.stack_water_mark.r12ds = - osThreadGetStackSpace(osThreadGetId()); - -#endif - - sbus_to_rc(sbus_rx_buf[0],&cmd_rc); - - if(cmd_rc.offline ==1) - { - R12ds_HandleOffline(); - } - - osMessageQueueReset(task_runtime.msgq.cmd.raw.rc); - osMessageQueuePut(task_runtime.msgq.cmd.raw.rc,(&cmd_rc),0,0); -#endif - - tick += delay_tick; /* 计算下一个唤醒时*/ - - osDelay(10); - - } - - - - - } diff --git a/User/task/r12ds_task.h b/User/task/r12ds_task.h deleted file mode 100644 index ebf5d49..0000000 --- a/User/task/r12ds_task.h +++ /dev/null @@ -1,16 +0,0 @@ -#ifndef _R12DS_TASK_H -#define _R12DS_TASK_H - - - - - - - - - - - - - -#endif \ No newline at end of file diff --git a/User/task/dr16_task.c b/User/task/rc_task.c similarity index 88% rename from User/task/dr16_task.c rename to User/task/rc_task.c index 7ad1e7e..5584765 100644 --- a/User/task/dr16_task.c +++ b/User/task/rc_task.c @@ -5,7 +5,7 @@ /* Includes ----------------------------------------------------------------- */ #include -#include "dr16.h" +#include "rc.h" #include "user_task.h" /* Private typedef ---------------------------------------------------------- */ @@ -31,15 +31,15 @@ static CMD_RC_t cmd_rc; * * \param argument 未使用 */ -void Task_dr16(void *argument) { +void Task_rc(void *argument) { (void)argument; /* 未使用,消除警告 */ - RC_SBUS_Init(); /* 初始化dr16 */ + RC_SBUS_Init(); /* 初始化 */ while (1) { #ifdef DEBUG /* */ - task_runtime.stack_water_mark.dr16 = osThreadGetStackSpace(osThreadGetId()); + task_runtime.stack_water_mark.rc = osThreadGetStackSpace(osThreadGetId()); #endif /* 开启DMA */ RC_SBUS_StartDmaRecv(); diff --git a/User/task/user_task.c b/User/task/user_task.c index 569ce05..8c37e77 100644 --- a/User/task/user_task.c +++ b/User/task/user_task.c @@ -58,7 +58,7 @@ const osThreadAttr_t attr_error_detect = { .stack_size = 128 *4, }; -const osThreadAttr_t attr_dr16 = { +const osThreadAttr_t attr_rc = { .name = "dr16", .priority = osPriorityRealtime, .stack_size = 128 *4, diff --git a/User/task/user_task.h b/User/task/user_task.h index 02fdf1a..2108081 100644 --- a/User/task/user_task.h +++ b/User/task/user_task.h @@ -21,7 +21,7 @@ #define TASK_FREQ_NUC (500u) #define TASK_FREQ_CAN (1000u) #define TASK_FREQ_R12DS (1000u) -#define TASK_FREQ_DR16 (1000u) +#define TASK_FREQ_RC (1000u) #define TASK_FREQ_ERROR_DTC (3u) @@ -40,8 +40,7 @@ typedef struct { osThreadId_t chassis; osThreadId_t up; - osThreadId_t dr16; - osThreadId_t r12ds; + osThreadId_t rc; osThreadId_t can; osThreadId_t cmd; osThreadId_t nuc; @@ -111,8 +110,7 @@ typedef struct { UBaseType_t can; UBaseType_t atti_esti; - UBaseType_t dr16; - UBaseType_t r12ds; + UBaseType_t rc; UBaseType_t cmd; UBaseType_t nuc; @@ -124,8 +122,7 @@ typedef struct { float chassis; float can; float atti_esti; - float r12ds; - float dr16; + float rc; float up; float cmd; @@ -137,8 +134,7 @@ typedef struct { float chassis; float can; float atti_esti; - float r12ds; - float dr16; + float rc; float up; float cmd; @@ -166,7 +162,7 @@ extern const osThreadAttr_t attr_nuc; extern const osThreadAttr_t attr_error_detect; -extern const osThreadAttr_t attr_dr16; +extern const osThreadAttr_t attr_rc; //extern const osThreadAttr_t attr_r12ds; @@ -179,17 +175,13 @@ void Task_Chassis(void *argument); void Task_up(void *argument); - void Task_can(void *argument); void Task_cmd(void *argument); void Task_nuc(void *argument); - void Task_error_detect(void *argument); -void Task_r12ds(void *argument); - -void Task_dr16(void *argument); +void Task_rc(void *argument); #endif