紧急通知:禁止一切关于政治&VPN翻墙等话题,发现相关帖子会立马删除封号
小鱼 ROS 2 新书上线!点击链接查看, 新书配套视频点击链接查看。
提问前必看的发帖注意事项—— 提问前必看!不符合要求的问题拒绝回答!!
社区使用指南—如何添加标签修改密码
小鱼 ROS 2 新书上线!点击链接查看, 新书配套视频点击链接查看。
提问前必看的发帖注意事项—— 提问前必看!不符合要求的问题拒绝回答!!
社区使用指南—如何添加标签修改密码
使用rviz2中的PointCloud打点Status:Error
-
原码如下:
#include "rclcpp/rclcpp.hpp" #include "std_msgs/msg/string.hpp" #include "std_msgs/msg/u_int32.hpp" #include "sensor_msgs/point_cloud_conversion.hpp" #include "sensor_msgs/point_cloud2_iterator.hpp" #include <chrono> #include <memory> using namespace std::chrono_literals; using namespace geometry_msgs; using std::placeholders::_1; using std::placeholders::_2; /* 创建一个类节点,名字叫做SingleDogNode,继承自Node. */ class SingleDogNode : public rclcpp::Node { public: // 构造函数,有一个参数为节点名称 SingleDogNode(std::string name) : Node(name) { publisher_ = this->create_publisher<sensor_msgs::msg::PointCloud>("multi_points", 10); timer_ = this->create_wall_timer(1s, std::bind(&SingleDogNode::timer_callback, this)); } private: rclcpp::TimerBase::SharedPtr timer_; sensor_msgs::msg::PointCloud point_data; rclcpp::Publisher<sensor_msgs::msg::PointCloud>::SharedPtr publisher_; char count_x = 0; char count_y = 0; void timer_callback() { geometry_msgs::msg::Point32 p; p.x = count_x; p.y = count_y; p.z = 0; point_data.points.push_back(p); publisher_->publish(point_data); count_x++; count_y++; } }; int main(int argc, char **argv) { rclcpp::init(argc, argv); /*产生一个Wang2的节点*/ auto node = std::make_shared<SingleDogNode>("li4"); /* 运行节点,并检测退出信号*/ rclcpp::spin(node); rclcpp::shutdown(); return 0; }
运行结果:
工程目录
请问是哪一块出问题了
-
@2235674044 看错误很简单,fixedframe为map的时候tf变换不到这个坐标系,所以你应该重新选一个fixedframe即可。
-
@小鱼 你好 这个怎么重新选一个fixedframe呢
-
@2235674044 在 使用rviz2中的PointCloud打点Status:Error 中说:
point_data
在你的程序,这个数据里应该可以给frame_id进行赋值,赋一个字符串,接着你在修改rviz2中第一栏frame_id保持和程序中的相同即可
-
@小鱼 请问ros2中怎么给话题的frame_id赋值呢
-
@2235674044 look
fishros@fishros-MS-7D42:~$ ros2 interface show sensor_msgs/msg/PointCloud ## THIS MESSAGE IS DEPRECATED AS OF FOXY ## Please use sensor_msgs/PointCloud2 # This message holds a collection of 3d points, plus optional additional # information about each point. # Time of sensor data acquisition, coordinate frame ID. std_msgs/Header header builtin_interfaces/Time stamp int32 sec uint32 nanosec string frame_id # Array of 3d points. Each Point32 should be interpreted as a 3d point # in the frame given in the header. geometry_msgs/Point32[] points # # float32 x float32 y float32 z # Each channel should have the same number of elements as points array, # and the data in each channel should correspond 1:1 with each point. # Channel names in common practice are listed in ChannelFloat32.msg. ChannelFloat32[] channels # string name float32[] values
so
rclcpp::TimerBase::SharedPtr timer_; sensor_msgs::msg::PointCloud point_data; point_data.header.frame_id = "你的frameid"; rclcpp::Publisher<sensor_msgs::msg::PointCloud>::SharedPtr publisher_; char count_x = 0; char count_y = 0;
-
@小鱼 解决了 感谢大佬
-
@2235674044 基操勿6