update
This commit is contained in:
@@ -101,7 +101,7 @@ void EncodeScan(const LaserScan& scan, UnixTime stamp, std::string* out) {
|
||||
}
|
||||
|
||||
void EncodeCloud(const PointCloudXYZ& cloud, UnixTime stamp, uint32_t max_points,
|
||||
float quant_m, std::string* out) {
|
||||
float quant_m, const Pose2D& delta, std::string* out) {
|
||||
if (quant_m <= 0.0f) quant_m = 0.01f;
|
||||
|
||||
// Lay buoc deu thay vi cat duoi: cat duoi lam mat ca mot vung khong gian,
|
||||
@@ -118,22 +118,27 @@ void EncodeCloud(const PointCloudXYZ& cloud, UnixTime stamp, uint32_t max_points
|
||||
}
|
||||
|
||||
PutHeader(out, BinaryType::kCloud, stamp);
|
||||
// Goc = (0,0,0): cloud da o frame base_footprint sau gravity_align.
|
||||
// Goc = (0,0,0): sau khi ap `delta` o vong duoi, diem nam trong he
|
||||
// base_footprint HIEN TAI -- dung he ma trinh duyet ve.
|
||||
PutF32(out, 0.0f);
|
||||
PutF32(out, 0.0f);
|
||||
PutF32(out, 0.0f);
|
||||
PutF32(out, quant_m);
|
||||
PutU32(out, n_out);
|
||||
|
||||
const double dc = std::cos(delta.theta), ds = std::sin(delta.theta);
|
||||
const float inv = 1.0f / quant_m;
|
||||
constexpr float kLim = 32767.0f;
|
||||
for (size_t i = 0; i < n_in; i += stride) {
|
||||
const PointXYZ& p = cloud.points[i];
|
||||
if (!std::isfinite(p.x) || !std::isfinite(p.y) || !std::isfinite(p.z)) continue;
|
||||
// z khong doi: `delta` la SE(2), robot khong di chuyen theo phuong dung.
|
||||
const double bx = delta.x + dc * p.x - ds * p.y;
|
||||
const double by = delta.y + ds * p.x + dc * p.y;
|
||||
// Kep vao dai i16. Voi quant 0.01 m thi dai la +-327 m -- khong bao gio
|
||||
// cham toi trong nha, nhung kep van re hon la de tran am tham.
|
||||
const float qx = std::max(-kLim, std::min(kLim, p.x * inv));
|
||||
const float qy = std::max(-kLim, std::min(kLim, p.y * inv));
|
||||
const float qx = std::max(-kLim, std::min(kLim, static_cast<float>(bx) * inv));
|
||||
const float qy = std::max(-kLim, std::min(kLim, static_cast<float>(by) * inv));
|
||||
const float qz = std::max(-kLim, std::min(kLim, p.z * inv));
|
||||
PutI16(out, static_cast<int16_t>(std::lround(qx)));
|
||||
PutI16(out, static_cast<int16_t>(std::lround(qy)));
|
||||
|
||||
@@ -118,6 +118,39 @@ class WebServerImpl {
|
||||
mutable std::mutex world_mu;
|
||||
std::string world_blob;
|
||||
|
||||
// --- Nhip gui rieng cho tung kenh -------------------------------------
|
||||
// `status_rate_hz`, `scan_rate_hz`, `cloud_rate_hz`, `path_rate_hz` da nam
|
||||
// trong system.yaml tu dau va da duoc parse vao WebConfig, nhung KHONG cho
|
||||
// nao ap dung chung -- chi `tools/vslam_web_demo.cc`. Publish() gui ca ba
|
||||
// kenh o MOI lan goi, tuc o status_rate_hz = 10 Hz.
|
||||
//
|
||||
// Do duoc: cloud 4000 diem = 24 kB, gui 10 Hz la 240 kB/s -- gap DOI ngan
|
||||
// sach 120 kB/s cua ca UI. Hang doi 4 khung day lien tuc, drop khung cu
|
||||
// nhat, va man hinh tut lai 1-2 giay so voi robot. Chinh cai bay ma
|
||||
// system.yaml da ghi ("109 kB/s chi vi PATH gui o 9.8 Hz thay vi 1 Hz"),
|
||||
// quay lai o ca ba kenh.
|
||||
//
|
||||
// CHI luong goi Publish() cham vao -- khong khoa.
|
||||
UnixTime last_scan_at, last_cloud_at, last_path_at;
|
||||
bool have_scan_at = false, have_cloud_at = false, have_path_at = false;
|
||||
|
||||
// Den luot kenh nay chua? `rate <= 0` = khong gioi han.
|
||||
//
|
||||
// Gate theo STAMP CUA SNAPSHOT, khong theo dong ho tuong: phat lai ban ghi
|
||||
// nhanh hon thoi gian that phai ra cung ket qua nhu chay live. Cung ly do
|
||||
// da ghi trong DepthFilter::Apply().
|
||||
static bool Due(double rate, UnixTime now, UnixTime* last, bool* have) {
|
||||
if (rate <= 0.0) return true;
|
||||
if (*have) {
|
||||
const double dt = SecondsBetween(now, *last);
|
||||
// dt < 0 = dong ho lui (ban ghi phat lai tu dau) -> gui va dat lai moc.
|
||||
if (dt >= 0.0 && dt < 1.0 / rate) return false;
|
||||
}
|
||||
*last = now;
|
||||
*have = true;
|
||||
return true;
|
||||
}
|
||||
|
||||
WebServerImpl(WebConfig c, WebServer::CommandHandler cmd,
|
||||
WebServer::TeleopHandler tel)
|
||||
: cfg(std::move(c)), on_command(std::move(cmd)), on_teleop(std::move(tel)) {}
|
||||
@@ -712,20 +745,26 @@ void WebServer::Publish(const WebSnapshot& snap) {
|
||||
WriteStateJson(snap, state.get());
|
||||
for (const auto& s : targets) s->Send(state, /*binary=*/false, /*is_map=*/false);
|
||||
|
||||
if (snap.scan) {
|
||||
if (snap.scan && impl_->Due(impl_->cfg.scan_hz, snap.stamp,
|
||||
&impl_->last_scan_at, &impl_->have_scan_at)) {
|
||||
auto buf = std::make_shared<std::string>();
|
||||
EncodeScan(*snap.scan, snap.stamp, buf.get());
|
||||
for (const auto& s : targets) s->Send(buf, true, false);
|
||||
}
|
||||
|
||||
if (snap.cloud) {
|
||||
if (snap.cloud && impl_->Due(impl_->cfg.cloud_hz, snap.stamp,
|
||||
&impl_->last_cloud_at, &impl_->have_cloud_at)) {
|
||||
auto buf = std::make_shared<std::string>();
|
||||
EncodeCloud(*snap.cloud, snap.stamp, impl_->cfg.cloud_max_points,
|
||||
impl_->cfg.cloud_quant_m, buf.get());
|
||||
impl_->cfg.cloud_quant_m,
|
||||
snap.have_cloud_delta ? snap.cloud_delta : Pose2D{},
|
||||
buf.get());
|
||||
for (const auto& s : targets) s->Send(buf, true, false);
|
||||
}
|
||||
|
||||
if (!snap.trajectory.empty()) {
|
||||
if (!snap.trajectory.empty() &&
|
||||
impl_->Due(impl_->cfg.path_hz, snap.stamp, &impl_->last_path_at,
|
||||
&impl_->have_path_at)) {
|
||||
auto buf = std::make_shared<std::string>();
|
||||
EncodePath(snap.trajectory, snap.stamp, impl_->cfg.path_min_step_m, buf.get());
|
||||
for (const auto& s : targets) s->Send(buf, true, false);
|
||||
|
||||
Reference in New Issue
Block a user