def create_rollout_agent(agent_config, metrics, run_phase_subject):
    '''Returns an rollout agent object
       agent_config - Dictionary containing the key specified in ConfigParams
       metrics - Metrics object for the agent
       run_phase_subject - Subject that notifies observers when the run phase changes
    '''
    model_metadata = agent_config['model_metadata']
    observation_list, network, version = model_metadata.get_model_metadata_info()
    agent_name = agent_config[ConfigParams.CAR_CTRL_CONFIG.value][ConfigParams.AGENT_NAME.value]
    sensor = construct_sensor(agent_name, observation_list, SensorFactory)
    network_settings = get_network_settings(sensor, network)
    FrustumManager.get_instance().add(agent_name=agent_name,
                                      observation_list=observation_list,
                                      version=version)

    ctrl_config = agent_config[ConfigParams.CAR_CTRL_CONFIG.value]
    ctrl = RolloutCtrl(ctrl_config, run_phase_subject, metrics)

    return Agent(network_settings, sensor, ctrl)
Beispiel #2
0
    def get_objects_in_camera_frustums(self,
                                       agent_name,
                                       car_pose,
                                       object_order=None):
        """Returns list of tuple (idx, object.pose) for the objects
        that are in camera frustums"""

        frustum = FrustumManager.get_instance().get(agent_name=agent_name)
        frustum.update(car_pose)
        objects_in_frustum = []

        object_order = (object_order if object_order is not None else range(
            len(self.object_poses.values())))

        object_poses = [pose for pose in self.object_poses.values()]
        object_dims = [pose for pose in self.object_dims.values()]
        for idx, order_idx in enumerate(object_order):
            object_pose = object_poses[order_idx]
            object_dim = object_dims[order_idx]

            object_position = np.array([
                object_pose.position.x, object_pose.position.y,
                object_pose.position.z
            ])
            object_points = TrackData.get_object_bounding_rect(
                object_pose, object_dim)
            object_points.append(object_position)
            # Check collision between frustum and object points
            # object points contains object position + points in bounding rectangle on the floor
            # Camera pitch and roll are fixed so checking bounding rectangle on the floor should be good enough
            # One edge case that this detection can miss is similar as below:
            #     FFFFFFFFFFFFFFF
            #     F             F
            #   AAAFAAAAAAAAAAAFAAAAAAAAAAAAAA
            #   A   F         F              A
            #   A    F       F  X            A
            #   AAAAAAFAAAAAFAAAAAAAAAAAAAAAAA
            #          F   F
            #           FFF
            # F = frustum / A = object / X = center of mass of the object
            if any([frustum.is_visible(p) for p in object_points]):
                objects_in_frustum.append((idx, object_pose))
        return objects_in_frustum