#ifndef BALL_HPP #define BALL_HPP #include "main.h" #include "cmsis_os.h" #include "FreeRTOS.h" #include "bsp_delay.h" #include "GO_M8010_6_Driver.h" // 定义状态枚举 typedef enum { BALL_IDLE, // 空闲状态 BALL_RELEASE, // 下球气缸弹出,爪子张开 BALL_JOINT_REVERSE, // 关节电机反转置水平位置 BALL_FALLING, // 球加速落下 BALL_WAIT_BOUNCE, // 等待光电检测反弹 BALL_NET_CLOSE // 收网状态 } BallState_t; // 定义光电传感器检测宏 #define IS_PHOTOELECTRIC_BALL() (HAL_GPIO_ReadPin(up_ball_GPIO_Port, up_ball_Pin) == GPIO_PIN_RESET) class Ball { public: Ball(); void ballHadling(void); void ballCatch(void); void ballFlow(void); void ballStop(void); void ballZero(void); void ballStateMachine(void); int ballState; //球状态 0:无球 1:有球 private: //int ballState; //球状态 0:无球 1:有球 int up_ball_state; //上球状态 0:无球 1:有球 GO_Motorfield *goData[GO_NUM]; //电机数据指针 float angleSet[GO_NUM]; //电机目标角度 float offestAngle[GO_NUM]; //电机初始角度 float Kp; //比例系数 float Kd; //微分系数 float allowRange; //可活动角度 }; #endif