Skip to content

Agent Module

ForwardOnlyAgent ¤

__init__(self, vehicle, agent_settings, **kwargs) special ¤

Source code in ROAR/agent_module/forward_only_agent.py
def __init__(self, vehicle: Vehicle, agent_settings: AgentConfig, **kwargs):
    super().__init__(vehicle, agent_settings, **kwargs)

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/agent_module/forward_only_agent.py
def run_step(self, sensors_data: SensorsData, vehicle: Vehicle) -> VehicleControl:
    super().run_step(sensors_data=sensors_data, vehicle=vehicle)
    print(self.vehicle.transform)
    control = VehicleControl(throttle=0.4, steering=0)
    return control

OpenCVTensorflowObjectDetectionAgent ¤

__init__(self, vehicle, agent_settings) special ¤

Source code in ROAR/agent_module/opencv_tensorflow_object_detection_agent.py
def __init__(self, vehicle: Vehicle, agent_settings: AgentConfig):
    super().__init__(vehicle, agent_settings)
    folder_name = "ssd_mobilenet_v2_coco_2018_03_29"
    self.weights_folder_path = \
        Path("/home/michael/Desktop/projects/ROAR/ROAR-Sim/data/weights/")
    frozen_graph_weights_path: Path = self.weights_folder_path / 'opencv_weights_and_config' / folder_name / 'frozen_inference_graph.pb'
    frozen_graph_struct_path: Path = self.weights_folder_path / 'opencv_weights_and_config' / folder_name / 'model_structure.pbtxt'
    print(f"Path set \n{frozen_graph_weights_path}\n{frozen_graph_struct_path}")
    self.tensorflowNet = cv2.dnn.readNetFromTensorflow(
        frozen_graph_weights_path.as_posix(),
        frozen_graph_struct_path.as_posix()
    )
    print("OpenCVTensorflowObjectDetectionAgent initialized")

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/agent_module/opencv_tensorflow_object_detection_agent.py
def run_step(self, sensors_data: SensorsData, vehicle: Vehicle) -> VehicleControl:
    super(OpenCVTensorflowObjectDetectionAgent, self).run_step(sensors_data=sensors_data, vehicle=vehicle)
    image = self.front_rgb_camera.data.copy()
    rows, cols, channels = image.shape
    # image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
    # Use the given image as input, which needs to be blob(s).
    self.tensorflowNet.setInput(cv2.dnn.blobFromImage(image, size=(300, 300), swapRB=True, crop=False))

    # Runs a forward pass to compute the net output
    networkOutput = self.tensorflowNet.forward()

    # Loop on the outputs
    for detection in networkOutput[0, 0]:

        score = float(detection[2])
        if score > 0.3:
            left = detection[3] * cols
            top = detection[4] * rows
            right = detection[5] * cols
            bottom = detection[6] * rows
            area = (right - left) * (bottom - top)

            # draw a red rectangle around detected objects
            if area < 10000:
                cv2.rectangle(image, (int(left), int(top)), (int(right), int(bottom)), (0, 0, 255), thickness=2)
                self.logger.debug(f"Detection confirmed. Score = {score}")
            # cv2.rectangle(image, (int(left), int(top)), (int(right), int(bottom)), (0, 0, 255), thickness=2)
    # Show the image with a rectagle surrounding the detected objects
    cv2.imshow('Image', image)
    cv2.waitKey(1)
    return VehicleControl()

PIDAgent ¤

__init__(self, target_speed=40, **kwargs) special ¤

Source code in ROAR/agent_module/pid_agent.py
def __init__(self, target_speed=40, **kwargs):
    super().__init__(**kwargs)
    self.target_speed = target_speed
    self.logger = logging.getLogger("PID Agent")
    self.route_file_path = Path(self.agent_settings.waypoint_file_path)
    self.pid_controller = PIDController(agent=self, steering_boundary=(-1, 1), throttle_boundary=(0, 1))
    self.mission_planner = WaypointFollowingMissionPlanner(agent=self)
    # initiated right after mission plan

    self.behavior_planner = BehaviorPlanner(agent=self)
    self.local_planner = SimpleWaypointFollowingLocalPlanner(
        agent=self,
        controller=self.pid_controller,
        mission_planner=self.mission_planner,
        behavior_planner=self.behavior_planner,
        closeness_threshold=1)
    self.logger.debug(
        f"Waypoint Following Agent Initiated. Reading f"
        f"rom {self.route_file_path.as_posix()}")

run_step(self, vehicle, sensors_data) ¤

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/agent_module/pid_agent.py
def run_step(self, vehicle: Vehicle,
             sensors_data: SensorsData) -> VehicleControl:
    super(PIDAgent, self).run_step(vehicle=vehicle,
                                   sensors_data=sensors_data)
    self.transform_history.append(self.vehicle.transform)
    # print(self.vehicle.transform, self.vehicle.velocity)
    if self.is_done:
        control = VehicleControl()
        self.logger.debug("Path Following Agent is Done. Idling.")
    else:
        control = self.local_planner.run_in_series()
    return control

PurePursuitAgent ¤

__init__(self, vehicle, agent_settings, target_speed=50) special ¤

Source code in ROAR/agent_module/pure_pursuit_agent.py
def __init__(self, vehicle: Vehicle, agent_settings: AgentConfig, target_speed=50):
    super().__init__(vehicle=vehicle, agent_settings=agent_settings)
    self.route_file_path = Path(self.agent_settings.waypoint_file_path)
    self.pure_pursuit_controller = \
        PurePursuitController(agent=self,
                              target_speed=target_speed,
                              look_ahead_gain=0.1,
                              look_ahead_distance=3)
    self.mission_planner = WaypointFollowingMissionPlanner(agent=self)

    # initiated right after mission plan
    self.behavior_planner = BehaviorPlanner(agent=self)
    self.local_planner = SimpleWaypointFollowingLocalPlanner(
        agent=self,
        controller=self.pure_pursuit_controller,
        mission_planner=self.mission_planner,
        behavior_planner=self.behavior_planner,
        closeness_threshold=3)

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/agent_module/pure_pursuit_agent.py
def run_step(self, sensors_data: SensorsData,
             vehicle: Vehicle) -> VehicleControl:
    super(PurePursuitAgent, self).run_step(sensors_data=sensors_data,
                                           vehicle=vehicle)
    vehicle_control = self.local_planner.run_in_series()

    return vehicle_control

LQRAgent ¤

__init__(self, target_speed=40, **kwargs) special ¤

Source code in ROAR/agent_module/lqr_agent.py
def __init__(self, target_speed=40, **kwargs):
    super().__init__(**kwargs)
    self.target_speed = target_speed
    self.logger = logging.getLogger("LQR Agent")
    self.route_file_path = Path(self.agent_settings.waypoint_file_path)
    self.lqr_controller = LQRController(agent=self, steering_boundary=(-1, 1), throttle_boundary=(-1, 1))
    self.mission_planner = WaypointFollowingMissionPlanner(agent=self)
    # initiated right after mission plan

    self.behavior_planner = BehaviorPlanner(agent=self)
    self.local_planner = SmoothWaypointFollowingLocalPlanner(
        agent=self,
        controller=self.lqr_controller,
        mission_planner=self.mission_planner,
        behavior_planner=self.behavior_planner,
        closeness_threshold=1)
    self.logger.debug(
        f"Waypoint Following Agent Initiated. Reading f"
        f"rom {self.route_file_path.as_posix()}")

run_step(self, vehicle, sensors_data) ¤

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/agent_module/lqr_agent.py
def run_step(self, vehicle: Vehicle,
             sensors_data: SensorsData) -> VehicleControl:
    super(LQRAgent, self).run_step(vehicle=vehicle,
                                   sensors_data=sensors_data)
    self.transform_history.append(self.vehicle.transform)
    if self.local_planner.is_done():
        control = VehicleControl()
        self.logger.debug("Path Following Agent is Done. Idling.")
    else:
        control = self.local_planner.run_in_series()
    return control