improve: field_localization twist finished
This commit is contained in:
1 parent
96445bd5f1
commit
4db635ec78
16 files changed
+143
-6
No files matched your search
@@ -71,7 +71,7 @@ ros2 launch src/sentry_sim/launch/sentry_arena.launch.py headless:=true \
|
||||
- 内部状态原点为 IMU,`q` 将 IMU 坐标旋转到 map,`v/g` 在 map 系。误差顺序为 `p,v,theta,bg,ba,g`,右扰动态度误差。
|
||||
- `get_pose()` 返回 `map → base_link`;`get_snapshot()` 在一把互斥锁内返回配套的位姿、滤波状态、协方差与状态时间。
|
||||
- 只发布 TF `map → odom`:`T_map_odom = T_map_base × inverse(T_odom_base)`,两个变换使用同一时间。`publish_map_to_odom=false` 可关闭;不能与 AMCL 同时发布。
|
||||
- `/field_localization/odometry` 为 map 系车体位姿及变换后的位姿协方差;twist 未填充,不能用于速度反馈(速度状态可通过 core 快照读取)。不额外广播 body TF。
|
||||
- `/field_localization/odometry` 为 map 系车体位姿(含 6×6 位姿协方差)以及 `base_link` 系车体线速度/角速度 `twist`(已扣除陀螺零偏与 IMU 偏心安装杆臂速度,含 6×6 速度协方差);也可直接通过 core 快照或 `get_twist()` 读取。不额外广播 body TF。
|
||||
- 每 5 秒打印模式、降级原因、有效点数、残差 RMSE、内点数/比例、退化维数与子空间基、关键帧数和地图点数,同时输出 `/field_localization/status` 摘要。
|
||||
- 支持 `--ros-args -p use_sim_time:=true`。只有消息/ROS 仿真时间参与状态计算。检测到 `/clock` 回跳后停止输出;必须显式调用 `/field_localization/reset` 或重启,以配置的已知初始位姿重新开始。
|
||||
|
||||
|
||||
@@ -24,6 +24,7 @@ types → imu_integration → eskf → registration → map_io → localization_
|
||||
| `PointXYZI` | `timestamp_sec`、`position`、`intensity` | `position` 是 **float**(`Eigen::Vector3f`) |
|
||||
| `PointCloud` | `timestamp_sec`、`frame_id`、`points` | |
|
||||
| `Pose3D` | `rotation`(`Eigen::Quaterniond`)、`translation` | 表示「子坐标系 → 父坐标系」的变换 |
|
||||
| `Twist3D` | `linear`、`angular`(均为 `Eigen::Vector3d`) | 车体坐标系下的三维线速度(m/s)与角速度(rad/s) |
|
||||
|
||||
**所有时间戳的单位都是秒**(`double`),不是 ROS 的纳秒。
|
||||
|
||||
@@ -35,6 +36,7 @@ types → imu_integration → eskf → registration → map_io → localization_
|
||||
|---|---|
|
||||
| `skew(v)` / `exp_so3(v)` / `log_so3(q)` | 反对称矩阵、旋转向量 ⇄ 四元数 |
|
||||
| `compose(a, b)` / `inverse(p)` | 位姿复合与求逆 |
|
||||
| `base_twist(state, raw_w, base_from_imu)` | 扣除陀螺零偏与 IMU 偏心安装杆臂效应,求 `base_link` 刚体线速度与角速度 |
|
||||
| `valid_imu(imu)` | 时间戳合法、数值全部有限 |
|
||||
| `interpolate_imu(samples, time)` | 在相邻两个 IMU 样本之间线性插值 |
|
||||
| `integrate_midpoint(state, a, b)` | 中值积分,推进一步 |
|
||||
@@ -189,7 +191,7 @@ FLPC v1 的布局(小端):8 字节魔数 `FLPC0001`、`uint32` 版本号
|
||||
|
||||
任何一条不满足就立刻失效并把连续计数清零;`accepted_corrections` 倒退(被 reset)也判失效。
|
||||
|
||||
`base_pose_covariance()` 把 IMU 原点的位姿协方差换算到 base_link,`update()` 和 ROS 节点都用它。
|
||||
`base_pose_covariance()` 与 `base_twist_covariance()` 分别通过 6×18 解析雅可比把 IMU 原点的位姿/速度/零偏协方差换算到 `base_link`(其中速度协方差额外叠加单步陀螺采样白噪声),`update()` 和 ROS 节点都用它们。
|
||||
|
||||
## 默认值速查
|
||||
|
||||
|
||||
@@ -19,6 +19,9 @@ struct MotionState {
|
||||
Eigen::Vector3d accel_bias{Eigen::Vector3d::Zero()};
|
||||
Eigen::Vector3d gravity{0.0, 0.0, -9.81};
|
||||
};
|
||||
// Body-frame (base_link) linear and angular velocity with gyro-bias and lever-arm compensation.
|
||||
Twist3D base_twist(const MotionState &state, const Eigen::Vector3d &raw_angular_velocity,
|
||||
const Pose3D &base_from_imu);
|
||||
struct Preintegration {
|
||||
Eigen::Quaterniond dR{Eigen::Quaterniond::Identity()};
|
||||
Eigen::Vector3d dv{Eigen::Vector3d::Zero()};
|
||||
|
||||
@@ -59,6 +59,9 @@ struct LocalizationSnapshot {
|
||||
Pose3D pose;
|
||||
FilterSnapshot filter;
|
||||
LocalizationStatus status;
|
||||
Twist3D twist{};
|
||||
Eigen::Vector3d raw_angular_velocity{Eigen::Vector3d::Zero()};
|
||||
double imu_dt{0.0};
|
||||
};
|
||||
class LocalizationCore {
|
||||
public:
|
||||
@@ -78,6 +81,9 @@ public:
|
||||
// 获取当前位姿
|
||||
[[nodiscard]] Pose3D get_pose() const;
|
||||
|
||||
// 获取当前车体坐标系(base_link)线速度与角速度
|
||||
[[nodiscard]] Twist3D get_twist() const;
|
||||
|
||||
// 设置位姿(用于初始化和后续算法集成)
|
||||
void set_pose(const Pose3D &pose);
|
||||
|
||||
@@ -99,6 +105,8 @@ private:
|
||||
std::vector<ImuData> imu_history_;
|
||||
std::vector<FilterSnapshot> state_history_;
|
||||
Pose3D pose_{};
|
||||
Twist3D twist_{};
|
||||
double last_imu_dt_{0.0};
|
||||
LocalizationStatus status_{};
|
||||
};
|
||||
|
||||
|
||||
@@ -11,6 +11,26 @@ inline Matrix6 base_pose_covariance(const LocalizationSnapshot &s,const Pose3D &
|
||||
j.block<3,3>(3,6)=base_from_imu.rotation.toRotationMatrix();
|
||||
return j*s.filter.covariance*j.transpose();
|
||||
}
|
||||
inline Matrix6 base_twist_covariance(const LocalizationSnapshot &s,const Pose3D &base_from_imu,
|
||||
double gyro_noise_density=0.0) {
|
||||
const Eigen::Matrix3d r_bi=base_from_imu.rotation.normalized().toRotationMatrix();
|
||||
const Eigen::Matrix3d r_mi=s.filter.state.pose.rotation.normalized().toRotationMatrix();
|
||||
const Eigen::Matrix3d lever_r=skew(base_from_imu.translation)*r_bi;
|
||||
Eigen::Matrix<double,6,18> j=Eigen::Matrix<double,6,18>::Zero();
|
||||
j.block<3,3>(0,3)=r_bi*r_mi.transpose();
|
||||
j.block<3,3>(0,6)=r_bi*skew(r_mi.transpose()*s.filter.state.velocity);
|
||||
j.block<3,3>(0,9)=-lever_r;
|
||||
j.block<3,3>(3,9)=-r_bi;
|
||||
Matrix6 cov=j*s.filter.covariance*j.transpose();
|
||||
if(gyro_noise_density>0.0 && s.imu_dt>1e-6) {
|
||||
const double sample_var=(gyro_noise_density*gyro_noise_density)/s.imu_dt;
|
||||
Eigen::Matrix<double,6,3> g;
|
||||
g.topRows<3>()=-lever_r;
|
||||
g.bottomRows<3>()=-r_bi;
|
||||
cov.noalias()+=sample_var*(g*g.transpose());
|
||||
}
|
||||
return 0.5*(cov+cov.transpose());
|
||||
}
|
||||
struct HealthOptions {
|
||||
double correction_timeout{0.3},imu_timeout{0.1},clock_tolerance{0.05};
|
||||
double position_three_sigma{0.5},yaw_three_sigma{15*std::numbers::pi/180};
|
||||
|
||||
@@ -39,4 +39,10 @@ struct Pose3D {
|
||||
Eigen::Vector3d translation{Eigen::Vector3d::Zero()};
|
||||
};
|
||||
|
||||
struct Twist3D {
|
||||
Eigen::Vector3d linear{Eigen::Vector3d::Zero()};
|
||||
|
||||
Eigen::Vector3d angular{Eigen::Vector3d::Zero()};
|
||||
};
|
||||
|
||||
} // namespace field_localization::core
|
||||
@@ -14,6 +14,7 @@ namespace field_localization::ros {
|
||||
core::PointCloud convert_cloud(const sensor_msgs::msg::PointCloud2 &msg);
|
||||
core::Pose3D from_transform(const geometry_msgs::msg::Transform &transform);
|
||||
geometry_msgs::msg::Transform to_transform(const core::Pose3D &pose);
|
||||
geometry_msgs::msg::Twist to_twist(const core::Twist3D &twist);
|
||||
}
|
||||
```
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
#include "field_localization/core/dataset.hpp"
|
||||
#include <sensor_msgs/msg/point_cloud2.hpp>
|
||||
#include <geometry_msgs/msg/transform.hpp>
|
||||
#include <geometry_msgs/msg/twist.hpp>
|
||||
#include <tf2_ros/buffer.hpp>
|
||||
namespace rclcpp { class Node; }
|
||||
namespace field_localization::ros {
|
||||
@@ -11,4 +12,5 @@ core::PointCloud convert_cloud_in_frame(const sensor_msgs::msg::PointCloud2 &msg
|
||||
std::optional<core::MapBounds> declare_map_bounds(rclcpp::Node &node);
|
||||
core::Pose3D from_transform(const geometry_msgs::msg::Transform &transform);
|
||||
geometry_msgs::msg::Transform to_transform(const core::Pose3D &pose);
|
||||
geometry_msgs::msg::Twist to_twist(const core::Twist3D &twist);
|
||||
} // namespace field_localization::ros
|
||||
@@ -27,6 +27,14 @@ Pose3D inverse(const Pose3D &p) {
|
||||
const Eigen::Quaterniond q = p.rotation.conjugate();
|
||||
return {q, -(q * p.translation)};
|
||||
}
|
||||
Twist3D base_twist(const MotionState &state, const Eigen::Vector3d &raw_angular_velocity,
|
||||
const Pose3D &base_from_imu) {
|
||||
const Eigen::Matrix3d r_bi = base_from_imu.rotation.normalized().toRotationMatrix();
|
||||
const Eigen::Matrix3d r_mi = state.pose.rotation.normalized().toRotationMatrix();
|
||||
const Eigen::Vector3d omega_b = r_bi * (raw_angular_velocity - state.gyro_bias);
|
||||
const Eigen::Vector3d v_imu_in_b = r_bi * (r_mi.transpose() * state.velocity);
|
||||
return {v_imu_in_b - omega_b.cross(base_from_imu.translation), omega_b};
|
||||
}
|
||||
bool valid_imu(const ImuData &imu) {
|
||||
return std::isfinite(imu.timestamp_sec) && imu.timestamp_sec >= 0 &&
|
||||
imu.angular_velocity.allFinite() && imu.linear_acceleration.allFinite();
|
||||
|
||||
@@ -31,7 +31,8 @@ void LocalizationCore::set_map_points(std::span<const Eigen::Vector3d> points) {
|
||||
}
|
||||
LocalizationSnapshot LocalizationCore::get_snapshot() const {
|
||||
std::lock_guard<std::mutex> lock(mutex_);
|
||||
return {pose_,filter_.snapshot(),status_};
|
||||
return {pose_,filter_.snapshot(),status_,twist_,
|
||||
previous_imu_ ? previous_imu_->angular_velocity : Eigen::Vector3d::Zero(),last_imu_dt_};
|
||||
}
|
||||
|
||||
|
||||
@@ -61,15 +62,20 @@ bool LocalizationCore::process_imu(const ImuData &imu) {
|
||||
}
|
||||
|
||||
if (previous_imu_) {
|
||||
const double dt=imu.timestamp_sec-previous_imu_->timestamp_sec;
|
||||
if (!filter_.propagate(*previous_imu_,imu)) {
|
||||
status_.mode=TrackingMode::IMU_ONLY; status_.reason=FailureReason::IMU_GAP;
|
||||
auto snapshot=filter_.snapshot(); snapshot.state.timestamp_sec=imu.timestamp_sec;
|
||||
snapshot.covariance.diagonal().array()+=1.0;
|
||||
filter_.restore(snapshot); imu_history_.clear(); state_history_.clear();
|
||||
last_imu_dt_=0.0;
|
||||
} else {
|
||||
last_imu_dt_=dt;
|
||||
}
|
||||
} else {
|
||||
auto snapshot=filter_.snapshot(); snapshot.state.timestamp_sec=imu.timestamp_sec;
|
||||
filter_.restore(snapshot);
|
||||
last_imu_dt_=0.0;
|
||||
}
|
||||
if (status_.has_point_cloud && imu.timestamp_sec-status_.last_point_cloud_timestamp>0.3) {
|
||||
status_.mode=TrackingMode::IMU_ONLY; status_.reason=FailureReason::LIDAR_TIMEOUT;
|
||||
@@ -79,7 +85,9 @@ bool LocalizationCore::process_imu(const ImuData &imu) {
|
||||
while (imu_history_.size()>1 && imu.timestamp_sec-imu_history_[1].timestamp_sec>2.0) {
|
||||
imu_history_.erase(imu_history_.begin()); state_history_.erase(state_history_.begin());
|
||||
}
|
||||
pose_=compose(filter_.snapshot().state.pose,inverse(options_.base_from_imu));
|
||||
const auto current_state=filter_.snapshot().state;
|
||||
pose_=compose(current_state.pose,inverse(options_.base_from_imu));
|
||||
twist_=base_twist(current_state,imu.angular_velocity,options_.base_from_imu);
|
||||
status_.state_timestamp=imu.timestamp_sec;
|
||||
status_.has_imu = true;
|
||||
status_.last_imu_timestamp = imu.timestamp_sec;
|
||||
@@ -216,7 +224,9 @@ bool LocalizationCore::process_point_cloud(const PointCloud &cloud) {
|
||||
}
|
||||
status_.last_correction_timestamp=end; ++status_.accepted_corrections;
|
||||
last_correction_time_=end; status_.mode=TrackingMode::FULL; status_.reason=FailureReason::NONE;
|
||||
pose_=compose(filter_.snapshot().state.pose,inverse(options_.base_from_imu));
|
||||
const auto posterior_state=filter_.snapshot().state;
|
||||
pose_=compose(posterior_state.pose,inverse(options_.base_from_imu));
|
||||
if (previous_imu_) twist_=base_twist(posterior_state,previous_imu_->angular_velocity,options_.base_from_imu);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -225,6 +235,11 @@ Pose3D LocalizationCore::get_pose() const {
|
||||
return pose_;
|
||||
}
|
||||
|
||||
Twist3D LocalizationCore::get_twist() const {
|
||||
std::lock_guard<std::mutex> lock(mutex_);
|
||||
return twist_;
|
||||
}
|
||||
|
||||
void LocalizationCore::set_pose(const Pose3D &pose) {
|
||||
if (!pose.translation.allFinite() || !pose.rotation.coeffs().allFinite() ||
|
||||
pose.rotation.norm() < 1e-12) {
|
||||
@@ -235,6 +250,8 @@ void LocalizationCore::set_pose(const Pose3D &pose) {
|
||||
|
||||
pose_ = pose;
|
||||
pose_.rotation.normalize();
|
||||
twist_ = Twist3D{};
|
||||
last_imu_dt_ = 0.0;
|
||||
MotionState initial; initial.pose=compose(pose_,options_.base_from_imu);
|
||||
filter_.initialize(initial); last_correction_time_=-1; previous_imu_.reset();
|
||||
imu_history_.clear(); state_history_.clear(); status_.has_imu=false;
|
||||
@@ -251,6 +268,8 @@ void LocalizationCore::reset() {
|
||||
std::lock_guard<std::mutex> lock(mutex_);
|
||||
|
||||
pose_ = options_.initial_pose;
|
||||
twist_ = Twist3D{};
|
||||
last_imu_dt_ = 0.0;
|
||||
MotionState initial; initial.pose=compose(pose_,options_.base_from_imu);
|
||||
filter_.initialize(initial); last_correction_time_=-1; previous_imu_.reset(); imu_history_.clear(); state_history_.clear();
|
||||
if (options_.map_mode==MapMode::MAPPING) map_.clear();
|
||||
|
||||
@@ -37,7 +37,7 @@ ros/
|
||||
| 订阅 | `point_cloud_topic`(默认 `/scan/points`) | `sensor_msgs/PointCloud2` | 点云。帧可以是 `lidar_frame` / `base_frame` / `imu_frame`,节点会转到雷达系 |
|
||||
| 订阅 | `imu_topic`(默认 `/imu`) | `sensor_msgs/Imu` | IMU 消息的坐标系原点必须是配置的 IMU 原点 |
|
||||
| 订阅 | TF | — | 读固定外参:`base_frame ← imu_frame`、`imu_frame ← lidar_frame`、点云的帧到 `lidar_frame` |
|
||||
| 发布 | `~/odometry` | `nav_msgs/Odometry` | map 系的 base_link 位姿 + 6×6 协方差。**twist 没填,不能当速度用** |
|
||||
| 发布 | `~/odometry` | `nav_msgs/Odometry` | map 系的 `base_link` 位姿(6×6 协方差)+ `base_link` 系的刚体速度 `twist`(已扣除零偏与 IMU 杆臂效应,含 6×6 协方差) |
|
||||
| 发布 | `~/navigation_valid` | `std_msgs/Bool` | 定位能否用于导航。状态一变立即发,另有 10 Hz 心跳 |
|
||||
| 发布 | `~/status` | `std_msgs/String` | 每 5 秒一次,内容是 `模式,原因,退化维数` |
|
||||
| 发布 | TF `map_frame → odom_frame` | — | 唯一的 `map → odom` 来源,不能和 AMCL 同时开 |
|
||||
|
||||
@@ -67,4 +67,10 @@ geometry_msgs::msg::Transform to_transform(const core::Pose3D &p) {
|
||||
geometry_msgs::msg::Transform t; t.translation.x=p.translation.x(); t.translation.y=p.translation.y(); t.translation.z=p.translation.z();
|
||||
t.rotation.w=p.rotation.w(); t.rotation.x=p.rotation.x(); t.rotation.y=p.rotation.y(); t.rotation.z=p.rotation.z(); return t;
|
||||
}
|
||||
geometry_msgs::msg::Twist to_twist(const core::Twist3D &v) {
|
||||
geometry_msgs::msg::Twist t;
|
||||
t.linear.x=v.linear.x(); t.linear.y=v.linear.y(); t.linear.z=v.linear.z();
|
||||
t.angular.x=v.angular.x(); t.angular.y=v.angular.y(); t.angular.z=v.angular.z();
|
||||
return t;
|
||||
}
|
||||
} // namespace field_localization::ros
|
||||
@@ -178,6 +178,10 @@ void LocalizationNode::publish_estimate() {
|
||||
odom.pose.pose.orientation=transform.rotation;
|
||||
const core::Matrix6 covariance=core::base_pose_covariance(snapshot,core_options_.base_from_imu);
|
||||
for (int i=0;i<6;++i) for (int j=0;j<6;++j) odom.pose.covariance[6*i+j]=covariance(i,j);
|
||||
odom.twist.twist=to_twist(snapshot.twist);
|
||||
const core::Matrix6 twist_covariance=core::base_twist_covariance(
|
||||
snapshot,core_options_.base_from_imu,core_options_.noise.gyro);
|
||||
for (int i=0;i<6;++i) for (int j=0;j<6;++j) odom.twist.covariance[6*i+j]=twist_covariance(i,j);
|
||||
odometry_pub_->publish(odom); last_published_=snapshot.status.state_timestamp;
|
||||
pending_tf_.push_back(snapshot); if (pending_tf_.size()>30) pending_tf_.pop_front();
|
||||
}
|
||||
|
||||
@@ -88,7 +88,26 @@ int main() {
|
||||
}
|
||||
CHECK_NEAR(moving.get_pose().translation.x(),0.5,1e-9);
|
||||
CHECK_NEAR(moving.get_snapshot().filter.state.velocity.x(),1,1e-9);
|
||||
CHECK_NEAR(moving.get_twist().linear.x(),1.0,1e-9);
|
||||
CHECK_NEAR(moving.get_twist().linear.y(),0.0,1e-9);
|
||||
CHECK_NEAR(moving.get_snapshot().imu_dt,0.01,1e-12);
|
||||
CHECK(moving.get_status().mode==TrackingMode::IMU_ONLY);
|
||||
|
||||
// 偏心安装 IMU 原地小陀螺时,base_twist 必须消除杆臂切向速度 (v_base = 0)
|
||||
const Pose3D base_from_imu_offset{exp_so3({0,0,0.5*3.14159265358979323846}),Eigen::Vector3d{0.20,-0.10,0.15}};
|
||||
MotionState spin_state;
|
||||
spin_state.pose=compose(Pose3D{exp_so3({0,0,0.7}),Eigen::Vector3d{1.0,-2.0,0.0}},base_from_imu_offset);
|
||||
const Eigen::Vector3d omega_base{0.0,0.0,4.0};
|
||||
const Eigen::Vector3d gyro_bias_imu{0.02,-0.03,0.01};
|
||||
const Eigen::Vector3d raw_omega_imu=base_from_imu_offset.rotation.conjugate()*omega_base+gyro_bias_imu;
|
||||
// 刚体原地绕 base_link Z 轴旋转时,偏心 IMU 在 map 系的真实线速度为 R_MB * (omega_base x p_BI^B)
|
||||
const Eigen::Quaterniond r_mb=exp_so3({0,0,0.7});
|
||||
spin_state.velocity=r_mb*(omega_base.cross(base_from_imu_offset.translation));
|
||||
spin_state.gyro_bias=gyro_bias_imu;
|
||||
const Twist3D recovered_twist=base_twist(spin_state,raw_omega_imu,base_from_imu_offset);
|
||||
CHECK(recovered_twist.linear.norm()<1e-12);
|
||||
CHECK((recovered_twist.angular-omega_base).norm()<1e-12);
|
||||
|
||||
accelerated.timestamp_sec=0.5;
|
||||
CHECK(!moving.process_imu(accelerated));
|
||||
CHECK(moving.get_status().reason==FailureReason::TIME_ORDER);
|
||||
|
||||
@@ -52,5 +52,13 @@ int main() {
|
||||
CHECK(in_imu.frame_id=="imu_link"); CHECK(in_imu.points.size()==1);
|
||||
if (in_imu.points.size()==1) CHECK((in_imu.points.front().position.cast<double>()-feature).norm()<1e-6);
|
||||
}
|
||||
const core::Twist3D body_twist{{1.8,-0.25,0.03},{-0.01,0.02,3.4}};
|
||||
const auto ros_twist=ros::to_twist(body_twist);
|
||||
CHECK_NEAR(ros_twist.linear.x,1.8,1e-12);
|
||||
CHECK_NEAR(ros_twist.linear.y,-0.25,1e-12);
|
||||
CHECK_NEAR(ros_twist.linear.z,0.03,1e-12);
|
||||
CHECK_NEAR(ros_twist.angular.x,-0.01,1e-12);
|
||||
CHECK_NEAR(ros_twist.angular.y,0.02,1e-12);
|
||||
CHECK_NEAR(ros_twist.angular.z,3.4,1e-12);
|
||||
return sentry_nav_test::Summary("RosConversion");
|
||||
}
|
||||
@@ -30,5 +30,36 @@ int main() {
|
||||
gate.health(true,1.31);CHECK(gate.allowed(1.31));gate.health(false,1.32);CHECK(!gate.allowed(1.32));
|
||||
CHECK(!gate.allowed(0.9));
|
||||
sentry_nav::core::MotionInterlock manual(false);manual.command(2);CHECK(manual.allowed(2.1));CHECK(!manual.allowed(2.31));
|
||||
|
||||
// Verify base_twist_covariance analytical Jacobian against 18-DOF numerical central differences.
|
||||
LocalizationSnapshot ts;
|
||||
const Pose3D b_from_i{exp_so3({0.1,-0.2,0.6}),Eigen::Vector3d{0.18,-0.12,0.15}};
|
||||
ts.filter.state.pose={exp_so3({-0.05,0.08,1.1}),Eigen::Vector3d{-2.0,1.5,0.0}};
|
||||
ts.filter.state.velocity={2.3,-0.7,0.1};
|
||||
ts.filter.state.gyro_bias={0.01,-0.02,0.015};
|
||||
ts.raw_angular_velocity={0.1,0.2,3.5};
|
||||
ts.imu_dt=0.01;
|
||||
Matrix18 p18=0.02*Matrix18::Identity();
|
||||
Vector18 corr;
|
||||
for(int k=0;k<18;++k) corr[k]=0.01*(k+1);
|
||||
p18+=corr*corr.transpose();
|
||||
ts.filter.covariance=p18;
|
||||
Eigen::Matrix<double,6,18> j_num=Eigen::Matrix<double,6,18>::Zero();
|
||||
constexpr double eps=1e-6;
|
||||
for(int k=0;k<18;++k) {
|
||||
Vector18 delta=Vector18::Zero(); delta[k]=eps;
|
||||
const auto plus=base_twist(ErrorStateFilter::inject(ts.filter.state,delta),ts.raw_angular_velocity,b_from_i);
|
||||
const auto minus=base_twist(ErrorStateFilter::inject(ts.filter.state,-delta),ts.raw_angular_velocity,b_from_i);
|
||||
j_num.block<3,1>(0,k)=(plus.linear-minus.linear)/(2*eps);
|
||||
j_num.block<3,1>(3,k)=(plus.angular-minus.angular)/(2*eps);
|
||||
}
|
||||
const Matrix6 expected_cov=j_num*p18*j_num.transpose();
|
||||
const Matrix6 analytic_cov=base_twist_covariance(ts,b_from_i,0.0);
|
||||
CHECK((analytic_cov-expected_cov).norm()<1e-8);
|
||||
const Matrix6 noisy_cov=base_twist_covariance(ts,b_from_i,0.003);
|
||||
const Eigen::SelfAdjointEigenSolver<Matrix6> eig(noisy_cov);
|
||||
CHECK(eig.info()==Eigen::Success && eig.eigenvalues().minCoeff()>0.0);
|
||||
CHECK(noisy_cov(5,5)>analytic_cov(5,5));
|
||||
|
||||
return sentry_nav_test::Summary("TrackingSafety");
|
||||
}
|
||||
Reference in new issue
Block a user