19#include "yaml-cpp/yaml.h"
33 attr.set_channel_name(FLAGS_tf_static_topic);
34 attr.mutable_qos_profile()->CopyFrom(
41void StaticTransformComponent::SendTransforms() {
42 std::vector<TransformStamped> tranform_stamped_vec;
43 for (
auto& extrinsic_file : conf_.extrinsic_file()) {
44 if (extrinsic_file.enable()) {
45 AINFO <<
"Broadcast static transform, frame id ["
46 << extrinsic_file.frame_id() <<
"], child frame id ["
47 << extrinsic_file.child_frame_id() <<
"]";
49 if (ParseFromYaml(extrinsic_file.file_path(), &transform)) {
50 tranform_stamped_vec.emplace_back(transform);
54 SendTransform(tranform_stamped_vec);
57bool StaticTransformComponent::ParseFromYaml(
58 const std::string& file_path, TransformStamped* transform_stamped) {
60 AERROR <<
"Extrinsic yaml file does not exist: " << file_path;
63 YAML::Node tf = YAML::LoadFile(file_path);
65 transform_stamped->mutable_header()->set_frame_id(
66 tf[
"header"][
"frame_id"].as<std::string>());
67 transform_stamped->set_child_frame_id(
68 tf[
"child_frame_id"].as<std::string>());
71 transform_stamped->mutable_transform()->mutable_translation();
72 translation->set_x(tf[
"transform"][
"translation"][
"x"].as<double>());
73 translation->set_y(tf[
"transform"][
"translation"][
"y"].as<double>());
74 translation->set_z(tf[
"transform"][
"translation"][
"z"].as<double>());
76 auto rotation = transform_stamped->mutable_transform()->mutable_rotation();
77 rotation->set_qx(tf[
"transform"][
"rotation"][
"x"].as<double>());
78 rotation->set_qy(tf[
"transform"][
"rotation"][
"y"].as<double>());
79 rotation->set_qz(tf[
"transform"][
"rotation"][
"z"].as<double>());
80 rotation->set_qw(tf[
"transform"][
"rotation"][
"w"].as<double>());
82 AERROR <<
"Extrinsic yaml file parse failed: " << file_path;
88void StaticTransformComponent::SendTransform(
89 const std::vector<TransformStamped>& msgtf) {
90 for (
auto it_in = msgtf.begin(); it_in != msgtf.end(); ++it_in) {
91 bool match_found =
false;
92 for (
auto& it_msg : *transform_stampeds_.mutable_transforms()) {
93 if (it_in->child_frame_id() == it_msg.child_frame_id()) {
100 *transform_stampeds_.add_transforms() = *it_in;
104 common::util::FillHeader(
node_->Name(), &transform_stampeds_);
105 writer_->Write(transform_stampeds_);
bool GetProtoConfig(T *config) const
const std::string & ConfigFilePath() const
std::shared_ptr< Node > node_
static const QosProfile QOS_PROFILE_TF_STATIC
Some string util functions.
bool PathExists(const std::string &path)
Check if the path exists.