0
$\begingroup$

I'm interested in building a multi-robot learning environment using a simulator such as Gym for the environment and ROS 1 for handling communication between robots.

I'd like to set up my environment to be something like this:

class Robot():
    def __init__(self, name):
        self.name = name
        self.data = None 

        rospy.init_node(name)
        rospy.Subscriber('/data', Data, self.callback)
        self.pub = rospy.Publisher('/data', Data, queue_size=1)

    def callback(self, data):
        self.data = data

    def step(self):
        # Not Implemented
        pass


if __name__ == '__main__':
    rospy.init_node('multirobot_env')
    xml_file = 'multirobot.xml'
    env = gym.make(xml_file)
    env.reset()

    robots = [Robot('robot0'), Robot('robot1')]

    while not rospy.is_shutdown():
        done = env.step(robots[0].state, robots[1].state)
        for robot in robots:
            robot.step() 

where I have a class defining each robot, and each robot has its own node for computation (and can publish/subscribe to the same topic for sharing data with one another). I also want a separate node to handle computation for the environment.

Code similar to the above will not run, because multiple ROS nodes would be launched in the same Python subprocess.

I know how to do something like the above using ROS Launch files but the problem with this method is that I will not have direct access to the objects representing the robots (I'd like the environment to be able to directly access the robots' states etc. to keep everything synced up instead of having to receive them via ROS topics).

Is it possible to do something like I've described above using ROS 1?

$\endgroup$

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.