{"record":{"id":"8a1455ee237e650f","repo":"AtsushiSakai/PythonRobotics","slug":"path-position-not-found-for-time-i","errorCode":null,"errorMessage":"Path position not found for time {i}.","messagePattern":"Path position not found for time (.+?)\\.","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"error","filePath":"PathPlanning/TimeBasedPathPlanning/Plotting.py","lineNumber":44,"sourceCode":"    (start_and_goal,) = ax.plot([], [], \"mD\", ms=15, label=\"Start and Goal\")\n    start_and_goal.set_data([start.x, goal.x], [start.y, goal.y])\n    (obs_points,) = ax.plot([], [], \"ro\", ms=15, label=\"Obstacles\")\n    (path_points,) = ax.plot([], [], \"bo\", ms=10, label=\"Path Found\")\n    ax.legend(bbox_to_anchor=(1.05, 1))\n\n    # for stopping simulation with the esc key.\n    plt.gcf().canvas.mpl_connect(\n        \"key_release_event\",\n        lambda event: [exit(0) if event.key == \"escape\" else None]\n        if isinstance(event, KeyEvent) else None\n    )\n\n    for i in range(0, path.goal_reached_time()):\n        obs_positions = grid.get_obstacle_positions_at_time(i)\n        obs_points.set_data(obs_positions[0], obs_positions[1])\n        path_position = path.get_position(i)\n        if not path_position:\n            raise Exception(f\"Path position not found for time {i}.\")\n\n        path_points.set_data([path_position.x], [path_position.y])\n        plt.pause(0.2)\n    plt.show()\n\n'''\nPlot a series of agent paths.\n'''\ndef PlotNodePaths(grid: Grid, start_and_goals: list[StartAndGoal], paths: list[NodePath]):\n    fig = plt.figure(figsize=(10, 7))\n\n    ax = fig.add_subplot(\n        autoscale_on=False,\n        xlim=(0, grid.grid_size[0] - 1),\n        ylim=(0, grid.grid_size[1] - 1),\n    )\n    ax.set_aspect(\"equal\")\n    ax.grid()","sourceCodeStart":26,"sourceCodeEnd":62,"githubUrl":"https://github.com/AtsushiSakai/PythonRobotics/blob/1fe4fb980f6a12fe21c3c33d2b4da97a52c9154d/PathPlanning/TimeBasedPathPlanning/Plotting.py#L26-L62","documentation":"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.","triggerScenarios":"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.","commonSituations":"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().","solutions":["Inspect path.path node times and ensure they are consecutive from 0 through goal_reached_time()","Fix the planner/path construction so get_position(i) is defined for all i in [0, goal_reached_time())","If the path is genuinely sparse, build a filled NodePath (insert wait nodes) before plotting"],"exampleFix":"# before\nnode_path = NodePath([Node(Position(0, 0), 0), Node(Position(2, 0), 2)])  # gap at t=1\nPlotNodePath(grid, node_path)\n\n# after\nnode_path = NodePath([Node(Position(0, 0), 0), Node(Position(1, 0), 1), Node(Position(2, 0), 2)])\nPlotNodePath(grid, node_path)","handlingStrategy":"validation","validationCode":"times = [n.time for n in node_path.path]\nassert times == list(range(times[0], times[-1] + 1)), \"path has time gaps\"\nassert all(node_path.get_position(i) for i in range(node_path.goal_reached_time()))","typeGuard":"def is_dense_node_path(p) -> bool:\n    times = [n.time for n in p.path]\n    return times == list(range(times[0], times[-1] + 1)) and times[0] == 0","tryCatchPattern":null,"preventionTips":["Only plot paths produced by the bundled planners, which emit consecutive timesteps","Validate path density before plotting or persisting paths"],"tags":["path-planning","plotting","animation","path-validation"],"backgroundTag":"incomplete-path-data","analyzedSha":"1fe4fb980f6a12fe21c3c33d2b4da97a52c9154d","analyzedAt":"2026-08-28T13:23:33.733Z","schemaVersion":2},"datasetVersion":"2026-08-28T16:17:29.566Z"}