本人在项目中需要在运行一个ROS 节点的过程中,在特定时刻触发和启动另外一个ROS 节点开始执行,这里提供一种只需一次编译的方法。
两个地方需要配置:
需要配置地方1:
- generat a file wih “ros_run.sh” and write the command following inside:
#! /bin/sh
rosrun rosbag_name node_name (e.g. rosrun turble nin_turtle)
- add the excuteble permisiton by run :“chmod +x ros_run.sh”
需要配置地方2:
#inlcude <stdio.h>
...
int i = 0; // can not execute this line repeatedly !
...
if((execute condtion) && (i==0))
{
i = i + 1; // control the time of executeing, generally one time !
std::string DropWaterCommand = "ros_run.sh address string ";
FILE *pp = popen(DropWaterCommand.c_str(), "r");
if (pp !=NULL)
{
ROS_INFO("shell open success !");
}
else
{
ROS_INFO("shell open error!");
}
}
该方法,只需要一次编译,此后如果执行指令发生了改变则只需要修改 ros_run.sh 文件中的节点执行指令即可,别忘记了添加可执行权限 ! good luck !