Skip to content

Commit 12c2040

Browse files
switch to vec of array
1 parent 09a7be4 commit 12c2040

2 files changed

Lines changed: 21 additions & 3 deletions

File tree

fuse_models/include/fuse_models/transform_sensor.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,7 @@ class TransformSensor : public fuse_core::AsyncSensorModel
144144
std::unique_ptr<tf2_ros::TransformListener> tf_listener_;
145145
std::set<std::string> fiducial_frames_;
146146
std::set<std::string> estimation_frames_;
147+
std::vector<std::array<double, 6>> pose_covariances_;
147148

148149
rclcpp::Subscription<MessageType>::SharedPtr sub_;
149150

fuse_models/src/transform_sensor.cpp

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,21 @@ void TransformSensor::onInit()
117117
estimation_frames_.insert(name);
118118
}
119119

120+
if (params_.pose_covariance.size() != 6 * estimation_frames_.size())
121+
{
122+
throw std::runtime_error("Must provide 6 `pose_covariance` values per estimation frame");
123+
}
124+
125+
for (std::size_t i = 0; i < estimation_frames_.size(); ++i)
126+
{
127+
pose_covariances_.emplace_back();
128+
auto& cur_entry = pose_covariances_.back();
129+
for (std::size_t j = 0; j < 6; ++j)
130+
{
131+
cur_entry[j] = params_.pose_covariance[(i * 6) + j];
132+
}
133+
}
134+
120135
tf_buffer_ = std::make_unique<tf2_ros::Buffer>(clock_);
121136
tf_listener_ = std::make_unique<tf2_ros::TransformListener>(*tf_buffer_, &interfaces_);
122137
}
@@ -145,7 +160,8 @@ void TransformSensor::process(MessageType const& msg)
145160

146161
std::string const& child_tf_name = transform.child_frame_id;
147162
bool const child_of_interest = fiducial_frames_.find(child_tf_name) != fiducial_frames_.end();
148-
bool const parent_of_interest = estimation_frames_.find(parent_tf_name) != estimation_frames_.end();
163+
auto const parent_it = estimation_frames_.find(parent_tf_name);
164+
bool const parent_of_interest = parent_it != estimation_frames_.end();
149165

150166
if (!child_of_interest)
151167
{
@@ -165,6 +181,7 @@ void TransformSensor::process(MessageType const& msg)
165181
continue;
166182
}
167183
}
184+
std::size_t estimation_index = std::distance(estimation_frames_.begin(), parent_it);
168185
RCLCPP_DEBUG(logger_, "Got transform of interest from %s to %s", transform.header.frame_id.c_str(),
169186
child_tf_name.c_str());
170187
// Create a transaction object
@@ -232,9 +249,9 @@ void TransformSensor::process(MessageType const& msg)
232249
pose.pose.pose.position.z = net_transform.getOrigin().z();
233250

234251
// TODO(henrygerardmoore): figure out better method to set the covariance
235-
for (std::size_t i = 0; i < params_.pose_covariance.size(); ++i)
252+
for (std::size_t i = 0; i < pose_covariances_[estimation_index].size(); ++i)
236253
{
237-
pose.pose.covariance[i * 7] = params_.pose_covariance[i];
254+
pose.pose.covariance[i * 7] = pose_covariances_[estimation_index][i];
238255
}
239256

240257
bool const validate = !params_.disable_checks;

0 commit comments

Comments
 (0)