@@ -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