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