Race Code Functions

Our Race Code provides a great starting point to controlling your YetiBorg without having to start from scratch.
The simplest way to get started is to alter the Race Code Instructions contained in the Race.py script.

The special functions available to Race.py are all listed below.

The Race Code Functions

These are the functions currently provided by the standard Race Code.

Basic control

WaitForGo()

Waits for the starting signal lights before continuing.
This will also control the LED on the ZeroBorg to indicate the YetiBorg is ready.

FinishRace()

Turns the motors off and tells the main Formula.py script the race has ended.
This will also control the LED on the ZeroBorg to indicate the YetiBorg has finished.

WaitForSeconds(seconds)

Delays the code for a fixed amount of time in seconds.
This is the same as using the standard time.sleep call from the Python library.

Speed(percentage)

Sets the speed of the YetiBorg in percent, 0 to 100.
Values which are too low will prevent movement, especially when turning.

AimForLane(position)

Changes where on the track the YetiBorg is aiming for.
Values range from +3 for the outside wall to -3 for the inside wall.
Center of the track is 0, we recommend staying between +2.5 and -2.5 to avoid driving into the wall itself.

Distance markers

WaitForWaypoint(pointNumber)

Wait until a waypoint is reached, see the track layout for waypoint numbers.
If you are already between the requested waypoint and the next one the call will come back immediately.

WaitForDistance(distance)

Wait until a distance in meters has been reached, see the track layout for relevant distances.
The track distance is always based on the centre line, which is 22 meters long in total.

LapCount() → laps

Read the current number of completed laps.
Useful to know if you have finished the race or not.

GetDistance() → distance

Read the distance in meters along the current lap.
This is based on the speed travelled and gets reset to 0 when crossing the start/finish line.

Camera processing results

TrackFound() → found

Use this to check if the YetiBorg can see the track, True for when it can be seen, False for when it cannot be seen.
The calls below are only valid if True.

CurrentTrackPosition() → position

Where the YetiBorg is across the track.
Values range from +3 for the outside wall to -3 for the inside wall, the center of the track is 0.

CurrentAngle() → degrees

What angle the YetiBorg is facing verses the track.
Values range from +90 for facing the outside wall to -90 for facing the inside wall.
0 means we are driving parallel to the track.

TrackCurve() → curveAmount

Measures how quickly the track is curving in front of the YetiBorg.
Positive values mean the track is curving towards the left, negative values mean the track is curving to the right.
Low numbers (< ±0.1) typically mean the track is straight ahead.
The Largest numbers are typically seen when the YetiBorg has just entered the corner itself.

TrackLines() → linesList

Gets the points found by the image processing used to calculate the above results.
This is probably only useful to advanced users who need more information than the other functions return.
Each lane on the track (such as the red/green boundary) is represented as a list of the points found.
These lists are then returned as a list containing each list of points separately.

Camera images

GetLatestImage() → image

Get an OpenCV compatible image of the last raw frame grabbed from the camera.
This is the same image used by the internal camera processing

PerformProcessingStage(stage, image) → newImage(s)

Perform one of the processing stages used by the standard camera processing.
See the current guide for a list of the processing stages and the expected input and output images.
Mostly for testing or experimentation use.

SaveImage(image, name)

Saves an image to the race results folder.

Race logging

StartDetailedLoging()

Begins recording a log of what the various parts of the auto-drive system are doing.

StartUserLog()

Begins recording a log of what commands are given to the auto-drive system from the script.

EndDetailedLog()

Stops recording the auto-drive system log.

EndUserLog()

Stops recording the user commands log.

Add new comment

Filtered HTML

  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <blockquote> <code> <ul> <ol> <li> <dl> <dt> <dd> <pre>
  • Syntax highlight code surrounded by the <pre class="brush: lang">...</pre> tags, where lang is one of the following language brushes: bash, cpp, perl, python.
  • Lines and paragraphs break automatically.

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.
CAPTCHA
This question is for testing whether or not you are a human visitor and to prevent automated spam submissions.