Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/363.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在一个python脚本中运行ros.init_node()?_Python_Linux_Ros - Fatal编程技术网

如何在一个python脚本中运行ros.init_node()?

如何在一个python脚本中运行ros.init_node()?,python,linux,ros,Python,Linux,Ros,我已经用python和ROS编写了一个程序。它包含一个用于“机器人远程操作”的GUI,在主窗口中我添加了3个小部件(rviz、操纵杆、按钮面板)。启动MainWindow时,出现以下错误: raise rospy.exceptions.ROSException(“rospy.init_node()已经用不同的参数调用:”+str(_init_node_args)) rospy.exceptions.ROSException:rospy.init_node()已被删除 使用不同的参数调用:('te

我已经用python和ROS编写了一个程序。它包含一个用于“机器人远程操作”的GUI,在主窗口中我添加了3个小部件(rviz、操纵杆、按钮面板)。启动MainWindow时,出现以下错误:

raise rospy.exceptions.ROSException(“rospy.init_node()已经用不同的参数调用:”+str(_init_node_args))

rospy.exceptions.ROSException:rospy.init_node()已被删除 使用不同的参数调用:('teleop_twist_keyboard', ['MainWindow.py'],False,None,False,False)

mogage.py和Button.py包含
ros.init_node()
函数。在MainWindow中,我实例化了操纵杆和按钮类,并将它们添加到MainWindow中。我需要多次调用
ros.init\u node()
与各个节点通信

在程序中只能初始化一次。您应该在主脚本的开头集中节点的初始化,其余导入的模块不应该尝试初始化新节点,因为这是不允许的


如果您希望不同的子模块处理不同的数据,那么您应该在同一节点中创建单独的主题。

在导入语句之前,将其放在脚本顶部的某个位置

import os 
os.system("rosrun my_package_name my_node_script.py")

你好,卢卡,欢迎来到StackOverflow!为了帮助您,您应该直接将代码添加到文章中,而不是粘贴图像。看看感谢,我认为总是
rospy.Publisher()
有自己的
ros.init\u node()
。一切正常。不,节点是父进程,它可以包含任意数量的发布者和订阅者。我很高兴这有帮助
import PyQt5
import rospy
from std_msgs.msg import String


class BaseArmPosition(PyQt5.QtWidgets.QWidget):
    def __init__(self, *args, **kwargs):
        super(BaseArmPosition, self).__init__(*args, **kwargs)            
        self.initUI()

    def initUI(self):
        self.pushButton_moveInit = PyQt5.QtWidgets.QPushButton("moveInit",self)
        self.pushButton_moveLeft = PyQt5.QtWidgets.QPushButton("moveLeft",self)
        self.pushButton_moveRight = PyQt5.QtWidgets.QPushButton("moveRight",self)

        layout = PyQt5.QtWidgets.QVBoxLayout(self)
        layout.addWidget(self.pushButton_moveRight)
        layout.addWidget(self.pushButton_moveLeft)
        layout.addWidget(self.pushButton_moveInit)

        self.pushButton_moveInit.clicked.connect(self.moveInit)
        self.pushButton_moveLeft.clicked.connect(self.moveLeft)
        self.pushButton_moveRight.clicked.connect(self.moveRight)

        rospy.init_node("controller_ur")
        self.pub_arm = rospy.Publisher("/controller_ur/order",String,queue_size=1)

    def moveInit(self):
        moveInit = "moveInit"
        msg = String()
        msg.data = moveInit
        self.pub_arm.publish(moveInit)

    def moveLeft(self):
        moveInit = "moveLeft"
        msg = String()
        msg.data = moveInit
        self.pub_arm.publish(moveInit)

    def moveRight(self):
        moveInit = "moveRight"
        msg = String()
        msg.data = moveInit
        self.pub_arm.publish(moveInit)
import os 
os.system("rosrun my_package_name my_node_script.py")