Skip to content

Energy challenge coding part

Here you can find some information that will help you get started coding the different systems needed for the Energy Challenge.

Installing the carlib library

The car library files carlib.h and carlib.c are available on Canvas. This library contains useful annotated tips, variables and methods to operate the car subsystems. Some methods are incomplete and it is up to you to fill them. To install the library simply copy these two files to the library folder of the installed libpynq. You are free to code you own libraries in any case.

General code structure

The whole code should be developed with the final structure in mind. Because all of the modules of the code will have to run in a loop, make sure that there are no blocking statements. Create separate functions for different modules of the code for ease of development and troubleshooting. These functions can be stored in either main.c or carlib.c. In the main function, first initialise all of the needed systems of the PYNQ board (GPIO, UART, etc.) Define all of the necessary variables. Finally, an infinite while loop should be started where all of the functions needed for different modules should be called.

Code-structure

Modules

Here some hints are provided to help you start coding the different systems.

Speed measurement

Use the PULSECOUNTER functions to detect the pulses and a timer (GTimer) to measure the time between pulses. Using this data the speed of the car can be calculated.

LEDs

Use the GPIO library to interface the LED strips via serial.

Cruise control

Make sure to first develop the speed measurement system before you start the cruise control.

UART

To update the throttle values, you first need to develop the UART functions in carlib.c. In the table below the communication protocol is described.

UART-table

PID

If you are developing a PID controller for the cruise control, you can use GTimer library for the calculations of the integral and derivative components.

Tip: when testing the car using the power adapter instead of the battery, make sure to keep the throttle levels low, otherwise, the voltage will drop too much and the PYNQ and control board will crash.

Toll payment

Use IR and radio functions from carlib.c to implement the toll payment system.