Skip to content
racecar-neo-library documentation
⌘ K
racecar-neo-library documentation

Contents:

  • Modules
    • Core
    • Camera
    • Controller
    • Display
    • Drive
    • Led
    • Lidar
    • Nav
    • Physics
    • Slam
    • Telemetry
    • Utils
    • Vision
  • Guides
    • Generalized Bad Apple
racecar-neo-library documentation
/
Modules
/
Nav

Nav#

rc.nav

rc.nav sends the car to points on the loaded map with the car’s navigator, as racecar nav and the Planner (http://<car>:8090) do. A goal holds the driving, not the program: update() keeps running, and rc.drive calls are ignored until the goal ends. A second goal while one runs is refused. In RacecarSim the status is always "off".

Each call stands on parts you built earlier in the course:

  • the pose on the map: rc.slam.get_pose() and your localization.

  • path planning: compare get_path() with the path your planner finds.

  • path following: what your controller did with rc.drive.

  • obstacles: what your lidar code saw before the planner did.

def update():
    if rc.controller.was_pressed(rc.controller.Button.A):
        rc.nav.go_to(2.0, 1.0)          # map meters, any heading
    if rc.controller.was_pressed(rc.controller.Button.B):
        rc.nav.cancel()
    if rc.nav.get_status() == rc.nav.ARRIVED:
        print("Made it")

The program holds the car from create_racecar() until it exits, and a notebook until its kernel is shut down. While something else drives (an app, a Planner mission), rc.drive and rc.nav do nothing and the terminal says who drives, once.

Copyright MIT GNU General Public License v3.0

BWSI Autonomous RACECAR Course Racecar Neo LTS

File Name: nav.py File Description: Defines the interface of the Nav module of the racecar_core library. Sends the car to points on the loaded map with the driver’s navigator (Nav2), as racecar nav and the Planner (port 8090) do.

class nav.Nav#

Drives the car to points on the loaded map.

A goal holds the car’s driving, not the program: update() goes on as usual, and rc.drive calls are ignored until the goal ends. Positions are map meters and headings degrees, as in rc.slam.

Status words (get_status):

“off”: no navigation (no map loaded, the simulator, or no driver). “idle”: this program has no goal. “navigating”: driving to a waypoint. “waiting”: at a mission waypoint, during its wait. “lost”: localization lost. The car stops and goes on once localized. “paused”: paused from the Planner; goes on at Resume. “arrived”, “failed”, “stalled”, “canceled”: how the last goal ended, until the next goal.

abstractmethod cancel() → None#

Stops this program’s goal or mission; the car stops.

Note

BACK and the end of the program cancel it too. A goal or mission started elsewhere (the Planner, racecar nav) is left alone.

abstractmethod get_distance_left() → float | None#

Returns the meters left to the current waypoint, or None without a goal.

abstractmethod get_missions() → List[str]#

Returns the names of the missions saved for the loaded map, [] without a map.

abstractmethod get_path() → List[Tuple[float, float]]#

Returns the path Nav2 planned to the current waypoint as (x, y) points, [] without a goal. Compare it with a path your own planner finds.

abstractmethod get_status() → str#

Returns the status word (see the class description).

Example:

if rc.nav.get_status() == rc.nav.ARRIVED:
    print("Made it")
abstractmethod go_to(x: float, y: float, heading: float | None = None) → bool#

Drives to a point on the loaded map.

Parameters:
  • x – Map x in meters.

  • y – Map y in meters.

  • heading – The heading to face there in degrees, or None for any.

Returns:

True when the goal started. False when it was refused (another goal or mission runs, something else drives, no map, not localized, or stalled). The reason is printed once.

Example:

# Drive to (2, 1) when A is pressed
if rc.controller.was_pressed(rc.controller.Button.A):
    rc.nav.go_to(2.0, 1.0)
abstractmethod is_active() → bool#

Returns True while this program’s goal or mission holds the driving: navigating, waiting, lost or paused.

abstractmethod move(distance: float) → bool#

Drives a distance along the car’s heading.

Parameters:

distance – Meters ahead; negative backs up.

Returns:

True when the goal started, else False (see go_to).

abstractmethod run_mission(name: str) → bool#

Runs a mission saved in the Planner for the loaded map.

Parameters:

name – The mission’s name (see get_missions).

Returns:

True when the mission started, else False (see go_to).

Note

A mission run from a program does not record; recording is the Planner’s.

abstractmethod wait(timeout: float | None = None) → str#

Blocks until the goal ends or timeout seconds pass. For notebooks only. Do not call it in update().

Returns:

The status word.

On this page

  • Nav
    • Nav.cancel()
    • Nav.get_distance_left()
    • Nav.get_missions()
    • Nav.get_path()
    • Nav.get_status()
    • Nav.go_to()
    • Nav.is_active()
    • Nav.move()
    • Nav.run_mission()
    • Nav.wait()

© 2024-2026, MIT. Built with Sphinx 9.0.4