|
NASA Astrobee Robot Software
0.19.1
Flight software for the Astrobee robots operating inside the International Space Station.
|
Go to the documentation of this file.
19 #ifndef LOCALIZATION_COMMON_UTILITIES_H_
20 #define LOCALIZATION_COMMON_UTILITIES_H_
23 #include <ff_msgs/CombinedNavState.h>
24 #include <ff_msgs/GraphVIOState.h>
25 #include <ff_msgs/VisualLandmarks.h>
32 #include <gtsam/geometry/Cal3_S2.h>
33 #include <gtsam/geometry/Pose3.h>
34 #include <gtsam/linear/NoiseModel.h>
35 #include <gtsam/nonlinear/NonlinearFactorGraph.h>
39 #include <geometry_msgs/Pose.h>
40 #include <geometry_msgs/PoseStamped.h>
41 #include <geometry_msgs/TransformStamped.h>
42 #include <std_msgs/Header.h>
50 const std::string& prefix =
"");
53 const std::string& prefix =
"");
56 const std::string& intrinsics_config_name,
const std::string& prefix =
"");
59 const std::string& prefix =
"");
75 void SetEnvironmentConfigs(
const std::string& world =
"iss",
const std::string& robot_config_file =
"bumble.config");
87 gtsam::Pose3
PoseFromMsg(
const geometry_msgs::PoseStamped& msg);
89 gtsam::Pose3
PoseFromMsg(
const geometry_msgs::Pose& msg_pose);
91 void PoseToMsg(
const gtsam::Pose3& pose, geometry_msgs::Pose& msg_pose);
94 const std::string& child_frame,
const Time timestamp,
95 const std::string& platform_name =
"");
97 geometry_msgs::TransformStamped
PoseToTF(
const gtsam::Pose3& pose,
const std::string& parent_frame,
98 const std::string& child_frame,
const Time timestamp,
99 const std::string& platform_name =
"");
109 const gtsam::Pose3& body_T_imu,
110 const gtsam::Pose3& global_T_body,
111 const gtsam::Vector3& uncorrected_accelerometer_measurement);
115 const Eigen::Matrix3d& velocity_covariance,
116 const Eigen::Matrix<double, 6, 6>& imu_bias_covariance,
117 const TimestampedSet<PoseCovariance>& correlation_covariances = {});
119 template <
class LocMsgType>
122 template <
class LocMsgType>
125 template <
typename MatrixType>
129 const double position_covariance_threshold = 0,
130 const double orientation_covariance_threshold = 0,
131 const bool check_position_covariance =
true,
const bool check_orientation_covariance =
true);
133 template <
typename RotationType>
136 double Deg2Rad(
const double degrees);
138 double Rad2Deg(
const double radians);
149 const boost::optional<PoseCovariance> covariance_a_b = boost::none);
154 const Eigen::Matrix<double, 6, 6>& a_F_relative_pose_covariance,
const Eigen::Isometry3d& b_T_a);
161 template <
int CostDim,
int StateDim>
163 const std::vector<Eigen::Matrix<double, CostDim, StateDim>>& cost_jacobians);
165 template <
typename T>
168 template <
typename T>
169 std::vector<T>
Rotate(
const std::vector<T>& a_F_a_T_elements,
const Eigen::Matrix3d& b_R_a);
172 const std::vector<Eigen::Vector3d>& points,
const std::vector<Eigen::Vector3d>& normals,
178 PoseWithCovariance
Interpolate(
const PoseWithCovariance& lower_bound_pose,
const PoseWithCovariance& upper_bound_pose,
181 gtsam::noiseModel::Robust::shared_ptr
Robust(
const gtsam::SharedNoiseModel& noise,
const double huber_k);
183 template <
typename FactorType>
186 template <
typename FactorType>
187 int NumFactors(
const gtsam::NonlinearFactorGraph& graph);
189 template <
typename FactorType>
190 std::vector<const FactorType*>
Factors(
const gtsam::NonlinearFactorGraph& graph);
193 template <
class LocMsgType>
202 template <
class LocMsgType>
220 template <
typename MatrixType>
222 return std::log10(matrix.determinant());
225 template <
typename RotationType>
228 pose.translation() = translation;
229 pose.linear() = Eigen::Quaterniond(rotation).toRotationMatrix();
233 template <
int CostDim,
int StateDim>
235 const std::vector<Eigen::Matrix<double, CostDim, StateDim>>& cost_jacobians) {
236 const int num_costs = cost_jacobians.size();
237 Eigen::MatrixXd stacked_jacobians(num_costs * CostDim, StateDim);
239 for (
const auto& jacobian : cost_jacobians) {
240 stacked_jacobians.block(row_index, 0, CostDim, StateDim) = jacobian;
241 row_index += CostDim;
243 const Eigen::Matrix<double, 6, 6> hessian = stacked_jacobians.transpose() * stacked_jacobians;
244 const Eigen::FullPivLU<Eigen::Matrix<double, StateDim, StateDim>> lu(hessian);
245 if (!lu.isInvertible())
return boost::none;
247 const Eigen::Matrix<double, 6, 6> covariance = lu.inverse();
251 template <
typename T>
253 std::vector<T> b_T_elements;
254 for (
const auto& a_T_element : a_T_elements) {
255 b_T_elements.emplace_back(b_T_a * a_T_element);
260 template <
typename T>
261 std::vector<T>
Rotate(
const std::vector<T>& a_F_a_T_elements,
const Eigen::Matrix3d& b_R_a) {
262 std::vector<T> b_F_a_T_elements;
263 for (
const auto& a_F_a_T_element : a_F_a_T_elements) {
264 b_F_a_T_elements.emplace_back(b_R_a * a_F_a_T_element);
266 return b_F_a_T_elements;
269 template <
typename FactorType>
271 int num_removed_factors = 0;
272 for (
auto factor_it = graph.begin(); factor_it != graph.end();) {
273 if (
dynamic_cast<FactorType*
>(factor_it->get())) {
274 factor_it = graph.erase(factor_it);
275 ++num_removed_factors;
282 template <
typename FactorType>
285 for (
const auto& factor : graph) {
286 if (
dynamic_cast<const FactorType*
>(factor.get())) {
293 template <
typename FactorType>
294 std::vector<const FactorType*>
Factors(
const gtsam::NonlinearFactorGraph& graph) {
295 std::vector<const FactorType*> factors;
296 for (
const auto& factor : graph) {
297 const FactorType* casted_factor =
dynamic_cast<const FactorType*
>(factor.get());
299 factors.emplace_back(casted_factor);
306 #endif // LOCALIZATION_COMMON_UTILITIES_H_
Definition: averager.h:33
double Rad2Deg(const double radians)
Definition: utilities.cc:212
Time TimeFromRosTime(const ros::Time &time)
Definition: utilities.cc:111
Eigen::Vector3d velocity_variances() const
Definition: combined_nav_state_covariances.h:48
CombinedNavState CombinedNavStateFromMsg(const ff_msgs::CombinedNavState &msg)
Definition: utilities.cc:147
void DeleteFactors(gtsam::NonlinearFactorGraph &graph)
Definition: utilities.h:270
gtsam::Pose3 PoseFromMsg(const geometry_msgs::PoseStamped &msg)
Definition: utilities.cc:117
std::pair< std::vector< Eigen::Vector3d >, std::vector< Eigen::Vector3d > > TransformPointsWithNormals(const std::vector< Eigen::Vector3d > &points, const std::vector< Eigen::Vector3d > &normals, const Eigen::Isometry3d &b_T_a)
Definition: utilities.cc:305
Definition: combined_nav_state.h:48
Time timestamp() const
Definition: combined_nav_state.h:54
Eigen::Matrix3d RotationFromEulerAngles(const double yaw, const double pitch, const double roll)
Definition: utilities.cc:222
boost::optional< Eigen::Matrix< double, StateDim, StateDim > > LeastSquaresCovariance(const std::vector< Eigen::Matrix< double, CostDim, StateDim >> &cost_jacobians)
Definition: utilities.h:234
void SetEnvironmentConfigs(const std::string &world="iss", const std::string &robot_config_file="bumble.config")
Definition: utilities.cc:98
Eigen::Vector3d CylindricalToCartesian(const Eigen::Vector3d &cylindrical_coordinates)
Definition: utilities.cc:214
void LoadGraphVIOConfig(config_reader::ConfigReader &config, const std::string &path_prefix="")
Definition: utilities.cc:85
std::vector< T > Rotate(const std::vector< T > &a_F_a_T_elements, const Eigen::Matrix3d &b_R_a)
Definition: utilities.h:261
ff_msgs::CombinedNavState CombinedNavStateToMsg(const CombinedNavState &combined_nav_state, const PoseCovariance &pose_covariance, const Eigen::Matrix3d &velocity_covariance, const Eigen::Matrix< double, 6, 6 > &imu_bias_covariance, const TimestampedSet< PoseCovariance > &correlation_covariances={})
Definition: utilities.cc:182
Eigen::Isometry3d Isometry3d(const cv::Mat &rodrigues_rotation_cv, const cv::Mat &translation_cv)
Definition: utilities.cc:58
Eigen::Isometry3d EigenPose(const CombinedNavState &combined_nav_state)
Definition: utilities.cc:64
double Deg2Rad(const double degrees)
Definition: utilities.cc:210
gtsam::Vector3 RemoveGravityFromAccelerometerMeasurement(const gtsam::Vector3 &global_F_gravity, const gtsam::Pose3 &body_T_imu, const gtsam::Pose3 &global_T_body, const gtsam::Vector3 &uncorrected_accelerometer_measurement)
Definition: utilities.cc:172
double LogDeterminant(const MatrixType &matrix)
Definition: utilities.h:221
gtsam::Pose3 PoseFromMsgWithExtrinsics(const geometry_msgs::Pose &pose, const gtsam::Pose3 &sensor_T_body)
Definition: utilities.cc:68
Eigen::Matrix< double, 6, 6 > PoseCovariance
Definition: pose_with_covariance.h:27
geometry_msgs::TransformStamped PoseToTF(const Eigen::Isometry3d &pose, const std::string &parent_frame, const std::string &child_frame, const Time timestamp, const std::string &platform_name="")
Definition: utilities.cc:136
void CombinedNavStateCovariancesToLocMsg(const CombinedNavStateCovariances &covariances, LocMsgType &loc_msg)
Definition: utilities.h:203
Eigen::Vector3d gyro_bias_variances() const
Definition: combined_nav_state_covariances.h:49
Eigen::Isometry3d Isometry3d(const Eigen::Vector3d &translation, const RotationType &rotation)
Definition: utilities.h:226
void PoseToMsg(const gtsam::Pose3 &pose, geometry_msgs::Pose &msg_pose)
Definition: utilities.cc:124
std::vector< T > Transform(const std::vector< T > &a_T_elements, const Eigen::Isometry3d &b_T_a)
Definition: utilities.h:252
double PoseCovarianceSane(const Eigen::Matrix< double, 6, 6 > &pose_covariance, const double position_covariance_threshold=0, const double orientation_covariance_threshold=0, const bool check_position_covariance=true, const bool check_orientation_covariance=true)
Definition: utilities.cc:288
CombinedNavStateCovariances CombinedNavStateCovariancesFromMsg(const ff_msgs::CombinedNavState &msg)
Definition: utilities.cc:156
void VectorToMsg(const VectorType &vector, MsgVectorType &msg_vector)
Definition: msg_conversions.h:137
Eigen::Vector3d Vector3d(const PointType &point)
Definition: utilities.h:328
const gtsam::Velocity3 & velocity() const
Definition: combined_nav_state.h:57
void LoadGraphLocalizerConfig(config_reader::ConfigReader &config, const std::string &path_prefix="")
Definition: utilities.cc:74
PoseWithCovariance InvertPoseWithCovariance(const PoseWithCovariance &pose_with_covariance)
Definition: utilities.cc:280
gtsam::Cal3_S2 LoadCameraIntrinsics(config_reader::ConfigReader &config, const std::string &intrinsics_config_name, const std::string &prefix="")
Definition: utilities.cc:53
PoseWithCovariance FrameChangeRelativePoseWithCovariance(const PoseWithCovariance &a_F_relative_pose_with_covariance, const Eigen::Isometry3d &b_T_a)
Definition: utilities.cc:271
Eigen::Vector3d accel_bias_variances() const
Definition: combined_nav_state_covariances.h:50
Eigen::Isometry3d FrameChangeRelativePose(const Eigen::Isometry3d &a_F_relative_pose, const Eigen::Isometry3d &b_T_a)
Definition: utilities.cc:258
Time TimeFromHeader(const std_msgs::Header &header)
Definition: utilities.cc:109
Definition: config_reader.h:48
gtsam::Pose3 LoadTransform(config_reader::ConfigReader &config, const std::string &transform_config_name, const std::string &prefix="")
Definition: utilities.cc:34
const gtsam::imuBias::ConstantBias & bias() const
Definition: combined_nav_state.h:58
void TimeToMsg(const Time timestamp, ros::Time &time_msg)
Definition: utilities.cc:115
Eigen::Isometry3d Interpolate(const Eigen::Isometry3d &lower_bound_pose, const Eigen::Isometry3d &upper_bound_pose, const double alpha)
Definition: utilities.cc:313
Eigen::Matrix< double, 6, 6 > FrameChangeRelativeCovariance(const Eigen::Matrix< double, 6, 6 > &a_F_relative_pose_covariance, const Eigen::Isometry3d &b_T_a)
Definition: utilities.cc:265
PoseCovariance RelativePoseCovariance(const PoseWithCovariance &a, const PoseWithCovariance &b, const boost::optional< PoseCovariance > covariance_a_b=boost::none)
Definition: utilities.cc:233
gtsam::Vector3 LoadVector3(config_reader::ConfigReader &config, const std::string &config_name, const std::string &prefix="")
Definition: utilities.cc:40
gtsam::Pose3 pose() const
Definition: combined_nav_state.h:56
gtsam::Pose3 GtPose(const Eigen::Isometry3d &eigen_pose)
Definition: utilities.cc:60
ros::Time RosTimeFromHeader(const std_msgs::Header &header)
Definition: utilities.cc:107
int NumFactors(const gtsam::NonlinearFactorGraph &graph)
Definition: utilities.h:283
Definition: combined_nav_state_covariances.h:27
void CombinedNavStateToLocMsg(const CombinedNavState &combined_nav_state, LocMsgType &loc_msg)
Definition: utilities.h:194
void TimeToHeader(const Time timestamp, std_msgs::Header &header)
Definition: utilities.cc:113
gtsam::noiseModel::Robust::shared_ptr Robust(const gtsam::SharedNoiseModel &noise, const double huber_k)
Definition: utilities.cc:334
Eigen::Vector3d position_variances() const
Definition: combined_nav_state_covariances.h:46
Eigen::Vector3d orientation_variances() const
Definition: combined_nav_state_covariances.h:47
double Time
Definition: time.h:23
std::vector< const FactorType * > Factors(const gtsam::NonlinearFactorGraph &graph)
Definition: utilities.h:294
TimestampedSet< PoseCovariance > CorrelationCovariancesFromMsg(const ff_msgs::CombinedNavState &msg)
Definition: utilities.cc:163
void VariancesToCovDiag(const Eigen::Vector3d &variances, float *const cov_diag)
Definition: msg_conversions.cc:388
Eigen::Matrix3d LoadCameraIntrinsicsMatrix(config_reader::ConfigReader &config, const std::string &intrinsics_config_name, const std::string &prefix="")
Definition: utilities.cc:47