ROS错误。处理请求时出错:信号仅在主线程";中工作。
问题描述
我正在使用Robot操作系统(ROS),并尝试创建一个服务器/客户端,其中服务器将引导客户端指定的ROS节点。要执行"启动",我使用的是基于以下建议的rosLaunch:http://wiki.ros.org/roslaunch/API%20Usage
我可以在窗口中运行rocore,然后我可以运行启动良好的服务器。但是,只要我尝试通过客户端发送要引导的节点名,就会收到以下错误:
"错误处理请求:信号仅在主线程中工作"
然后它指向一些我尚未追踪到的各个领域的文件。
我已经尝试在我为要启动的节点(在本例中为turtlesim_node和turtle_telop_key)单独创建的每个启动文件上使用一个简单的rosunch调用,它们启动良好,只需运行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.
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>
我在谷歌上搜索了一下,没有发现ROS有类似的问题(尽管Django等有一些类似的错误,但它们没有关联)。
感谢您的帮助!
附注。值得注意的是,当出现错误时,我会转到第34行(process=Launch.Launch(Node))。
解决方案
实际上是文档中提到的
您没有从Python主线程调用init_node()。Python仅允许从主线程注册信号。
查看此处rospyOverviewInitialization and Shutdown
相关文章