103 lines
3.2 KiB
C
103 lines
3.2 KiB
C
#pragma once
|
||
|
||
#ifdef __cplusplus
|
||
extern "C" {
|
||
#endif
|
||
|
||
#include "bsp/can.h"
|
||
#include "device/device.h"
|
||
//#include "referee.h"
|
||
|
||
#define SUPERCAP_CAN BSP_CAN_1
|
||
//#define SUPERCAP_CAN BSP_CAN_2
|
||
|
||
#define SUPERCAP_TX_ID 0x001 //C板发给超级电容的ID
|
||
#define SUPERCAP_RX_ID 0x100 //超级电容发给C板的ID
|
||
|
||
|
||
//超级电容的状态标志位,超级电容运行或者保护的具体状态反馈
|
||
typedef enum
|
||
{
|
||
DISCHARGE =0 , //放电状态
|
||
CHARGE =1, //充电状态
|
||
WAIT =2, //待机状态
|
||
SOFTSTART_PROTECTION =3,//处于软起动状态
|
||
OVER_LOAD_PROTECTION = 4, //超电过载保护状态
|
||
BAT_OVER_VOLTAGE_PROTECTION =5, //过压保护状态
|
||
BAT_UNDER_VOLTAGE_PROTECTION =6, //电池欠压保护,电池要没电了,换电池
|
||
CAP_UNDER_VOLTAGE_PROTECTION =7, //超级电容欠压保护,超级电容用完电了,要充一会才能用
|
||
OVER_TEMPERATURE_PROTECTION =8, //过温保护,太热了
|
||
BOOM = 9, //超电爆炸了
|
||
}SuperCapStateEnum;
|
||
|
||
//超级电容准备状态,用于判断超级电容是否可以使用
|
||
typedef enum
|
||
{
|
||
SUPERCAP_STATUS_OFFLINE =0 ,
|
||
SUPERCAP_STATUS_RUNNING =1,
|
||
}SuperCap_Status_t;
|
||
|
||
// 发送给超级电容的数据
|
||
typedef struct {
|
||
FunctionalState Enable ; //超级电容使能。1使能,0失能
|
||
SuperCapStateEnum Charge ; //V1.1超级电容充电。1充电,0放电,在PLUS版本中,此标志位无效,超电的充放电是自动的
|
||
uint8_t Powerlimit; //裁判系统功率限制
|
||
uint8_t ChargePower; //V1.1超级电容充电功率,在PLUS版本中,此参数,超电的充电功率随着底盘功率变化
|
||
}CAN_SuperCapTXDataTypeDef;
|
||
|
||
// 从超级电容接收到的数据
|
||
typedef struct {
|
||
uint8_t SuperCapEnergy;//超级电容可用能量:0-100%
|
||
uint16_t ChassisPower; //底盘功率,0-512,由于传输的时候为了扩大量程右移了一位,所以接收的时候需要左移还原(丢精度)。
|
||
SuperCap_Status_t SuperCapReady;//超级电容【可用标志】:1为可用,0为不可用
|
||
SuperCapStateEnum SuperCapState;//超级电容【状态标志】:各个状态对应的状态码查看E_SuperCapState枚举。
|
||
uint8_t BatVoltage; //通过超级电容监控电池电压*10,
|
||
uint8_t BatPower;
|
||
}CAN_SuperCapRXDataTypeDef;
|
||
|
||
extern CAN_SuperCapRXDataTypeDef CAN_SuperCapRXData;
|
||
|
||
void set_supercap_power_offset(uint8_t offset);
|
||
|
||
|
||
// 以下函数是超电控制所需要调用的函数
|
||
void transfer_SuperCap_measure( uint8_t *data);
|
||
int8_t CAN_TX_SuperCapData(CAN_SuperCapTXDataTypeDef * TX_Temp);
|
||
|
||
|
||
/**
|
||
* @brief 获取超级电容在线状态,1在线,0离线
|
||
*/
|
||
uint8_t get_supercap_online_state(void);
|
||
|
||
|
||
/**
|
||
* @brief 获取超级电容的运行状态,具体查看枚举SuperCapStateEnum
|
||
*/
|
||
SuperCapStateEnum get_supercap_state(void);
|
||
|
||
|
||
/**
|
||
* @brief 获取超级电容读到的电池电压,单位伏(V)
|
||
*/
|
||
float get_battery_voltage_from_supercap(void);
|
||
|
||
|
||
/**
|
||
* @brief 获取超级电容可用能量,范围:0-100%
|
||
*/
|
||
uint8_t get_supercap_energy(void);
|
||
|
||
|
||
/**
|
||
* @brief 获取根据超级电容功率统计的底盘消耗能量,单位:焦耳(J)
|
||
*/
|
||
uint32_t get_chassis_energy_from_supercap(void);
|
||
|
||
int8_t SuperCap_Init(void);
|
||
int8_t SuperCap_Update(void);
|
||
|
||
#ifdef __cplusplus
|
||
}
|
||
#endif /*SUPERCAP_H*/
|