igp2.planlibrary package¶
Submodules¶
igp2.planlibrary.controller module¶
- class igp2.planlibrary.controller.AdaptiveCruiseControl(dt=0.05, a_a=5, b_a=5, delta=4.0, s_0=2.0, T_a=1.5)[source]¶
Bases:
object
Defines an adaptive cruise controller based on the intelligent driver model (IDM)
- class igp2.planlibrary.controller.PIDController(dt: float = 0.05, args_lateral: Dict[str, float] | None = None, args_longitudinal: Dict[str, float] | None = None, max_steering=1.0)[source]¶
Bases:
object
PID controller based on the CARLA PID controller implementation.
- next_action(target_acceleration, target_steering) -> (<class 'float'>, <class 'float'>)[source]¶
- Execute one step of control invoking both lateral and longitudinal
PID controllers to reach a target waypoint at a given target_speed.
- Parameters:
target_acceleration – Desired acceleration.
target_steering – Target steering
- Returns:
Acceleration and steering to execute
- class igp2.planlibrary.controller.PIDLateralController(K_P=1.0, K_I=0.0, K_D=0.0, dt=0.05)[source]¶
Bases:
object
PIDLateralController implements lateral control using a PID.
igp2.planlibrary.macro_action module¶
- class igp2.planlibrary.macro_action.ChangeLane(config: MacroActionConfig, agent_id: int, frame: Dict[int, AgentState], scenario_map: Map)[source]¶
Bases:
MacroAction
- CHECK_ONCOMING = False¶
- static check_applicability(state: AgentState, scenario_map: Map, left: bool) bool [source]¶
True if current lane not in junction, or at appropriate distance from a junction
- static get_possible_lanes(state: AgentState, scenario_map: Map, goal: Goal | None = None, left: bool = True) List[List[Lane]] [source]¶
Returns all possible lane changes when passing through a junction and there are multiple valid lane sequences. This will only really be applied when the vehicle is passing through a roundabout.
- class igp2.planlibrary.macro_action.ChangeLaneLeft(config: MacroActionConfig, agent_id: int, frame: Dict[int, AgentState], scenario_map: Map)[source]¶
Bases:
ChangeLane
- static applicable(state: AgentState, scenario_map: Map) bool [source]¶
True if valid target lane on the left and lane change is valid.
- static get_possible_args(state: AgentState, scenario_map: Map, goal: Goal | None = None) List[Dict] [source]¶
Return a list of keyword arguments used to initialise all possible variations of a macro action. Currently, only Exit returns more than one option, giving the Exits to all possible leaving points.
- Parameters:
state – Current state of the agent
scenario_map – The road layout of the scenario
goal – Optional goal to use during AStar planning
- Returns:
A list of possible initialisations in the current state
- class igp2.planlibrary.macro_action.ChangeLaneRight(config: MacroActionConfig, agent_id: int, frame: Dict[int, AgentState], scenario_map: Map)[source]¶
Bases:
ChangeLane
- static applicable(state: AgentState, scenario_map: Map) bool [source]¶
True if valid target lane on the right and lane change is valid.
- static get_possible_args(state: AgentState, scenario_map: Map, goal: Goal | None = None) List[Dict] [source]¶
Return a list of keyword arguments used to initialise all possible variations of a macro action. Currently, only Exit returns more than one option, giving the Exits to all possible leaving points.
- Parameters:
state – Current state of the agent
scenario_map – The road layout of the scenario
goal – Optional goal to use during AStar planning
- Returns:
A list of possible initialisations in the current state
- class igp2.planlibrary.macro_action.Continue(config: MacroActionConfig, agent_id: int, frame: Dict[int, AgentState], scenario_map: Map)[source]¶
Bases:
MacroAction
Follow the current lane until the given point or to the end of the lane. If the current lane is split across multiple roads then follow lane until a junction is encountered.
- static applicable(state: AgentState, scenario_map: Map) bool [source]¶
True if vehicle on a lane, and not approaching junction or not in junction
- static get_possible_args(state: AgentState, scenario_map: Map, goal: Goal | None = None) List[Dict] [source]¶
Return empty dictionary if no goal point is provided, otherwise check if goal point in lane and return center of goal point as termination point.
- class igp2.planlibrary.macro_action.Exit(config: MacroActionConfig, agent_id: int, frame: Dict[int, AgentState], scenario_map: Map)[source]¶
Bases:
MacroAction
- TURN_TARGET_THRESHOLD = 1¶
- static applicable(state: AgentState, scenario_map: Map) bool [source]¶
True if either Turn (in junction) or GiveWay is applicable (ahead of junction) and not on a roundabout road.
- static get_possible_args(state: AgentState, scenario_map: Map, goal: Goal | None = None) List[Dict] [source]¶
Return turn endpoint if approaching junction; if in junction return all possible turns within angle threshold
- class igp2.planlibrary.macro_action.MacroAction(config: MacroActionConfig, agent_id: int, frame: Dict[int, AgentState], scenario_map: Map)[source]¶
Bases:
ABC
Base class for all MacroActions.
- static applicable(state: AgentState, scenario_map: Map) bool [source]¶
Return True if the macro action is applicable in the given state of the environment.
- property current_maneuver: Maneuver¶
The current maneuver being executed during closed loop control.
- done(observation: Observation) bool [source]¶
Returns True if the execution of the macro action has completed.
- static get_possible_args(state: AgentState, scenario_map: Map, goal: Goal | None = None) List[Dict] [source]¶
Return a list of keyword arguments used to initialise all possible variations of a macro action. Currently, only Exit returns more than one option, giving the Exits to all possible leaving points.
- Parameters:
state – Current state of the agent
scenario_map – The road layout of the scenario
goal – Optional goal to use during AStar planning
- Returns:
A list of possible initialisations in the current state
- get_trajectory() VelocityTrajectory [source]¶
If open_loop is True then get the complete trajectory of the macro action.
- Returns:
A VelocityTrajectory that describes the complete open loop trajectory of the macro action
- next_action(observation: Observation) Action | None [source]¶
Return the next action of a closed-loop macro action given by its current maneuver. If the current maneuver is done, then advance to the next maneuver.
- static play_forward_macro_action(agent_id: int, scenario_map: Map, frame: Dict[int, AgentState], macro_action: MacroAction)[source]¶
Play forward current frame with the given macro action for the current agent. Assumes constant velocity lane follow behaviour for other agents.
- Parameters:
agent_id – ID of the ego agent
scenario_map – The road layout of the current scenario
frame – The current frame of the environment
macro_action – The macro action to play forward
- Returns:
A new frame describing the future state of the environment
- class igp2.planlibrary.macro_action.MacroActionConfig(config_dict: dict)[source]¶
Bases:
object
Macro action configuration class.
- property fps¶
Closed-loop controller execution frequency.
- property left: bool¶
Whether to change lanes left or right.
- property open_loop: bool¶
Whether the macro action should be execute with or without control.
- property stop: bool¶
Whether GiveWay should stop for oncoming vehicles.
- property stop_duration: float¶
Stop duration for the stop macro action.
- property termination_point: ndarray¶
Point at which the macro action will terminate. Used in Continue and Stop.
- property turn_target: ndarray¶
Endpoint of a turn in a junction.
- property type: str¶
- class igp2.planlibrary.macro_action.MacroActionFactory[source]¶
Bases:
object
Used to register and create macro actions.
- classmethod create(config: MacroActionConfig, agent_id: int, frame: Dict[int, AgentState], scenario_map: Map) MacroAction [source]¶
Create a new macro action in the given state of the environment with the given configuration.
- Parameters:
config – The macro action configuration file.
agent_id – The agent for whom the macro action is created.
frame – The state of all observable agents in the environment.
scenario_map – The road layout.
- classmethod get_applicable_actions(agent_state: AgentState, scenario_map: Map, goal: Goal | None = None) List[Type[MacroAction]] [source]¶
Return all applicable macro actions.
- Parameters:
agent_state – Current state of the examined agent
scenario_map – The road layout of the scenario
goal – If given and ahead within current lane boundary, then will always return at least a Continue
- Returns:
A list of applicable macro action types
- macro_action_types = {'ChangeLaneLeft': <class 'igp2.planlibrary.macro_action.ChangeLaneLeft'>, 'ChangeLaneRight': <class 'igp2.planlibrary.macro_action.ChangeLaneRight'>, 'Continue': <class 'igp2.planlibrary.macro_action.Continue'>, 'Exit': <class 'igp2.planlibrary.macro_action.Exit'>, 'Stop': <class 'igp2.planlibrary.macro_action.StopMA'>}¶
- class igp2.planlibrary.macro_action.StopMA(config: MacroActionConfig, agent_id: int, frame: Dict[int, AgentState], scenario_map: Map)[source]¶
Bases:
MacroAction
- static applicable(state: AgentState, scenario_map: Map) bool [source]¶
We do not allow stopping in a junction.
- static get_possible_args(state: AgentState, scenario_map: Map, goal: Goal | None = None) List[Dict] [source]¶
Return a list of keyword arguments used to initialise all possible variations of a macro action. Currently, only Exit returns more than one option, giving the Exits to all possible leaving points.
- Parameters:
state – Current state of the agent
scenario_map – The road layout of the scenario
goal – Optional goal to use during AStar planning
- Returns:
A list of possible initialisations in the current state
igp2.planlibrary.maneuver module¶
- class igp2.planlibrary.maneuver.FollowLane(config: ManeuverConfig, agent_id: int, frame: Dict[int, AgentState], scenario_map: Map)[source]¶
Bases:
Maneuver
Defines a follow-lane maneuver
- static applicable(state: AgentState, scenario_map: Map) bool [source]¶
- Checks whether the follow lane maneuver is applicable for an agent.
Follow lane is applicable if the agent is in a drivable lane.
- Parameters:
state – Current state of the agent
scenario_map – local road map
- Returns:
Boolean indicating whether the maneuver is applicable
- get_trajectory(frame: Dict[int, AgentState], scenario_map: Map) VelocityTrajectory [source]¶
Generates the target trajectory for the maneuver
- Parameters:
frame – dictionary containing state of all observable agents
scenario_map – local road map
- Returns:
Target trajectory
- class igp2.planlibrary.maneuver.GiveWay(config: ManeuverConfig, agent_id: int, frame: Dict[int, AgentState], scenario_map: Map)[source]¶
Bases:
FollowLane
- GAP_TIME = 5¶
- GIVE_WAY_DISTANCE = 15¶
- MAX_ONCOMING_VEHICLE_DIST = 100¶
- SLOW_DOWN_VEL = 2¶
- STANDBY_VEL = 3¶
- static applicable(state: AgentState, scenario_map: Map) bool [source]¶
- Checks whether the give way maneuver is applicable for an agent.
Give way is applicable if the next lane is in a junction.
- Parameters:
state – Current state of the agent
scenario_map – local road map
- Returns:
Boolean indicating whether the maneuver is applicable
- get_trajectory(frame: Dict[int, AgentState], scenario_map: Map) VelocityTrajectory [source]¶
Generates the target trajectory for the maneuver
- Parameters:
frame – dictionary containing state of all observable agents
scenario_map – local road map
- Returns:
Target trajectory
- class igp2.planlibrary.maneuver.Maneuver(config: ManeuverConfig, agent_id: int, frame: Dict[int, AgentState], scenario_map: Map)[source]¶
Bases:
ABC
Abstract class for a vehicle maneuver
- HEADING_DIF_THRESHOLD = 0.08726646259971647¶
- LON_SWERVE_DISTANCE = 3¶
- MAX_RAD_S = 0.6981317007977318¶
- MAX_SPEED = 10¶
- MIN_POINT_SPACING = 0.05¶
- MIN_SPEED = 3¶
- NORM_WIDTH_ACCEPTABLE = 0.5¶
- POINT_SPACING = 0.25¶
- abstract static applicable(state: AgentState, scenario_map: Map) bool [source]¶
Checks whether the maneuver is applicable for an agent
- Parameters:
state – current state of the agent
scenario_map – local road map
- Returns:
Boolean value indicating whether the maneuver is applicable
- classmethod get_curvature_velocity(path: ndarray) ndarray [source]¶
Generate target velocities based on the curvature of the road
- abstract get_trajectory(frame: Dict[int, AgentState], scenario_map: Map) VelocityTrajectory [source]¶
Generates the target trajectory for the maneuver
- Parameters:
frame – dictionary containing state of all observable agents
scenario_map – local road map
- Returns:
Target trajectory
- static get_vehicle_in_front(agent_id: int, frame: Dict[int, AgentState], lane_path: List[Lane]) Tuple[int, float, LineString] [source]¶
Finds the vehicle in front of an agent.
- Parameters:
agent_id – The agent ID to use for checking vehicles in front
frame – dictionary containing state of all observable agents
lane_path – sequence of lanes that the agent will travel along
- Returns:
ID for the agent in front dist: distance to the vehicle in front lane_ls: LineString of the lane midline
- Return type:
vehicle_in_front
- static get_vehicles_in_path(lane_path: List[Lane], frame: Dict[int, AgentState]) List[int] [source]¶
- get_velocity(path: ndarray, frame: Dict[int, AgentState], lane_path: List[Lane]) ndarray [source]¶
Generate target velocities based on the curvature of the path and vehicle in front.
- Parameters:
path – target path along which the agent will travel
frame – dictionary containing state of all observable agents
lane_path – sequence of lanes that the agent will travel along
- Returns:
array of target velocities
- static play_forward_maneuver(agent_id: int, scenario_map: Map, frame: Dict[int, AgentState], maneuver: Maneuver, offset: float | None = None) Dict[int, AgentState] [source]¶
Play forward current frame with the given maneuver for the current agent. Assumes constant velocity lane follow behaviour for other agents.
- Parameters:
agent_id – ID of the ego agent
scenario_map – The road layout of the current scenario
frame – The current frame of the environment
maneuver – The maneuver to play forward
offset – If not None, then add an extra point at the end of the maneuver’s trajectory with distance given by this parameter
- Returns:
A new frame describing the future state of the environment
- class igp2.planlibrary.maneuver.ManeuverConfig(config_dict)[source]¶
Bases:
object
Contains the parameters describing a maneuver
- property adjust_swerving: bool¶
Specifies whether to adjust points for swerving or not.
- property fps¶
Closed-loop controller execution frequency.
- property junction_lane_id: int¶
Lane id of the lane which will be followed at the junction
- property junction_road_id: int¶
Road id of the lane which will be followed at the junction
- property stop: bool¶
Whether give-way should check for stopping.
- property stop_duration: float¶
Stop duration for the stop maneuver.
- property termination_point: ndarray¶
Point at which the maneuver trajectory terminates. Used as the stopping point in the Stop maneuver.
- property type: str¶
The type of the maneuver. Acceptable values are {‘follow-lane’, ‘switch-left’, ‘switch-right’, ‘turn’, ‘give-way’, ‘trajectory’}
- class igp2.planlibrary.maneuver.Stop(config: ManeuverConfig, agent_id: int, frame: Dict[int, AgentState], scenario_map: Map)[source]¶
Bases:
FollowLane
Generate a Stop for a given duration.
- DEFAULT_STOP_DURATION = 5¶
- STOP_VELOCITY = 0.01¶
- static applicable(state: AgentState, scenario_map: Map) bool [source]¶
We do not allow stopping in a junction.
- get_trajectory(frame: Dict[int, AgentState], scenario_map: Map) VelocityTrajectory [source]¶
To avoid errors with velocity smoothing and to be able to take derivatives this maneuver defines three very closely spaced points as trajectory with near-zero velocity.
- class igp2.planlibrary.maneuver.SwitchLane(config: ManeuverConfig, agent_id: int, frame: Dict[int, AgentState], scenario_map: Map)[source]¶
Bases:
Maneuver
,ABC
Defines a switch lane maneuver
- MIN_SWITCH_LENGTH = 10¶
- TARGET_SWITCH_LENGTH = 20¶
- get_trajectory(frame: Dict[int, AgentState], scenario_map: Map) VelocityTrajectory [source]¶
Generates the target trajectory for the maneuver
- Parameters:
frame – dictionary containing state of all observable agents
scenario_map – local road map
- Returns:
Target trajectory
- class igp2.planlibrary.maneuver.SwitchLaneLeft(config: ManeuverConfig, agent_id: int, frame: Dict[int, AgentState], scenario_map: Map)[source]¶
Bases:
SwitchLane
Defines a switch lane left maneuver
- static applicable(state: AgentState, scenario_map: Map) bool [source]¶
- Checks whether the switch lane left maneuver is applicable for an agent.
Switch lane left is applicable if it is legal to switch to a lane left of the current lane.
- Parameters:
state – Current state of the agent
scenario_map – local road map
- Returns:
Boolean indicating whether the maneuver is applicable
- class igp2.planlibrary.maneuver.SwitchLaneRight(config: ManeuverConfig, agent_id: int, frame: Dict[int, AgentState], scenario_map: Map)[source]¶
Bases:
SwitchLane
- static applicable(state: AgentState, scenario_map: Map) bool [source]¶
- Checks whether the switch right left maneuver is applicable for an agent.
Switch lane right is applicable if it is legal to switch to a lane right of the current lane.
- Parameters:
state – Current state of the agent
scenario_map – local road map
- Returns:
Boolean indicating whether the maneuver is applicable
- class igp2.planlibrary.maneuver.TrajectoryManeuver(config: ManeuverConfig, agent_id: int, frame: Dict[int, AgentState], scenario_map: Map, trajectory: VelocityTrajectory)[source]¶
Bases:
Maneuver
Maneuver that follows a pre-defined trajectory.
- static applicable(state: AgentState, scenario_map: Map) bool [source]¶
Checks whether the maneuver is applicable for an agent
- Parameters:
state – current state of the agent
scenario_map – local road map
- Returns:
Boolean value indicating whether the maneuver is applicable
- get_trajectory(frame: Dict[int, AgentState], scenario_map: Map) VelocityTrajectory [source]¶
Generates the target trajectory for the maneuver
- Parameters:
frame – dictionary containing state of all observable agents
scenario_map – local road map
- Returns:
Target trajectory
- class igp2.planlibrary.maneuver.Turn(config: ManeuverConfig, agent_id: int, frame: Dict[int, AgentState], scenario_map: Map)[source]¶
Bases:
FollowLane
Defines a turn maneuver
- static applicable(state: AgentState, scenario_map: Map) bool [source]¶
- Checks whether the turn maneuver is applicable for an agent.
Turn is applicable if the agents current lane or next lane is in a junction.
- Parameters:
state – Current state of the agent
scenario_map – local road map
- Returns:
Boolean indicating whether the maneuver is applicable
- get_velocity(path: ndarray, frame: Dict[int, AgentState], lane_path: List[Lane]) ndarray [source]¶
Generate target velocities based on the curvature of the path and vehicle in front.
- Parameters:
path – target path along which the agent will travel
frame – dictionary containing state of all observable agents
lane_path – sequence of lanes that the agent will travel along
- Returns:
array of target velocities
igp2.planlibrary.maneuver_cl module¶
- class igp2.planlibrary.maneuver_cl.CLManeuverFactory[source]¶
Bases:
object
Used to register and create closed-loop maneuvers.
- classmethod create(config: ManeuverConfig, agent_id: int, frame: Dict[int, AgentState], scenario_map: Map)[source]¶
Create a new closed-loop maneuver in the given state of the environment with the given configuration.
- Parameters:
config – The maneuver configuration file.
agent_id – The agent for whom the maneuver is created.
frame – The state of all observable agents in the environment.
scenario_map – The road layout.
- maneuver_types = {'follow-lane': <class 'igp2.planlibrary.maneuver_cl.FollowLaneCL'>, 'give-way': <class 'igp2.planlibrary.maneuver_cl.GiveWayCL'>, 'stop': <class 'igp2.planlibrary.maneuver_cl.StopCL'>, 'switch-left': <class 'igp2.planlibrary.maneuver_cl.SwitchLaneLeftCL'>, 'switch-right': <class 'igp2.planlibrary.maneuver_cl.SwitchLaneRightCL'>, 'trajectory': <class 'igp2.planlibrary.maneuver_cl.TrajectoryManeuverCL'>, 'turn': <class 'igp2.planlibrary.maneuver_cl.TurnCL'>}¶
- class igp2.planlibrary.maneuver_cl.ClosedLoopManeuver(config: ManeuverConfig, agent_id: int, frame: Dict[int, AgentState], scenario_map: Map)[source]¶
Bases:
Maneuver
,ABC
Defines a maneuver in which sensor feedback is used
- done(observation: Observation) bool [source]¶
Checks if the maneuver is finished
- Parameters:
observation – current environment Observation
- Returns:
Bool indicating whether the maneuver is completed
- next_action(observation: Observation) Action [source]¶
Selects the next action for the vehicle to take
- Parameters:
observation – current environment Observation
- Returns:
Action that the vehicle should take
- class igp2.planlibrary.maneuver_cl.FollowLaneCL(config: ManeuverConfig, agent_id: int, frame: Dict[int, AgentState], scenario_map: Map)[source]¶
Bases:
FollowLane
,WaypointManeuver
Closed loop follow lane maneuver
- class igp2.planlibrary.maneuver_cl.GiveWayCL(config: ManeuverConfig, agent_id: int, frame: Dict[int, AgentState], scenario_map: Map)[source]¶
Bases:
GiveWay
,WaypointManeuver
Closed loop give way maneuver
- next_action(observation: Observation) Action [source]¶
Selects the next action for the vehicle to take
- Parameters:
observation – current environment Observation
- Returns:
Action that the vehicle should take
- class igp2.planlibrary.maneuver_cl.StopCL(config: ManeuverConfig, agent_id: int, frame: Dict[int, AgentState], scenario_map: Map)[source]¶
Bases:
Stop
,WaypointManeuver
- done(observation: Observation) bool [source]¶
Checks if the maneuver is finished
- Parameters:
observation – current environment Observation
- Returns:
Bool indicating whether the maneuver is completed
- next_action(observation: Observation) Action [source]¶
Selects the next action for the vehicle to take
- Parameters:
observation – current environment Observation
- Returns:
Action that the vehicle should take
- class igp2.planlibrary.maneuver_cl.SwitchLaneLeftCL(config: ManeuverConfig, agent_id: int, frame: Dict[int, AgentState], scenario_map: Map)[source]¶
Bases:
SwitchLaneLeft
,WaypointManeuver
Closed loop switch lane left maneuver
- class igp2.planlibrary.maneuver_cl.SwitchLaneRightCL(config: ManeuverConfig, agent_id: int, frame: Dict[int, AgentState], scenario_map: Map)[source]¶
Bases:
SwitchLaneRight
,WaypointManeuver
Closed loop switch lane right maneuver
- class igp2.planlibrary.maneuver_cl.TrajectoryManeuverCL(config: ManeuverConfig, agent_id: int, frame: Dict[int, AgentState], scenario_map: Map, trajectory: VelocityTrajectory)[source]¶
Bases:
TrajectoryManeuver
,WaypointManeuver
Closed loop maneuver that follows a pre-defined trajectory
- class igp2.planlibrary.maneuver_cl.TurnCL(config: ManeuverConfig, agent_id: int, frame: Dict[int, AgentState], scenario_map: Map)[source]¶
Bases:
Turn
,WaypointManeuver
Closed loop turn maneuver
- class igp2.planlibrary.maneuver_cl.WaypointManeuver(config: ManeuverConfig, agent_id: int, frame: Dict[int, AgentState], scenario_map: Map)[source]¶
Bases:
ClosedLoopManeuver
,ABC
- ACC_ARGS = {'T_a': 1.5, 'a_a': 5, 'b_a': 5, 'delta': 4.0, 's_0': 2.0}¶
- COMPLETION_MARGIN = 0.5¶
- LATERAL_ARGS = {'K_D': 0.0, 'K_I': 0.2, 'K_P': 1.95}¶
- LONGITUDINAL_ARGS = {'K_D': 0.0, 'K_I': 0.05, 'K_P': 1.0}¶
- WAYPOINT_MARGIN = 1¶
- done(observation: Observation) bool [source]¶
Checks if the maneuver is finished
- Parameters:
observation – current environment Observation
- Returns:
Bool indicating whether the maneuver is completed
- get_target_waypoint(state: AgentState)[source]¶
Get the index of the target waypoint in the reference trajectory
- next_action(observation: Observation) Action [source]¶
Selects the next action for the vehicle to take
- Parameters:
observation – current environment Observation
- Returns:
Action that the vehicle should take