Skip to content

Commit ee74333

Browse files
committed
wip: add diverged status getter for robot model and dev tracker
1 parent 5f5e3ce commit ee74333

5 files changed

Lines changed: 55 additions & 30 deletions

File tree

src/kernel/auto_aim.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ struct AutoAim::Impl {
173173
if (auto aim_2d = estimator.make_point2d(aimed->attack)) {
174174
visual.draw_later(Canvas::Point {
175175
.origin = aim_2d->make<cv::Point2i>(),
176-
.radius = 5,
176+
.radius = 3,
177177
.color = aimed->shoot ? kRed : kGreen,
178178
});
179179
}

src/kernel/tracker.cpp

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ struct TrackerV2::Impl {
4141

4242
RobotModel::Config robot_config;
4343
std::unordered_map<ArmorGenre, Timestamp> robot_stamps;
44-
std::unordered_map<ArmorGenre, RobotModel> robots;
44+
std::unordered_map<ArmorGenre, RobotModel> robot_models;
4545

4646
OutpostModel::Config outpost_config;
4747
Timestamp outpost_stamp;
@@ -128,7 +128,7 @@ struct TrackerV2::Impl {
128128

129129
const auto dt = std::chrono::duration<double> { timestamp - stamp };
130130
if (dt.count() > config.timeout_seconds) {
131-
robots.erase(id);
131+
robot_models.erase(id);
132132
logging.warn("Timeout model with {}", get_enum_name(id));
133133
return true;
134134
}
@@ -182,17 +182,18 @@ struct TrackerV2::Impl {
182182
if (id == DeviceId::OUTPOST) {
183183
continue;
184184
}
185-
if (robots.contains(id) == false) {
186-
robots.try_emplace(id, robot_config);
187-
robots[id].configure_camera(
185+
if (robot_models.contains(id) == false) {
186+
robot_models.try_emplace(id, robot_config);
187+
robot_models[id].update_camera(
188188
std::bit_cast<std::array<double, 9>>(camera.camera_matrix),
189189
camera.distort_coeff);
190-
robots[id].update_transform({
190+
robot_models[id].update_transform({
191191
.translation = camera.translation,
192192
.orientation = camera.orientation,
193193
});
194-
if (!robots[id].start_with(target.armor2ds)) {
195-
robots.erase(id);
194+
if (!robot_models[id].init(target.armor2ds)) {
195+
robot_models.erase(id);
196+
robot_stamps.erase(id);
196197
logging.warn("Init failed with {}", get_enum_name(id));
197198
} else {
198199
logging.info("Init OK with {}", get_enum_name(id));
@@ -202,13 +203,19 @@ struct TrackerV2::Impl {
202203
timestamp - robot_stamps[id],
203204
};
204205

205-
auto& model = robots[id];
206+
auto& model = robot_models[id];
206207
model.update_transform({
207208
.translation = camera.translation,
208209
.orientation = camera.orientation,
209210
});
210211
model.predict(dt.count());
211212
model.correct(target.armor2ds, target.bars);
213+
214+
if (model.diverged()) {
215+
robot_models.erase(id);
216+
robot_stamps.erase(id);
217+
logging.warn("{} is diverged", get_enum_name(id));
218+
}
212219
}
213220
robot_stamps[id] = timestamp;
214221
}
@@ -229,6 +236,8 @@ struct TrackerV2::Impl {
229236
auto result = Trackable::Unique { };
230237
auto better = std::numeric_limits<double>::max();
231238
{
239+
/// @FIXME:
240+
/// 1. 误识别的机器人,也会被认为是收敛的,因为只进行了一帧 init
232241
if (outpost && outpost->converge()) {
233242
const auto state = outpost->state();
234243
const auto score = calculate(DeviceId::OUTPOST, state.direction());
@@ -240,7 +249,7 @@ struct TrackerV2::Impl {
240249
}
241250
std::ranges::copy(outpost->full(), std::back_inserter(addition.tracked3d));
242251
}
243-
for (const auto& [id, model] : robots) {
252+
for (const auto& [id, model] : robot_models) {
244253
if (model.converge()) {
245254
const auto state = model.state();
246255
const auto score = calculate(id, state.direction());

src/kernel/tracker.hpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
#pragma once
22

3-
#include <optional>
4-
#include <span>
5-
#include <yaml-cpp/yaml.h>
6-
73
#include "module/tracker/trackable.hpp"
84
#include "utility/clock.hpp"
95
#include "utility/pimpl.hpp"
106
#include "utility/robot/armor.hpp"
117

8+
#include <span>
9+
#include <yaml-cpp/yaml.h>
10+
1211
namespace rmcs::kernel {
1312

1413
class TrackerV2 {

src/module/tracker/model/robot.cpp

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -652,7 +652,7 @@ struct RobotModel::Impl {
652652
}
653653

654654
auto converge() const -> bool {
655-
constexpr auto kMinUpdate = std::size_t { 5 };
655+
constexpr auto kMinUpdate = std::size_t { 10 };
656656
constexpr auto kMaxCovXY = 1.0;
657657

658658
if (update_count < kMinUpdate) return false;
@@ -663,21 +663,41 @@ struct RobotModel::Impl {
663663

664664
return true;
665665
}
666+
auto diverged() const -> bool {
667+
const auto& state = context.posteriors_state;
668+
const auto& cov = context.posteriors_covariance;
669+
return std::ranges::any_of(
670+
std::array {
671+
cov(kStateX, kStateX) > 150,
672+
cov(kStateY, kStateY) > 150,
673+
674+
std::abs(state[kStateX]) > 15.0,
675+
std::abs(state[kStateY]) > 15.0,
676+
std::abs(state[kStateZ]) > 02.0,
677+
std::abs(state[kStateW]) > 10.0 * std::numbers::pi,
678+
679+
std::abs(state[kStateVx]) > 5.,
680+
std::abs(state[kStateVy]) > 5.,
681+
std::abs(state[kStateVz]) > 1.,
682+
683+
state.hasNaN() == true,
684+
state.allFinite() == false,
685+
},
686+
std::identity { });
687+
}
666688
};
667689

668690
RobotModel::RobotModel(const Config& cfg) noexcept
669691
: pimpl { std::make_unique<Impl>(cfg) } { }
670692

671693
RobotModel::~RobotModel() noexcept = default;
672694

673-
auto RobotModel::configure(const Config& cfg) noexcept -> void { pimpl->config = cfg; }
674-
675-
auto RobotModel::configure_camera(
676-
std::array<double, 9> matrix, std::array<double, 5> coeff) noexcept -> void {
695+
auto RobotModel::update_camera(std::array<double, 9> matrix, std::array<double, 5> coeff) noexcept
696+
-> void {
677697
pimpl->configure_camera(matrix, coeff);
678698
}
679699

680-
auto RobotModel::start_with(std::span<const Armor2d> armors) noexcept -> bool {
700+
auto RobotModel::init(std::span<const Armor2d> armors) noexcept -> bool {
681701
return pimpl->start_with(armors);
682702
}
683703

@@ -697,5 +717,6 @@ auto RobotModel::state() const noexcept -> State { return pimpl->context.get_sta
697717
auto RobotModel::full() const -> std::array<Armor3d, 4> { return pimpl->full(); }
698718

699719
auto RobotModel::converge() const -> bool { return pimpl->converge(); }
720+
auto RobotModel::diverged() const -> bool { return pimpl->diverged(); }
700721

701722
auto RobotModel::addition() const -> const Addition& { return pimpl->addition; }

src/module/tracker/model/robot.hpp

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -86,22 +86,18 @@ class RobotModel {
8686

8787
explicit RobotModel(const Config&) noexcept;
8888

89-
auto configure(const Config&) noexcept -> void;
90-
91-
auto configure_camera(std::array<double, 9>, std::array<double, 5>) noexcept -> void;
92-
89+
auto update_camera(std::array<double, 9>, std::array<double, 5>) noexcept -> void;
9390
auto update_transform(const Transform&) noexcept -> void;
9491

95-
auto start_with(std::span<const Armor2d>) noexcept -> bool;
92+
auto init(std::span<const Armor2d>) noexcept -> bool;
9693
auto predict(double dt) noexcept -> void;
9794
auto correct(std::span<const Armor2d>, std::span<const Lightbar2d>) noexcept -> void;
9895

99-
auto state() const noexcept -> State;
100-
101-
auto full() const -> std::array<Armor3d, 4>;
102-
10396
auto converge() const -> bool;
97+
auto diverged() const -> bool;
10498

99+
auto state() const noexcept -> State;
100+
auto full() const -> std::array<Armor3d, 4>;
105101
auto addition() const -> const Addition&;
106102
};
107103

0 commit comments

Comments
 (0)