我正在使用機器人操作系統(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
沒問題。我很欣賞反饋! –