我正在使用机器人操作系统(ROS),并且正在尝试制作服务器/客户机,其中服务器将启动由客户机指定的ROS节点。要执行“启动”我使用roslaunch基于这里找到的建议:http://wiki.ros.org/roslaunch/API%20UsageROS错误。 “错误处理请求:信号只在主线程中起作用”
我可以在窗口中运行roscore,然后我可以运行服务器启动罚款。然而,当我尝试发送我想通过客户端启动的节点名称,我得到以下错误:
“错误处理请求:信号只能在主线程”
它然后指向我还没有追踪的各个领域的一堆文件。
我试过对每个启动文件使用一个简单的roslaunch调用,我分别为我想要启动的节点(在本例中为turtlesim_node和turtle_teleop_key)启动,它们启动正常,只需运行roslaunch [package] turtlesim_launch.launch等
下面是我的服务器代码:
#!/usr/bin/env python
#Filename: primary_server.py
import rospy
import roslaunch
from robot_man.srv import *
class StartUpServer(object):
def __init__(self):
self._nodes = []
def handle_startup(self, names):
self._temp = names.nodes.split(",") #This reades in the
# information from the srv file sent by the client and
# separates each node/package pair
#This loop separates the input from pairs of 2 corresponding
# to the package and node names the user inputs
for i in range(len(self._temp)):
self._nodes.append(self._temp[i].split())
#This loop will launch each node that the user has specified
for package, executable in self._nodes:
print('package is: {0}, executable is: {1}'.format(package, executable))
node = roslaunch.core.Node(package, executable)
launch = roslaunch.scriptapi.ROSLaunch()
launch.start()
process = launch.launch(node)
print('running node: %s'%executable)
return StartUpResponse(self._nodes) #I will change this later
if __name__ == '__main__':
rospy.init_node('startup_node')
server = StartUpServer()
rospy.Service('startup', StartUp, server.handle_startup)
print('The servers are up and running')
rospy.spin()
这里是我的客户代码:
#!/usr/bin/env python
#Filename: primary_client_startup.py
import rospy
from robot_man.srv import *
def main(nodes):
rospy.wait_for_service('startup')
proxy = rospy.ServiceProxy('startup', StartUp)
response = proxy(nodes)
return response
if __name__ == '__main__':
nodes = input('Please enter the node packages followed by \
node names separated by spaces. \n To activate multiple nodes \
separate entries with a comma > ')
main(nodes)
这是我的SRV文件:
#This should be a string of space/comma separated values
string nodes
---
#This should return "success" if node/s start up successfully, else "fail"
string status
最后,这里是我已经发动龟模拟器两个发射文件:
turtlesim_launch.launch
<launch>
<node name="turtlesim_node" pkg="turtlesim" type="turtlesim_node" />
</launch>
turtle_teleop_launch.launch
<launch>
<node name="turtle_teleop_key" pkg="turtlesim" type="turtle_teleop_key" />
</launch>
我已经做了一些谷歌搜索,发现没有类似的问题fo ROS(虽然Django等存在一些类似的错误,但它们没有关联)。
我很感激帮助!
P.S.值得注意的是,当错误发生时(流程= launch.launch(node)),我将它设置为第34行。
嗯,好的呼叫。你知道一种使用类似方法远程初始化节点的方法吗? –
我堕入同一陷阱,这就是为什么我找到你的问题。我认为这篇文章中的大型启动文件http://wiki.ros.org/ROS/Tutorials/Roslaunch%20tips%20for%20larger%20projects在gerneal中是一个很好的解决方案,或者你可以在Discourse.ros.org上询问解决方案。对不起,我其实不知道 – user3732793
没问题。我很欣赏反馈! –