예제 #1
0
    def test_read_write(self):
        """
        Unit test of reader.
        """
        self.assertTrue(cyber.ok())
        # Read.
        reader_node = cyber.Node("listener")
        reader = reader_node.create_reader("channel/chatter", SimpleMessage,
                                           self.callback)
        self.assertEqual(reader.name, "channel/chatter")
        self.assertEqual(reader.data_type, SimpleMessage)
        self.assertEqual(SimpleMessage.DESCRIPTOR.full_name,
                         "apollo.common.util.test.SimpleMessage")

        # Write.
        msg = SimpleMessage()
        msg.text = "talker:send Alex!"
        msg.integer = 0

        self.assertTrue(cyber.ok())
        writer_node = cyber.Node("writer")
        writer = writer_node.create_writer("channel/chatter", SimpleMessage, 7)
        self.assertEqual(writer.name, "channel/chatter")
        self.assertEqual(writer.data_type,
                         "apollo.common.util.test.SimpleMessage")
        self.assertTrue(writer.write(msg))

        # Wait for data to be processed by callback function.
        time.sleep(0.1)
예제 #2
0
def gnss_simulation(q):
    cyber.init()
    #rospy.init_node("pose_offline",anonymous=True)
    node = cyber.Node("pose_offline")

    #localization_pub = rospy.Publisher(
    #	"/apollo/localization/pose",localization_pb2.LocalizationEstimate,queue_size=1)
    localization_pub = node.create_writer(
        "/apollo/localization/pose", localization_pb2.LocalizationEstimate)

    #generate localization info
    LocalizationEstimate = localization_pb2.LocalizationEstimate()

    #send pose to /apollo/localization/pose
    count = 0
    #r = rospy.Rate(20)
    #while not rospy.is_shutdown():
    while not cyber.is_shutdown():
        now = time.time()
        #localization_pub.publish(gps_list(LocalizationEstimate,count,q))
        localization_pub.write(gps_list(LocalizationEstimate, count, q))
        sleep_time = 0.05 - (time.time() - now)
        if sleep_time > 0:
            time.sleep(sleep_time)
        count += 1
예제 #3
0
def main():
    cyber.init("fault_injector")
    fault_injector_node = cyber.Node("fault_injector")
    writer = fault_injector_node.create_writer(
        "/apollo/sensor/camera/front_6mm/image", Image)

    for image_file in read_image_list():
        image = cv2.imread(DATASET_FOLDER + IMAGES_FOLDER + image_file)
        image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
        #image = cv2.resize(image, (1920, 1080), 1.0, 1.0, cv2.INTER_CUBIC)

        image = adjust_contrast_brightness(image, 2.0, 50.0)

        image_frame = np.zeros((1080, 1920, 3), dtype="uint8")
        image_frame[OFFSET_Y:OFFSET_Y + image.shape[0],
                    OFFSET_X:OFFSET_X + image.shape[1]] = image

        proto_image = Image()
        proto_image.header.frame_id = "front_6mm"
        proto_image.header.timestamp_sec = cyber.time.time()
        proto_image.measurement_time = cyber.time.time()
        proto_image.width = image_frame.shape[1]
        proto_image.height = image_frame.shape[0]
        proto_image.encoding = "rgb8"
        proto_image.step = 3 * image_frame.shape[1]
        proto_image.data = image_frame.tobytes()

        writer.write(proto_image)

        time.sleep(0.2)
    cyber.shutdown()
예제 #4
0
def main():
    """
    Main rosnode
    """
    cyber.init()
    node = cyber.Node("mock_routing_requester")
    sequence_num = 0

    routing_request = routing_pb2.RoutingRequest()

    routing_request.header.timestamp_sec = time.time()
    routing_request.header.module_name = 'routing_request'
    routing_request.header.sequence_num = sequence_num
    sequence_num = sequence_num + 1

    waypoint = routing_request.waypoint.add()
    waypoint.pose.x = 587696.82286
    waypoint.pose.y = 4141446.66696
    waypoint.id = '1-1'
    waypoint.s = 1

    waypoint = routing_request.waypoint.add()
    waypoint.pose.x = 586948.740120
    waypoint.pose.y = 4141171.118641
    waypoint.id = '1-1'
    waypoint.s = 80

    writer = node.create_writer('/apollo/routing_request',
                                routing_pb2.RoutingRequest)
    time.sleep(2.0)
    print("routing_request", routing_request)
    writer.write(routing_request)
예제 #5
0
    def __init__(self, carla_world, params):
        """
        Constructor

        :param carla_world: carla world object
        :type carla_world: carla.World
        :param params: dict of parameters, see settings.yaml
        :type params: dict
        """
        cyber.init()
        self.cyber_node = cyber.Node('carla_cyber_client_node')
        self.params = params
        self.use_object_sensor = self.params.get("object_sensor") is not None
        super(CarlaCyberBridge, self).__init__(carla_id=0,
                                               carla_world=carla_world,
                                               frame_id='/map')

        self.timestamp_last_run = 0.0
        self.tf_to_publish = []
        self.msgs_to_publish = []
        self.actor_list = []
        self.map = self.carla_world.get_map()

        # register callback to create/delete actors
        self.update_child_actors_lock = threading.Lock()
        self.carla_world.on_tick(self._carla_update_child_actors)

        # register callback to update actors
        self.update_lock = threading.Lock()
        self.carla_world.on_tick(self._carla_time_tick)

        self.writers = {}
예제 #6
0
def listener():
    cyber.init()
    test_node = cyber.Node("control_listener")
    test_node.create_reader("/apollo/control",
                            control_cmd_pb2.ControlCommand, callback)
    test_node.spin()
    cyber.shutdown()
예제 #7
0
def main(argv):
    """
    Main node
    """
    node = cyber.Node("rtk_recorder")
    argv = FLAGS(argv)
    log_dir = os.path.dirname(os.path.abspath(__file__)) + "/../../../data/log/"
    if not os.path.exists(log_dir):
        os.makedirs(log_dir)
    Logger.config(
        log_file=log_dir + "rtk_recorder.log",
        use_stdout=True,
        log_level=logging.DEBUG)
    print("runtime log is in %s%s" % (log_dir, "rtk_recorder.log"))
    record_file = log_dir + "/garage.csv"
    recorder = RtkRecord(record_file)
    atexit.register(recorder.shutdown)
    node.create_reader('/apollo/canbus/chassis', chassis_pb2.Chassis,
                     recorder.chassis_callback)

    node.create_reader('/apollo/localization/pose',
                     localization_pb2.LocalizationEstimate,
                     recorder.localization_callback)

    while not cyber.is_shutdown():
        time.sleep(0.002)
예제 #8
0
def test_listener_class():
    """
    Reader message.
    """
    print "=" * 120
    test_node = cyber.Node("listener")
    test_node.create_reader("channel/chatter", SimpleMessage, callback)
    test_node.spin()
예제 #9
0
파일: listener.py 프로젝트: dustinksi/Edith
def test_listener_class():
    """
    Reader message.
    """
    print("=" * 120)
    test_node = cyber.Node("listener")
    test_node.create_reader("channel/chatter", ChatterBenchmark, callback)
    test_node.spin()
예제 #10
0
def test_service_class():
    """
    Reader message.
    """
    print "=" * 120
    node = cyber.Node("service_node")
    r = node.create_service("server_01", ChatterBenchmark, ChatterBenchmark,
                            callback)
    node.spin()
예제 #11
0
    def test_params(self):
        param1 = parameter.Parameter("author_name", "WanderingEarth")
        param2 = parameter.Parameter("author_age", 5000)
        param3 = parameter.Parameter("author_score", 888.88)

        test_node = cyber.Node(PARAM_SERVICE_NAME)
        srv = parameter.ParameterServer(test_node)

        node_handle = cyber.Node("service_client_node")
        clt = parameter.ParameterClient(test_node, PARAM_SERVICE_NAME)
        clt.set_parameter(param1)
        clt.set_parameter(param2)
        clt.set_parameter(param3)

        param_list = clt.get_paramslist()
        self.assertEqual(3, len(param_list))
        param_list = srv.get_paramslist()
        self.assertEqual(3, len(param_list))
예제 #12
0
def main():
    print("potential_field_planning start")

    cyber.init()
    planning_node = cyber.Node("planning_potential")
    _ = planning(planning_node)

    planning_node.spin()
    cyber.shutdown()
예제 #13
0
def main():
    """
    Main rosnode
    """
    node = cyber.Node('ins_stat_publisher')
    ins_stat = InsStat(node)
    while not cyber.is_shutdown():
        now = cyber_time.Time.now().to_sec()
        ins_stat.publish_statmsg()
        sleep_time = 0.5 - (cyber_time.Time.now().to_sec() - now)
        if sleep_time > 0:
            time.sleep(sleep_time)
예제 #14
0
 def test_reader(self):
     """
     Unit test of reader.
     """
     self.assertTrue(cyber.ok())
     test_node = cyber.Node("listener")
     reader = test_node.create_reader("channel/chatter", SimpleMessage,
                                      callback)
     self.assertEqual(reader.name, "channel/chatter")
     self.assertEqual(reader.data_type, SimpleMessage)
     self.assertEqual(SimpleMessage.DESCRIPTOR.full_name,
                      "apollo.common.util.test.SimpleMessage")
예제 #15
0
def main(args):
    if not os.path.exists(args.out_dir):
        os.makedirs(args.out_dir)
    meta_msg = g_message_manager.get_msg_meta_by_topic(args.topic)
    if not meta_msg:
        print('Unknown topic name: %s' % args.topic)
        sys.exit(1)
    cyber.init()
    node = cyber.Node("transcribe_node")
    node.create_reader(args.topic, meta_msg.msg_type, transcribe)
    while not cyber.is_shutdown():
        time.sleep(0.005)
예제 #16
0
def subscreber_ctrl_pad(client, q_drivemode, q_drivemode2control):
    cyber.init()
    pad = control_pad(client, q_drivemode, q_drivemode2control)
    #rospy.init_node('simulation_control_pad', anonymous=True)
    node = cyber.Node("simulation_control_pad")

    #rospy.Subscriber('/apollo/control/pad', pad_msg_pb2.PadMessage,
    #                 pad.sim_control_pad_callback)
    node.create_reader('/apollo/control/pad', pad_msg_pb2.PadMessage,
                       pad.sim_control_pad_callback)
    #rospy.spin()
    node.spin()
예제 #17
0
def subscreber_ctrl_cmd(client, q_speed, q_drivemode2control, q_gear):
    cyber.init()
    control = control_obj(client, q_speed, q_drivemode2control, q_gear)
    #rospy.init_node('simulation_control', anonymous=True)
    node = cyber.Node("simulation_control")

    #rospy.Subscriber('/apollo/control', control_cmd_pb2.ControlCommand,
    #                 control.sim_control_callback)
    node.create_reader('/apollo/control', control_cmd_pb2.ControlCommand,
                       control.sim_control_callback)

    #rospy.spin()
    node.spin()
예제 #18
0
def main():
    """
    Main rosnode
    """
    node = cyber.Node('odom_publisher')
    odom = OdomPublisher(node)
    node.create_reader('/apollo/localization/pose', localization_pb2.LocalizationEstimate, odom.localization_callback)
    while not cyber.is_shutdown():
        now = cyber_time.Time.now().to_sec()
        odom.publish_odom()
        sleep_time = 0.01 - (cyber_time.Time.now().to_sec() - now)
        if sleep_time > 0:
            time.sleep(sleep_time)
예제 #19
0
def prediction_publisher(prediction_channel, rate):
    """publisher"""
    cyber.init()
    node = cyber.Node("prediction")
    writer = node.create_writer(prediction_channel, PredictionObstacles)
    prediction = PredictionObstacles()
    prediction.header.sequence_num = seq_num
    prediction.header.timestamp_sec = cyber_time.Time.now().to_sec()
    prediction.header.module_name = "prediction"
    i=0
    writer.write(prediction)
    seq_num += 1
    time.sleep(sleep_time)
예제 #20
0
def main():
    """
    Main cyber
    """
    parser = argparse.ArgumentParser(
        description='Generate Planning Trajectory from Data File')
    parser.add_argument(
        '-s',
        '--speedmulti',
        help='Speed multiplier in percentage (Default is 100) ',
        type=float,
        default='100')
    parser.add_argument('-c',
                        '--complete',
                        help='Generate complete path (t/F)',
                        default='F')
    parser.add_argument('-r',
                        '--replan',
                        help='Always replan based on current position(t/F)',
                        default='F')
    args = vars(parser.parse_args())

    node = cyber.Node("rtk_player")

    Logger.config(log_file=os.path.join(APOLLO_ROOT,
                                        'data/log/rtk_player.log'),
                  use_stdout=True,
                  log_level=logging.DEBUG)

    record_file = os.path.join(APOLLO_ROOT, 'data/log/garage.csv')

    player = RtkPlayer(record_file, node, args['speedmulti'],
                       args['complete'].lower(), args['replan'].lower())
    atexit.register(player.shutdown)

    node.create_reader('/apollo/canbus/chassis', chassis_pb2.Chassis,
                       player.chassis_callback)

    node.create_reader('/apollo/localization/pose',
                       localization_pb2.LocalizationEstimate,
                       player.localization_callback)

    node.create_reader('/apollo/control/pad', pad_msg_pb2.PadMessage,
                       player.padmsg_callback)

    while not cyber.is_shutdown():
        now = time.time()
        player.publish_planningmsg()
        sleep_time = 0.1 - (time.time() - now)
        if sleep_time > 0:
            time.sleep(sleep_time)
예제 #21
0
    def test_writer(self):
        """
        unit test of writer.
        """
        msg = SimpleMessage()
        msg.text = "talker:send Alex!"
        msg.integer = 0

        self.assertTrue(cyber.ok())
        test_node = cyber.Node("node_name1")
        writer = test_node.create_writer("channel/chatter", SimpleMessage, 7)
        self.assertEqual(writer.name, "channel/chatter")
        self.assertEqual(writer.data_type, "apollo.common.util.test.SimpleMessage")
        self.assertTrue(writer.write(msg))
예제 #22
0
def main(args):
    drive_event_meta_msg = g_message_manager.get_msg_meta_by_topic(
        args.drive_event_topic)
    if not drive_event_meta_msg:
        print('Unknown drive_event topic name: %s' % args.drive_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("derive_event_node")
    node.create_reader(localization_meta_msg.topic,
                       localization_meta_msg.msg_type, OnReceiveLocalization)

    writer = node.create_writer(drive_event_meta_msg.topic,
                                drive_event_meta_msg.msg_type)
    seq_num = 0
    while not cyber.is_shutdown():
        event_type = input(
            "Type in Event Type('d') and press Enter (current time: " +
            str(datetime.datetime.now()) + ")\n>")
        event_type = event_type.strip()
        if len(event_type) != 1 or event_type[0].lower() != 'd':
            continue
        current_time = cyber_time.Time.now().to_sec()
        event_str = None
        while not event_str:
            event_str = input("Type Event:>")
            event_str = event_str.strip()
        event_msg = drive_event_meta_msg.msg_type()
        event_msg.header.timestamp_sec = current_time
        event_msg.header.module_name = 'drive_event'
        seq_num += 1
        event_msg.header.sequence_num = seq_num
        event_msg.header.version = 1
        event_msg.event = event_str
        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_drive_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)
예제 #23
0
def print_param_srv():
    param1 = parameter.Parameter("author_name", "WanderingEarth")
    param2 = parameter.Parameter("author_age", 5000)
    param3 = parameter.Parameter("author_score", 888.88)

    test_node = cyber.Node(PARAM_SERVICE_NAME)
    srv = parameter.ParameterServer(test_node)

    node_handle = cyber.Node("service_client_node")
    clt = parameter.ParameterClient(test_node, PARAM_SERVICE_NAME)
    clt.set_parameter(param1)
    clt.set_parameter(param2)
    clt.set_parameter(param3)

    param_list = clt.get_paramslist()
    print "clt param lst len is ", len(param_list)
    for param in param_list:
        print param.debug_string()

    print ""
    param_list = srv.get_paramslist()
    print "srv param lst len is ", len(param_list)
    for param in param_list:
        print param.debug_string()
예제 #24
0
def perception_publisher(perception_channel, files, period):
    """publisher"""
    cyber.init()
    node = cyber.Node("perception")
    writer = node.create_writer(perception_channel, PerceptionObstacles)
    perception_description = load_descrptions(files)
    sleep_time = int(1.0 / period)  # 10hz
    global _s_delta_t
    _s_delta_t = period
    perception = None
    while not cyber.is_shutdown():
        perception = generate_perception(perception_description, perception)
        print str(perception)
        writer.write(perception)
        time.sleep(sleep_time)
예제 #25
0
def prediction_publisher(prediction_channel, rate):
    """publisher"""
    cyber.init()
    node = cyber.Node("prediction")
    writer = node.create_writer(prediction_channel, PredictionObstacles)
    sleep_time = 1.0 / rate
    seq_num = 1
    while not cyber.is_shutdown():
        prediction = PredictionObstacles()
        prediction.header.sequence_num = seq_num
        prediction.header.timestamp_sec = cyber_time.Time.now().to_sec()
        prediction.header.module_name = "prediction"
        print(str(prediction))
        writer.write(prediction)
        seq_num += 1
        time.sleep(sleep_time)
예제 #26
0
def test_client_class():
    """
    Client send request
    """
    node = cyber.Node("client_node")
    client = node.create_client("server_01", ChatterBenchmark,
                                ChatterBenchmark)
    req = ChatterBenchmark()
    req.content = "clt:Hello service!"
    req.seq = 0
    count = 0
    while not cyber.is_shutdown():
        time.sleep(1)
        count = count + 1
        req.seq = count
        print "-" * 80
        response = client.send_request(req)
        print "get Response [ ", response, " ]"
예제 #27
0
def main():
    """
    Main function
    """
    node = cyber.Node("data_collector")

    data_collector = DataCollector(node)
    plotter = Plotter()
    node.create_reader('/apollo/localization/pose',
                       localization_pb2.LocalizationEstimate,
                       data_collector.callback_localization)
    node.create_reader('/apollo/canbus/chassis', chassis_pb2.Chassis,
                       data_collector.callback_canbus)

    print('Enter q to quit.')
    print('Enter p to plot result from last run.')
    print('Enter x to remove result from last run.')
    print('Enter x y z, where x is acceleration command, ' +
          'y is speed limit, z is decceleration command.')
    print('Positive number for throttle and negative number for brake.')

    while True:
        cmd = raw_input("Enter commands: ").split()
        if len(cmd) == 0:
            print('Quiting.')
            break
        elif len(cmd) == 1:
            if cmd[0] == "q":
                break
            elif cmd[0] == "p":
                print('Plotting result.')
                if os.path.exists(data_collector.outfile):
                    plotter.process_data(data_collector.outfile)
                    plotter.plot_result()
                else:
                    print('File does not exist: %s' % data_collector.outfile)
            elif cmd[0] == "x":
                print('Removing last result.')
                if os.path.exists(data_collector.outfile):
                    os.remove(data_collector.outfile)
                else:
                    print('File does not exist: %s' % date_collector.outfile)
        elif len(cmd) == 3:
            data_collector.run(cmd)
예제 #28
0
def test_talker_class():
    """
    Test talker.
    """
    msg = SimpleMessage()
    msg.text = "talker:send Alex!"
    msg.integer = 0

    test_node = cyber.Node("node_name1")
    g_count = 1

    writer = test_node.create_writer("channel/chatter", SimpleMessage, 6)
    while not cyber.is_shutdown():
        time.sleep(1)
        g_count = g_count + 1
        msg.integer = g_count
        print "=" * 80
        print "write msg -> %s" % msg
        writer.write(msg)
예제 #29
0
    def __init__(self):

        self.car = Lexus()
        self.car_state_mutex = allocate_lock()

        self.params = self.pars_arguments()
        self.trajectory_file_handler = self.create_trajectory_file_handler()
        self.trajectory = self.load_trajectory()
        self.nearest_point_id = 0

        cyber.init()
        self.cyber_node = cyber.Node("oscar_tools_trajectory_player")
        self.cyber_trajectory_pub = self.cyber_node.create_writer(
            '/apollo/planning', planning_pb2.ADCTrajectory)

        self.localization_received = False
        self.planning_msg_count = 0
        self.min_along_path_neighbors_dist = 2 * pi * self.car.min_radius * 0.8
        self.estop = False

        atexit.register(self.shutdown)
예제 #30
0
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)