6 geometry_msgs::msg::Pose msg;
7 msg.position.x = pose.x();
8 msg.position.y = pose.y();
9 msg.position.z = pose.z();
10 auto rotation = pose.rotation().quaternion();
11 msg.orientation.w = rotation[0];
12 msg.orientation.x = rotation[1];
13 msg.orientation.y = rotation[2];
14 msg.orientation.z = rotation[3];
18 geometry_msgs::msg::Transform
20 geometry_msgs::msg::Transform msg;
21 msg.translation.x = pose.x();
22 msg.translation.y = pose.y();
23 msg.translation.z = pose.z();
25 auto rotation = pose.rotation().quaternion();
26 msg.rotation.w = rotation[0];
27 msg.rotation.x = rotation[1];
28 msg.rotation.y = rotation[2];
29 msg.rotation.z = rotation[3];
34 std::vector<cslam_common_interfaces::msg::PoseGraphValue>
36 std::vector<cslam_common_interfaces::msg::PoseGraphValue> poses;
37 for (
const auto key_value : values) {
38 auto p =
dynamic_cast<const gtsam::GenericValue<gtsam::Pose3> *
>(
42 cslam_common_interfaces::msg::PoseGraphValue pose_msg;
44 auto key = gtsam::LabeledSymbol(key_value.key);
45 pose_msg.key.robot_id =
ROBOT_ID(key.label());
46 pose_msg.key.keyframe_id = key.index();
48 poses.emplace_back(pose_msg);
53 std::vector<cslam_common_interfaces::msg::PoseGraphValue>
58 std::vector<cslam_common_interfaces::msg::PoseGraphEdge>
60 std::vector<cslam_common_interfaces::msg::PoseGraphEdge> edges;
61 for (
const auto &factor_ : factors) {
63 boost::dynamic_pointer_cast<gtsam::BetweenFactor<gtsam::Pose3>>(
66 cslam_common_interfaces::msg::PoseGraphEdge edge_msg;
68 auto key_from = gtsam::LabeledSymbol(factor->key1());
69 auto key_to = gtsam::LabeledSymbol(factor->key2());
70 edge_msg.key_from.robot_id =
ROBOT_ID(key_from.label());
71 edge_msg.key_from.keyframe_id = key_from.index();
72 edge_msg.key_to.robot_id =
ROBOT_ID(key_to.label());
73 edge_msg.key_to.keyframe_id = key_to.index();
77 gtsam::SharedNoiseModel model = factor->noiseModel();
79 boost::dynamic_pointer_cast<gtsam::noiseModel::Diagonal>(model);
80 auto sigmas = noise->sigmas();
81 for (
unsigned int i = 0; i < 6; i++) {
82 edge_msg.noise_std[i] = sigmas[i];
85 edges.emplace_back(edge_msg);
91 std::vector<cslam_common_interfaces::msg::PoseGraphEdge>
97 gtsam::Rot3 rotation(msg.rotation.w, msg.rotation.x, msg.rotation.y,
100 rotation, {msg.translation.x, msg.translation.y, msg.translation.z});
104 gtsam::Rot3 rotation(pose.orientation.w, pose.orientation.x,
105 pose.orientation.y, pose.orientation.z);
106 return gtsam::Pose3(rotation,
107 {pose.position.x, pose.position.y, pose.position.z});
115 const std::vector<cslam_common_interfaces::msg::PoseGraphValue> &msg) {
116 auto values = boost::make_shared<gtsam::Values>();
121 values->insert(symbol, pose);
127 const std::vector<cslam_common_interfaces::msg::PoseGraphEdge> &msg) {
128 auto graph = boost::make_shared<gtsam::NonlinearFactorGraph>();
131 gtsam::LabeledSymbol symbol_from(
134 e.key_to.keyframe_id);
136 Eigen::VectorXd sigmas(6);
137 sigmas << e.noise_std[0], e.noise_std[1], e.noise_std[2], e.noise_std[3],
138 e.noise_std[4], e.noise_std[5];
139 auto noise_model = gtsam::noiseModel::Diagonal::Sigmas(sigmas);
141 gtsam::BetweenFactor<gtsam::Pose3> factor(symbol_from, symbol_to, pose,
143 graph->push_back(factor);
gtsam::NonlinearFactorGraph::shared_ptr edges_msg_to_gtsam(const std::vector< cslam_common_interfaces::msg::PoseGraphEdge > &edges)
Converts from ROS 2 message to GTSAM.
gtsam::Pose3 odometry_msg_to_pose3(const nav_msgs::msg::Odometry &odom_msg)
Converts odometry message to gtsam::Pose3.
std::vector< cslam_common_interfaces::msg::PoseGraphValue > gtsam_values_to_msg(const gtsam::Values::shared_ptr values)
Converts from GTSAM to ROS 2 message.
gtsam::Pose3 pose_msg_to_gtsam(const geometry_msgs::msg::Pose &pose)
Converts from ROS 2 message to GTSAM.
gtsam::Values::shared_ptr values_msg_to_gtsam(const std::vector< cslam_common_interfaces::msg::PoseGraphValue > &values)
Converts from ROS 2 message to GTSAM.
gtsam::Pose3 transform_msg_to_pose3(const geometry_msgs::msg::Transform &msg)
Converts a transform msg into a gtsam::Pose3.
geometry_msgs::msg::Pose gtsam_pose_to_msg(const gtsam::Pose3 &pose)
Converts from GTSAM to ROS 2 message.
std::vector< cslam_common_interfaces::msg::PoseGraphEdge > gtsam_factors_to_msg(const gtsam::NonlinearFactorGraph::shared_ptr factors)
Converts from GTSAM to ROS 2 message.
geometry_msgs::msg::Transform gtsam_pose_to_transform_msg(const gtsam::Pose3 &pose)
Converts from GTSAM to ROS 2 message.