Esempio n. 1
0
def center_point1():
    outdir = get_comptests_output_dir()
    templates = load_tile_types()

    for k, v in templates.items():
        if isinstance(v, LaneSegment):

            area = RectangularArea((-2, -2), (3, 3))
            dest = os.path.join(outdir, k)

            N = len(v.control_points)
            betas = list(np.linspace(-2, N + 1, 20))
            betas.extend(range(N))
            betas = sorted(betas)
            transforms = []
            for timestamp in betas:
                beta = timestamp
                p = v.center_point(beta)
                # print('%s: %s' % (beta, geo.SE2.friendly(p)))

                transform = SE2Transform.from_SE2(p)
                transforms.append(transform)

            c = SampledSequence[SE2Transform](betas, transforms)
            v.set_object("a", PlacedObject(), ground_truth=c)
            draw_static(v, dest, area=area)
Esempio n. 2
0
def svg2():
    outdir = get_comptests_output_dir()
    templates = load_tile_types()

    for k, v in templates.items():
        area = RectangularArea((-1, -1), (1, 1))
        dest = os.path.join(outdir, k)
        draw_static(v, dest, area=area)
Esempio n. 3
0
def lane_pose_test1():
    outdir = get_comptests_output_dir()

    # load one of the maps (see the list using dt-world-draw-maps)
    dw = load_map("udem1")

    v = 5

    # define a SampledSequence with timestamp, command
    commands_sequence = SampledSequence.from_iterator(
        [
            # we set these velocities at 1.0
            (1.0, WheelVelocityCommands(0.1 * v, 0.1 * v)),
            # at 2.0 we switch and so on
            (2.0, WheelVelocityCommands(0.1 * v, 0.4 * v)),
            (4.0, WheelVelocityCommands(0.1 * v, 0.4 * v)),
            (5.0, WheelVelocityCommands(0.1 * v, 0.2 * v)),
            (6.0, WheelVelocityCommands(0.1 * v, 0.1 * v)),
        ]
    )

    # we upsample the sequence by 5
    commands_sequence = commands_sequence.upsample(5)

    ## Simulate the dynamics of the vehicle
    # start from q0
    q0 = geo.SE2_from_translation_angle([1.8, 0.7], 0)

    # instantiate the class that represents the dynamics
    dynamics = reasonable_duckiebot()
    # this function integrates the dynamics
    poses_sequence = get_robot_trajectory(dynamics, q0, commands_sequence)

    #################
    # Visualization and rule evaluation

    # Creates an object 'duckiebot'
    ego_name = "duckiebot"
    db = DB18()  # class that gives the appearance

    # convert from SE2 to SE2Transform representation
    transforms_sequence = poses_sequence.transform_values(SE2Transform.from_SE2)
    # puts the object in the world with a certain "ground_truth" constraint
    dw.set_object(ego_name, db, ground_truth=transforms_sequence)

    # Rule evaluation (do not touch)
    interval = SampledSequence.from_iterator(enumerate(commands_sequence.timestamps))
    evaluated = evaluate_rules(
        poses_sequence=transforms_sequence,
        interval=interval,
        world=dw,
        ego_name=ego_name,
    )
    timeseries = make_timeseries(evaluated)
    # Drawing
    area = RectangularArea((0, 0), (3, 3))
    draw_static(dw, outdir, area=area, timeseries=timeseries)
Esempio n. 4
0
def svg1():
    outdir = get_comptests_output_dir()
    control_points = [
        SE2Transform.from_SE2(geo.SE2_from_translation_angle([0, 0], 0)),
        SE2Transform.from_SE2(geo.SE2_from_translation_angle([1, 0], 0)),
        SE2Transform.from_SE2(geo.SE2_from_translation_angle([2, -1], np.deg2rad(-90))),
    ]

    width = 0.3

    ls = LaneSegment(width, control_points)

    area = RectangularArea((-1, -2), (3, 2))
    draw_static(ls, outdir, area=area)
Esempio n. 5
0
def lane_pose_test1():
    outdir = get_comptests_output_dir()

    dm = load_map('udem1')

    print(get_object_tree(dm, attributes=True))

    res = get_skeleton_graph(dm)

    # area = RectangularArea((0, 0), (3, 3))
    draw_static(res.root2, outdir + '/root2')

    # draw_static(dm, outdir + '/orig')

    print(get_object_tree(res.root2, attributes=True))
Esempio n. 6
0
def lane_pose_segment1():
    outdir = get_comptests_output_dir()

    dm = load_map("udem1")

    _ = get_object_tree(dm, attributes=True)

    res = get_skeleton_graph(dm)

    # area = RectangularArea((0, 0), (3, 3))
    draw_static(res.root2, outdir + "/root2")

    # draw_static(dm, outdir + '/orig')

    _ = get_object_tree(res.root2, attributes=True)
Esempio n. 7
0
 def _eval_poses_sequence(self, poses_sequence, outdir=None):
     """
     :param poses_sequence:
     :param outdir: If None evaluation outputs plots won't be saved
     :return:
     """
     # puts the object in the world with a certain "ground_truth" constraint
     self.dw.set_object(self.ego_name, self.db, ground_truth=poses_sequence)
     # Rule evaluation (do not touch)
     interval = SampledSequence.from_iterator(
         enumerate(poses_sequence.timestamps))
     evaluated = evaluate_rules(poses_sequence=poses_sequence,
                                interval=interval,
                                world=self.dw,
                                ego_name=self.ego_name)
     if outdir is not None:
         timeseries = make_timeseries(evaluated)
         draw_static(self.dw, outdir, timeseries=timeseries)
     print(self.dw.get_drawing_children())
     self.dw.remove_object(self.ego_name)
     self.dw.remove_object('visualization')
     return evaluated
Esempio n. 8
0
def check_car_dynamics_correct(klass, CarCommands, CarParams):
    """

    :param klass: the implementation
    :return:
    """

    # load one of the maps (see the list using dt-world-draw-maps)
    outdir = get_comptests_output_dir()
    dw = load_map('udem1')

    v = 5

    # define a SampledSequence with timestamp, command
    commands_sequence = SampledSequence.from_iterator([
        # we set these velocities at 1.0
        (1.0, CarCommands(0.1 * v, 0.1 * v)),
        # at 2.0 we switch and so on
        (2.0, CarCommands(0.1 * v, 0.4 * v)),
        (4.0, CarCommands(0.1 * v, 0.4 * v)),
        (5.0, CarCommands(0.1 * v, 0.2 * v)),
        (6.0, CarCommands(0.1 * v, 0.1 * v)),
    ])

    # we upsample the sequence by 5
    commands_sequence = commands_sequence.upsample(5)

    ## Simulate the dynamics of the vehicle
    # start from q0 and v0
    q0 = geo.SE2_from_translation_angle([1.8, 0.7], 0)
    v0 = geo.se2.zero()
    c0 = q0, v0
    # instantiate the class that represents the dynamics
    dynamics = CarParams(10.0)
    # this function integrates the dynamics
    poses_sequence = get_robot_trajectory(dynamics, q0, commands_sequence)

    #################
    # Visualization and rule evaluation

    # Creates an object 'duckiebot'
    ego_name = 'duckiebot'
    db = DB18()  # class that gives the appearance

    # convert from SE2 to SE2Transform representation
    transforms_sequence = poses_sequence.transform_values(
        SE2Transform.from_SE2)
    # puts the object in the world with a certain "ground_truth" constraint
    dw.set_object(ego_name, db, ground_truth=transforms_sequence)

    # Rule evaluation (do not touch)
    interval = SampledSequence.from_iterator(
        enumerate(commands_sequence.timestamps))
    evaluated = evaluate_rules(poses_sequence=transforms_sequence,
                               interval=interval,
                               world=dw,
                               ego_name=ego_name)
    timeseries = make_timeseries(evaluated)
    # Drawing
    area = RectangularArea((0, 0), (3, 3))
    draw_static(dw, outdir, area=area, timeseries=timeseries)

    expected = {
        1.0:
        geo.SE2_from_translation_angle([1.8, 0.7], 0.0),
        1.6:
        geo.SE2_from_translation_angle([2.09998657, 0.70245831],
                                       0.016389074695313716),
        2.0:
        geo.SE2_from_translation_angle([2.29993783, 0.70682836],
                                       0.027315124492189525),
        2.4:
        geo.SE2_from_translation_angle([2.49991893, 0.70792121],
                                       -0.016385672773040847),
        2.8:
        geo.SE2_from_translation_angle([2.69975684, 0.70027647],
                                       -0.060086470038271216),
        3.2:
        geo.SE2_from_translation_angle([2.89906999, 0.68390873],
                                       -0.10378726730350164),
        3.6:
        geo.SE2_from_translation_angle([3.09747779, 0.65884924],
                                       -0.14748806456873198),
        4.0:
        geo.SE2_from_translation_angle([3.2946014, 0.62514586],
                                       -0.19118886183396236),
        4.6:
        geo.SE2_from_translation_angle([3.58705642, 0.55852875],
                                       -0.25674005773180786),
        5.0:
        geo.SE2_from_translation_angle([3.77932992, 0.50353298],
                                       -0.3004408549970382),
        6.0:
        geo.SE2_from_translation_angle([4.2622088, 0.37429798],
                                       -0.22257046876429318),
    }
    for t, expected_pose in expected.items():
        assert np.allclose(poses_sequence.at(t=t), expected_pose), t

    print('All tests passed successfully!')