/*
上层控制任务
*/
/* Includes ----------------------------------------------------------------- */

#include "up.h"
#include "user_task.h"
#include "can_use.h"
#include <cmsis_os2.h>

#include "vofa.h"

static  CAN_t can;


#ifdef DEBUG

CAN_Output_t UP_CAN_out;

UP_t UP  ;

CMD_t up_cmd;


#else 

static CAN_Output_t up_can_out;

static UP_t UP;

static CMD_t up_cmd;

#endif
float  aaa=0;
float bbb=0;
float CCC=0;
float ddd=0;


/**
 * \brief 
 *
 * \param argument 
 */
void Task_up(void *argument)
{
	
	 (void)argument; /* 未使用argument,消除警告*/
	const uint32_t delay_tick = osKernelGetTickFreq() / TASK_FREQ_UP;
	
  uint32_t tick = osKernelGetTickCount();
	up_init(&UP,&(task_runtime.config.config->up ),TASK_FREQ_UP);
	
	while(1)
		{
#ifdef DEBUG
    task_runtime.stack_water_mark.up = osThreadGetStackSpace(osThreadGetId());
#endif
		UP_UpdateFeedback(&UP, &can,&up_cmd) ;

      UP_control(&UP,&UP_CAN_out,&up_cmd);
//			UP.motor_target .go_shoot =aaa;
//			UP.motor_target .M2006_angle =bbb ;

//			UP.motor_target .M3508_angle =CCC;
//			UP.motor_target .go_shoot =aaa;
//			UP.motor_target .M2006_angle =bbb;
//			UP.motor_target .go_spin  =ddd;
//			
			ALL_Motor_Control(&UP,&UP_CAN_out);

		osDelay(1);
	/*can上设备数据获取*/	
	osMessageQueueGet(task_runtime.msgq.can.feedback.UP_CAN_feedback, &can, NULL, 0);
					
	osMessageQueueGet(task_runtime.msgq.cmd.UP_cmd_ctrl_t,&up_cmd, NULL, 0);
	
	/*锁定RTOS(实时操作系统)内核,防止任务切换,直到 osKernelUnlock() 被调用*/		
	osKernelLock();
	
	 /*解锁*/
      osKernelUnlock();



		osMessageQueueReset(task_runtime.msgq.can.output.up_dribble_3508 );//运球
		osMessageQueuePut(task_runtime.msgq.can.output.up_dribble_3508, &UP_CAN_out.motor_UP3508_Dribble , 0, 0);  
		osMessageQueueReset(task_runtime.msgq.can.output.up_shoot_3508 );//发射
		osMessageQueuePut(task_runtime.msgq.can.output.up_shoot_3508, &UP_CAN_out.motor_UP3508_shoot , 0, 0);  
		
		osMessageQueuePut(task_runtime.msgq.can.output.shoot5065 ,&UP_CAN_out.chassis5065, 0, 0); 
	

//   vofa_send [0]=UP.vofa_send [0];
//   vofa_send [1]=UP.vofa_send [1];
	 vofa_tx_main (vofa_send);
	 
	tick += delay_tick;
        osDelayUntil(tick);
		 
	  }
	
}