2022-10-20 17:13:02 +08:00
|
|
|
|
/**
|
|
|
|
|
******************************************************************************
|
|
|
|
|
* @file user_lib.h
|
|
|
|
|
* @author Wang Hongxi
|
|
|
|
|
* @version V1.0.0
|
|
|
|
|
* @date 2021/2/18
|
|
|
|
|
* @brief
|
|
|
|
|
******************************************************************************
|
|
|
|
|
* @attention
|
|
|
|
|
*
|
|
|
|
|
******************************************************************************
|
|
|
|
|
*/
|
|
|
|
|
#ifndef _USER_LIB_H
|
|
|
|
|
#define _USER_LIB_H
|
|
|
|
|
#include "stdint.h"
|
|
|
|
|
#include "main.h"
|
|
|
|
|
#include "cmsis_os.h"
|
|
|
|
|
|
|
|
|
|
enum
|
|
|
|
|
{
|
|
|
|
|
CHASSIS_DEBUG = 1,
|
|
|
|
|
GIMBAL_DEBUG,
|
|
|
|
|
INS_DEBUG,
|
|
|
|
|
RC_DEBUG,
|
|
|
|
|
IMU_HEAT_DEBUG,
|
|
|
|
|
SHOOT_DEBUG,
|
|
|
|
|
AIMASSIST_DEBUG,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
extern uint8_t GlobalDebugMode;
|
|
|
|
|
|
|
|
|
|
#ifndef user_malloc
|
|
|
|
|
#ifdef _CMSIS_OS_H
|
|
|
|
|
#define user_malloc pvPortMalloc
|
|
|
|
|
#else
|
|
|
|
|
#define user_malloc malloc
|
|
|
|
|
#endif
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
/* boolean type definitions */
|
|
|
|
|
#ifndef TRUE
|
|
|
|
|
#define TRUE 1 /**< boolean true */
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
#ifndef FALSE
|
|
|
|
|
#define FALSE 0 /**< boolean fails */
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
/* math relevant */
|
|
|
|
|
/* radian coefficient */
|
|
|
|
|
#ifndef RADIAN_COEF
|
|
|
|
|
#define RADIAN_COEF 57.295779513f
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
/* circumference ratio */
|
|
|
|
|
#ifndef PI
|
|
|
|
|
#define PI 3.14159265354f
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
#define VAL_LIMIT(val, min, max) \
|
|
|
|
|
do \
|
|
|
|
|
{ \
|
|
|
|
|
if ((val) <= (min)) \
|
|
|
|
|
{ \
|
|
|
|
|
(val) = (min); \
|
|
|
|
|
} \
|
|
|
|
|
else if ((val) >= (max)) \
|
|
|
|
|
{ \
|
|
|
|
|
(val) = (max); \
|
|
|
|
|
} \
|
|
|
|
|
} while (0)
|
|
|
|
|
|
|
|
|
|
#define ANGLE_LIMIT_360(val, angle) \
|
|
|
|
|
do \
|
|
|
|
|
{ \
|
|
|
|
|
(val) = (angle) - (int)(angle); \
|
|
|
|
|
(val) += (int)(angle) % 360; \
|
|
|
|
|
} while (0)
|
|
|
|
|
|
|
|
|
|
#define ANGLE_LIMIT_360_TO_180(val) \
|
|
|
|
|
do \
|
|
|
|
|
{ \
|
|
|
|
|
if ((val) > 180) \
|
|
|
|
|
(val) -= 360; \
|
|
|
|
|
} while (0)
|
|
|
|
|
|
|
|
|
|
#define VAL_MIN(a, b) ((a) < (b) ? (a) : (b))
|
|
|
|
|
#define VAL_MAX(a, b) ((a) > (b) ? (a) : (b))
|
|
|
|
|
|
2023-02-04 22:48:53 +08:00
|
|
|
|
/**
|
2023-04-13 16:09:03 +08:00
|
|
|
|
* @brief 返回一块干净的内<EFBFBD>?,不过仍然需要强制转<EFBFBD>?为你需要的类型
|
2023-02-04 22:48:53 +08:00
|
|
|
|
*
|
|
|
|
|
* @param size 分配大小
|
|
|
|
|
* @return void*
|
|
|
|
|
*/
|
|
|
|
|
void* zero_malloc(size_t size);
|
2022-10-20 17:13:02 +08:00
|
|
|
|
|
2022-10-31 20:20:16 +08:00
|
|
|
|
//<2F><><EFBFBD>ٿ<EFBFBD><D9BF><EFBFBD>
|
2022-10-20 17:13:02 +08:00
|
|
|
|
float Sqrt(float x);
|
2022-10-31 20:20:16 +08:00
|
|
|
|
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
2022-10-20 17:13:02 +08:00
|
|
|
|
float abs_limit(float num, float Limit);
|
2022-10-31 20:20:16 +08:00
|
|
|
|
//<2F>жϷ<D0B6><CFB7><EFBFBD>λ
|
2022-10-20 17:13:02 +08:00
|
|
|
|
float sign(float value);
|
2022-10-31 20:20:16 +08:00
|
|
|
|
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
2022-10-20 17:13:02 +08:00
|
|
|
|
float float_deadband(float Value, float minValue, float maxValue);
|
2022-10-31 20:20:16 +08:00
|
|
|
|
//<2F><EFBFBD><DEB7><EFBFBD><EFBFBD><EFBFBD>
|
2022-10-20 17:13:02 +08:00
|
|
|
|
float float_constrain(float Value, float minValue, float maxValue);
|
2022-10-31 20:20:16 +08:00
|
|
|
|
//<2F><EFBFBD><DEB7><EFBFBD><EFBFBD><EFBFBD>
|
2022-10-20 17:13:02 +08:00
|
|
|
|
int16_t int16_constrain(int16_t Value, int16_t minValue, int16_t maxValue);
|
2022-10-31 20:20:16 +08:00
|
|
|
|
//ѭ<><D1AD><EFBFBD><EFBFBD><DEB7><EFBFBD><EFBFBD><EFBFBD>
|
2022-10-20 17:13:02 +08:00
|
|
|
|
float loop_float_constrain(float Input, float minValue, float maxValue);
|
2022-10-31 20:20:16 +08:00
|
|
|
|
//<2F>Ƕ<EFBFBD> <20><><EFBFBD><EFBFBD> 180 ~ -180
|
2022-10-20 17:13:02 +08:00
|
|
|
|
float theta_format(float Ang);
|
|
|
|
|
|
|
|
|
|
int float_rounding(float raw);
|
|
|
|
|
|
2023-04-13 10:31:06 +08:00
|
|
|
|
float* Norm3d(float* v);
|
|
|
|
|
|
2023-04-13 16:09:03 +08:00
|
|
|
|
float NormOf3d(float* v);
|
|
|
|
|
|
2023-04-13 10:31:06 +08:00
|
|
|
|
void Cross3d(float* v1, float* v2, float* res);
|
|
|
|
|
|
|
|
|
|
float Dot3d(float* v1, float* v2);
|
|
|
|
|
|
2022-10-31 20:20:16 +08:00
|
|
|
|
//<2F><><EFBFBD>ȸ<EFBFBD>ʽ<EFBFBD><CABD>Ϊ-PI~PI
|
2022-10-20 17:13:02 +08:00
|
|
|
|
#define rad_format(Ang) loop_float_constrain((Ang), -PI, PI)
|
|
|
|
|
|
|
|
|
|
#endif
|