Skip to content

Commit 4b17a02

Browse files
authored
Merge pull request #24 from KumarRobotics/feature/object-tracking
added generic version of object tracking from scenic
2 parents bbf3eb0 + 531e675 commit 4b17a02

File tree

7 files changed

+187
-0
lines changed

7 files changed

+187
-0
lines changed

glider/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ add_library(${PROJECT_NAME} SHARED
6262
src/differential_gps.cpp
6363
src/odometry.cpp
6464
src/odometry_with_covariance.cpp
65+
src/point.cpp
6566
src/factor_manager.cpp
6667
src/glider.cpp
6768
)

glider/include/glider/core/factor_manager.hpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131

3232
#include "odometry_with_covariance.hpp"
3333
#include "odometry.hpp"
34+
#include "point.hpp"
3435
#include "glider/utils/parameters.hpp"
3536
#include "glider/utils/time.hpp"
3637

@@ -92,8 +93,19 @@ class FactorManager
9293
* @param gyro: gyroscopre reading
9394
* @param orient: orientation in quaternion (w,x,y,z) format */
9495
void addImuFactor(int64_t timestamp, const Eigen::Vector3d& accel, const Eigen::Vector3d& gyro, const Eigen::Vector4d& orient);
96+
/*! @brief adds a landmark factor for an estimated utm point and covariance
97+
* @param timestamp: time of the landmark measurements
98+
* @param landmark_id: a unique id for the landmark
99+
* @param utm: the estimated utm coordinate of the landmark
100+
* @param cov: the 3x3 covariance matrix for the estimated utm coordinate of the landmark */
101+
void addLandmarkFactor(int64_t timestamp, size_t landmark_id, const Eigen::Vector3d& utm, const Eigen::Matrix3d& cov);
102+
95103

96104
// getters and checkers
105+
/*! @brief gets the estimated landmark utm coordinate and covariance
106+
* @param landmark_id: the uinque id for the landmark
107+
* @return the estimated utm point and covariance */
108+
PointWithCovariance getLandmarkPoint(size_t landmark_id) const;
97109
/*! @brief gets the complete factor graph */
98110
gtsam::ExpressionFactorGraph getGraph();
99111
/*! @brief checks if the imu has been initialized
@@ -210,5 +222,9 @@ class FactorManager
210222
bool imu_initialized_;
211223
// @param tracks if a gps measurement has been received
212224
bool gps_initialized_;
225+
226+
// landmark variables
227+
std::unordered_map<size_t, Eigen::Matrix3d> landmark_info_;
228+
std::unordered_map<size_t, Eigen::Vector3d> landmark_info_vec_;
213229
};
214230
}

glider/include/glider/core/glider.hpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,9 @@ class Glider
4343
* @param gyro: gyroscope measurement in the imu's frame
4444
* @param quat: the orientation measurement in the imu's frame */
4545
void addImu(int64_t timestamp, Eigen::Vector3d& accel, Eigen::Vector3d& gyro, Eigen::Vector4d& quat);
46+
void addLandmark(int64_t timestamp, size_t lid, const Eigen::Vector3d& utm, const Eigen::Matrix3d& cov);
47+
PointWithCovariance getLandmark(size_t lid);
48+
4649

4750
/*! @brief calls the factor manager to interpolate between GPS
4851
* measurements using the pim
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
/*!
2+
* Jason Hughes
3+
* January 2026
4+
*
5+
*
6+
* Struct to track landmark points
7+
*/
8+
9+
#pragma once
10+
11+
#include <Eigen/Dense>
12+
#include <gtsam/geometry/Pose3.h>
13+
14+
namespace Glider
15+
{
16+
class Point
17+
{
18+
public:
19+
Point() = default;
20+
Point(const Eigen::Vector3d& p);
21+
Point(double x, double y, double z);
22+
23+
double x() const { return x_; }
24+
double y() const { return y_; }
25+
double z() const { return z_; }
26+
27+
void x(double x) { x_ = x; }
28+
void y(double y) { y_ = y; }
29+
void z(double z) { z_ = z; }
30+
31+
Eigen::Vector3d vector() const;
32+
33+
bool isInitialized() const { return initialized_; }
34+
35+
private:
36+
bool initialized_{false};
37+
double x_{0.0}, y_{0.0}, z_{0.0};
38+
};
39+
40+
class PointWithCovariance : public Point
41+
{
42+
public:
43+
using Point::Point;
44+
PointWithCovariance() = default;
45+
PointWithCovariance(const Eigen::Vector3d& p, const Eigen::Matrix3d& c);
46+
47+
Eigen::Matrix3d cov() const;
48+
double cov(int r, int c) const;
49+
50+
Eigen::Vector3d var() const;
51+
double var(int i) const;
52+
53+
Eigen::Vector3d std() const;
54+
double std(int i) const;
55+
56+
double trace() const;
57+
58+
private:
59+
Eigen::Matrix3d cov_{Eigen::Matrix3d::Identity()};
60+
};
61+
} // namespace Glider

glider/src/factor_manager.cpp

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,29 @@ void FactorManager::addImuFactor(int64_t timestamp, const Eigen::Vector3d& accel
252252
last_imu_time_ = current_time;
253253
}
254254

255+
void FactorManager::addLandmarkFactor(int64_t timestamp, size_t landmark_id, const Eigen::Vector3d& utm, const Eigen::Matrix3d& cov)
256+
{
257+
Eigen::Matrix3d obs_info = cov.inverse();
258+
auto it = landmark_info_.find(landmark_id);
259+
if (it == landmark_info_.end()) {
260+
landmark_info_[landmark_id] = obs_info;
261+
landmark_info_vec_[landmark_id] = obs_info * utm;
262+
} else {
263+
it->second += obs_info;
264+
landmark_info_vec_[landmark_id] += obs_info * utm;
265+
}
266+
}
267+
268+
PointWithCovariance FactorManager::getLandmarkPoint(size_t landmark_id) const
269+
{
270+
auto it = landmark_info_.find(landmark_id);
271+
if (it == landmark_info_.end()) return PointWithCovariance();
272+
273+
Eigen::Matrix3d cov = it->second.inverse();
274+
Eigen::Vector3d point = cov * landmark_info_vec_.at(landmark_id);
275+
return PointWithCovariance(point, cov);
276+
}
277+
255278
Odometry FactorManager::predict(int64_t timestamp)
256279
{
257280
// TODO update this.

glider/src/glider.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,16 @@ void Glider::addImu(int64_t timestamp, Eigen::Vector3d& accel, Eigen::Vector3d&
121121
}
122122
}
123123

124+
void Glider::addLandmark(int64_t timestamp, size_t lid, const Eigen::Vector3d& utm, const Eigen::Matrix3d& cov)
125+
{
126+
factor_manager_.addLandmarkFactor(timestamp, lid, utm, cov);
127+
}
128+
129+
PointWithCovariance Glider::getLandmark(size_t lid)
130+
{
131+
return factor_manager_.getLandmarkPoint(lid);
132+
}
133+
124134
Odometry Glider::interpolate(int64_t timestamp)
125135
{
126136
try

glider/src/point.cpp

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
/*!
2+
* Jason Hughes
3+
* January 2026
4+
*
5+
* Point and PointWithCovariance obejcts
6+
*/
7+
8+
#include "glider/core/point.hpp"
9+
10+
using namespace Glider;
11+
12+
Point::Point(const Eigen::Vector3d& p)
13+
{
14+
x_ = p.x();
15+
y_ = p.y();
16+
z_ = p.z();
17+
initialized_ = true;
18+
}
19+
20+
Point::Point(double x, double y, double z)
21+
{
22+
x_ = x;
23+
y_ = y;
24+
z_ = z;
25+
initialized_ = true;
26+
}
27+
28+
Eigen::Vector3d Point::vector() const
29+
{
30+
return Eigen::Vector3d(x_, y_, z_);
31+
}
32+
33+
PointWithCovariance::PointWithCovariance(const Eigen::Vector3d& p, const Eigen::Matrix3d& c) : Point(p)
34+
{
35+
cov_ = c;
36+
}
37+
38+
Eigen::Matrix3d PointWithCovariance::cov() const
39+
{
40+
return cov_;
41+
}
42+
43+
double PointWithCovariance::cov(int r, int c) const
44+
{
45+
return cov_(r, c);
46+
}
47+
48+
Eigen::Vector3d PointWithCovariance::var() const
49+
{
50+
return cov_.diagonal();
51+
}
52+
53+
double PointWithCovariance::var(int i) const
54+
{
55+
Eigen::Vector3d var = cov_.diagonal();
56+
return var(i);
57+
}
58+
59+
Eigen::Vector3d PointWithCovariance::std() const
60+
{
61+
return cov_.diagonal().cwiseSqrt();
62+
}
63+
64+
double PointWithCovariance::std(int i) const
65+
{
66+
Eigen::Vector3d std = cov_.diagonal().cwiseSqrt();
67+
return std(i);
68+
}
69+
70+
double PointWithCovariance::trace() const
71+
{
72+
return cov_.trace();
73+
}

0 commit comments

Comments
 (0)