<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[如何删除rviz上单个marker]]></title><description><![CDATA[<p dir="auto">尝试了marker：：DELETE，还有lifetime，都没有用，有dalao有解决方案吗？</p>
]]></description><link>http://community.bwbot.org/topic/16595/如何删除rviz上单个marker</link><generator>RSS for Node</generator><lastBuildDate>Mon, 16 Mar 2026 05:51:11 GMT</lastBuildDate><atom:link href="http://community.bwbot.org/topic/16595.rss" rel="self" type="application/rss+xml"/><pubDate>Fri, 30 Jun 2023 09:00:29 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to 如何删除rviz上单个marker on Mon, 03 Jul 2023 03:28:28 GMT]]></title><description><![CDATA[<p dir="auto">在RViz中删除单个marker，可以使用以下方法：</p>
<ol>
<li>
<p dir="auto">使用marker的ID进行删除：在发布marker消息时，为每个marker设置一个唯一的ID。要删除特定的marker，可以发布一个新的marker消息，将该marker的ID设置为之前发布的marker的ID，并将其颜色设置为透明（alpha=0）。这样，RViz会将该marker视为已删除。</p>
</li>
<li>
<p dir="auto">使用marker数组进行删除：如果你在RViz中使用了marker数组，可以通过发布一个新的marker数组消息，将不需要的marker从数组中删除，并将其颜色设置为透明。RViz会根据新的marker数组消息更新显示。</p>
</li>
</ol>
<p dir="auto">以下是一个示例代码，演示如何删除RViz中的单个marker：</p>
<pre><code class="language-cpp">#include 
#include 

int main(int argc, char** argv)
{
    ros::init(argc, argv, "marker_delete_example");
    ros::NodeHandle nh;
    ros::Publisher marker_pub = nh.advertise("visualization_marker", 1);

    // 创建一个marker消息
    visualization_msgs::Marker marker;
    marker.header.frame_id = "map";
    marker.header.stamp = ros::Time::now();
    marker.ns = "my_namespace";
    marker.id = 0;
    marker.type = visualization_msgs::Marker::SPHERE;
    marker.action = visualization_msgs::Marker::ADD;
    marker.pose.position.x = 1.0;
    marker.pose.position.y = 2.0;
    marker.pose.position.z = 0.0;
    marker.pose.orientation.x = 0.0;
    marker.pose.orientation.y = 0.0;
    marker.pose.orientation.z = 0.0;
    marker.pose.orientation.w = 1.0;
    marker.scale.x = 1.0;
    marker.scale.y = 1.0;
    marker.scale.z = 1.0;
    marker.color.r = 1.0;
    marker.color.g = 0.0;
    marker.color.b = 0.0;
    marker.color.a = 1.0;
    marker.lifetime = ros::Duration(); // 持久显示

    // 发布marker消息
    marker_pub.publish(marker);

    // 删除marker
    marker.action = visualization_msgs::Marker::DELETE;
    marker_pub.publish(marker);

    ros::spinOnce();
    return 0;
}
</code></pre>
<p dir="auto">在上面的示例中，首先发布一个marker消息来显示一个红色的球体。然后，通过将marker的action设置为DELETE，再次发布marker消息来删除该marker。</p>
<p dir="auto">请注意，删除marker后，RViz中可能仍然会显示一段时间的残留效果，这是由于RViz的渲染机制造成的。</p>
]]></description><link>http://community.bwbot.org/post/17181</link><guid isPermaLink="true">http://community.bwbot.org/post/17181</guid><dc:creator><![CDATA[小助理]]></dc:creator><pubDate>Mon, 03 Jul 2023 03:28:28 GMT</pubDate></item></channel></rss>