一个ROS节点在运行中如何开启另外一个节点 ?(C/C++)

本人在项目中需要在运行一个ROS 节点的过程中,在特定时刻触发和启动另外一个ROS 节点开始执行,这里提供一种只需一次编译的方法。

两个地方需要配置:

需要配置地方1:

  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)
  1. 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 !

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值