乐迪遥控器,急停,已测试
This commit is contained in:
parent
0ce8941b04
commit
6039db40c5
MDK-ARM
User
@ -163,17 +163,27 @@
|
||||
<Ww>
|
||||
<count>1</count>
|
||||
<WinNumber>1</WinNumber>
|
||||
<ItemText>rc_ctrl,0x0A</ItemText>
|
||||
<ItemText>aaaaaaa,0x0A</ItemText>
|
||||
</Ww>
|
||||
<Ww>
|
||||
<count>2</count>
|
||||
<WinNumber>1</WinNumber>
|
||||
<ItemText>cmd,0x0A</ItemText>
|
||||
<ItemText>cmd_rc,0x0A</ItemText>
|
||||
</Ww>
|
||||
<Ww>
|
||||
<count>3</count>
|
||||
<WinNumber>1</WinNumber>
|
||||
<ItemText>chassis,0x0A</ItemText>
|
||||
<ItemText>cmd,0x0A</ItemText>
|
||||
</Ww>
|
||||
<Ww>
|
||||
<count>4</count>
|
||||
<WinNumber>1</WinNumber>
|
||||
<ItemText>rc_ctrl,0x0A</ItemText>
|
||||
</Ww>
|
||||
<Ww>
|
||||
<count>5</count>
|
||||
<WinNumber>1</WinNumber>
|
||||
<ItemText>buf0ready,0x0A</ItemText>
|
||||
</Ww>
|
||||
</WatchWindow1>
|
||||
<WatchWindow2>
|
||||
|
Binary file not shown.
@ -38,10 +38,12 @@ return 0;
|
||||
static void CMD_RcLogic(const CMD_RC_t *rc, CMD_t *cmd) {
|
||||
|
||||
/* 将操纵杆的对应值转换为底盘的控制向量和云台变化的欧拉角 */
|
||||
|
||||
|
||||
// RC_dr16 ,
|
||||
// RC_r12ds
|
||||
//
|
||||
#ifdef r12ds_t
|
||||
/*乐迪反馈值转换(-1 -- 1 )范围*/
|
||||
|
||||
if(rc->ch_x<0) cmd->Vx =map_fp32(rc->ch_x,-337,0,-1,0);
|
||||
else cmd->Vx =map_fp32(rc->ch_x,0,310,0,1);
|
||||
|
||||
@ -55,7 +57,10 @@ static void CMD_RcLogic(const CMD_RC_t *rc, CMD_t *cmd) {
|
||||
|
||||
cmd->key_ctrl_l = rc->key [0];
|
||||
cmd->key_ctrl_r = rc->key [1];
|
||||
|
||||
#elif defined(dr16_t)
|
||||
|
||||
|
||||
|
||||
cmd->Vx = rc->ch_r_x;
|
||||
cmd->Vy = -rc->ch_r_y;
|
||||
@ -66,14 +71,14 @@ static void CMD_RcLogic(const CMD_RC_t *rc, CMD_t *cmd) {
|
||||
cmd->key_ctrl_l = rc->sw_l;
|
||||
cmd->key_ctrl_r = rc->sw_r ;
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
@ -90,15 +95,15 @@ static void CMD_RcLostLogic(CMD_t *cmd){
|
||||
int8_t CMD_ParseRc(CMD_t *cmd,CMD_RC_t *rc){
|
||||
if (cmd == NULL) return -1;
|
||||
if (rc == NULL) return -1;
|
||||
#ifdef dr16_t
|
||||
//#ifdef dr16_t
|
||||
/*c当rc丢控时,恢复机器人至默认状态 */
|
||||
if ((rc->ch_w == CMD_SW_ERR) || (rc->ch_y == CMD_SW_ERR)) {
|
||||
CMD_RcLostLogic(cmd);
|
||||
} else {
|
||||
// if ((rc->ch_w == CMD_SW_ERR) || (rc->ch_y == CMD_SW_ERR)) {
|
||||
// CMD_RcLostLogic(cmd);
|
||||
// } else {
|
||||
CMD_RcLogic(rc, cmd);
|
||||
}
|
||||
// }
|
||||
|
||||
#endif
|
||||
//#endif
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -71,16 +71,10 @@ typedef enum {
|
||||
CMD_SW_DOWN = 2,
|
||||
} CMD_SwitchPos_t;
|
||||
|
||||
typedef enum
|
||||
{
|
||||
RC_dr16 ,
|
||||
RC_r12ds
|
||||
}remote_type;
|
||||
|
||||
/*遥控器值,使用CMD_RcLogic函数传入CMD_t结构体*/
|
||||
typedef struct {
|
||||
|
||||
remote_type RC_type;
|
||||
#ifdef dr16_t
|
||||
|
||||
float ch_l_x; /* 遥控器左侧摇杆横轴值,上为正 */
|
||||
|
@ -60,7 +60,7 @@ static bool DR16_DataCorrupted(const DR16_t *dr16) {
|
||||
int8_t DR16_Init(DR16_t *dr16) {
|
||||
if (dr16 == NULL) return DEVICE_ERR_NULL;
|
||||
if ((thread_alert = osThreadGetId()) == NULL) return DEVICE_ERR_NULL;
|
||||
|
||||
|
||||
BSP_UART_RegisterCallback(BSP_UART_REMOTE, BSP_UART_IDLE_LINE_CB,
|
||||
DR16_RxCpltCallback);
|
||||
return DEVICE_OK;
|
||||
@ -106,7 +106,7 @@ int8_t DR16_ParseRC(const DR16_t *dr16, CMD_RC_t *rc) {
|
||||
} else {
|
||||
memset(rc, 0, sizeof(*rc));
|
||||
}
|
||||
|
||||
rc->RC_type = RC_dr16;
|
||||
float full_range = (float)(DR16_CH_VALUE_MAX - DR16_CH_VALUE_MIN);
|
||||
|
||||
rc->ch_r_x = 2 * ((float)dr16->data.ch_r_x - DR16_CH_VALUE_MID) / full_range;
|
||||
|
@ -49,4 +49,5 @@ int8_t DR16_HandleOffline(const DR16_t *dr16, CMD_RC_t *rc);
|
||||
|
||||
#endif
|
||||
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
@ -21,7 +21,7 @@ extern DMA_HandleTypeDef hdma_usart3_rx;
|
||||
|
||||
osThreadId_t thread_alert;
|
||||
|
||||
int buf0ready =0;
|
||||
int buf0ready =0; /*不起作用*/
|
||||
int buf1ready =0;
|
||||
|
||||
/* Private function -------------------------------------------------------- */
|
||||
@ -124,6 +124,7 @@ 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)
|
||||
{
|
||||
if (sbus_buf == NULL || rc_ctrl == NULL)
|
||||
@ -131,6 +132,7 @@ int8_t sbus_to_rc(volatile const uint8_t *sbus_buf, CMD_RC_t *rc_ctrl)
|
||||
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
|
||||
@ -172,10 +174,19 @@ int8_t sbus_to_rc(volatile const uint8_t *sbus_buf, CMD_RC_t *rc_ctrl)
|
||||
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(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
|
||||
|
||||
|
@ -21,8 +21,6 @@ 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);
|
||||
|
||||
|
||||
//void R12ds_HandleOffline(void);
|
||||
|
||||
|
||||
|
||||
|
||||
|
@ -25,13 +25,11 @@ CMD_RC_t *R12ds_DataGet(){
|
||||
}
|
||||
|
||||
|
||||
//void R12ds_HandleOffline(void) {
|
||||
// CMD_RC_t *rc;
|
||||
// rc = R12ds_DataGet();
|
||||
|
||||
// memset(rc, 0, sizeof(*rc));
|
||||
// rc->offline = 1;//用作遥控器断电后急停使用
|
||||
//}
|
||||
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
|
||||
|
||||
@ -54,19 +52,17 @@ void Task_r12ds(void *argument)
|
||||
|
||||
#endif
|
||||
|
||||
// if(R12Buf0_WaitDmaCplt(1))
|
||||
// {
|
||||
sbus_to_rc(sbus_rx_buf[0],&cmd_rc);
|
||||
// R12ds_HandleOffline();
|
||||
// }
|
||||
// else if(R12Buf1_WaitDmaCplt(1))
|
||||
// {
|
||||
// sbus_to_rc(sbus_rx_buf[1],&cmd_rc);
|
||||
// }
|
||||
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);
|
||||
|
||||
tick += delay_tick; /* 计算下一个唤醒时刄1ķ*/
|
||||
tick += delay_tick; /* 计算下一个唤醒时*/
|
||||
osDelay(10);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user