.. _program_listing_file__tmp_ws_src_robot_state_publisher_include_robot_state_publisher_robot_state_publisher.hpp: Program Listing for File robot_state_publisher.hpp ================================================== |exhale_lsh| :ref:`Return to documentation for file ` (``/tmp/ws/src/robot_state_publisher/include/robot_state_publisher/robot_state_publisher.hpp``) .. |exhale_lsh| unicode:: U+021B0 .. UPWARDS ARROW WITH TIP LEFTWARDS .. code-block:: cpp // Copyright (c) 2008, Willow Garage, Inc. // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are met: // // * Redistributions of source code must retain the above copyright // notice, this list of conditions and the following disclaimer. // // * Redistributions in binary form must reproduce the above copyright // notice, this list of conditions and the following disclaimer in the // documentation and/or other materials provided with the distribution. // // * Neither the name of the Willow Garage nor the names of its // contributors may be used to endorse or promote products derived from // this software without specific prior written permission. // // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE // ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE // LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE // POSSIBILITY OF SUCH DAMAGE. /* Author: Wim Meeussen */ #ifndef ROBOT_STATE_PUBLISHER__ROBOT_STATE_PUBLISHER_HPP_ #define ROBOT_STATE_PUBLISHER__ROBOT_STATE_PUBLISHER_HPP_ #include #include #include #include #include "builtin_interfaces/msg/time.hpp" #include "kdl/tree.hpp" #include "rcl_interfaces/msg/parameter_event.hpp" #include "rcl_interfaces/msg/set_parameters_result.hpp" #include "rclcpp/rclcpp.hpp" #include "sensor_msgs/msg/joint_state.hpp" #include "std_msgs/msg/string.hpp" #include "tf2_ros/static_transform_broadcaster.h" #include "tf2_ros/transform_broadcaster.h" #include "urdf/model.h" using MimicMap = std::map; namespace robot_state_publisher { class SegmentPair final { public: explicit SegmentPair( const KDL::Segment & p_segment, const std::string & p_root, const std::string & p_tip) : segment(p_segment), root(p_root), tip(p_tip) {} KDL::Segment segment; std::string root; std::string tip; }; class RobotStatePublisher : public rclcpp::Node { public: explicit RobotStatePublisher(const rclcpp::NodeOptions & options); protected: KDL::Tree parseURDF(const std::string & urdf_xml, urdf::Model & model); void setupURDF(const std::string & urdf_xml); void addChildren( const urdf::Model & model, const KDL::SegmentMap::const_iterator segment); void publishTransforms( const std::map & joint_positions, const builtin_interfaces::msg::Time & time); void publishFixedTransforms(); void callbackJointState(const sensor_msgs::msg::JointState::ConstSharedPtr state); rcl_interfaces::msg::SetParametersResult parameterUpdate( const std::vector & parameters); void onParameterEvent(std::shared_ptr event); std::map segments_; std::map segments_fixed_; std::unique_ptr tf_broadcaster_; std::unique_ptr static_tf_broadcaster_; rclcpp::Publisher::SharedPtr description_pub_; rclcpp::Subscription::SharedPtr joint_state_sub_; rclcpp::Time last_callback_time_; std::map last_publish_time_; MimicMap mimic_; rclcpp::node_interfaces::OnSetParametersCallbackHandle::SharedPtr param_cb_; std::shared_ptr>> parameter_subscription_; }; } // namespace robot_state_publisher #endif // ROBOT_STATE_PUBLISHER__ROBOT_STATE_PUBLISHER_HPP_