RVIZ2 - PointCloud2 - No tf data
Hello,
I have a very simple ROS2 node which is periodically publishing PointCloud2 messages. Now I want to show them in RVIZ2. After adding a PointCloud2 with Topic value "rtp" and changing the Fixed Frame value from "map" to "rtframe" the points are displayed, but I still get the warning message **"No tf data. Actual error: Frame [rtframe] does not exist"**. Why? What causes this warning? How to fix it?
Furthermore, if I leave the Fixed Frame value at "map" I get the error message "Could not Transform from [rt_frame] to [map]".If I then try to manually add a TF object in RVIZ2 to define the transformation from "rt_frame" to "map" I cannot select any frames. Why can't I define a transformation in RVIZ2?
ROS2 node:
#include <math.h>
#include <stdio.h>
#include <stdint.h>
#include <chrono>
#include <rclcpp/rclcpp.hpp>
#include <rclcpp/time.hpp>
#include "std_msgs/msg/header.hpp"
#include "sensor_msgs/msg/point_cloud2.hpp"
#include "sensor_msgs/point_cloud2_iterator.hpp"
#include "sensor_msgs/msg/point_field.hpp"
class RTN : public rclcpp::Node
{
public:
RTN()
: Node("RTN"), mCount(0)
{
mPublisher = this->create_publisher<sensor_msgs::msg::PointCloud2>("rtp", 1024);
mTimer = this->create_wall_timer(std::chrono::milliseconds(500), std::bind(&RTN::timer_callback, this));
}
private:
void timer_callback()
{
auto lPC = sensor_msgs::msg::PointCloud2();
lPC.header.stamp = this->now();
lPC.header.frame_id = "rt_frame";
lPC.width=1;
lPC.height=1;
auto lPCM = sensor_msgs::PointCloud2Modifier(lPC);
lPCM.setPointCloud2Fields(3, "x", 1, sensor_msgs::msg::PointField::FLOAT32, "y", 1, sensor_msgs::msg::PointField::FLOAT32, "z", 1, sensor_msgs::msg::PointField::FLOAT32);
lPCM.resize(2);
auto lXItr = sensor_msgs::PointCloud2Iterator<float>(lPC, "x");
auto lYItr = sensor_msgs::PointCloud2Iterator<float>(lPC, "y");
auto lZItr = sensor_msgs::PointCloud2Iterator<float>(lPC, "z");
*lXItr = 0;
*lYItr = 0;
*lZItr = 0;
++lXItr; ++lYItr; ++lZItr;
*lXItr = cosf(3.141f * 2 * 0.1f * (float)mCount);
*lYItr = sinf(3.141f * 2 * 0.1f * (float)mCount);
*lZItr = 0;
++lXItr; ++lYItr; ++lZItr;
RCLCPP_INFO(this->get_logger(), "Publishing: '%i'", mCount++);
mPublisher->publish(lPC);
}
private:
rclcpp::TimerBase::SharedPtr mTimer;
rclcpp::Publisher<sensor_msgs::msg::PointCloud2>::SharedPtr mPublisher;
int mCount;
};
int main(int argc, char * argv[])
{
rclcpp::init(argc, argv);
rclcpp::spin(std::make_shared<RTN>());
rclcpp::shutdown();
return 0;
}
Asked by osccon on 2021-01-07 15:52:01 UTC
Comments
Hello! Did you find a solution for your problem? I'm having a similar one
Asked by Trebe on 2022-06-23 10:58:34 UTC