Skip to content

Commit 568eeb1

Browse files
committed
Code review.
1 parent 52d10f1 commit 568eeb1

30 files changed

+116
-542
lines changed

.vscode/extensions.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,9 @@
1616
"davidanson.vscode-markdownlint",
1717
"marus25.cortex-debug",
1818
"xyz.local-history",
19-
"usernamehw.errorlens"
19+
"usernamehw.errorlens",
20+
"wayou.vscode-todo-highlight",
21+
"gruntfuggly.todo-tree"
2022
],
2123
// List of extensions recommended by VS Code that should not be recommended for users of this workspace.
2224
"unwantedRecommendations": []

src/device/ai/dev_ai.cpp

Lines changed: 15 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ AI::AI(bool autoscan_enable)
2424
AI *ai = static_cast<AI *>(arg);
2525
ai->data_ready_.Post();
2626
};
27-
27+
// TODO: AUTOAIM和AI串口接收都要加idle回调
2828
bsp_uart_register_callback(BSP_UART_AI, BSP_UART_RX_CPLT_CB, rx_cplt_callback,
2929
this);
3030

@@ -59,9 +59,7 @@ AI::AI(bool autoscan_enable)
5959
ai->ai_tp_.Publish(ai->cmd_for_ref_);
6060

6161
/* 发送数据到上位机 */
62-
// quat_sub.DumpData(ai->quat_);
6362
ai->PackMCU();
64-
6563
ai->StartTrans();
6664

6765
System::Thread::Sleep(2);
@@ -201,9 +199,10 @@ void AI::DecideAction() {
201199
}
202200

203201
/* 发射机构行为 */
204-
if (this->notice_ == 2) { /* 开火 */
202+
// TODO: notice应该按位与,防止命令冲突
203+
if (this->notice_ == AI_NOTICE_FIRE) { /* 开火 */
205204
this->action_.ai_launcher = AI::Action::FIRE;
206-
} else if (this->notice_ == 5) {
205+
} else if (this->notice_ == AI_NOTICE_AUTO_AIM) {
207206
this->action_.ai_launcher = AI::Action::CEASEFIRE; /* 不发弹 */
208207
}
209208
}
@@ -241,35 +240,23 @@ bool AI::PackCMD() {
241240
case SCANF:
242241
/*yaw轴旋转加入随机数扰动*/
243242
static float smoothed_random =
244-
0.0f; // 静态变量,用于存储平滑后的随机值
245-
float alpha = 0.1f; // 平滑系数,控制新随机值的影响程度
243+
0.0f; /* 静态变量,用于存储平滑后的随机值 */
244+
float alpha = 0.1f; /* 平滑系数,控制新随机值的影响程度 */
246245
float raw_random =
247-
static_cast<float>(rand() % 10 - 5) / 1000.0f; // 原始随机扰动
246+
static_cast<float>(rand() % 10 - 5) / 1000.0f; /* 原始随机扰动 */
248247
smoothed_random = alpha * raw_random +
249-
(1.0f - alpha) * smoothed_random; // 低通滤波
248+
(1.0f - alpha) * smoothed_random; /* 低通滤波 */
250249
float yaw_rate = this->scanf_mode_.scanf_yaw_rate;
251250
this->target_scan_angle_ += yaw_rate * (1.0f + smoothed_random);
252-
// this->cmd_.gimbal.eulr.yaw = this->target_scan_angle_;
253251
this->cmd_.gimbal.eulr.yaw = this->eulr_.yaw;
254252

255253
float t = static_cast<float>(bsp_time_get_ms()) / 1000.0f;
256-
// float pit_phase =
257-
// fmodf(t * this->scanf_mode_.scanf_pit_omega, 2.0f * M_PI);
258-
// // 三角波输出范围 [0, 1]
259-
// float triangle_wave =
260-
// (pit_phase < M_PI ? pit_phase / M_PI
261-
// : (2.0f * M_PI - pit_phase) / M_PI);
262-
// float mapped_triangle_wave = 2.0f * triangle_wave - 1.0f;
263-
// // 计算俯仰角
264-
// this->cmd_.gimbal.eulr.pit =
265-
// this->scanf_mode_.scanf_pit_center +
266-
// this->scanf_mode_.scanf_pit_range * mapped_triangle_wave;
267-
268-
/*计算三角波*/
254+
255+
/* 计算三角波 */
269256
float phase =
270257
fmodf(t * this->scanf_mode_.scanf_pit_omega, 2.0f * M_PI);
271258
float triangle_wave_mapped =
272-
(fabsf(phase / M_PI - 1.0f) * 2.0f) - 1.0f;
259+
(fabsf(phase / static_cast<float>(M_PI) - 1.0f) * 2.0f) - 1.0f;
273260
this->cmd_.gimbal.eulr.pit =
274261
this->scanf_mode_.scanf_pit_center +
275262
this->scanf_mode_.scanf_pit_range * triangle_wave_mapped;
@@ -340,14 +327,14 @@ bool AI::PackCMD() {
340327
}
341328

342329
void AI::PraseRef() {
330+
// TODO: 错误的射速
343331
#if RB_HERO
344-
this->ref_.ball_speed = BULLET_SPEED_LIMIT_42MM
332+
this->ref_.ball_speed = BULLET_SPEED_LIMIT_42MM;
345333
#else
346334
this->ref_.ball_speed = BULLET_SPEED_LIMIT_17MM;
347335
#endif
348336

349-
this->ref_.max_hp =
350-
this->raw_ref_.robot_status.max_hp;
337+
this->ref_.max_hp = this->raw_ref_.robot_status.max_hp;
351338

352339
this->ref_.hp = this->raw_ref_.robot_status.remain_hp;
353340

@@ -397,12 +384,11 @@ void AI::PraseRef() {
397384

398385
this->ref_.game_progress = this->raw_ref_.game_status.game_progress;
399386

387+
// TODO: game_robot_hp只有哨兵?
400388
if (this->raw_ref_.robot_status.robot_id < 100) {
401389
this->ref_.base_hp = this->raw_ref_.game_robot_hp.red_base;
402390
this->ref_.outpost_hp = this->raw_ref_.game_robot_hp.red_outpose;
403391
this->ref_.hp = this->raw_ref_.game_robot_hp.red_7;
404-
// this->ref_.hp = 400;
405-
406392
} else {
407393
this->ref_.base_hp = this->raw_ref_.game_robot_hp.blue_base;
408394
this->ref_.outpost_hp = this->raw_ref_.game_robot_hp.blue_outpose;

src/device/ai/dev_ai.hpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,9 +134,7 @@ class AI {
134134

135135
/* angle record */
136136
float chassis_yaw_offset_ = 0;
137-
// float gimbal_scan_start_angle_;
138137
Component::Type::Eulr eulr_;
139-
// Component::Type::Quaternion quat_;
140138
Component::Type::CycleValue target_scan_angle_ = 0.0;
141139
struct {
142140
float yaw; /* 偏航角(Yaw angle) */

src/device/aim/dev_aim.cpp

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,14 @@ AIM::AIM()
1919
aim->data_ready_.Post();
2020
};
2121

22+
auto rx_idle_callback = [](void* arg){
23+
AIM *aim = static_cast<AIM *>(arg);
24+
aim->data_ready_.Post();
25+
};
26+
2227
bsp_uart_register_callback(BSP_UART_AI, BSP_UART_RX_CPLT_CB, rx_cplt_callback,
2328
this);
29+
bsp_uart_register_callback(BSP_UART_AI, BSP_UART_IDLE_LINE_CB, rx_idle_callback, this);
2430

2531
Component::CMD::RegisterController(this->cmd_tp_);
2632
auto ai_thread = [](AIM *aim) {
@@ -34,28 +40,21 @@ AIM::AIM()
3440

3541
/* 接收上位机数据 */
3642
aim->StartRecv();
37-
if (aim->data_ready_.Wait(0))
43+
if (aim->data_ready_.Wait(10))
3844
{
3945
aim->PraseHost();
4046
aim->PackCMD();
4147
}
4248

43-
//发送数据给上位机
49+
/* 发送数据给上位机 */
4450
aim->PackMCU();
4551
aim->StartTran();
46-
47-
System::Thread::Sleep(2);
4852
}
4953
};
5054
this->thread_.Create(ai_thread, this, "aim_thread", DEVICE_AI_TASK_STACK_DEPTH,
5155
System::Thread::REALTIME);
5256
}
5357

54-
double convert_to_0_to_2pi(double theta_prime) {
55-
double theta = fmod(theta_prime + 2 * M_PI, 2 * M_PI);
56-
return theta;
57-
}
58-
5958
bool AIM::PackCMD() {
6059
/* 确保遥控器开关最高控制权,关遥控器即断控 */
6160
if (!Component::CMD::Online()) {
@@ -106,7 +105,7 @@ bool AIM::PraseHost() {
106105
return false;
107106
}
108107

109-
double convert_to_minus_pi_to_pi(double theta) {
108+
float convert_to_minus_pi_to_pi(float theta) {
110109
while (theta > M_PI) {
111110
theta -= 2 * M_PI;
112111
}
@@ -141,7 +140,7 @@ bool AIM::StartTran()
141140
void *src = NULL;
142141
src = &(this->to_host_);
143142
memcpy(txbuf, src, len);
144-
return bsp_uart_transmit(BSP_UART_AI, txbuf, len,false) == BSP_OK;
143+
return bsp_uart_transmit(BSP_UART_AI, txbuf, len, false) == BSP_OK;
145144
}
146145

147146
bool AIM::StartRecv()

src/device/aim/dev_aim.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ namespace Device {
1616
class AIM {
1717
public:
1818

19-
//MCU需要从上位机获取的数据
19+
// TODO: 移动到protocol里面
2020
typedef struct __attribute__((packed)) RevforAI{
2121
uint8_t header = 0xA5;
2222
bool is_fire : 1;
@@ -28,7 +28,7 @@ class AIM {
2828
float pitch;
2929
float yaw;
3030
uint16_t checksum = 0;
31-
}RefForAI_t;
31+
} RefForAI_t;
3232

3333
typedef struct __attribute__ ((packed)) TranToAI{
3434
uint8_t header = 0x5A;
@@ -118,6 +118,6 @@ class AIM {
118118

119119
bool PackMCU();
120120

121-
uint32_t last_online_time_ = 0;
121+
uint32_t last_online_time_ = 0;
122122
};
123123
} // namespace Device

src/device/imu/Kconfig

Lines changed: 0 additions & 4 deletions
This file was deleted.

src/device/imu/dev_can_imu.cpp

Lines changed: 0 additions & 92 deletions
This file was deleted.

src/device/imu/dev_can_imu.hpp

Lines changed: 0 additions & 46 deletions
This file was deleted.

src/device/imu/info.cmake

Lines changed: 0 additions & 8 deletions
This file was deleted.

0 commit comments

Comments
 (0)