c++ - ROS 启动文件设置变量值

标签 c++ parameters launch ros

我有两个不同但相关的问题

1st:是否可以使用启动文件设置变量的值? 我在网上看到了它,但我不明白如何使用它。

第二:我找不到任何关于如何使用启动文件来设置消息中变量值的信息。例如,如果我有:

mymessagevector.msg:

mymessage myvector[2]

我的消息.msg:

int32 value
string ID

有没有办法设置 myvector[0].ID="ID1"和 myvector[1].ID="ID2"并始终发布它,而不必在每次向主题发送消息时都定义它?

最佳答案

第一个答案很容易在 roslaunch documentation 中找到(和相关小节)。

一个简单的例子如下:

<launch>
  <node pkg="pkg_name" type="node_type" name="node_name">
    <param name="var_name" type="var_type" value="var_value" />
  </node>
</launch>

您可以在以下链接中找到所有这些参数的含义:paramnode .

对不起,但我不知道如何使用 roslaunch 初始化“第一条消息”(如果可能的话......)。您可以改用变量。

更新:

我将向您展示一个 C++ 文件中的示例

/* Retrieves information from parameters (if there are some specified) */

/* this handle let you access all the parameters of the node (and other stuffs) */
ros::NodeHandle node_handle = new ros::NodeHandle("~");

/* for example I need to retrieve the name of the serial port which is a parameter of my node */
std::string serial_port = "";
/* this member function searches for the parameter and stores it into 'serial_port' if it exists, 
 * otherwise it uses the third parameter of the function (a default value) */
node_handle->param("<name_of_param_in_roslaunch>", serial_port, std::string(DEFAULT_VALUE));

您可以找到ros::NodeHandle 文档here .

关于c++ - ROS 启动文件设置变量值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29211979/

相关文章:

c# - 如何判断方法是否访问默认值

xml - 无需输入 XML 的 XSLT 参数身份转换

java - OS X Catalina 以管理员权限破坏了 osascript 启动

java - 分享 eclipse/springsource 工具套件服务器启动配置

c++ - C++ 中定义异常类和抛出异常的标准方法

c++ - 用于#include 和其他文件的不同路径

python : call a function with n arguments

ios - 启动图像在不应显示时显示 - iOS

c++ - ffmpeg c/c++ 获取帧数或时间戳和 fps

c++ - 使用 Visual C++ 2010 在两个窗体之间传递数据