#include <geometry_msgs/msg/transform_stamped.hpp>
#include "geometry_msgs/msg/twist.hpp"
#include "nav_msgs/msg/odometry.hpp"
#include <rclcpp/rclcpp.hpp>
#include <tf2/LinearMath/Quaternion.h>
#include <tf2_ros/transform_broadcaster.h>
#include <memory>
#include <string>
#include <geometry_msgs/msg/transform_stamped.hpp>
#include <rclcpp/rclcpp.hpp>
#include <tf2/LinearMath/Quaternion.h>
#include <tf2_ros/transform_broadcaster.h>
#include <turtlesim/msg/pose.hpp>
#include <memory>
#include <string>
#include <chrono>
#include <functional>
#include <memory>
#include <string>
#include "rclcpp/rclcpp.hpp"
#include "std_msgs/msg/string.hpp"
using std::placeholders::_1;
class OdomPublisher:public rclcpp ::Node
{
rclcpp::Subscription<geometry_msgs::msg::Twist>::SharedPtr subscription_;
rclcpp::Publisher<nav_msgs::msg::Odometry>::SharedPtr odom_publisher_;
std::unique_ptr<tf2_ros::TransformBroadcaster> tf_broadcaster_;
double linear_scale_x_ = 0.0 ;
double linear_scale_y_ = 0.0;
double vel_dt_ = 0.0;
double x_pos_ = 0.0;
double y_pos_ = 0.0;
double heading_ = 0.0;
double linear_velocity_x_ = 0.0;
double linear_velocity_y_ = 0.0;
double angular_velocity_z_ = 0.0;
double wheelbase_ = 0.25;
bool pub_odom_tf_ = false;
rclcpp::Time last_vel_time_ ;
public:
OdomPublisher()
: Node("base_node")
{
this->declare_parameter<double>("wheelbase",0.25);
this->declare_parameter<std::string>("odom_frame","odom");
this->declare_parameter<std::string>("base_footprint_frame","base_footprint");
this->declare_parameter<double>("linear_scale_x",1.0);
this->declare_parameter<double>("linear_scale_y",1.0);
this->declare_parameter<bool>("pub_odom_tf",true);
this->get_parameter<double>("linear_scale_x",linear_scale_x_);
ROS2代码阅读笔记1-发布里程计消息和广播相应的 TF 变换
最新推荐文章于 2024-12-13 13:18:31 发布