rm_balance/User/component/limiter.h
2026-01-14 10:50:31 +08:00

94 lines
2.8 KiB
C
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/*
限制器
*/
#pragma once
#ifdef __cplusplus
extern "C" {
#endif
#include <stdbool.h>
#include <stdint.h>
/* USER INCLUDE BEGIN */
/* USER INCLUDE END */
/* USER DEFINE BEGIN */
/* USER DEFINE END */
/**
* @brief 限制底盘功率不超过power_limit
*
* @param power_limit 最大功率
* @param motor_out 电机输出值
* @param speed 电机转速
* @param len 电机数量
* @return int8_t 0对应没有错误
*/
int8_t PowerLimit_ChassicOutput(float power_limit, float *motor_out,
float *speed, uint32_t len);
/**
* @brief 电容输入功率计算
*
* @param power_in 底盘当前功率
* @param power_limit 裁判系统功率限制值
* @param power_buffer 缓冲能量
* @return float 裁判系统输出最大值
*/
float PowerLimit_CapInput(float power_in, float power_limit,
float power_buffer);
/**
* @brief 使用缓冲能量计算底盘最大功率
*
* @param power_limit 裁判系统功率限制值
* @param power_buffer 缓冲能量
* @return float 底盘输出最大值
*/
float PowerLimit_TargetPower(float power_limit, float power_buffer);
/**
* @brief 射击频率控制
*
* @param heat 当前热量
* @param heat_limit 热量上限
* @param cooling_rate 冷却速率
* @param heat_increase 冷却增加
* @param shoot_freq 经过热量限制后的射击频率
* @return float 射击频率
*/
float HeatLimit_ShootFreq(float heat, float heat_limit, float cooling_rate,
float heat_increase, bool is_big);
/**
* @brief 圆周角度限位器 - 考虑电机与IMU坐标系偏差
* @note 用于将 IMU 坐标系下的目标角度限制在电机坐标系的限位范围内
*
* @param setpoint 目标角度IMU坐标系会被直接修改
* @param motor_angle 电机当前角度
* @param imu_angle IMU当前角度
* @param limit_max 电机坐标系下的最大限位值
* @param limit_min 电机坐标系下的最小限位值
* @param range 角度循环范围(通常为 M_2PI
*/
void CircleAngleLimit(float *setpoint, float motor_angle, float imu_angle,
float limit_max, float limit_min, float range);
/**
* @brief 圆周角度增量限位器 - 考虑电机与IMU坐标系偏差
* @note 用于限制增量控制时不超过电机限位范围
*
* @param delta 增量值,会被直接修改
* @param setpoint 当前目标角度IMU坐标系
* @param motor_angle 电机当前角度
* @param imu_angle IMU当前角度
* @param limit_max 电机坐标系下的最大限位值
* @param limit_min 电机坐标系下的最小限位值
* @param range 角度循环范围(通常为 M_2PI
*/
void CircleAngleDeltaLimit(float *delta, float setpoint, float motor_angle,
float imu_angle, float limit_max, float limit_min,
float range);