Exemplo n.º 1
0
    def test_idm_controller(self):
        rg = make_two_lane_road()
        idm = IdmController(
            road=rg, path_or_branches=ScanStrategy.kPath,
            road_position_strategy=RoadPositionStrategy.kExhaustiveSearch,
            period_sec=0.)
        context = idm.CreateDefaultContext()
        output = idm.AllocateOutput()

        # Fix the inputs.
        pose_vector1 = PoseVector()
        pose_vector1.set_translation([1., 2., 3.])
        ego_pose_index = idm.ego_pose_input().get_index()
        context.FixInputPort(ego_pose_index, pose_vector1)

        w = [0., 0., 0.]
        v = [1., 0., 0.]
        frame_velocity1 = FrameVelocity(SpatialVelocity(w=w, v=v))
        ego_velocity_index = idm.ego_velocity_input().get_index()
        context.FixInputPort(ego_velocity_index, frame_velocity1)

        pose_vector2 = PoseVector()
        pose_vector2.set_translation([6., 0., 0.])
        bundle = PoseBundle(num_poses=1)
        bundle.set_pose(
            0, Isometry3(Quaternion(), pose_vector2.get_translation()))
        traffic_index = idm.traffic_input().get_index()
        context.FixInputPort(
            traffic_index, framework.AbstractValue.Make(bundle))

        # Verify the inputs.
        pose_vector_eval = idm.EvalVectorInput(context, 0)
        self.assertTrue(np.allclose(pose_vector1.get_translation(),
                                    pose_vector_eval.get_translation()))
        frame_velocity_eval = idm.EvalVectorInput(context, 1)
        self.assertTrue(np.allclose(
            frame_velocity1.get_velocity().translational(),
            frame_velocity_eval.get_velocity().translational()))
        self.assertTrue(np.allclose(
            frame_velocity1.get_velocity().rotational(),
            frame_velocity_eval.get_velocity().rotational()))

        # Verify the outputs.
        idm.CalcOutput(context, output)
        accel_command_index = idm.acceleration_output().get_index()
        accel = output.get_vector_data(accel_command_index)
        self.assertEqual(len(accel.get_value()), 1)
        self.assertTrue(accel.get_value() < 0.)
Exemplo n.º 2
0
    def test_idm_controller(self):
        rg = make_two_lane_road()
        idm = IdmController(
            road=rg, path_or_branches=ScanStrategy.kPath,
            road_position_strategy=RoadPositionStrategy.kExhaustiveSearch,
            period_sec=0.)
        context = idm.CreateDefaultContext()
        output = idm.AllocateOutput()

        # Fix the inputs.
        pose_vector1 = PoseVector()
        pose_vector1.set_translation([1., 2., 3.])
        ego_pose_index = idm.ego_pose_input().get_index()
        context.FixInputPort(ego_pose_index, pose_vector1)

        w = [0., 0., 0.]
        v = [1., 0., 0.]
        frame_velocity1 = FrameVelocity(SpatialVelocity(w=w, v=v))
        ego_velocity_index = idm.ego_velocity_input().get_index()
        context.FixInputPort(ego_velocity_index, frame_velocity1)

        pose_vector2 = PoseVector()
        pose_vector2.set_translation([6., 0., 0.])
        bundle = PoseBundle(num_poses=1)
        bundle.set_pose(
            0, Isometry3(Quaternion(), pose_vector2.get_translation()))
        traffic_index = idm.traffic_input().get_index()
        context.FixInputPort(
            traffic_index, framework.AbstractValue.Make(bundle))

        # Verify the inputs.
        pose_vector_eval = idm.EvalVectorInput(context, 0)
        self.assertTrue(np.allclose(pose_vector1.get_translation(),
                                    pose_vector_eval.get_translation()))
        frame_velocity_eval = idm.EvalVectorInput(context, 1)
        self.assertTrue(np.allclose(
            frame_velocity1.get_velocity().translational(),
            frame_velocity_eval.get_velocity().translational()))
        self.assertTrue(np.allclose(
            frame_velocity1.get_velocity().rotational(),
            frame_velocity_eval.get_velocity().rotational()))

        # Verify the outputs.
        idm.CalcOutput(context, output)
        accel_command_index = idm.acceleration_output().get_index()
        accel = output.get_vector_data(accel_command_index)
        self.assertEqual(len(accel.get_value()), 1)
        self.assertTrue(accel.get_value() < 0.)