#ifndef BALL_HPP
#define BALL_HPP
#include "main.h"
#include "cmsis_os.h"
#include "FreeRTOS.h"
#include "bsp_delay.h"
#include "djiMotor.h"
#include "pid.h"

// 定义状态枚举
typedef enum {
    BALL_IDLE,          // 空闲状态
    BALL_RELEASE,       // 下球气缸弹出，爪子张开
    BALL_JOINT_REVERSE, // 关节电机反转置水平位置
    BALL_FALLING,       // 球加速落下
    BALL_WAIT_BOUNCE,   // 等待光电检测反弹
    BALL_NET_CLOSE      // 收网状态
} BallState_t;

typedef enum
{
    MOTOR_1 = 0,
    MOTOR_2 = 1,
    MOTOR_3 = 2,
    MOTOR_DOWN = 3,
    MOTOR_NUM
}motorhangd_e;

// 定义光电传感器检测宏
#define IS_PHOTOELECTRIC_BALL() (HAL_GPIO_ReadPin(up_ball_GPIO_Port, up_ball_Pin) == GPIO_PIN_RESET)

class Ball
{
public:
    Ball();
    void Spin(float speed);
    void ballHadling(void);
    void ballStateMachine(void);

    int16_t result[MOTOR_NUM];
   
private:

    int up_ball_state; //上球状态 0:无球 1:有球
    motor_measure_t *hand_Motor[MOTOR_NUM];
    //三个摩擦轮
    static const float M3508_speed_PID[3];
    static const float M3508_angle_PID[3];

    //电机速度pid结构体
    pid_type_def speed_pid[MOTOR_NUM];
    //位置环pid
    pid_type_def angle_pid[MOTOR_NUM];

    float angleSet;
    float speedSet[MOTOR_NUM];
};

#endif
