void common_pack::debug_show_result(const std::vector<autoware_msgs::Waypoint> &path_array, ros::Publisher pub) { if (path_array.size() <= 0) return; visualization_msgs::MarkerArray static_path; for (int i = 0; i < path_array.size(); i++) { visualization_msgs::Marker arrow; arrow.header.frame_id = "map"; // arrow.header.stamp = ros::Time::now(); arrow.id = i + 1; arrow.type = visualization_msgs::Marker::ARROW; arrow.action = visualization_msgs::Marker::ADD; arrow.scale.x = 0.3; arrow.scale.y = 0.15; arrow.scale.z = 0.05; arrow.color.r = 0; arrow.color.g = 0; arrow.color.b = 1; arrow.color.a = 1; arrow.pose = path_array[i].pose.pose; static_path.markers.push_back(arrow); } // ros::Duration(3.0).sleep(); pub.publish(static_path); }这段代码有什么问题,为什么rviz上不显示
时间: 2024-02-28 17:52:54 浏览: 21
这段代码本身没有明显的问题,但是在rviz上不显示可能是因为没有正确设置Marker的lifetime属性。在没有设置lifetime的情况下,Marker默认的生命周期为0,即只显示一帧就消失了。你可以尝试添加以下代码来设置lifetime属性:
```arrow.lifetime = ros::Duration(0.1);```
此外,还需要确保在调用debug_show_result函数时,已经创建了正确的ros节点以及正确的topic和message类型,并且rviz已经正确配置了Marker的显示。
相关问题
没有与这些操作数匹配的 "=" 运算符C/C++(349) listener_str.cpp(12, 23): 操作数类型为: std::shared_ptr<rclcpp::Subscription<std_msgs::msg::String, std::allocator<void>, rclcpp::message_memory_strategy::MessageMemoryStrategy<std_msgs::msg::String, std::allocator<void>>>> = std::shared_ptr<rclcpp::Subscription<const std::shared_ptr<std_msgs::msg::String_<std::allocator<void>>> &, std::allocator<void>, rclcpp::message_memory_strategy::MessageMemoryStrategy<const std::shared_ptr<std_msgs::msg::String_<std::allocator<void>>> &, std::allocator<void>>>>
这个错误通常是因为尝试将一个类型为`std::shared_ptr<rclcpp::Subscription<const std::shared_ptr<std_msgs::msg::String_<std::allocator<void>>> &, std::allocator<void>, rclcpp::message_memory_strategy::MessageMemoryStrategy<const std::shared_ptr<std_msgs::msg::String_<std::allocator<void>>> &, std::allocator<void>>>>`的变量赋值给一个类型为`std::shared_ptr<rclcpp::Subscription<std_msgs::msg::String, std::allocator<void>, rclcpp::message_memory_strategy::MessageMemoryStrategy<std_msgs::msg::String, std::allocator<void>>>>`的变量,这两个类型虽然都是指向`rclcpp::Subscription`的`shared_ptr`,但是模板参数不同,无法直接赋值。
解决方法是将两个类型匹配,可以通过使用`std::static_pointer_cast`将其中一个类型转换成另一个类型,例如:
```
std::shared_ptr<rclcpp::Subscription<std_msgs::msg::String, std::allocator<void>, rclcpp::message_memory_strategy::MessageMemoryStrategy<std_msgs::msg::String, std::allocator<void>>>> sub;
std::shared_ptr<rclcpp::Subscription<const std::shared_ptr<std_msgs::msg::String_<std::allocator<void>>> &, std::allocator<void>, rclcpp::message_memory_strategy::MessageMemoryStrategy<const std::shared_ptr<std_msgs::msg::String_<std::allocator<void>>> &, std::allocator<void>>>> sub_const;
// 将 sub_const 转换成 sub 的类型
sub = std::static_pointer_cast<rclcpp::Subscription<std_msgs::msg::String, std::allocator<void>, rclcpp::message_memory_strategy::MessageMemoryStrategy<std_msgs::msg::String, std::allocator<void>>>>(sub_const);
```
void checkIntersections(const autoware_msgs::Lane& path_)这个函数会改变传入的path吗
根据函数的声明 `void checkIntersections(const autoware_msgs::Lane& path_)`,可以看出该函数接受一个 `autoware_msgs::Lane` 类型的常量引用参数 `path_`。
由于参数是常量引用,意味着函数内部不能对参数进行修改。
因此,即使在 `checkIntersections` 函数内部对 `path_` 进行操作,传入的 `path` 不会被改变。这样的设计可以确保函数不会无意间修改传入的参数。