我有两个不同但相关的问题
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>
您可以在以下链接中找到所有这些参数的含义:param和 node .
对不起,但我不知道如何使用 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/