无法获取bash和roslaunch中定义的ros::params以在c++脚本中打印



我有一个bash脚本,如下所示:

foldername=camera_calibration_$(date +"%m-%d-%Y")
im_name="/cam0"
roslaunch image_pub cam_calibration.launch foldername:=$foldername image_name:=$im_name

我的roslaunch脚本如下:

<launch>
<arg name = "foldername" default="camera_calibration" />
<arg name = "image_name" default="/cam1" />

<param name="foldername" type="string" value="$(arg foldername)" />
<param name="image_name" type="string" value="$(arg image_name)" />
<param name="size_name" type="string" value="12x8" />
<param name="square" type="string" value="0.05" />

<node name="im_pub_sub_node" pkg="image_pub" type="im_pub_sub" output="screen"/>
<node name="cameracalibrator_node" pkg="camera_calibration" type="cameracalibrator.py" output="screen"/>
</launch>

我的C++脚本(im_pub_sub.cpp(如下:

int main(int argc, char** argv) {
std::string foldername;
std::string imagename;
std::string si_name;
ros::param::get("/size_name", si_name);
ros::param::get("/foldername", foldername);
ros::param::get("/image_name", imagename);
std::cout<<imagename<<std::endl;
std::cout<<foldername<<std::endl;
std::cout<<si_name<<std::endl;
std::cout<<"hi"<<std::endl;
}

当我启动它时;嗨"在我的控制台上打印,但不打印foldername、bash中定义的imagename和启动文件中定义的si-name参数。对于定义的其他参数,它打印为空。

我可以在我的python脚本中打印这些params,但我无法使用c++来完成同样的操作。这完全是";怪异";。

谁能告诉我我的语法有什么错误吗?

我得到了。这是因为在定义rosnode初始化和node Nodehandler之前,您无法从启动文件中获得rosparams。

int main(int argc, char** argv) {
ros::init(argc, argv, "im_sub_pub_cpp");
ros::NodeHandle nh_;
std::string foldername;
std::string imagename;
std::string si_name;
ros::param::get("/size_name", si_name);
ros::param::get("/foldername", foldername);
ros::param::get("/image_name", imagename);
std::cout<<imagename<<std::endl;
std::cout<<foldername<<std::endl;
std::cout<<si_name<<std::endl;
std::cout<<"hi"<<std::endl;
}

然后这就行了。

相关内容

  • 没有找到相关文章

最新更新