| 165 | } |
| 166 | |
| 167 | void Odometry::publish(const rclcpp::Time & now) |
| 168 | { |
| 169 | auto odom_msg = std::make_unique<nav_msgs::msg::Odometry>(); |
| 170 | |
| 171 | odom_msg->header.frame_id = frame_id_of_odometry_; |
| 172 | odom_msg->child_frame_id = child_frame_id_of_odometry_; |
| 173 | odom_msg->header.stamp = now; |
| 174 | |
| 175 | odom_msg->pose.pose.position.x = robot_pose_[0]; |
| 176 | odom_msg->pose.pose.position.y = robot_pose_[1]; |
| 177 | odom_msg->pose.pose.position.z = 0; |
| 178 | |
| 179 | tf2::Quaternion q; |
| 180 | q.setRPY(0.0, 0.0, robot_pose_[2]); |
| 181 | |
| 182 | odom_msg->pose.pose.orientation.x = q.x(); |
| 183 | odom_msg->pose.pose.orientation.y = q.y(); |
| 184 | odom_msg->pose.pose.orientation.z = q.z(); |
| 185 | odom_msg->pose.pose.orientation.w = q.w(); |
| 186 | |
| 187 | odom_msg->twist.twist.linear.x = robot_vel_[0]; |
| 188 | odom_msg->twist.twist.angular.z = robot_vel_[2]; |
| 189 | |
| 190 | // TODO(Will Son): Find more accurate covariance. |
| 191 | // odom_msg->pose.covariance[0] = 0.05; |
| 192 | // odom_msg->pose.covariance[7] = 0.05; |
| 193 | // odom_msg->pose.covariance[14] = 1.0e-9; |
| 194 | // odom_msg->pose.covariance[21] = 1.0e-9; |
| 195 | // odom_msg->pose.covariance[28] = 1.0e-9; |
| 196 | // odom_msg->pose.covariance[35] = 0.0872665; |
| 197 | |
| 198 | // odom_msg->twist.covariance[0] = 0.001; |
| 199 | // odom_msg->twist.covariance[7] = 1.0e-9; |
| 200 | // odom_msg->twist.covariance[14] = 1.0e-9; |
| 201 | // odom_msg->twist.covariance[21] = 1.0e-9; |
| 202 | // odom_msg->twist.covariance[28] = 1.0e-9; |
| 203 | // odom_msg->twist.covariance[35] = 0.001; |
| 204 | |
| 205 | geometry_msgs::msg::TransformStamped odom_tf; |
| 206 | |
| 207 | odom_tf.transform.translation.x = odom_msg->pose.pose.position.x; |
| 208 | odom_tf.transform.translation.y = odom_msg->pose.pose.position.y; |
| 209 | odom_tf.transform.translation.z = odom_msg->pose.pose.position.z; |
| 210 | odom_tf.transform.rotation = odom_msg->pose.pose.orientation; |
| 211 | |
| 212 | odom_tf.header.frame_id = frame_id_of_odometry_; |
| 213 | odom_tf.child_frame_id = child_frame_id_of_odometry_; |
| 214 | odom_tf.header.stamp = now; |
| 215 | |
| 216 | odom_pub_->publish(std::move(odom_msg)); |
| 217 | |
| 218 | if (publish_tf_) { |
| 219 | tf_broadcaster_->sendTransform(odom_tf); |
| 220 | } |
| 221 | } |
| 222 | |
| 223 | void Odometry::update_joint_state( |
| 224 | const std::shared_ptr<sensor_msgs::msg::JointState const> & joint_state) |
no outgoing calls
no test coverage detected