Exemplo n.º 1
0
    def test_road_odometry(self):
        RoadOdometry()
        rg = make_two_lane_road()
        lane_0 = rg.junction(0).segment(0).lane(0)
        lane_1 = rg.junction(0).segment(0).lane(1)
        lane_pos = LanePosition(s=1., r=2., h=3.)
        road_pos = RoadPosition(lane=lane_0, pos=lane_pos)
        w = [5., 7., 9.]
        v = [11., 13., 15.]
        frame_velocity = FrameVelocity(SpatialVelocity(w=w, v=v))
        road_odom = RoadOdometry(
            road_position=road_pos, frame_velocity=frame_velocity)

        self.assertEqual(road_odom.lane.id().string(), lane_0.id().string())
        self.assertTrue(np.allclose(road_odom.pos.srh(), lane_pos.srh()))
        self.assertTrue(np.allclose(
            frame_velocity.get_velocity().translational(),
            road_odom.vel.get_velocity().translational()))
        lane_pos_new = LanePosition(s=10., r=20., h=30.)
        v_new = [42., 43., 44.]
        frame_velocity_new = FrameVelocity(SpatialVelocity(w=w, v=v_new))
        road_odom.lane = lane_1
        road_odom.pos = lane_pos_new
        road_odom.vel = frame_velocity_new

        self.assertEqual(road_odom.lane.id().string(), lane_1.id().string())
        self.assertTrue(np.allclose(road_odom.pos.srh(), lane_pos_new.srh()))
        self.assertTrue(np.allclose(
            frame_velocity_new.get_velocity().translational(),
            road_odom.vel.get_velocity().translational()))
Exemplo n.º 2
0
    def test_road_odometry(self):
        RoadOdometry()
        rg = make_two_lane_road()
        lane_0 = rg.junction(0).segment(0).lane(0)
        lane_1 = rg.junction(0).segment(0).lane(1)
        lane_pos = LanePosition(s=1., r=2., h=3.)
        road_pos = RoadPosition(lane=lane_0, pos=lane_pos)
        w = [5., 7., 9.]
        v = [11., 13., 15.]
        frame_velocity = FrameVelocity(SpatialVelocity(w=w, v=v))
        road_odom = RoadOdometry(
            road_position=road_pos, frame_velocity=frame_velocity)

        self.assertEqual(road_odom.lane.id().string(), lane_0.id().string())
        self.assertTrue(np.allclose(road_odom.pos.srh(), lane_pos.srh()))
        self.assertTrue(np.allclose(
            frame_velocity.get_velocity().translational(),
            road_odom.vel.get_velocity().translational()))
        lane_pos_new = LanePosition(s=10., r=20., h=30.)
        v_new = [42., 43., 44.]
        frame_velocity_new = FrameVelocity(SpatialVelocity(w=w, v=v_new))
        road_odom.lane = lane_1
        road_odom.pos = lane_pos_new
        road_odom.vel = frame_velocity_new

        self.assertEqual(road_odom.lane.id().string(), lane_1.id().string())
        self.assertTrue(np.allclose(road_odom.pos.srh(), lane_pos_new.srh()))
        self.assertTrue(np.allclose(
            frame_velocity_new.get_velocity().translational(),
            road_odom.vel.get_velocity().translational()))
Exemplo n.º 3
0
    def test_pose_selector(self):
        kScanDistance = 4.
        rg = make_two_lane_road()
        lane = rg.junction(0).segment(0).lane(0)
        pose0 = PoseVector()
        pose0.set_translation([1., 0., 0.])
        pose1 = PoseVector()
        # N.B. Set pose1 3 meters ahead of pose0.
        pose1.set_translation([4., 0., 0.])

        bundle = PoseBundle(num_poses=2)
        bundle.set_pose(0, Isometry3(Quaternion(), pose0.get_translation()))
        bundle.set_pose(1, Isometry3(Quaternion(), pose1.get_translation()))

        closest_pose = PoseSelector.FindSingleClosestPose(
            lane=lane,
            ego_pose=pose0,
            traffic_poses=bundle,
            scan_distance=kScanDistance,
            side=AheadOrBehind.kAhead,
            path_or_branches=ScanStrategy.kPath)
        self.assertEqual(closest_pose.odometry.lane.id().string(),
                         lane.id().string())
        self.assertTrue(closest_pose.distance == 3.)

        closest_pair = PoseSelector.FindClosestPair(
            lane=lane,
            ego_pose=pose0,
            traffic_poses=bundle,
            scan_distance=kScanDistance,
            path_or_branches=ScanStrategy.kPath)
        self.assertEqual(
            closest_pair[AheadOrBehind.kAhead].odometry.lane.id().string(),
            lane.id().string())
        self.assertEqual(closest_pair[AheadOrBehind.kAhead].distance, 3.)
        self.assertEqual(
            closest_pair[AheadOrBehind.kBehind].odometry.lane.id().string(),
            lane.id().string())
        self.assertEqual(closest_pair[AheadOrBehind.kBehind].distance,
                         float('inf'))

        lane_pos = LanePosition(s=1., r=0., h=0.)
        road_pos = RoadPosition(lane=lane, pos=lane_pos)
        w = [1., 2., 3.]
        v = [-4., -5., -6.]
        frame_velocity = FrameVelocity(SpatialVelocity(w=w, v=v))
        road_odom = RoadOdometry(road_position=road_pos,
                                 frame_velocity=frame_velocity)
        sigma_v = PoseSelector.GetSigmaVelocity(road_odom)
        self.assertEqual(sigma_v, v[0])
Exemplo n.º 4
0
    def test_closest_pose(self):
        ClosestPose()
        rg = make_two_lane_road()
        lane_0 = rg.junction(0).segment(0).lane(0)
        lane_1 = rg.junction(0).segment(0).lane(1)
        lane_pos = LanePosition(s=1., r=2., h=3.)
        road_pos = RoadPosition(lane=lane_0, pos=lane_pos)
        w = [5., 7., 9.]
        v = [11., 13., 15.]
        frame_velocity = FrameVelocity(SpatialVelocity(w=w, v=v))
        road_odom = RoadOdometry(
            road_position=road_pos, frame_velocity=frame_velocity)

        closest_pose = ClosestPose(odom=road_odom, dist=12.7)
        self.assertEqual(closest_pose.odometry.lane.id().string(),
                         lane_0.id().string())
        self.assertEqual(closest_pose.distance, 12.7)

        closest_pose.odometry.lane = lane_1
        closest_pose.distance = 5.9
        self.assertEqual(closest_pose.odometry.lane.id().string(),
                         lane_1.id().string())
        self.assertEqual(closest_pose.distance, 5.9)