@@ -1325,8 +1325,32 @@ fn log_maze_obstacles(rec: &rerun::RecordingStream, maze: &Maze) {
1325
1325
/// A struct to hold trajectory data
1326
1326
/// # Fields
1327
1327
/// * `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
1328
1330
struct Trajectory {
1329
1331
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
+ }
1330
1354
}
1331
1355
1332
1356
/// log trajectory data to the rerun recording stream
@@ -1427,9 +1451,7 @@ fn main() {
1427
1451
let mut maze = Maze :: new ( lower_bounds, upper_bounds, 20 ) ;
1428
1452
let camera = Camera :: new ( ( 128 , 96 ) , 90.0_f32 . to_radians ( ) , 0.1 , 5.0 ) ;
1429
1453
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 ) ) ;
1433
1455
rec. set_time_seconds ( "timestamp" , 0 ) ;
1434
1456
log_mesh ( & rec, 5 , 0.5 ) ;
1435
1457
log_maze_tube ( & rec, & maze) ;
@@ -1468,7 +1490,7 @@ fn main() {
1468
1490
let ( true_accel, true_gyro) = quad. read_imu ( ) ;
1469
1491
let ( _measured_accel, _measured_gyro) = imu. read ( true_accel, true_gyro) ;
1470
1492
if i % 5 == 0 {
1471
- trajectory. points . push ( quad. position ) ;
1493
+ trajectory. add_point ( quad. position ) ;
1472
1494
log_trajectory ( & rec, & trajectory) ;
1473
1495
log_data (
1474
1496
& rec,
0 commit comments