def main():
    # Get parameters
    bundle_topic = rospy.get_param('~bundle_topic', '/bc/bundle')
    src_bag_path = rospy.get_param('~source_bag_path', None)
    backchannel_topic = rospy.get_param('~backchannel_topic', '/bc/backchannels')
    sink_bag_path = rospy.get_param('~sink_bag_path', None)

    # Instantiate source
    if src_bag_path:
        bundle_source = BagSource(src_bag_path, bundle_topic)
    else:
        bundle_source = TopicSource(bundle_topic, Bundle)

    # Instantiate sinks
    if sink_bag_path:
        bag = rosbag.Bag(sink_bag_path, 'w')
        backchannel_sink = BagSink(bag, backchannel_topic, Backchannel)
    else:
        bag = None
        backchannel_sink = TopicSink(backchannel_topic, Backchannel)

    with conditional(bag, bag):
        with bundle_source, backchannel_sink:
            for msg, t in bundle_source:
                if random.random() > 0.2:
                    backchannel_msg = Backchannel()
                    backchannel_msg.header.stamp = t
                    pids = [1,2,3]
                    to_pid = random.choice(pids)
                    pids.remove(to_pid)
                    from_pid = random.choice(pids)
                    backchannel_msg.to_pid = to_pid
                    backchannel_msg.from_pid = from_pid
                    backchannel_sink.put(backchannel_msg, t)
Ejemplo n.º 2
0
def main():
    # Get parameters
    bundle_topic = rospy.get_param('~bundle_topic', '/bc/bundle')
    src_bag_path = rospy.get_param('~source_bag_path', None)
    csv_path = rospy.get_param('~csv_path')

    # Instantiate source
    if src_bag_path:
        bundle_source = BagSource(src_bag_path, bundle_topic)
    else:
        bundle_source = TopicSource(bundle_topic, Bundle)

    with bundle_source, open(csv_path, 'w') as csv_file:
        writer = None
        for msg, t in bundle_source:
            row = bundle_msg_to_dict(msg)
            for key in row.keys():
                if row[key] == 'True':
                    row[key] = 1
                elif row[key] == 'False':
                    row[key] = 0
            row['time'] = t.to_sec()
            pairwise_rows = create_pairwise_rows(row)
            if not writer:
                headers = pairwise_rows[0].keys()
                writer = csv.DictWriter(csv_file, headers)
                writer.writeheader()
            for pairwise_row in pairwise_rows:
                writer.writerow(pairwise_row)
Ejemplo n.º 3
0
def main():
    input_topic = rospy.get_param('~input_topic')
    threadsafe = rospy.get_param('~threadsafe', False)
    dst = rospy.get_param('~dst', 'out.wav')

    source = TopicSource(input_topic, AudioData)
    wf = None
    with source:
        for msg, t in source:
            if not wf:
                wf = wave.open(dst, 'wb')
                wf.setnchannels(msg.num_channels)
                wf.setframerate(msg.sample_rate)
                wf.setsampwidth(msg.sample_width)
            if msg.is_bigendian:
                # Wave files are little-endian
                msg.data = switch_endianness(data=msg.data,
                                             width=msg.sample_width)
            wf.writeframes(msg.data)
Ejemplo n.º 4
0
 def test_topic(self):
     from std_msgs.msg import String
     rospy.init_node('test_topic', anonymous=True)
     topic = '/test_topic'
     source = TopicSource(topic, String)
     sink = TopicSink(topic, String)
     pub = rospy.Publisher(topic, String)
     with source, sink:
         while pub.get_num_connections() < 1:
             rospy.sleep(2)
         test_strs = ['a', 'b', 'c']
         for s in test_strs:
             sink.put(s, rospy.Time.now())
         for msg, t in source:
             self.assertTrue(msg.data in test_strs)
             i = test_strs.index(msg.data)
             test_strs.pop(i)
             if not test_strs:
                 return