Skip to content

Local Planner

local_planner ¤

LocalPlanner ¤

__init__(self, vehicle, controller=None, behavior_planner=None, mission_planner=None) special ¤

Source code in ROAR_simulation/roar_autonomous_system/planning_module/local_planner/local_planner.py
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
def __init__(
    self,
    vehicle: Vehicle,
    controller: Optional[Controller] = None,
    behavior_planner: Optional[BehaviorPlanner] = None,
    mission_planner: Optional[MissionPlanner] = None,
):
    super().__init__(vehicle)
    self.controller = (
        Controller(vehicle=vehicle) if controller is None else controller
    )
    self.behavior_planner = (
        BehaviorPlanner(vehicle=vehicle)
        if behavior_planner is None
        else behavior_planner
    )
    self.mission_planner = (
        MissionPlanner(vehicle=vehicle)
        if mission_planner is None
        else mission_planner
    )
    self.way_points_queue = deque()

run_step(self, vehicle) ¤

On every step, produce an actionable plan

Returns:

Type Description
VehicleControl
Source code in ROAR_simulation/roar_autonomous_system/planning_module/local_planner/local_planner.py
46
47
48
@abstractmethod
def run_step(self, vehicle: Vehicle) -> VehicleControl:
    return VehicleControl()

simple_waypoint_following_local_planner ¤

SimpleWaypointFollowingLocalPlanner ¤

__init__(self, vehicle, controller, mission_planner, behavior_planner, closeness_threshold=0.5) special ¤

Initialize Simple Waypoint Following Planner

Parameters:

Name Type Description Default
vehicle Vehicle

Vehicle information

required
controller Controller

Control module used

required
mission_planner MissionPlanner

mission planner used

required
behavior_planner BehaviorPlanner

behavior planner used

required
closeness_threshold

how close can a waypoint be with the vehicle

0.5
Source code in ROAR_simulation/roar_autonomous_system/planning_module/local_planner/simple_waypoint_following_local_planner.py
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
def __init__(
    self,
    vehicle: Vehicle,
    controller: Controller,
    mission_planner: MissionPlanner,
    behavior_planner: BehaviorPlanner,
    closeness_threshold=0.5,
):
    """
    Initialize Simple Waypoint Following Planner
    Args:
        vehicle: Vehicle information
        controller: Control module used
        mission_planner: mission planner used
        behavior_planner: behavior planner used
        closeness_threshold: how close can a waypoint be with the vehicle
    """
    super().__init__(
        vehicle=vehicle,
        controller=controller,
        mission_planner=mission_planner,
        behavior_planner=behavior_planner,
    )
    self.logger = logging.getLogger("SimplePathFollowingLocalPlanner")
    self.set_mission_plan()
    self.logger.debug("Simple Path Following Local Planner Initiated")
    self.closeness_threshold = closeness_threshold

is_done(self) ¤

If there are nothing in self.way_points_queue, that means you have finished a lap, you are done

Returns:

Type Description
bool

True if Done, False otherwise

Source code in ROAR_simulation/roar_autonomous_system/planning_module/local_planner/simple_waypoint_following_local_planner.py
69
70
71
72
73
74
75
76
77
def is_done(self) -> bool:
    """
    If there are nothing in self.way_points_queue,
    that means you have finished a lap, you are done

    Returns:
        True if Done, False otherwise
    """
    return len(self.way_points_queue) == 0

run_step(self, vehicle) ¤

Procedure

  1. Sync data
  2. get the correct look ahead for current speed
  3. get the correct next waypoint
  4. feed waypoint into controller
  5. return result from controller

Parameters:

Name Type Description Default
vehicle Vehicle

current vehicle state

required

Returns:

Type Description
VehicleControl

next control that the local think the agent should execute.

Source code in ROAR_simulation/roar_autonomous_system/planning_module/local_planner/simple_waypoint_following_local_planner.py
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
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
def run_step(self, vehicle: Vehicle) -> VehicleControl:
    """
    Run step for the local planner
    Procedure:
        1. Sync data
        2. get the correct look ahead for current speed
        3. get the correct next waypoint
        4. feed waypoint into controller
        5. return result from controller

    Args:
        vehicle: current vehicle state

    Returns:
        next control that the local think the agent should execute.
    """
    self.sync_data(vehicle=vehicle)  # on every run step, sync first
    if (
        len(self.mission_planner.mission_plan) == 0
        and len(self.way_points_queue) == 0
    ):
        return VehicleControl()

    # get vehicle's location
    vehicle_transform: Union[Transform, None] = self.vehicle.transform

    if vehicle_transform is None:
        raise AgentException("I do not know where I am, I cannot proceed forward")

    # redefine closeness level based on speed
    curr_speed = Vehicle.get_speed(self.vehicle)
    if curr_speed < 60:
        self.closeness_threshold = 5
    elif curr_speed < 80:
        self.closeness_threshold = 15
    elif curr_speed < 120:
        self.closeness_threshold = 20
    else:
        self.closeness_threshold = 50
    # print(f"Curr closeness threshold = {self.closeness_threshold}")

    # get current waypoint
    curr_closest_dist = float("inf")
    while True:
        if len(self.way_points_queue) == 0:
            self.logger.info("Destination reached")
            return VehicleControl()
        waypoint: Transform = self.way_points_queue[0]
        curr_dist = vehicle_transform.location.distance(waypoint.location)
        if curr_dist < curr_closest_dist:
            # if i find a waypoint that is closer to me than before
            # note that i will always enter here to start the calculation for curr_closest_dist
            curr_closest_dist = curr_dist
        elif curr_dist < self.closeness_threshold:
            # i have moved onto a waypoint, remove that waypoint from the queue
            self.way_points_queue.popleft()
        else:
            break

    target_waypoint = self.way_points_queue[0]
    # target_waypoint = Transform.average(self.way_points_queue[0], self.way_points_queue[1])
    # target_waypoint = Transform.average(self.way_points_queue[2], target_waypoint)

    control: VehicleControl = self.controller.run_step(
        vehicle=vehicle, next_waypoint=target_waypoint
    )
    # self.logger.debug(
    #     f"Target_Location {target_waypoint.location} "
    #     f"| Curr_Location {vehicle_transform.location} "
    #     f"| Distance {int(curr_closest_dist)}")
    return control

set_mission_plan(self) ¤

clears current waypoints, and reset mission plan from start I am simply transfering the mission plan into my waypoint queue. Assuming that this current run will run all the way to the end

Returns:

Type Description
None

None

Source code in ROAR_simulation/roar_autonomous_system/planning_module/local_planner/simple_waypoint_following_local_planner.py
54
55
56
57
58
59
60
61
62
63
64
65
66
67
def set_mission_plan(self) -> None:
    """
    clears current waypoints, and reset mission plan from start
    I am simply transfering the mission plan into my waypoint queue.
    Assuming that this current run will run all the way to the end

    Returns:
        None
    """
    self.way_points_queue.clear()
    while (
        self.mission_planner.mission_plan
    ):  # this actually clears the mission plan!!
        self.way_points_queue.append(self.mission_planner.mission_plan.popleft())