Robotics StackExchange | Archived questions

how can a python script connect to 2 rosmasters at the same time?

Hello,

I made a basic script that takes apriltagros /tagdetections topic and republishes it as odometry data. The python script is as follows:

#!/usr/bin/env python
import roslib;
import rospy
from apriltag_ros.msg import AprilTagDetectionArray
from nav_msgs.msg import Odometry

class OdomApril():
def __init__(self):
    rospy.init_node('odom_april', anonymous=False)
    self.april_pub = rospy.Publisher('/odom_april', Odometry, queue_size=128)
    rospy.wait_for_message('/tag_detections', AprilTagDetectionArray)
    rospy.Subscriber('/tag_detections', AprilTagDetectionArray, self.pub_april_odom)
    rospy.loginfo("Publishing april odometry on /odom_april")

def pub_april_odom(self, msg):
    odom = Odometry()
    if(msg.detections):
      odom.header = msg.header
      odom.child_frame_id = 'base_footprint'
  odom.pose = msg.detections[0].pose.pose
      self.april_pub.publish(odom)

if __name__ == '__main__':
try:
    OdomApril()
    rospy.spin()
except:
    pass

I am running a robot, with robotposeekf, imu, and odometry in the raspberry pi on board the robot. However I am running apriltag_ros software in a laptop, attached to a ceiling mounted camera.

my purpose is to visualize both the robots odomety, and the apriltag based odometry in the same rviz.

Could it be possible for a python program, to subscribe to one ros master, and then publish to another ros master?

Best regards, C.A.

Asked by wintermute on 2019-11-10 07:42:00 UTC

Comments

Answers

Taking a step back from the question you've asked and looking at the underlying goal of your application, I think this is a case where you'd want to take advantage of ROS's support for distributed systems. Rather than running separate ROS masters on each machine and trying to communicate between them, you'd run a single ROS master on one machine and tell the second machine how to find the master over the network connection.

There are two tutorials that I've found helpful for figuring out how to do this: Network Setup, and Multiple Machines. The wiki page on the rolaunch xml <machine> tag provides useful info on starting nodes on multiple machines from a single launch file.

Asked by jschornak on 2019-11-13 14:05:00 UTC

Comments