Skip to content

Commit 6dffa78

Browse files
committed
optimize trajectory logging
1 parent 2bdb73a commit 6dffa78

File tree

1 file changed

+26
-4
lines changed

1 file changed

+26
-4
lines changed

src/main.rs

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1325,8 +1325,32 @@ fn log_maze_obstacles(rec: &rerun::RecordingStream, maze: &Maze) {
13251325
/// A struct to hold trajectory data
13261326
/// # Fields
13271327
/// * `points` - A vector of 3D points
1328+
/// * `last_logged_point` - The last point that was logged
1329+
/// * `min_distance_threadhold` - The minimum distance between points to log
13281330
struct Trajectory {
13291331
points: Vec<Vector3<f32>>,
1332+
last_logged_point: Vector3<f32>,
1333+
min_distance_threadhold: f32,
1334+
}
1335+
1336+
impl Trajectory {
1337+
fn new(initial_point: Vector3<f32>) -> Self {
1338+
Self {
1339+
points: vec![initial_point],
1340+
last_logged_point: initial_point,
1341+
min_distance_threadhold: 0.1,
1342+
}
1343+
}
1344+
/// Add a point to the trajectory
1345+
/// The point is only added if it is further than the minimum distance threshold
1346+
/// # Arguments
1347+
/// * `point` - The point to add
1348+
fn add_point(&mut self, point: Vector3<f32>) {
1349+
if (point - self.last_logged_point).norm() > self.min_distance_threadhold {
1350+
self.points.push(point);
1351+
self.last_logged_point = point;
1352+
}
1353+
}
13301354
}
13311355

13321356
/// log trajectory data to the rerun recording stream
@@ -1427,9 +1451,7 @@ fn main() {
14271451
let mut maze = Maze::new(lower_bounds, upper_bounds, 20);
14281452
let camera = Camera::new((128, 96), 90.0_f32.to_radians(), 0.1, 5.0);
14291453
let mut planner_manager = PlannerManager::new(Vector3::zeros(), 0.0);
1430-
let mut trajectory = Trajectory {
1431-
points: vec![Vector3::new(0.0, 0.0, 0.0)],
1432-
};
1454+
let mut trajectory = Trajectory::new(Vector3::new(0.0, 0.0, 0.0));
14331455
rec.set_time_seconds("timestamp", 0);
14341456
log_mesh(&rec, 5, 0.5);
14351457
log_maze_tube(&rec, &maze);
@@ -1468,7 +1490,7 @@ fn main() {
14681490
let (true_accel, true_gyro) = quad.read_imu();
14691491
let (_measured_accel, _measured_gyro) = imu.read(true_accel, true_gyro);
14701492
if i % 5 == 0 {
1471-
trajectory.points.push(quad.position);
1493+
trajectory.add_point(quad.position);
14721494
log_trajectory(&rec, &trajectory);
14731495
log_data(
14741496
&rec,

0 commit comments

Comments
 (0)