This commit is contained in:
trung09122002
2026-09-20 15:14:17 +07:00
parent 1ff3dccba9
commit 0c33efea2f
4 changed files with 66 additions and 5 deletions

View File

@@ -111,7 +111,8 @@ public:
// "count". Ban goc chi co getActualRPM() -- tuc chi co van toc, va tich
// phan van toc thi lo mot mau telemetry la mat vinh vien mot doan quang
// duong ma khong phat hien duoc. Xem thirdparty/PROVENANCE.md.
bool getPositionCounts(int32_t& out_left, int32_t& out_right);
bool getPositionCounts(int32_t& out_left, int32_t& out_right,
double* out_skew_sec = nullptr);
bool isReady() const { return hardware_ready_.load(); }
bool hasConnectionLost() const { return connection_lost_.load(); }
@@ -154,6 +155,8 @@ private:
std::atomic<int32_t> cached_left_pos_raw_{0};
std::atomic<int32_t> cached_right_pos_raw_{0};
std::atomic<bool> cached_pos_valid_{false};
// [vslam] Banh phai lay mau muon hon banh trai bay nhieu giay.
std::atomic<double> cached_pos_skew_sec_{0.0};
void telemetryLoop();
// Target caching

View File

@@ -291,13 +291,28 @@ void ZlacMotorDriver::telemetryLoop() {
auto rpdo = master_->RpdoMapped(node_id_);
cached_left_pos_raw_ = static_cast<int32_t>(rpdo[0x6064][1]);
cached_right_pos_raw_ = static_cast<int32_t>(rpdo[0x6064][2]);
// PDO: ca hai banh den trong CUNG mot khung CAN -> khong lech.
cached_pos_skew_sec_ = 0.0;
pos_ok = true;
} catch (...) {
// [vslam] DO do lech thay vi bo qua no.
//
// Hai lan doc la hai giao dich tuan tu, nen banh phai duoc lay mau
// SAU banh trai mot khoang. Moc thoi gian hieu dung cua moi lan doc
// nam o GIUA giao dich, nen:
// lech = (t2 - t0) / 2
// Ben goi dung so nay de ngoai suy banh trai toi thoi diem cua banh
// phai; khong bu thi cong thuc vi sai bien khoang lech do thanh quay
// gia.
const auto t0 = std::chrono::steady_clock::now();
auto lp = sdo_read_sync<int32_t>(*master_, node_id_, 0x6064, 1);
auto rp = sdo_read_sync<int32_t>(*master_, node_id_, 0x6064, 2);
const auto t2 = std::chrono::steady_clock::now();
if (lp.has_value() && rp.has_value()) {
cached_left_pos_raw_ = lp.value();
cached_right_pos_raw_ = rp.value();
cached_pos_skew_sec_ =
std::chrono::duration<double>(t2 - t0).count() / 2.0;
pos_ok = true;
}
}
@@ -318,10 +333,13 @@ bool ZlacMotorDriver::getActualRPM(double& out_left_rpm, double& out_right_rpm)
// [vslam] Xem PROVENANCE.md. 0x6064 la bo dem TUYET DOI trong driver motor:
// lo mot mau thi mau sau van dung, khac han tich phan van toc.
bool ZlacMotorDriver::getPositionCounts(int32_t& out_left, int32_t& out_right) {
bool ZlacMotorDriver::getPositionCounts(int32_t& out_left, int32_t& out_right,
double* out_skew_sec) {
if (!cached_pos_valid_.load()) return false;
out_left = cached_left_pos_raw_.load();
out_right = cached_right_pos_raw_.load();
// Banh PHAI duoc lay mau muon hon banh TRAI bay nhieu giay. 0 khi di qua PDO.
if (out_skew_sec) *out_skew_sec = cached_pos_skew_sec_.load();
return true;
}