Core#

Copyright MIT MIT License

BWSI Autonomous RACECAR Course Racecar Neo LTS

File Name: racecar_core.py File Description: Contains the Racecar class, the top level of the racecar_core library

class racecar_core.Racecar#

The top level racecar module containing several submodules which interface with and control the different pieces of the RACECAR hardware.

abstract get_delta_time() float#

Returns the number of seconds elapsed in the previous frame.

Returns:

The number of seconds between the start of the previous frame and the start of the current frame.

Example:

# Increases counter by the number of seconds elapsed in the previous frame
counter += rc.get_delta_time()
abstract go() None#

Starts the RACECAR, beginning in default drive mode.

Note

go idles blocks execution until the program is exited when START + END are pressed simultaneously.

abstract set_start_update(start: Callable[[], None], update: Callable[[], None], update_slow: Callable[[], None] | None = None) None#

Sets the start and update functions used in user program mode.

Parameters:
  • start – A function called once when the car enters user program mode.

  • update – A function called every frame in user program mode. Approximately 60 frames occur per second.

  • update_slow – A function called once per fixed time interval in user program mode (by default once per second).

Note

The provided functions should not take any parameters.

Example:

# Create a racecar object
rc = Racecar()

# Define a start function
def start():
    print("This function is called once")

# Define an update function
def update():
    print("This function is called every frame")

# Provide the racecar with the start and update functions
rc.set_start_update(start, update)

# Tell the racecar to run until the program is exited
rc.go()
abstract set_update_slow_time(time: float = 1.0) None#

Changes the time between calls to update_slow.

Parameters:

time – The time in seconds between calls to update_slow.

Example:

# Sets the time between calls to update_slow to 2 seconds
rc.set_update_slow_time(2)
racecar_core.create_racecar(isSimulation: bool | None = None) Racecar#

Generates a racecar object based on the isSimulation argument or execution flags.

Parameters:

isSimulation – If True, create a RacecarSim, if False, create a RacecarReal, if None, decide based on the command line arguments

Returns:

A RacecarSim object (for use with the Unity simulation) or a RacecarReal object (for use on the physical car).

Note

If isSimulation is None, this function will return a RacecarSim if the program was executed with the “-s” flag and a RacecarReal otherwise.

If the program was executed with the “-d” flag, a display window is created.

If the program was executed with the “-h” flag, it is run in headless mode, which disables the display module.