NASA Astrobee Robot Software  0.19.1
Flight software for the Astrobee robots operating inside the International Space Station.
sampled_trajectory.h
Go to the documentation of this file.
1 /* Copyright (c) 2017, United States Government, as represented by the
2  * Administrator of the National Aeronautics and Space Administration.
3  *
4  * All rights reserved.
5  *
6  * The Astrobee platform is licensed under the Apache License, Version 2.0
7  * (the "License"); you may not use this file except in compliance with the
8  * License. You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
14  * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
15  * License for the specific language governing permissions and limitations
16  * under the License.
17  */
18 
19 #ifndef MAPPER_SAMPLED_TRAJECTORY_H_
20 #define MAPPER_SAMPLED_TRAJECTORY_H_
21 
22 #include <geometry_msgs/Point.h>
23 #include <geometry_msgs/PointStamped.h>
24 #include <octomap/octomap.h>
25 #include <octomap/OcTree.h>
26 #include <visualization_msgs/MarkerArray.h>
27 #include <pcl/kdtree/kdtree_flann.h>
28 #include <pcl/kdtree/impl/kdtree_flann.hpp>
29 #include <ros/ros.h>
30 #include <Eigen/Dense>
31 #include <iostream>
32 #include <vector>
33 
34 #include "mapper/polynomials.h"
35 #include "mapper/linear_algebra.h"
37 
38 namespace sampled_traj {
39 
40 // Pos has the discretized points in the trajectory,
41 // and is compressed with the function compressSamples
42 // Time has the corresponding times within Pos
43 // nPoints has the number of points in the Pos vector
44 // ThickTraj is of the octree type to avoid repeated nodes
45 // that occurs when concatenating trajectories between two
46 // waypoints
48  public:
49  // Sampled trajectory variables
50  pcl::PointCloud<pcl::PointXYZ> pos_;
51  pcl::PointCloud<pcl::PointXYZ>::Ptr cloud_ptr_ =
52  pcl::PointCloud<pcl::PointXYZ>::Ptr(new pcl::PointCloud<pcl::PointXYZ>);
53  pcl::KdTreeFLANN<pcl::PointXYZ> kdtree_pos_;
54  std::vector<double> time_;
55  int n_points_;
56 
57  // Compressed samples (std::vector can delete entries, pcl::PointCloud isn't that easy)
58  std::vector<Eigen::Vector3d> compressed_pos_;
59  std::vector<double> compressed_time_;
60  int n_compressed_points_; // Number of points after compression
61  double max_dev_; // Max deviation for compression
62 
63  // Thick trajectory variables
64  octomap::OcTree thick_traj_ = octomap::OcTree(0.1); // Create empty tree with resolution 0.1
65  pcl::PointCloud< pcl::PointXYZ > point_cloud_traj_;
66  double resolution_;
67  double thickness_;
68 
69 
70  // Constructor
71  SampledTrajectory3D(const double &dt,
72  const polynomials::Trajectory3D &poly_trajectories);
73  SampledTrajectory3D(const std::vector<double> &time_vec,
74  const pcl::PointCloud<pcl::PointXYZ> &pos_vec);
76 
77  // Methods
78  void PrintSamples();
79  void SetMaxDev(const double &max_dev);
80  void SetResolution(const double &resolution);
81  void DeleteSample(const int &index);
82  void CompressSamples();
83  void Bresenham(const Eigen::Vector3d &p0,
84  const Eigen::Vector3d &pf,
85  std::vector<octomap::point3d> *points); // Bresenham line algorithm por printing a line
86  void ThickBresenham(const Eigen::Vector3d &p0,
87  const Eigen::Vector3d &pf); // Thick bresenham line algorithm por printing a line
88  void ThickTrajToPcl();
89  void CreateKdTree();
90  void SortCollisions(const std::vector<octomap::point3d> &colliding_nodes,
91  std::vector<geometry_msgs::PointStamped> *samples);
92  void TrajVisMarkers(visualization_msgs::MarkerArray* marker_array);
93  void SamplesVisMarkers(visualization_msgs::MarkerArray* marker_array);
94  void CompressedVisMarkers(visualization_msgs::MarkerArray* marker_array);
95  void ClearObject(); // Clear all the data within this object
96 };
97 
98 // Comparison funcion used in sort algorithm
99 bool ComparePointStamped(const geometry_msgs::PointStamped &sample1,
100  const geometry_msgs::PointStamped &sample2);
101 
102 
103 } // namespace sampled_traj
104 
105 #endif // MAPPER_SAMPLED_TRAJECTORY_H_
visualization_functions.h
sampled_traj::SampledTrajectory3D::n_points_
int n_points_
Definition: sampled_trajectory.h:55
sampled_traj
Definition: sampled_trajectory.h:38
sampled_traj::SampledTrajectory3D::PrintSamples
void PrintSamples()
Definition: sampled_trajectory.cc:62
sampled_traj::ComparePointStamped
bool ComparePointStamped(const geometry_msgs::PointStamped &sample1, const geometry_msgs::PointStamped &sample2)
Definition: sampled_trajectory.cc:541
polynomials.h
sampled_traj::SampledTrajectory3D::thick_traj_
octomap::OcTree thick_traj_
Definition: sampled_trajectory.h:64
sampled_traj::SampledTrajectory3D::cloud_ptr_
pcl::PointCloud< pcl::PointXYZ >::Ptr cloud_ptr_
Definition: sampled_trajectory.h:51
sampled_traj::SampledTrajectory3D::SetResolution
void SetResolution(const double &resolution)
Definition: sampled_trajectory.cc:75
sampled_traj::SampledTrajectory3D::thickness_
double thickness_
Definition: sampled_trajectory.h:67
sampled_traj::SampledTrajectory3D::SetMaxDev
void SetMaxDev(const double &max_dev)
Definition: sampled_trajectory.cc:70
sampled_traj::SampledTrajectory3D
Definition: sampled_trajectory.h:47
sampled_traj::SampledTrajectory3D::SamplesVisMarkers
void SamplesVisMarkers(visualization_msgs::MarkerArray *marker_array)
Definition: sampled_trajectory.cc:445
sampled_traj::SampledTrajectory3D::pos_
pcl::PointCloud< pcl::PointXYZ > pos_
Definition: sampled_trajectory.h:50
sampled_traj::SampledTrajectory3D::n_compressed_points_
int n_compressed_points_
Definition: sampled_trajectory.h:60
linear_algebra.h
sampled_traj::SampledTrajectory3D::Bresenham
void Bresenham(const Eigen::Vector3d &p0, const Eigen::Vector3d &pf, std::vector< octomap::point3d > *points)
Definition: sampled_trajectory.cc:169
sampled_traj::SampledTrajectory3D::DeleteSample
void DeleteSample(const int &index)
Definition: sampled_trajectory.cc:83
sampled_traj::SampledTrajectory3D::CreateKdTree
void CreateKdTree()
Definition: sampled_trajectory.cc:364
point_cloud_common::Vector3d
Eigen::Vector3d Vector3d(const PointType &point)
Definition: utilities.h:328
sampled_traj::SampledTrajectory3D::CompressedVisMarkers
void CompressedVisMarkers(visualization_msgs::MarkerArray *marker_array)
Definition: sampled_trajectory.cc:486
sampled_traj::SampledTrajectory3D::SampledTrajectory3D
SampledTrajectory3D()
Definition: sampled_trajectory.cc:58
sampled_traj::SampledTrajectory3D::compressed_time_
std::vector< double > compressed_time_
Definition: sampled_trajectory.h:59
sampled_traj::SampledTrajectory3D::SortCollisions
void SortCollisions(const std::vector< octomap::point3d > &colliding_nodes, std::vector< geometry_msgs::PointStamped > *samples)
Definition: sampled_trajectory.cc:369
sampled_traj::SampledTrajectory3D::resolution_
double resolution_
Definition: sampled_trajectory.h:66
sampled_traj::SampledTrajectory3D::point_cloud_traj_
pcl::PointCloud< pcl::PointXYZ > point_cloud_traj_
Definition: sampled_trajectory.h:65
sampled_traj::SampledTrajectory3D::compressed_pos_
std::vector< Eigen::Vector3d > compressed_pos_
Definition: sampled_trajectory.h:58
sampled_traj::SampledTrajectory3D::max_dev_
double max_dev_
Definition: sampled_trajectory.h:61
sampled_traj::SampledTrajectory3D::CompressSamples
void CompressSamples()
Definition: sampled_trajectory.cc:89
sampled_traj::SampledTrajectory3D::kdtree_pos_
pcl::KdTreeFLANN< pcl::PointXYZ > kdtree_pos_
Definition: sampled_trajectory.h:53
sampled_traj::SampledTrajectory3D::TrajVisMarkers
void TrajVisMarkers(visualization_msgs::MarkerArray *marker_array)
Definition: sampled_trajectory.cc:393
sampled_traj::SampledTrajectory3D::ClearObject
void ClearObject()
Definition: sampled_trajectory.cc:528
polynomials::Trajectory3D
Definition: polynomials.h:94
sampled_traj::SampledTrajectory3D::time_
std::vector< double > time_
Definition: sampled_trajectory.h:54
sampled_traj::SampledTrajectory3D::ThickBresenham
void ThickBresenham(const Eigen::Vector3d &p0, const Eigen::Vector3d &pf)
Definition: sampled_trajectory.cc:287
sampled_traj::SampledTrajectory3D::ThickTrajToPcl
void ThickTrajToPcl()
Definition: sampled_trajectory.cc:349