<?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[Topics tagged with ros教程]]></title><description><![CDATA[A list of topics that have been tagged with ros教程]]></description><link>http://community.bwbot.org/tags/ros教程</link><generator>RSS for Node</generator><lastBuildDate>Thu, 13 Aug 2026 15:15:27 GMT</lastBuildDate><atom:link href="http://community.bwbot.org/tags/ros教程.rss" rel="self" type="application/rss+xml"/><pubDate>Sun, 07 Sep 2025 07:59:24 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[ROS1节点在VSCode外的终端窗口中运行的时候，文件夹下没有生成结果文件。]]></title><description><![CDATA[<p dir="auto">这是一个非常典型的 <strong>文件路径问题</strong> 或 <strong>环境变量/工作目录差异</strong> 导致的问题。你提到：</p>

在 <strong>VSCode 中运行节点</strong> 时，文件正常生成。
在 <strong>外部终端运行节点</strong> 时，<strong>不生成文件</strong>，但节点运行正常，终端输出正常。
重启虚拟机可以临时解决。

<p dir="auto">这说明问题不是代码本身，而是 <strong>运行环境差异</strong>，尤其是 <strong>当前工作目录（Current Working Directory, CWD）</strong> 和 <strong>路径配置</strong>。</p>

✅ 一、可能原因分析
1. 当前工作目录（CWD）不同
<p dir="auto">在 VSCode 中运行 ROS 节点时，它默认使用你打开的 <strong>工作区根目录</strong> 或 launch.json 中指定的 cwd。</p>
<p dir="auto">而在外部终端中运行节点时，<strong>当前工作目录</strong> 可能是你当前所在的目录（比如 ~、/home/user、/tmp 等），而不是你的 ROS 工作空间目录（如 ~/catkin_ws）。</p>
<p dir="auto">如果你的代码中使用了相对路径（如 "output.txt"），那么生成的文件会出现在当前工作目录下。</p>

2. 文件权限问题（尤其是虚拟机共享文件夹）
<p dir="auto">在虚拟机中（如 VirtualBox + 共享文件夹 / VMware 共享文件夹），某些路径可能因为权限限制导致无法写入文件。</p>

VSCode 可能是以用户权限运行的，有写权限。
外部终端可能因为 shell 环境或权限设置不同，导致无法写入目标路径。


3. ROS 参数服务器路径配置错误
<p dir="auto">如果你的代码是通过 ROS 参数服务器获取路径（如 ~output_dir），那么：</p>

VSCode 中可能加载了正确的参数配置。
外部终端运行时没有加载参数文件（.yaml），导致路径为空或错误。


✅ 二、排查方法
方法 1：打印当前工作目录
<p dir="auto">在你的 ROS 节点中加入以下代码（C++ 示例）：</p>
#include 
#include 
#include 

char cwd[PATH_MAX];
if (getcwd(cwd, sizeof(cwd)) != NULL) {
    ROS_INFO("Current working directory: %s", cwd);
}

<p dir="auto">Python 示例：</p>
import os
rospy.loginfo(f"Current working directory: {os.getcwd()}")

<p dir="auto">这样你就可以看到在不同环境中运行时的工作目录是否一致。</p>

方法 2：检查文件写入路径是否绝对路径
<p dir="auto">如果你的代码中写文件使用的是相对路径：</p>
std::ofstream file("output.txt");

<p dir="auto">那文件会写入到当前工作目录中。</p>
<p dir="auto">建议改成绝对路径或根据 ROS 参数配置路径：</p>
std::string output_path;
nh.getParam("~output_path", output_path);  // 从参数服务器获取路径
std::ofstream file(output_path + "/output.txt");

<p dir="auto">或者使用 ros::package::getPath() 获取包路径：</p>
std::string package_path = ros::package::getPath("your_package_name");
std::ofstream file(package_path + "/output/output.txt");


方法 3：检查文件是否真的没有生成
<p dir="auto">在终端中运行：</p>
find ~/ -name "output.txt" 2&gt;/dev/null

<p dir="auto">或在虚拟机中搜索整个系统：</p>
sudo find / -name "output.txt"

<p dir="auto">确认文件是否真的没有生成，还是只是不在你预期的位置。</p>

方法 4：检查权限
<p dir="auto">如果你的路径是共享文件夹（如 VirtualBox 共享文件夹），尝试在终端中运行：</p>
ls -ld /path/to/output

<p dir="auto">确保当前用户有写权限。你也可以尝试手动创建一个测试文件：</p>
touch /path/to/output/test.txt

<p dir="auto">如果失败，说明权限有问题。</p>

✅ 三、解决方案建议
✅ 推荐做法：使用 ROS 参数配置路径
<p dir="auto">修改代码，使用参数服务器配置输出路径：</p>
# config/params.yaml
output_path: "/home/user/catkin_ws/src/your_package/output"

<p dir="auto">启动时加载参数：</p>
roslaunch your_package your_launch_file.launch --params-file config/params.yaml


✅ 推荐做法：在终端中指定工作目录
<p dir="auto">你可以手动指定工作目录运行节点：</p>
cd ~/catkin_ws
source devel/setup.bash
rosrun your_package your_node

<p dir="auto">或者使用 --cwd（仅限 rosrun 支持）：</p>
rosrun --prefix 'cd /home/user/catkin_ws &amp;&amp;' your_package your_node


✅ 推荐做法：在 launch 文件中设置工作目录
<p dir="auto">如果你用 roslaunch，可以在 .launch 文件中指定工作目录：</p>

  
    
  



✅ 四、总结



原因
解决方法




当前工作目录不同
使用 getcwd() 打印路径，统一运行目录


相对路径写入
改为绝对路径或使用 ros::package::getPath()


参数配置缺失
使用参数服务器统一配置路径


权限问题
检查路径权限，避免共享文件夹限制


虚拟机共享路径问题
尝试复制文件到本地路径测试




🧪 附加建议
<p dir="auto">你可以写一个最小可复现问题的测试程序，例如：</p>
#include 
#include 

int main() {
    std::ofstream file("test.txt");
    if (file.is_open()) {
        file &lt;&lt; "Test content\n";
        file.close();
        std::cout &lt;&lt; "File written successfully.\n";
    } else {
        std::cerr &lt;&lt; "Failed to open file.\n";
    }
    return 0;
}

<p dir="auto">然后分别在 VSCode 和外部终端运行，看是否能生成文件，这样可以快速定位是否是路径问题。</p>

<p dir="auto">如果你愿意贴出部分代码片段，我可以帮你具体分析路径写入逻辑。</p>
]]></description><link>http://community.bwbot.org/topic/16670/ros1节点在vscode外的终端窗口中运行的时候-文件夹下没有生成结果文件</link><guid isPermaLink="true">http://community.bwbot.org/topic/16670/ros1节点在vscode外的终端窗口中运行的时候-文件夹下没有生成结果文件</guid><dc:creator><![CDATA[小助理]]></dc:creator><pubDate>Sun, 07 Sep 2025 07:59:24 GMT</pubDate></item><item><title><![CDATA[rk3588在ros中使用ros_rknn_yolo包]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="http://community.bwbot.org/uid/1869">@natsuki</a> 在 <a href="/post/17457">rk3588在ros中使用ros_rknn_yolo包</a> 中说：</p>
<blockquote>
<p dir="auto">ros_rknn_yolo文件夹内有没有正确创建venv子文件夹，检查venv内的python虚拟环境是否正确创建了。<br />
同时可以手动按行执行一下rknn_yolo_node.sh这个bash文件中的指令内容，看是哪一行出了问题。</p>
</blockquote>
]]></description><link>http://community.bwbot.org/topic/16648/rk3588在ros中使用ros_rknn_yolo包</link><guid isPermaLink="true">http://community.bwbot.org/topic/16648/rk3588在ros中使用ros_rknn_yolo包</guid><dc:creator><![CDATA[xiaoqiang]]></dc:creator><pubDate>Tue, 15 Oct 2024 05:16:06 GMT</pubDate></item><item><title><![CDATA[ros]]></title><description><![CDATA[<p dir="auto">如果你想要继续使用rosdep update，可以尝试以下方法：</p>


<p dir="auto">确认你的操作系统版本是否支持ROS，ROS只支持特定版本的操作系统，可以在ROS官网上查看支持的操作系统版本。</p>


<p dir="auto">确认你的网络连接是否正常，rosdep update需要从网络上下载依赖包，如果网络连接不稳定或者被防火墙拦截，就会出现这个错误。</p>


<p dir="auto">确认你的ROS源是否配置正确，可以通过执行以下命令来检查：</p>
echo "source /opt/ros/melodic/setup.bash" &gt;&gt; ~/.bashrc
source ~/.bashrc

<p dir="auto">注意，这里的/opt/ros/melodic是ROS的安装路径，如果你安装的是其他版本的ROS，需要将路径替换成对应的版本号。</p>


<p dir="auto">如果以上方法都无法解决问题，可以尝试手动安装依赖包，具体方法可以参考ROS官方文档中的“Installing Dependencies”部分。</p>


<p dir="auto">希望这些方法能够帮助你解决问题。</p>
]]></description><link>http://community.bwbot.org/topic/16584/ros</link><guid isPermaLink="true">http://community.bwbot.org/topic/16584/ros</guid><dc:creator><![CDATA[小助理]]></dc:creator><pubDate>Mon, 08 May 2023 11:12:35 GMT</pubDate></item><item><title><![CDATA[小强主机开机黑屏，进入vim环境下sudo apt-get update &amp;&amp; sudo apt-get -upgrade 报错，如图所示]]></title><description><![CDATA[<p dir="auto">不客气，如果您还有其他问题，请随时提出。我会尽力帮助您解决问题。</p>
]]></description><link>http://community.bwbot.org/topic/16582/小强主机开机黑屏-进入vim环境下sudo-apt-get-update-sudo-apt-get-upgrade-报错-如图所示</link><guid isPermaLink="true">http://community.bwbot.org/topic/16582/小强主机开机黑屏-进入vim环境下sudo-apt-get-update-sudo-apt-get-upgrade-报错-如图所示</guid><dc:creator><![CDATA[小助理]]></dc:creator><pubDate>Tue, 18 Apr 2023 06:08:36 GMT</pubDate></item><item><title><![CDATA[求助，灵巧空间构建]]></title><description><![CDATA[<p dir="auto">ros进行灵巧空间构建，自己不知道怎么网格化划分和姿态离散化，麻烦各位了<br />
<img src="/assets/uploads/files/1632884309348-644c674cd55b0f8f23ac66cc061276d.jpg" alt="644c674cd55b0f8f23ac66cc061276d.jpg" class=" img-responsive img-markdown" width="1080" height="1440" /></p>
]]></description><link>http://community.bwbot.org/topic/16478/求助-灵巧空间构建</link><guid isPermaLink="true">http://community.bwbot.org/topic/16478/求助-灵巧空间构建</guid><dc:creator><![CDATA[sunday366]]></dc:creator><pubDate>Wed, 29 Sep 2021 02:59:47 GMT</pubDate></item><item><title><![CDATA[catkin_make第一天可以运行，第二天就不能了]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="http://community.bwbot.org/uid/1419">@chaizongjun</a> 图片上传失败了</p>
]]></description><link>http://community.bwbot.org/topic/16475/catkin_make第一天可以运行-第二天就不能了</link><guid isPermaLink="true">http://community.bwbot.org/topic/16475/catkin_make第一天可以运行-第二天就不能了</guid><dc:creator><![CDATA[weijiz]]></dc:creator><pubDate>Thu, 16 Sep 2021 12:02:01 GMT</pubDate></item><item><title><![CDATA[求助 对serial库未定义的引用]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="http://community.bwbot.org/uid/20">@xiaoqiang</a> 谢谢！问题解决了，是网上下载的功能包有问题。</p>
]]></description><link>http://community.bwbot.org/topic/16468/求助-对serial库未定义的引用</link><guid isPermaLink="true">http://community.bwbot.org/topic/16468/求助-对serial库未定义的引用</guid><dc:creator><![CDATA[Yuanren]]></dc:creator><pubDate>Sun, 18 Jul 2021 12:00:40 GMT</pubDate></item><item><title><![CDATA[求助，ROS如何编写判断节点启动的程序。]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="http://community.bwbot.org/uid/1119">@叫我小冬枣</a></p>
  ros::master::V_TopicInfo available_topics;
  ros::master::getTopics(available_topics);
  for (size_t it = 0; it&lt;available_topics.size(); it++){
    std::string available_topic_name = available_topics[it].name;
   
  }


]]></description><link>http://community.bwbot.org/topic/16439/求助-ros如何编写判断节点启动的程序</link><guid isPermaLink="true">http://community.bwbot.org/topic/16439/求助-ros如何编写判断节点启动的程序</guid><dc:creator><![CDATA[weijiz]]></dc:creator><pubDate>Tue, 18 May 2021 06:58:50 GMT</pubDate></item><item><title><![CDATA[求助，怎么在18.04的ubuntu上安装ros]]></title><description><![CDATA[<p dir="auto">我在安装小强镜像的时候总显示安装失败，现在安装了18.04的ubuntu系统，请问怎么在这上面安装ros</p>
]]></description><link>http://community.bwbot.org/topic/3006/求助-怎么在18-04的ubuntu上安装ros</link><guid isPermaLink="true">http://community.bwbot.org/topic/3006/求助-怎么在18-04的ubuntu上安装ros</guid><dc:creator><![CDATA[叫我小冬枣]]></dc:creator><pubDate>Sat, 30 Jan 2021 09:33:45 GMT</pubDate></item><item><title><![CDATA[上位机是树莓派，已经连接上串口，但是收不到下位机的里程计，IMU等消息]]></title><description><![CDATA[<p dir="auto">上位机是树莓派，已经连接上串口，运行xqserial.launch开启了主节点，但是收不到下位机的里程计，IMU等消息</p>
<p dir="auto">系统：Ubuntu18.04<br />
ros版本：melodic<br />
代码：xqserial_server foc_noetic分支<br />
驱动器：BW-DR13</p>
]]></description><link>http://community.bwbot.org/topic/3002/上位机是树莓派-已经连接上串口-但是收不到下位机的里程计-imu等消息</link><guid isPermaLink="true">http://community.bwbot.org/topic/3002/上位机是树莓派-已经连接上串口-但是收不到下位机的里程计-imu等消息</guid><dc:creator><![CDATA[lpa]]></dc:creator><pubDate>Tue, 26 Jan 2021 06:20:02 GMT</pubDate></item><item><title><![CDATA[镭神LS01B激光雷达ros驱动安装与测试]]></title><description><![CDATA[<p dir="auto">按照帖子的顺序执行文件后，发现小车报错，到后面找不到生成的对应日志，请问有什么解决办法65217cbc-519c-431c-aa53-62b5592adf19-image.png</p>
]]></description><link>http://community.bwbot.org/topic/2937/镭神ls01b激光雷达ros驱动安装与测试</link><guid isPermaLink="true">http://community.bwbot.org/topic/2937/镭神ls01b激光雷达ros驱动安装与测试</guid><dc:creator><![CDATA[radical_3]]></dc:creator><pubDate>Tue, 03 Dec 2024 03:22:53 GMT</pubDate></item><item><title><![CDATA[求助：教程（18）无法找到dso_live (已结帖)]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="http://community.bwbot.org/uid/1051">@山中客</a> 在 <a href="/post/1708">求助：教程（18）无法找到dso_live</a> 中说：</p>
<blockquote>
<p dir="auto">Pangolin X11: Failed to open X display<br />
Aborted</p>
</blockquote>
<p dir="auto">这个原因找到了，最后的Pangolin X11: Failed to open X display<br />
Aborted (core dumped)，是由于在ssh 下pangolin 无法显示图像。</p>
<p dir="auto">整个问题实际上在重编ROS 后解决的，另外dso_ros dso_live 不能通过ssh 执行，需要直接在小强主机或VNC 环境下执行。</p>
<p dir="auto">问题close.</p>
]]></description><link>http://community.bwbot.org/topic/877/求助-教程-18-无法找到dso_live-已结帖</link><guid isPermaLink="true">http://community.bwbot.org/topic/877/求助-教程-18-无法找到dso_live-已结帖</guid><dc:creator><![CDATA[山中客]]></dc:creator><pubDate>Wed, 12 Feb 2020 02:31:02 GMT</pubDate></item><item><title><![CDATA[小强ROS机器人教程(30)___ORB_SLAM2包的详细配置和深度使用]]></title><description><![CDATA[<p dir="auto">新手学习下 谢谢楼主</p>
]]></description><link>http://community.bwbot.org/topic/685/小强ros机器人教程-30-___orb_slam2包的详细配置和深度使用</link><guid isPermaLink="true">http://community.bwbot.org/topic/685/小强ros机器人教程-30-___orb_slam2包的详细配置和深度使用</guid><dc:creator><![CDATA[chenzixinbea]]></dc:creator><pubDate>Mon, 01 Jun 2020 08:52:59 GMT</pubDate></item><item><title><![CDATA[如何在Windows上使用roscpp]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="http://community.bwbot.org/uid/1588">@静听松风寒</a> 这个已经太过久远了，很多都不合适了，比如python现在都已经用3了。windows好像本身也可以直接装ros了</p>
]]></description><link>http://community.bwbot.org/topic/674/如何在windows上使用roscpp</link><guid isPermaLink="true">http://community.bwbot.org/topic/674/如何在windows上使用roscpp</guid><dc:creator><![CDATA[weijiz]]></dc:creator><pubDate>Thu, 13 Oct 2022 05:05:25 GMT</pubDate></item><item><title><![CDATA[RVIZ可视化窗口中能给检测到目标添加一个立方体的框吗？]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="http://community.bwbot.org/uid/680">@道灼</a> 可以用 <a href="http://wiki.ros.org/rviz/DisplayTypes/Marker#Line_List_.28LINE_LIST.3D5.29" target="_blank" rel="noopener noreferrer">line list</a> 类型。就是把点的坐标设置好，最后会生成点的连线图形。</p>
]]></description><link>http://community.bwbot.org/topic/665/rviz可视化窗口中能给检测到目标添加一个立方体的框吗</link><guid isPermaLink="true">http://community.bwbot.org/topic/665/rviz可视化窗口中能给检测到目标添加一个立方体的框吗</guid><dc:creator><![CDATA[weijiz]]></dc:creator><pubDate>Thu, 10 Jan 2019 06:02:54 GMT</pubDate></item><item><title><![CDATA[小强ROS机器人教程(28)___使用Intel RealSense D400系列深度摄像头进行自主移动避障]]></title><description><![CDATA[<h3>1.驱动测试</h3>
<p dir="auto">连接好RealSense摄像头后，运行下述命令可以测试sdk有没有安装成功</p>
<pre><code>#sdk的安装教程 https://github.com/IntelRealSense/librealsense/blob/master/doc/distribution_linux.md#installing-the-packages
rs-capture  
</code></pre>
<p dir="auto">正常的话可以看到类似下图的图像<br />
<img src="/assets/uploads/files/1542946295614-screenshot-from-2018-11-23-12-09-26-resized.png" alt="0_1542946289819_Screenshot from 2018-11-23 12-09-26.png" class=" img-responsive img-markdown" /><br />
关闭上述命令，继续测试ros驱动</p>
<pre><code>#ros驱动的安装教程 https://gitee.com/bluewhalerobot/realsense
roslaunch realsense2_camera rs_camera.launch
</code></pre>
<p dir="auto">如果正常，在rviz里面可以订阅显示深度和color图像话题。<br />
<img src="/assets/uploads/files/1542946824941-screenshot-from-2018-11-23-12-19-59-resized.png" alt="0_1542946818630_Screenshot from 2018-11-23 12-19-59.png" class=" img-responsive img-markdown" /></p>
<h3>2.关闭步骤1中命令，开始自主移动避障测试</h3>
<p dir="auto">intel RealsSense和kinect是兼容的，使用它来自主移动避障的教程也和kinect一样，区别是教程2.b、2.c步骤需要选择realsense。</p>
<pre><code>roslaunch realsense2_camera rs_camera_xiaoqiang.launch
</code></pre>
<p dir="auto"><a href="https://community.bwbot.org/topic/115/%E5%B0%8F%E5%BC%BAros%E6%9C%BA%E5%99%A8%E4%BA%BA%E6%95%99%E7%A8%8B-10-___%E4%BD%BF%E7%94%A8kinect%E8%BF%9B%E8%A1%8C%E8%87%AA%E4%B8%BB%E7%A7%BB%E5%8A%A8%E9%81%BF%E9%9A%9C" target="_blank" rel="noopener noreferrer">kinect避障教程</a>：<br />
https://community.bwbot.org/topic/115/小强ros机器人教程-10-___使用kinect进行自主移动避障</p>
]]></description><link>http://community.bwbot.org/topic/641/小强ros机器人教程-28-___使用intel-realsense-d400系列深度摄像头进行自主移动避障</link><guid isPermaLink="true">http://community.bwbot.org/topic/641/小强ros机器人教程-28-___使用intel-realsense-d400系列深度摄像头进行自主移动避障</guid><dc:creator><![CDATA[xiaoqiang]]></dc:creator><pubDate>Fri, 23 Nov 2018 04:25:32 GMT</pubDate></item><item><title><![CDATA[如何不设置HOST通过ROS远程连接]]></title><description><![CDATA[<p dir="auto">在有些情况下我们想要连接远程的master节点是没办法设置hosts文件的。比如在Android上运行rosjava时。这样就导致我们能够发布消息到远程节点，但是却无法订阅远程消息。问题在于默认的<code>ROS_MASTER_URI</code>是<code>http://computer-name:11311</code>。而我们连接的时候是通过IP连接的，这样导致本地节点订阅的是<code>http://xxx.xxx.xxx.xxx:11311</code>，其中<code>xxx.xxx.xxx.xxx</code>是远程机器的IP。这两个不一致，导致无法订阅消息。</p>
<p dir="auto">解决方法是把远程的<code>ROS_MASTER_URI</code>也设置成IP的形式。这个可以通过设置<code>ROS_IP</code>变量实现。比如在launch文件内添加</p>
<pre><code class="language-xml">&lt;env name="ROS_IP" value="xxx.xxx.xxx.xxx" /&gt;
</code></pre>
<p dir="auto">但是实际使用的时候远程节点IP可能并不是固定的。这样设置之后一旦IP发生变化，程序就没办法继续运行了。下面介绍一个更好的方法。使用<code>robot_upstart</code>软件包</p>
<p dir="auto">安装<code>robot_upstart</code>软件包</p>
<pre><code class="language-bash">sudo apt-get install ros-kinetic-robot-upstart
</code></pre>
<p dir="auto">安装自启动服务</p>
<pre><code class="language-bash">rosrun robot_upstart install --interface enp2s0 startup/launch/startup.launch
</code></pre>
<p dir="auto">需要注意的是这里的 <code>--interface</code>参数。这个参数指定网络设备，在程序启动的时候会自动获取这个网络设备的IP然后设置到<code>ROS_IP</code>环境变量。这样<code>ROS_MASTER_URI</code>就会和当前的IP一致。</p>
]]></description><link>http://community.bwbot.org/topic/634/如何不设置host通过ros远程连接</link><guid isPermaLink="true">http://community.bwbot.org/topic/634/如何不设置host通过ros远程连接</guid><dc:creator><![CDATA[weijiz]]></dc:creator><pubDate>Tue, 30 Oct 2018 12:01:00 GMT</pubDate></item><item><title><![CDATA[自定义消息在RVIZ中可视化如何实现？？？]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="http://community.bwbot.org/uid/20">@xiaoqiang</a> 您好，还有一些unvisualizable topic也是写对应的插件可以实现可视化吧?还是无法实现可视化？</p>
]]></description><link>http://community.bwbot.org/topic/632/自定义消息在rviz中可视化如何实现</link><guid isPermaLink="true">http://community.bwbot.org/topic/632/自定义消息在rviz中可视化如何实现</guid><dc:creator><![CDATA[道灼]]></dc:creator><pubDate>Fri, 02 Nov 2018 12:40:45 GMT</pubDate></item><item><title><![CDATA[小强中如何获得惯性导航数据]]></title><description><![CDATA[<p dir="auto">一般的ROS机器人都有惯性导航和全局导航(比如雷达，视觉)两种。小强也是如此。<br />
惯性导航利用底盘编码器和陀螺仪进行定位。这样的定位方式是具有累计误差的，只能保证局部的准确性。<br />
这样的惯性导航信息被称为小车的里程计(Odometry)。小强的Odom分布在 <code>/xqserial_server/Odom</code>。可以通过rostopic echo 读取到。发布频率为50hz。</p>
<p dir="auto">读取里程计指令</p>
<pre><code>rostopic echo /xqserial_server/Odom
</code></pre>
<p dir="auto">里程计的数据结构如下</p>
<pre><code>std_msgs/Header header
string child_frame_id
geometry_msgs/PoseWithCovariance pose
geometry_msgs/TwistWithCovariance twist
</code></pre>
<p dir="auto">其中header是数据头，包含时间戳和坐标系ID，pose为机器人里程计坐标，twist是当前小车的速度信息。</p>
]]></description><link>http://community.bwbot.org/topic/535/小强中如何获得惯性导航数据</link><guid isPermaLink="true">http://community.bwbot.org/topic/535/小强中如何获得惯性导航数据</guid><dc:creator><![CDATA[weijiz]]></dc:creator><pubDate>Sat, 18 Aug 2018 06:37:20 GMT</pubDate></item><item><title><![CDATA[在ROS中使用Python3]]></title><description><![CDATA[<p dir="auto">当前ROS是只支持Python2.7的。Python3的支持在ROS的计划中，详细的可以看<a href="https://github.com/ros-infrastructure/rep/blob/rep151/rep-0151.rst" target="_blank" rel="noopener noreferrer">这里</a>。简单说来就是要到2020年ROS的N版本才能完全支持Python3。</p>
<p dir="auto">首先要了解为什么ROS不能支持Python3.对于纯的Python代码同时支持Python3和Python2.7是比较容易的，基本上ROS的代码也都是支持的。问题在于包含了C++或者C的那部分Python代码。Python2.7和Python3的c module代码相差很大。一次只能编译其中的一种版本。而且很多module没有做好Python3的支持。在Python3环境下也无法编译。这就是ROS无法支持Python3的原因。目前ROS的核心包都是支持用Python3从源码编译的。但是官方并没有发布Python3的软件包。所以想要使用的话要自己编译。下面介绍两种使用Python3的方法。</p>
<ol>
<li>使用Python3和Python2.7的混合环境<br />
原理：使用virtualenv创建一个Python3的环境。然后在这个环境中编译安装自己需要的软件包。在引用软件包的时候，如果没有对应的Python3的软件包，会自动的去Python2.7的环境里面找。这样很多软件包都是可以通用的。当然对于没有做好Python3支持的软件包也是没法用的。</li>
</ol>
<p dir="auto">下面以geometry2为例子</p>
<pre><code class="language-bash">sudo apt-get install python3-dev
mkdir catkin_ws # 创建工作空间
cd catkin_ws
mkdir src
cd src 
# 下载geometry和geometry2的源代码
git clone https://github.com/ros/geometry
git clone https://github.com/ros/geometry2
cd ..
# 创建虚拟环境
virtualenv -p /usr/bin/python3 venv
source venv/bin/activate
pip install catkin_pkg pyyaml empy rospkg numpy
catkin_make
source devel/setup.bash
</code></pre>
<p dir="auto">这样就能够成功在Python3下使用tf的相关函数了。</p>
<p dir="auto">运行Python3程序</p>
<pre><code>Python 3.5.2 (default, Nov 23 2017, 16:37:01) 
[GCC 5.4.0 20160609] on linux
Type "help", "copyright", "credits" or "license" for more information.
&gt;&gt;&gt; import tf
&gt;&gt;&gt; tf.__file__
'/home/xiaoqiang/Desktop/catkin_ws/devel/lib/python3/dist-packages/tf/__init__.py'
&gt;&gt;&gt; import tf2_py
&gt;&gt;&gt; tf2_py.__file__
'/home/xiaoqiang/Desktop/catkin_ws/devel/lib/python3/dist-packages/tf2_py/__init__.py'
&gt;&gt;&gt; 
</code></pre>
<p dir="auto">可以看到我们的tf已经是在Python3的路径下了。</p>
<ol start="2">
<li>从源码安装ROS<br />
首先把ROS都卸载干净</li>
</ol>
<pre><code>sudo apt-get purge ros-*
sudo apt-get autoremove
</code></pre>
<p dir="auto">创建ROS工作空间</p>
<pre><code>mkdir ros
</code></pre>
<p dir="auto">创建Python3环境</p>
<pre><code>cd ros
# 把系统默认Python替换成Python3
sudo rm -rf /usr/bin/python
sudo ln -s /usr/bin/python3.5 /usr/bin/python
sudo apt install python3-pip
</code></pre>
<p dir="auto">安装ros的编译基础软件包</p>
<pre><code class="language-bash">sudo apt-get install python3-rosdep python3-rosinstall-generator python3-wstool python3-rosinstall build-essential
sudo pip3 install catkin_pkg
</code></pre>
<p dir="auto">开始下载相关软件包</p>
<pre><code class="language-bash">rosinstall_generator desktop --rosdistro kinetic --deps --tar &gt; kinetic-desktop.rosinstall
wstool init -j8 src kinetic-desktop.rosinstall
# 如果上一步有失败的，执行
wstool update -j 4 -t src
</code></pre>
<p dir="auto">这里安装的是kinetic版本。其他版本需要调整对应的参数。</p>
<p dir="auto">安装软件包依赖</p>
<pre><code class="language-bash">rosdep install --from-paths src --ignore-src --rosdistro kinetic -y
sudo apt-get install libtbb-dev python3-pyqt5
sudo pip3 install empy numpy defusedxml netifaces
# 修复 16.04 libboost_python3找不到的问题
sudo ln -s /usr/lib/x86_64-linux-gnu/libboost_python-py35.so /usr/lib/x86_64-linux-gnu/libboost_python3.so
</code></pre>
<p dir="auto">编译工作空间</p>
<pre><code>./src/catkin/bin/catkin_make_isolated --install -DCMAKE_BUILD_TYPE=Release
</code></pre>
<p dir="auto">如果这个过程中编译有错误，一般是缺少软件包之类的。需要下载安装对应的软件包然后再次编译。直到全部编译成功。</p>
<p dir="auto">添加环境变量</p>
<p dir="auto">在~/.bashrc里面添加</p>
<pre><code class="language-bash">source /home/xiaoqiang/Documents/ros/install_isolated/setup.bash
</code></pre>
<p dir="auto">这里是小强的路径，你要根据自己的工作空间的位置进行修改。</p>
<p dir="auto">之后再重新打开一个终端就可以了。</p>
<pre><code>In [2]: import tf2_ros

In [3]: tf2_ros.__file__
Out[3]: '/home/xiaoqiang/Documents/ros/install_isolated/lib/python3/dist-packages/tf2_ros/__init__.py'

In [4]: 
</code></pre>
<p dir="auto">可以看到现在的ROS使用的Python已经是Python3了。</p>
<p dir="auto">总结虽然以上两种方法都可以使用Python3,但是推荐还是使用第一种方法。第二种方法使用起来比较费事，而且一旦使用了Python3就没办法使用Pyhon2.7了。有些软件包并没有做好Pyhon3的支持。这样会在使用中产生不少问题。</p>
]]></description><link>http://community.bwbot.org/topic/499/在ros中使用python3</link><guid isPermaLink="true">http://community.bwbot.org/topic/499/在ros中使用python3</guid><dc:creator><![CDATA[weijiz]]></dc:creator><pubDate>Sat, 07 Jul 2018 08:09:17 GMT</pubDate></item></channel></rss>