# Overview of Example Code

This page explains the overview and features of the self driving code provided in aim_line_follow.py

Inside of `aim_line_follow.py`

, there is a function that receives vector information from the simulated Pixy camera and returns speed and steer values. The vector information is received through nxp_cup_interfaces that contains the PixyVector message and is nearly identical to the vector information sent by the Pixy over I2C.

The source code uses a simple algorithm to extract speed and steer values from the supplied vector data to drive the car. We expect contestants to improve upon this algorithm and show us how fast their simulated NXP Cup car can go!

## Key Components

### Important Variables and Functions

There are several important variables and functions that are used in the code. A key description of them is given below:

### Data Structure of PixyVector

This data structure contains the head and tail points of two vectors from the simulated pixy camera.

The two vectors are defined by **msg.m0_** __ and _ **msg.m1**_**_.**

## If-Else Block

The if-else block statements within `listener_callback()`

performs different instructions depending on how many vectors are found.

### Case: 0 vectors found

If no vectors are found (case 0), then a timer will start and tell the vehicle to stop after a certain amount of time

### Case: 1 vector found

If one vector is found, the algorithm finds the gradient of the vector and stores that in `steer`

, and the `speed`

### Case: 2 vectors found

If two vectors are found, then the example algorithm will find the offset in the x direction of the average of the two head points of each vector. This will give us a steering values that will steer the cup car in the correct direction. This value is stored in `steer`

. The speed value will be calculated and is stored in `speed`

.

Last updated