#include "shoot_task.h"
#include "TopDefine.h"
#include "FreeRTOS.h"
#include "attrTask.h"
#include <cmsis_os2.h>
#include "remote_control.h"
#include "shoot.h"
#include "odrive_shoot.h"
#include "read_spi.h"
#include "dji.h"
#include "go.h"

extern RC_mess_t RC_mess;
extern Encoder_t encoder;
extern motor_measure_t *trigger_motor_data;//3508电机数据
extern GO go;
int shoot_flag = 0;
int trigger_flag = 0;
int pos=0;
int gopos=0;
int speed_5065=0;


#define VESC_SHOOT 1


void Task_Shoot(void *argument)
{
    (void)argument; /* 未使用argument，消除警告 */
   const uint32_t delay_tick = osKernelGetTickFreq() / TASK_FREQ_CAN;
   
   #if GO1_SHOOT == 1   
   shooterInit();
   #endif

 uint32_t tick = osKernelGetTickCount(); /* 控制任务运行频率的计算 */

	 //go.angleSetgo[0] = 0; //id暂时未知
	  GO_TURN_ball(TURN,go,gopos); //发射舵机位置
	  osDelay(500);
    while(1)
    {
    
      #if VESC_SHOOT == 1
      gopos=35;//云台位置
      GO_TURN_ball(GIMBAL,go,gopos); //锁云台


      if(shoot_flag==1||RC_mess.RC_data.sw[0]==306)//加速
      {

        if(HAL_GPIO_ReadPin(ball_in1_GPIO_Port, ball_in1_Pin) == GPIO_PIN_RESET)
        {
          CAN_VESC_HEAD(1);
          CAN_VESC_HEAD(2);
        }
        else
        {
          speed_5065=35000;
          CAN_VESC_RPM(1, speed_5065); //发射电机转速
          CAN_VESC_RPM(2, speed_5065); //发射电机转速
          
        }


      }
      else if(shoot_flag == 2 || RC_mess.RC_data.sw[5]==1694)//返回//不拨动为306
      {
        speed_5065=-5000;
        CAN_VESC_RPM(1, speed_5065); //发射电机转速
        CAN_VESC_RPM(2, speed_5065); //发射电机转速
        
      }
      else if(shoot_flag == 0)
      {
        CAN_VESC_RPM(1, 0); //发射电机转速
        CAN_VESC_RPM(2, 0); //发射电机转速
       
      }


      #endif
     tick += delay_tick; /* 计算下一个唤醒时刻 */
     osDelayUntil(tick); /* 运行结束，等待下一个周期唤醒 */
    }

}
