GKD.RoboCtrl
载入中...
搜索中...
未找到
power_manager.h
1
6#pragma once
7
8#include <cstdint>
9#include <deque>
10#include <array>
11
12#define USE_POWER_CONTROLLER TRUE
13
14// If the capacitor is plugged into the circuit, make sure you enable the super
15// cap module successfully Otherwise, it will cause unexpected behavior of the
16// RLS model
17#define USE_SUPER_CAPACITOR TRUE
18
19#define USE_REFEREE_SYSTEM_COMM TRUE
20
21#include "utils/RLS.hpp"
22#include "core/logger.h"
23
24namespace roboctrl::ctrl
25{
26namespace power_manage{
27 constexpr static float refereeFullBuffSet = 60.0f; // 裁判系统满功率能量缓冲目标值
28 constexpr static float refereeBaseBuffSet = 50.0f; // 裁判系统基础功率能量缓冲目标值
29 constexpr static float capFullBuffSet = 250.0f; // 超级电容满功率能量缓冲目标值
30 constexpr static float capBaseBuffSet = 100.0f; // 超级电容基础功率能量缓冲目标值
31 constexpr static float error_powerDistribution_set = 20.0f; //功率分配算法的误差阈值
32 constexpr static float prop_powerDistribution_set = 15.0f; // 功率分配算法的比例阈值
33
34 // constexpr float MIN_MAXPOWER_CONFIGURED = 15.0f;
35 constexpr float MAX_CAP_POWER_OUT = 300.0f; // 超级电容最大输出功率
36 constexpr float CAP_OFFLINE_ENERGY_RUNOUT_POWER_THRESHOLD = 43.0f; // 电容离线时能量耗尽的功率阈值
37 constexpr float CAP_OFFLINE_ENERGY_TARGET_POWER = 37.0f; // 电容离线时的目标功率
38 constexpr float MAX_POEWR_REFEREE_BUFF = 60.0f; // 裁判系统最大功率缓冲
39 constexpr float REFEREE_GG_COE = 0.95f; // 裁判系统挂了的功率系数
40 constexpr float CAP_REFEREE_BOTH_GG_COE = 0.85f; // 电容和裁判系统都挂了时的功率系数
41
53 constexpr static uint8_t maxLevel = 11U; //最高等级
54 constexpr static uint8_t HeroChassisPowerLimit_HP_FIRST[maxLevel] = { 0, 55U, 60U, 65U,
55 70U, 75U, 80U, 85U,
56 90U, 100U, 120U }; // 英雄各等级功率限制
57 constexpr static uint8_t InfantryChassisPowerLimit_HP_FIRST[maxLevel] = { 0, 45U, 50U, 55U,
58 60U, 65U, 70U, 75U,
59 80U, 90U, 100U };// 步兵各等级功率限制
60 constexpr static uint8_t SentryChassisPowerLimit = 100U;
61
62 enum class Division
63 {
64 INFANTRY, // 0
65 HERO, // 1
66 SENTRY // 2
67 };
68
69 struct PowerObj
70 {
71 public:
72 float pidOutput; // torque current command, [-maxOutput, maxOutput], no unit
73 float curAv; // Measured angular velocity, [-maxAv, maxAv], rad/s
74 float setAv; // target angular velocity, [-maxAv, maxAv], rad/s
75 float pidMaxOutput; // pid max output
76 };
77
78 struct Manager
79 {
80 enum RLSEnabled : bool
81 {
82 Disable = 0,
83 Enable = 1
84 } rlsEnabled;
85
86 enum ErrorFlags
87 {
88 MotorDisconnect = 1U,
89 RefereeDisConnect = 2U,
90 CAPDisConnect = 4U
91 };
92
93 uint8_t error;
94
98 Manager() = delete;
99
100 Manager(
101 std::deque<Hardware::DJIMotor> &motors_,
102 const Division division_,
103 RLSEnabled rlsEnabled_ = Enable,
104 const float k1_ = 0.22f,
105 const float k2_ = 1.2f,
106 const float k3_ = 2.78f,
107 const float lambda_ = 0.9999f);
108
109 std::deque<Hardware::DJIMotor> &motors;
110 Division division;
111
112 float powerBuff;
113 float fullBuffSet;
114 float baseBuffSet;
115 float fullMaxPower;
116 float baseMaxPower;
117
118 float powerUpperLimit;
119 float powerLowerLimit;
120 float refereeMaxPower;
121
122 float userConfiguredMaxPower;
123 float (*callback)(void);
124
125 float measuredPower;
126 float estimatedPower;
127 float estimatedCapEnergy;
128
129 float k1;
130 float k2;
131 float k3;
132
133 size_t lastUpdateTick;
134
135 utils::RLS<2> rls;
136
137 ControllerList powerPD_base;
138 ControllerList powerPD_full;
139
140 std::shared_ptr<Robot::Robot_set> robot_set;
141 std::shared_ptr<Device::Super_Cap> supercap;
142 std::shared_ptr<Device::Dji_referee> referee;
143
144 void init(const std::shared_ptr<Robot::Robot_set> &robot);
145 std::array<float, 4> getControlledOutput(PowerObj *objs[4]);
146 void setMaxPowerConfigured(float maxPower);
147 void setMode(uint8_t mode); //功率最大值设置
148 [[noreturn]] void powerDaemon (); //电源守护进程
149 };
150
151#define POWER_PD_KP 50.0f
152 const typename Pid::PidConfig powerPD_base_pid_config{
153 POWER_PD_KP, 0.0f, 0.2f, MAX_CAP_POWER_OUT, 0.0f,
154 };
155 const typename Pid::PidConfig powerPD_full_pid_config{
156 POWER_PD_KP, 0.0f, 0.2f, MAX_CAP_POWER_OUT, 0.0f,
157 };
158
163 {
164 public:
165 float userConfiguredMaxPower;
166 float maxPowerLimited;
167 float sumPowerCmd_before_clamp;
168 float effectivePower;
169 float powerLoss;
170 float efficiency;
171 uint8_t estimatedCapEnergy;
172 Manager::ErrorFlags error;
173 };
174
175 // return the latest feedback referee power limit(before referee disconnected),
176 // according to the robot level
177 //TODO 完成定义
178 float getLatestFeedbackJudgePowerLimit();
179
186 std::array<float, 4> getControlledOutput(PowerObj *objs[4]);
187
192 const volatile PowerStatus &getPowerStatus();
193
200 void setMaxPowerConfigured(float maxPower);
201
202
210 void setRLSEnabled(uint8_t isUpdate);
211
212 void setMode(uint8_t mode);
213
214 void registerPowerCallbackFunc(float (*callback)(void));
215
216}
217
218} // namespace Power
管理一组协程回调的容器。
Definition callback.hpp:34
用于日志输出的组件。
asio::awaitable< T > awaitable
协程任务类型。
Definition async.hpp:42
Storing the power status of the chassis