R1_up/User/module/shoot.hpp
2025-06-14 01:07:21 +08:00

103 lines
2.2 KiB
C++

#ifndef SHOOT_HPP
#define SHOOT_HPP
#include "djiMotor.h"
#include "pid.h"
#include "GO_M8010_6_Driver.h"
#include "nuc.h"
#include "usart.h"
// 定义状态枚举
typedef enum {
SHOOT_IDLE, // 空闲状态
SHOOT_TOP, // 顶部状态
SHOOT_TENSION, // 拉回到设定
SHOOT_READY,
SHOOT_WAIT,
SHOOT_FIRE, // 发射状态
SHOOT_RETURN // 自动返回状态
} ShootState_t;
// // 定义状态枚举
// typedef enum {
// BALL_IDLE, // 空闲状态
// BALL_FINISH, // 完成状态
// //持球状态
// BALL_TAKE,
// BALL_LOSE
// } BallState_t;
typedef enum
{
UP1=1,
MIDDLE1,
DOWN1,
SHOOT,
WAIT
}rc_mode;
// 光电传感器读取宏
#define IS_PHOTOELECTRIC_TRIGGERED() (HAL_GPIO_ReadPin(STOP_GPIO_Port, STOP_Pin) == GPIO_PIN_RESET)
class Shoot
{
public:
Shoot();
void rc_mode();
void trigger_control(void);
void distanceGet(const NUC_t &nuc);
void shoot_control(void);
void shoot_Current(void);
void RemoveError(void);
int GO_SendData(float pos,float limit);
//go电机
GO_MotorCmd_t go1;
GO_MotorData_t *go1_data;//存放go电机数据
float control_pos; //控制位置
float fire_pos; //发射位置
struct feedback
{
float fd_gopos;
float fd_tpos;
}feedback;
//扳机
float speed_trigger;
int16_t result;
float t_speedSet;
float t_posSet;//扳机位置
float fd_tpos; //扳机反馈位置
motor_measure_t *trigger_Motor;
//==========================公共变量==========================
int16_t rc_key; //遥控器按键
int16_t trigger_key;
ShootState_t currentState; //状态机
//volatile BallState_t ballStatus;//是否有球
volatile uint32_t flag_thread;//接收传回的线程通知
float distance; //视觉距离
private:
//扳机2006
static const float M2006_speed_PID[3];
static const float M2006_angle_PID[3];
//电机速度pid结构体
pid_type_def speed_pid;
//位置环pid
pid_type_def angle_pid;
bool is_hooked; // 标记钩子是否已经钩住拉簧
};
#endif