ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question

Revision history [back]

I have a similar project, it works like that:

  1. Inside the project folder, I have a folder called packages, with a __init__.py inside. It's empty, just to make the module available
  2. In the packages folder yet, a file called initialize.py, where I have:

    import rospy as _rospy from std_msgs.msg import String as _String, Empty as _Empty

    def init():

        _rospy.init_node('controller', anonymous=True)
        global _sub
        _sub = _rospy.Subscriber("/model_name", _String, _nameCallback)
        global _pub
        _pub = _rospy.Publisher(_controllerName+'/encoder_updated',_Empty)
    

List item

  1. In the root folder, my script that imports the initialize library:

    import packages.initialize

    initialize.init()

I have a similar project, it works like that:

  1. Inside the project folder, I have a folder called packages, with a __init__.py inside. It's empty, just to make the module available
  2. In the packages folder yet, a file called initialize.py, where I have:

    import rospy as _rospy from std_msgs.msg import String as _String, Empty as _Empty

    def init():

        _rospy.init_node('controller', anonymous=True)
        global _sub
        _sub = _rospy.Subscriber("/model_name", _String, _nameCallback)
        global _pub
        _pub = _rospy.Publisher(_controllerName+'/encoder_updated',_Empty)
    

List item

  1. In the root folder, my script that imports the initialize library:

    import packages.initialize

    initialize.init()