<?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[使用python代码启动launch文件]]></title><description><![CDATA[<p dir="auto">在开发中我们经常会遇到使用python代码启动launch文件这样的问题。一般的做法是使用subprocess调用roslaunch。但是这种方法使用起来并不方便。要涉及到自己去控制进程的状态。由于roslaunch实际上是用python实现的。使用python调用launch文件实际上有更简单的方法。</p>
<pre><code class="language-python">import roslaunch

uuid = roslaunch.rlutil.get_or_generate_uuid(None, False)
roslaunch.configure_logging(uuid)
tracking_launch = roslaunch.parent.ROSLaunchParent(
    uuid, ["/home/xiaoqiang/Documents/ros/src/xiaoqiang_track/launch/track_body.launch"])
tracking_launch.start()
</code></pre>
<p dir="auto">这样就成功启动了一个launch文件。把uuid后面的路径换成自己的launch文件路径就可以了。</p>
<p dir="auto">而且我们可以通过roslaunch直接关闭launch文件启动的节点。</p>
<pre><code class="language-python">tracking_launch.shutdown() # tracking_launch 即是上面通过roslaunch获取到的变量
</code></pre>
<p dir="auto">这样使用起来就很方便了。</p>
]]></description><link>http://community.bwbot.org/topic/498/使用python代码启动launch文件</link><generator>RSS for Node</generator><lastBuildDate>Mon, 16 Mar 2026 06:17:42 GMT</lastBuildDate><atom:link href="http://community.bwbot.org/topic/498.rss" rel="self" type="application/rss+xml"/><pubDate>Sat, 07 Jul 2018 02:18:20 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to 使用python代码启动launch文件 on Sun, 28 Jun 2020 02:51:30 GMT]]></title><description><![CDATA[<p dir="auto">tracking_launch.spin()</p>
]]></description><link>http://community.bwbot.org/post/3842</link><guid isPermaLink="true">http://community.bwbot.org/post/3842</guid><dc:creator><![CDATA[黄哈哈]]></dc:creator><pubDate>Sun, 28 Jun 2020 02:51:30 GMT</pubDate></item><item><title><![CDATA[Reply to 使用python代码启动launch文件 on Wed, 13 Mar 2019 13:18:19 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="http://community.bwbot.org/uid/826">@几何木偶</a> 你的代码是什么样的，像我之前的例子那样写应该会正常退出。</p>
]]></description><link>http://community.bwbot.org/post/1141</link><guid isPermaLink="true">http://community.bwbot.org/post/1141</guid><dc:creator><![CDATA[weijiz]]></dc:creator><pubDate>Wed, 13 Mar 2019 13:18:19 GMT</pubDate></item><item><title><![CDATA[Reply to 使用python代码启动launch文件 on Wed, 13 Mar 2019 09:59:44 GMT]]></title><description><![CDATA[<p dir="auto"><img src="/assets/uploads/files/1552471101382-586d74d7-e403-4265-a4ef-969d5b16ebee-image.png" alt="586d74d7-e403-4265-a4ef-969d5b16ebee-image.png" class=" img-responsive img-markdown" width="730" height="410" /><br />
这样当我使用ctrl+c结束时，它没有跳出循环，变成死循环了。有办法吗？</p>
]]></description><link>http://community.bwbot.org/post/1140</link><guid isPermaLink="true">http://community.bwbot.org/post/1140</guid><dc:creator><![CDATA[几何木偶]]></dc:creator><pubDate>Wed, 13 Mar 2019 09:59:44 GMT</pubDate></item><item><title><![CDATA[Reply to 使用python代码启动launch文件 on Mon, 04 Mar 2019 00:59:27 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="http://community.bwbot.org/uid/826">@几何木偶</a> 因为没有join方法，所以程序出错后退出了。tracking_launch.start()是不阻塞的，需要自己阻塞主线程。比如</p>
<pre><code class="language-python">import roslaunch
import rospy
import time

uuid = roslaunch.rlutil.get_or_generate_uuid(None, False)
roslaunch.configure_logging(uuid)
tracking_launch = roslaunch.parent.ROSLaunchParent(
    uuid, ["/home/xiaoqiang/Documents/ros/src/xiaoqiang_track/launch/track_body.launch"])
tracking_launch.start()
while not rospy.is_shutdown():
    time.sleep(1)
</code></pre>
]]></description><link>http://community.bwbot.org/post/1107</link><guid isPermaLink="true">http://community.bwbot.org/post/1107</guid><dc:creator><![CDATA[weijiz]]></dc:creator><pubDate>Mon, 04 Mar 2019 00:59:27 GMT</pubDate></item><item><title><![CDATA[Reply to 使用python代码启动launch文件 on Sun, 03 Mar 2019 15:57:58 GMT]]></title><description><![CDATA[<p dir="auto"><img src="/assets/uploads/files/1551628674425-f31258e7-3a5b-425d-92ca-53b28be31ffc-image.png" alt="f31258e7-3a5b-425d-92ca-53b28be31ffc-image.png" class=" img-responsive img-markdown" width="1357" height="552" /></p>
]]></description><link>http://community.bwbot.org/post/1106</link><guid isPermaLink="true">http://community.bwbot.org/post/1106</guid><dc:creator><![CDATA[几何木偶]]></dc:creator><pubDate>Sun, 03 Mar 2019 15:57:58 GMT</pubDate></item><item><title><![CDATA[Reply to 使用python代码启动launch文件 on Sun, 03 Mar 2019 06:17:00 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="http://community.bwbot.org/uid/826">@几何木偶</a> 你的代码是什么样的</p>
]]></description><link>http://community.bwbot.org/post/1104</link><guid isPermaLink="true">http://community.bwbot.org/post/1104</guid><dc:creator><![CDATA[weijiz]]></dc:creator><pubDate>Sun, 03 Mar 2019 06:17:00 GMT</pubDate></item><item><title><![CDATA[Reply to 使用python代码启动launch文件 on Sun, 03 Mar 2019 05:28:18 GMT]]></title><description><![CDATA[<p dir="auto"><img src="/assets/uploads/files/1551590866893-f2fc16e0-f0de-4eec-bc7f-c09762cf99c2-image.png" alt="f2fc16e0-f0de-4eec-bc7f-c09762cf99c2-image.png" class=" img-responsive img-markdown" width="347" height="89" /> 这个程序运行后就被退出了（killing on exit），应该怎么做？</p>
]]></description><link>http://community.bwbot.org/post/1103</link><guid isPermaLink="true">http://community.bwbot.org/post/1103</guid><dc:creator><![CDATA[几何木偶]]></dc:creator><pubDate>Sun, 03 Mar 2019 05:28:18 GMT</pubDate></item></channel></rss>