AtsushiSakai/PythonRobotics · error · Exception

Path position not found for time {i}.

Error message

Path position not found for time {i}.

What it means

Raised in PlotNodePath when path.get_position(i) returns a falsy value for some timestep i before goal_reached_time(). The animation loop expects the NodePath to have a defined position at every timestep from 0 to the goal time; a missing entry means the path is malformed or its timing is inconsistent.

Source

Thrown at PathPlanning/TimeBasedPathPlanning/Plotting.py:44

    (start_and_goal,) = ax.plot([], [], "mD", ms=15, label="Start and Goal")
    start_and_goal.set_data([start.x, goal.x], [start.y, goal.y])
    (obs_points,) = ax.plot([], [], "ro", ms=15, label="Obstacles")
    (path_points,) = ax.plot([], [], "bo", ms=10, label="Path Found")
    ax.legend(bbox_to_anchor=(1.05, 1))

    # for stopping simulation with the esc key.
    plt.gcf().canvas.mpl_connect(
        "key_release_event",
        lambda event: [exit(0) if event.key == "escape" else None]
        if isinstance(event, KeyEvent) else None
    )

    for i in range(0, path.goal_reached_time()):
        obs_positions = grid.get_obstacle_positions_at_time(i)
        obs_points.set_data(obs_positions[0], obs_positions[1])
        path_position = path.get_position(i)
        if not path_position:
            raise Exception(f"Path position not found for time {i}.")

        path_points.set_data([path_position.x], [path_position.y])
        plt.pause(0.2)
    plt.show()

'''
Plot a series of agent paths.
'''
def PlotNodePaths(grid: Grid, start_and_goals: list[StartAndGoal], paths: list[NodePath]):
    fig = plt.figure(figsize=(10, 7))

    ax = fig.add_subplot(
        autoscale_on=False,
        xlim=(0, grid.grid_size[0] - 1),
        ylim=(0, grid.grid_size[1] - 1),
    )
    ax.set_aspect("equal")
    ax.grid()

View on GitHub (pinned to 1fe4fb980f)

Solutions

  1. Inspect path.path node times and ensure they are consecutive from 0 through goal_reached_time()
  2. Fix the planner/path construction so get_position(i) is defined for all i in [0, goal_reached_time())
  3. If the path is genuinely sparse, build a filled NodePath (insert wait nodes) before plotting

Example fix

# before
node_path = NodePath([Node(Position(0, 0), 0), Node(Position(2, 0), 2)])  # gap at t=1
PlotNodePath(grid, node_path)

# after
node_path = NodePath([Node(Position(0, 0), 0), Node(Position(1, 0), 1), Node(Position(2, 0), 2)])
PlotNodePath(grid, node_path)
Defensive patterns

Strategy: validation

Validate before calling

times = [n.time for n in node_path.path]
assert times == list(range(times[0], times[-1] + 1)), "path has time gaps"
assert all(node_path.get_position(i) for i in range(node_path.goal_reached_time()))

Type guard

def is_dense_node_path(p) -> bool:
    times = [n.time for n in p.path]
    return times == list(range(times[0], times[-1] + 1)) and times[0] == 0

Prevention

When it happens

Trigger: Passing a NodePath to PlotNodePath whose path list has gaps in time (non-consecutive node.time values) or whose goal_reached_time() exceeds the last node's time, e.g. after hand-constructing or mutating a path.

Common situations: Plotting a path built by a custom planner or edited manually where wait/move steps are missing; a path that starts at t>0; off-by-one in goal_reached_time().

Related errors


AI-assisted analysis of AtsushiSakai/PythonRobotics@1fe4fb980f (2026-08-28). Data as JSON: /api/errors/8a1455ee237e650f. Report an issue: GitHub.