Skip to content

Documentation for Agents¤

Agent ¤

Abstract Agent class that define the minimum of a ROAR agent.

Inherited agent can perform different duties.

__init__(self, vehicle, agent_settings, imu=None) special ¤

Initialize cameras, output folder, and logging utilities

Parameters:

Name Type Description Default
vehicle Vehicle

Vehicle instance

required
agent_settings AgentConfig

User specified settings for Agent

required
imu Optional[ROAR_simulation.roar_autonomous_system.utilities_module.data_structures_models.IMUData]

IMU data (will be deprecated to be passed in like this)

None
Source code in ROAR_simulation/roar_autonomous_system/agent_module/agent.py
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
def __init__(self,
             vehicle: Vehicle,
             agent_settings: AgentConfig,
             imu: Optional[IMUData] = None):
    """
    Initialize cameras, output folder, and logging utilities

    Args:
        vehicle: Vehicle instance
        agent_settings: User specified settings for Agent
        imu: IMU data (will be deprecated to be passed in like this)
    """
    self.logger = logging.getLogger(__name__)

    self.vehicle = vehicle
    self.agent_settings = agent_settings
    self.front_rgb_camera = agent_settings.front_rgb_cam
    self.front_depth_camera = agent_settings.front_depth_cam
    self.rear_rgb_camera = agent_settings.rear_rgb_cam
    self.imu = imu

    self.output_folder_path = \
        Path(self.agent_settings.output_data_folder_path)
    self.front_depth_camera_output_folder_path = \
        self.output_folder_path / "front_depth"
    self.front_rgb_camera_output_folder_path = \
        self.output_folder_path / "front_rgb"
    self.rear_rgb_camera_output_folder_path = \
        self.output_folder_path / "rear_rgb"
    self.should_save_sensor_data = self.agent_settings.save_sensor_data

    self.time_counter = 0

    self.transform_history: List[Transform] = []

    self.init_cam()

init_cam(self) ¤

Initialize the cameras by calculating the camera intrinsics and ensuring that the output folder path exists

Returns:

Type Description
None

None

Source code in ROAR_simulation/roar_autonomous_system/agent_module/agent.py
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
def init_cam(self) -> None:
    """
    Initialize the cameras by calculating the camera intrinsics and
    ensuring that the output folder path exists

    Returns:
        None
    """

    if self.front_rgb_camera is not None:
        self.front_rgb_camera.intrinsics_matrix = (
            self.front_rgb_camera.calculate_intrinsic_matrix()
        )
    if self.front_depth_camera is not None:
        self.front_depth_camera.intrinsics_matrix = (
            self.front_depth_camera.calculate_intrinsic_matrix()
        )
    if self.rear_rgb_camera is not None:
        self.rear_rgb_camera.intrinsics_matrix = (
            self.rear_rgb_camera.calculate_intrinsic_matrix()
        )

    if self.should_save_sensor_data:
        self.front_depth_camera_output_folder_path.mkdir(parents=True,
                                                         exist_ok=True)
        self.front_rgb_camera_output_folder_path.mkdir(parents=True,
                                                       exist_ok=True)
        self.rear_rgb_camera_output_folder_path.mkdir(parents=True,
                                                      exist_ok=True)

run_step(self, sensors_data, vehicle) ¤

Receive Sensor Data and vehicle state information on every step and return a control

Parameters:

Name Type Description Default
sensors_data SensorsData

sensor data on this frame

required
vehicle Vehicle

vehicle state on this frame

required

Returns:

Type Description
VehicleControl

Vehicle Control

Source code in ROAR_simulation/roar_autonomous_system/agent_module/agent.py
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
@abstractmethod
def run_step(self, sensors_data: SensorsData,
             vehicle: Vehicle) -> VehicleControl:
    """
    Receive Sensor Data and vehicle state information on every step and
    return a control

    Args:
        sensors_data: sensor data on this frame
        vehicle: vehicle state on this frame

    Returns:
        Vehicle Control

    """
    self.time_counter += 1
    self.sync_data(sensors_data=sensors_data, vehicle=vehicle)
    if self.should_save_sensor_data:
        self.save_sensor_data()
    return VehicleControl()

save_sensor_data(self) ¤

Failure-safe saving function that saves all the sensor data of the current frame

Returns:

Type Description
None

None

Source code in ROAR_simulation/roar_autonomous_system/agent_module/agent.py
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
def save_sensor_data(self) -> None:
    """
    Failure-safe saving function that saves all the sensor data of the
    current frame

    Returns:
        None
    """
    try:
        cv2.imwrite((self.front_rgb_camera_output_folder_path /
                     f"frame_{self.time_counter}.png").as_posix(),
                    self.front_rgb_camera.data)

        np.save((self.front_depth_camera_output_folder_path /
                 f"frame_{self.time_counter}").as_posix(),
                self.front_depth_camera.data)

        cv2.imwrite((self.rear_rgb_camera_output_folder_path /
                     f"frame_{self.time_counter}.png").as_posix(),
                    self.rear_rgb_camera.data)
    except Exception as e:
        self.logger.error(
            f"Failed to save at Frame {self.time_counter}. Error: {e}")

sync_data(self, sensors_data, vehicle) ¤

Sync agent's state by updating Sensor Data and vehicle information

Parameters:

Name Type Description Default
sensors_data SensorsData

the new frame's sensor data

required
vehicle Vehicle

the new frame's vehicle state

required

Returns:

Type Description
None

None

Source code in ROAR_simulation/roar_autonomous_system/agent_module/agent.py
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
def sync_data(self, sensors_data: SensorsData, vehicle: Vehicle) -> None:
    """
    Sync agent's state by updating Sensor Data and vehicle information

    Args:
        sensors_data: the new frame's sensor data
        vehicle: the new frame's vehicle state

    Returns:
        None
    """

    self.vehicle = vehicle
    self.transform_history.append(self.vehicle.transform)
    if self.front_rgb_camera is not None:
        self.front_rgb_camera.data = (
            sensors_data.front_rgb.data
            if sensors_data.front_rgb is not None
            else None
        )

    if self.front_depth_camera is not None:
        self.front_depth_camera.data = (
            sensors_data.front_depth.data
            if sensors_data.front_depth is not None
            else None
        )

    if self.rear_rgb_camera is not None:
        self.rear_rgb_camera.data = (
            sensors_data.rear_rgb.data
            if sensors_data.rear_rgb is not None
            else None
        )

    if self.imu is not None:
        self.imu = sensors_data.imu_data