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

@@ -207,8 +207,9 @@ class ZlacWrapper : public BaseInterface {
if (!impl_) return;
int32_t l = 0, r = 0;
double skew = 0.0;
EncoderReading out;
if (!impl_->getPositionCounts(l, r)) {
if (!impl_->getPositionCounts(l, r, &skew)) {
out.stamp = clock_->Now();
out.valid = false;
{
@@ -231,7 +232,35 @@ class ZlacWrapper : public BaseInterface {
}
const double scale = kTwoPi / static_cast<double>(counts_per_rev_);
out.left_rad = static_cast<double>(l - origin_l_) * scale;
double left_counts = static_cast<double>(l - origin_l_);
// ⚠️ BU DO LECH LAY MAU GIUA HAI BANH.
//
// Duong SDO doc hai banh bang hai giao dich tuan tu, nen banh PHAI duoc
// lay mau muon hon banh TRAI khoang `skew` giay. Cong thuc vi sai
// omega = (v_r - v_l) / L
// bien dung khoang lech do thanh QUAY GIA: o 0.3 m/s voi skew 5 ms, hai
// banh lech 1.5 mm, ra ~0.2 rad/s -- vua dung do lon cua canh bao
// "nghi TRUOT BANH" do duoc tren robot.
//
// Ngoai suy banh trai toi THOI DIEM cua banh phai bang chinh van toc gan
// nhat cua no, de hai gia tri cung mot moc thoi gian.
//
// Duong sua tan goc la map 0x6064:01 va :02 vao MOT TPDO (hai I32 = dung
// 8 byte CAN) -- luc do skew = 0 va khoi bu. Can khai bao mapping do
// trong master.dcf.
if (skew > 0.0 && have_prev_left_) {
const double dt = (out.stamp - prev_left_stamp_).toSec();
if (dt > 1e-4) {
const double v_counts = (left_counts - prev_left_counts_) / dt;
left_counts += v_counts * skew;
}
}
prev_left_counts_ = static_cast<double>(l - origin_l_);
prev_left_stamp_ = out.stamp;
have_prev_left_ = true;
out.left_rad = left_counts * scale;
// Banh phai lap doi chieu -- cung quy uoc voi KinematicsConfig o tren.
// Thieu phep doi dau nay thi robot di thang ma odometry bao dang quay.
out.right_rad = -static_cast<double>(r - origin_r_) * scale;
@@ -265,6 +294,10 @@ class ZlacWrapper : public BaseInterface {
int32_t origin_l_ = 0, origin_r_ = 0;
bool have_origin_ = false;
UnixTime last_enc_;
// Mau truoc cua banh TRAI, de uoc van toc khi bu do lech lay mau.
double prev_left_counts_ = 0.0;
UnixTime prev_left_stamp_;
bool have_prev_left_ = false;
mutable std::mutex cmd_mu_;
double cmd_linear_ = 0.0, cmd_angular_ = 0.0;