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

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

asked 2019-11-10 06:42:00 -0600

wintermute gravatar image

Hello,

I made a basic script that takes apriltag_ros /tag_detections 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 robot_pose_ekf, 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.

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
1

answered 2019-11-13 13:05:00 -0600

jschornak gravatar image

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.

edit flag offensive delete link more

Question Tools

2 followers

Stats

Asked: 2019-11-10 06:42:00 -0600

Seen: 862 times

Last updated: Nov 13 '19