Esempio n. 1
0
def main(argv):
    """Main function"""

    cyber.init("data_extractor")
    extractor = Extractor()

    valid_record_list = extractor.validate_record_files(kword='.record.')

    channels, extraction_rates = extractor.parse_channel_config()
    print(f'parsing the following channels: {channels}')

    output_tmp_path = extractor.create_tmp_directory()
    extractor.extract_data(valid_record_list, output_tmp_path, channels,
                           extraction_rates)

    output_abs_path = extractor.reorganize_extracted_data(
        tmp_data_path=output_tmp_path, remove_input_data_cache=True)

    print('Data extraction is completed successfully!')
    extractor.sanity_check_path(output_abs_path)
    cyber.shutdown()
    sys.exit(0)
Esempio n. 2
0
def topic_publisher(topic, filename, period):
    """publisher"""
    cyber.init()
    node = cyber.Node("replay_file")
    meta_msg = None
    msg = None
    if not topic:
        print("Topic not specified, start to guess")
        meta_msg, msg = g_message_manager.parse_file(filename)
        topic = meta_msg.topic()
    else:
        meta_msg = g_message_manager.get_msg_meta_by_topic(topic)
        if not meta_msg:
            print("Failed to find meta info for topic: %s" % (topic))
            return False
        msg = meta_msg.parse_file(filename)
        if not msg:
            print("Failed to parse file[%s] with topic[%s]" %
                  (filename, topic))
            return False

    if not msg or not meta_msg:
        print("Unknown topic: %s" % topic)
        return False

    writer = node.create_writer(topic, meta_msg.msg_type)

    if period == 0:
        while not cyber.is_shutdown():
            input("Press any key to publish one message...")
            writer.write(msg)
            print("Topic[%s] message published" % topic)
    else:
        print("started to publish topic[%s] message with rate period %s" %
              (topic, period))
        while not cyber.is_shutdown():
            writer.write(msg)
            time.sleep(period)
Esempio n. 3
0
    header = record_pb2.Header()
    header.ParseFromString(header_msg)

    print('\n++++++++++++Begin Channel Info Statistics++++++++++++++')
    print('-' * 40)
    print('record version: [%d:%d]' %
          (header.major_version, header.minor_version))
    print('record message_number: %s' % str(header.message_number))
    print('record file size(Byte): %s' % str(header.size))
    print('chunk_number: %d' % header.chunk_number)
    print('channel count: %d' % len(channels))
    print('-' * 40)
    count = 0
    for channel in channels:
        desc = freader.get_protodesc(channel)
        count += 1
        print('Channel: %s, count: %d, desc size: %d' %
              (channel, count, len(desc)))
        # print(desc)
    print("++++++++++++Finish Channel Info Statistics++++++++++++++\n")


if __name__ == '__main__':
    if len(sys.argv) < 2:
        print('Usage: %s record_file' % sys.argv[0])
        sys.exit(0)

    cyber.init()
    print_channel_info(sys.argv[1])
    cyber.shutdown()
Esempio n. 4
0
def main(argv):
    cyber.init("Preprocessor")
    preprocessor = Preprocessor()
    task_dir = preprocessor.create_tree()
    preprocessor.sanity_check_path(task_dir)
    cyber.shutdown()
Esempio n. 5
0
from cyber.proto.unit_test_pb2 import ChatterBenchmark


def test_talker_class():
    """
    Test talker.
    """
    msg = ChatterBenchmark()
    msg.content = "py:talker:send Alex!"
    msg.stamp = 9999
    msg.seq = 0
    print(msg)
    test_node = cyber.Node("node_name1")
    g_count = 1

    writer = test_node.create_writer("channel/chatter", ChatterBenchmark, 6)
    while not cyber.is_shutdown():
        time.sleep(1)
        g_count = g_count + 1
        msg.seq = g_count
        msg.content = "I am python talker."
        print("=" * 80)
        print("write msg -> %s" % msg)
        writer.write(msg)


if __name__ == '__main__':
    cyber.init("talker_sample")
    test_talker_class()
    cyber.shutdown()
Esempio n. 6
0
def listener():
    cyber.init()
    test_node = cyber.Node("planning_acc_listener")
    test_node.create_reader("/apollo/planning", planning_pb2.ADCTrajectory,
                            callback)
Esempio n. 7
0
def perception_receiver(perception_channel):
    """publisher"""
    cyber.init()
    node = cyber.Node("perception")
    node.create_reader(perception_channel, PerceptionObstacles, receiver)
    node.spin()
Esempio n. 8
0
def main(argv):
    """Main function"""
    argv = FLAGS(argv)

    print("""
    Keyboard Shortcut:
        [q]: Quit Tool
        [s]: Save Figure
        [a]: Auto-adjust x, y axis to display entire plot
        [x]: Update Figure to Display last few Planning Trajectory instead of all
        [h][r]: Go back Home, Display all Planning Trajectory
        [f]: Toggle Full Screen
        [n]: Reset all Plots
        [b]: Unsubscribe Topics

    Legend Description:
        Red Line: Current Planning Trajectory
        Blue Line: Past Car Status History
        Green Line: Past Planning Target History at every Car Status Frame
        Cyan Dashed Line: Past Planning Trajectory Frames
    """)
    cyber.init()
    planning_sub = cyber.Node("stat_planning")

    fig = plt.figure()

    if not FLAGS.show_st_graph:
        ax1 = plt.subplot(2, 2, 1)
        item1 = Xyitem(ax1, WindowSize, VehicleLength, "Trajectory", "X [m]",
                       "Y [m]")

        ax2 = plt.subplot(2, 2, 2)
        item2 = Item(ax2, "Speed", "Time [sec]", "Speed [m/s]", 0, 30)

        ax3 = plt.subplot(2, 2, 3, sharex=ax2)
        item3 = Item(ax3, "Curvature", "Time [sec]", "Curvature [m-1]", -0.2,
                     0.2)

        ax4 = plt.subplot(2, 2, 4, sharex=ax2)
        if not FLAGS.show_heading:
            item4 = Item(ax4, "Acceleration", "Time [sec]",
                         "Acceleration [m/sec^2]", -5, 5)
        else:
            item4 = Item(ax4, "Heading", "Time [sec]", "Heading [radian]", -4,
                         4)
    else:
        ax1 = plt.subplot(2, 2, 1)
        item1 = Stitem(ax1, "ST Graph", "Time [sec]", "S [m]")

        ax2 = plt.subplot(2, 2, 2)
        item2 = Stitem(ax2, "ST Graph", "Time [sec]", "S [m]")

        ax3 = plt.subplot(2, 2, 3)
        item3 = Stitem(ax3, "ST Graph", "Time [sec]", "S [m]")

        ax4 = plt.subplot(2, 2, 4)
        item4 = Stitem(ax4, "ST Graph", "Time [sec]", "S [m]")

    plt.tight_layout(pad=0.20)
    plt.ion()
    plt.show()

    plotter = Plotter(item1, item2, item3, item4, FLAGS.show_st_graph)
    fig.canvas.mpl_connect('key_press_event', plotter.press)
    planning_sub.create_reader('/apollo/planning',
                               ADCTrajectory, plotter.callback_planning)
    if not FLAGS.show_st_graph:
        localization_sub = cyber.Node("localization_sub")
        localization_sub.create_reader('/apollo/localization/pose',
                                       LocalizationEstimate, plotter.callback_localization)
        chassis_sub = cyber.Node("chassis_sub")
        chassis_sub.create_reader('/apollo/canbus/chassis',
                                  Chassis, plotter.callback_chassis)

    while not cyber.is_shutdown():
        ax1.draw_artist(ax1.patch)
        ax2.draw_artist(ax2.patch)
        ax3.draw_artist(ax3.patch)
        ax4.draw_artist(ax4.patch)

        with plotter.lock:
            item1.draw_lines()
            item2.draw_lines()
            item3.draw_lines()
            item4.draw_lines()

        fig.canvas.blit(ax1.bbox)
        fig.canvas.blit(ax2.bbox)
        fig.canvas.blit(ax3.bbox)
        fig.canvas.blit(ax4.bbox)
        fig.canvas.flush_events()
Esempio n. 9
0
def main(args):
    audio_event_meta_msg = g_message_manager.get_msg_meta_by_topic(
        args.audio_event_topic)
    if not audio_event_meta_msg:
        print('Unknown audio_event topic name: %s' % args.audio_event_topic)
        sys.exit(1)

    localization_meta_msg = g_message_manager.get_msg_meta_by_topic(
        args.localization_topic)
    if not localization_meta_msg:
        print('Unknown localization topic name: %s' % args.localization_topic)
        sys.exit(1)

    cyber.init()
    node = cyber.Node("audio_event_node")
    node.create_reader(localization_meta_msg.topic,
                       localization_meta_msg.msg_type, OnReceiveLocalization)

    writer = node.create_writer(audio_event_meta_msg.topic,
                                audio_event_meta_msg.msg_type)
    seq_num = 0
    while not cyber.is_shutdown():
        obstacle_id = input(
            "Type in obstacle ID and press Enter (current time: " +
            str(datetime.datetime.now()) + ")\n>")
        obstacle_id = obstacle_id.strip()
        # TODO(QiL) add obstacle id sanity check.
        current_time = cyber_time.Time.now().to_sec()
        moving_result = None
        audio_type = None
        siren_is_on = None
        audio_direction = None
        while not moving_result:
            moving_result = input("Type MovingResult:>")
            moving_result = moving_result.strip()
        while not audio_type:
            audio_type = input("Type AudioType:>")
            audio_type = audio_type.strip()
        while not siren_is_on:
            siren_is_on = input("Type SirenOnOffStatus:>")
            siren_is_on = siren_is_on.strip()
        while not audio_direction:
            audio_direction = input("Type AudioDirection:>")
            audio_direction = audio_direction.strip()
        event_msg = audio_event_meta_msg.msg_type()
        event_msg.header.timestamp_sec = current_time
        event_msg.header.module_name = 'audio_event'
        seq_num += 1
        event_msg.header.sequence_num = seq_num
        event_msg.header.version = 1
        event_msg.id = obstacle_id
        event_msg.moving_result = moving_result
        event_msg.audio_type = audio_type
        event_msg.siren_is_on = siren_is_on
        event_msg.audio_direction = audio_direction
        if g_localization:
            event_msg.location.CopyFrom(g_localization.pose)
        writer.write(event_msg)
        time_str = datetime.datetime.fromtimestamp(current_time).strftime(
            "%Y%m%d%H%M%S")
        filename = os.path.join(args.dir, "%s_audio_event.pb.txt" % time_str)
        proto_utils.write_pb_to_text_file(event_msg, filename)
        print('Logged to rosbag and written to file %s' % filename)
        time.sleep(0.1)
Esempio n. 10
0
 def setUpClass(cls):
     cyber.init()
Esempio n. 11
0
def listener():
    cyber.init()
    test_node = cyber.Node("chassis_acc_listener")
    test_node.create_reader("/apollo/canbus/chassis", chassis_pb2.Chassis,
                            callback)