Lab 8: Autonomus Vehicle
Week 1
Introduction
This first week is devoted to assembling and testing your autonomous robot car. First you and your partner will modify your SoC to include the peripherals necessary for communication with the car sensors. Then you will follow the video instructions to assemble the shadow chassis, which is the base platform for your Arty Bot. Your TA will be available to help you through the assembly process. Zip ties and “engineering grade” rubber bands will be available in the lab if you need them.
Lab Instructions
Start by downloading this IP Repository. It contains some of the IPs we’ll need for our robot project. Extract the “ip_repo” directory and place it in your SoC project directory.
- Now let us make some changes to our SoC (System on Chip). Start by opening your project in Vivado. In the Flow Navigator on the left side, navigate to “Open Block Design.”
- To add our downloaded IP to Vivado, navigate to “Project Settings” to open the Project Settings dialog. In the left panel select “IP,” then select the “Repository Manager” tab. Now add the IP repository folder you copied earlier. Select “Apply” and close the dialog.
Back in the block design of your SoC. We want to add IP to the SoC for communicating with the external Pmod peripherals. We will add AXI GPIO, Pmod_DHB1, and Pmod_Dual_MAXSONAR IP for communication with the two line detecting light sensors, Pmod MAXSONAR sensor, and Pmod DHB1 motor driver.
Do not use connection automation…
- AXI GPIO » jA » Pmod LS1:
- Using the + Add IP button and dialog. Add a new AXI GPIO and Pmod Bridge IP to your design.
- Connect the S_AXI bus port of the AXI GPIO to a port on the interconnect.
- Connect the two GPIO ports on the AXI GPIO with the GPIO_Top_Row and GPIO_Bottom_Row on the Pmod Bridge.
- Finally, in the “Board” window on the left, right-click the jA port under Pmod and select “connect component.” In the dialog that appears, find the Pmod bridge you just added and select the Pmod_out port as your connection. One more thing, enable interrupts for the AXI GPIO.
- Pmod_Dual_MAXSONAR » jB » Pmod MAXSONAR:
- Add the Pmod_Dual_MAXSONAR IP and connect it to a Pmod Bridge.
- You can connect the Pmod_out port of the Pmod Bridge to the jB Pmod port.
- Pmod_DHB1 » jD » Pmod DHB1:
- Add the Pmod_DHB1_v1_0 IP and connect it to the jD Pmod port through a Pmod Bridge.
- AXI GPIO » jA » Pmod LS1:
- Go to “Address Editor” window of the block design and assign memory addresses to the newly added IP.
- Validate your design and generate a bitstream.
Project Assignment
- Watch the assembly instruction video or follow the instructions given here to assembly the chassis of your robot.
- Mount the two IR (infrared) Proximity sensors somewhere on the front of car. Try to mount them as close as possible to the floor. Connect the sensors to one of S1, S2, S3, or S4 pin headers on the Pmod LS1 module. Finally, connect the Pmod LS1 module to the Arty board via the Pmod port you connected the AXI GPIO in the board design.
- Mount the two Pmod MAXSONAR sensors on the front of the car. Use the provided Pmod extension cables to connect the sensors to the Pmod port where you connected the AXI GPIO in the board design. Connect one sensor to the bottom row of the Pmod port and the other to the top row of the same Pmod port.
- Connect the Pmod DHB1 to the Arty board via the Pmod port you selected in the board design. Now make the following connections on the Pmod DHB1 module:
- Connect the left and right motors to the screw terminals J5 and J6.
- Connect the Hall effect sensors to J7 and J8. The red wire is VCC, black is GND, and white is motor feedback. The motor feedback signal is used to count wheel revolutions using the Hall effect sensors.
- Connect the AA battery pack to the screw terminal at J4.
Prelab Assignment
Take a look at the manuals listed in the references sections
- Tang, A. ArtyBot - A two-wheel robotics platform built on the Arty development board. Hackster.io
- Pmod Interface Specification
- Pmod LS1 Reference Manual
- Pmod MAXSONAR Reference Manual
- Pmod DHB1 Reference Manual
Week 2
Introduction
Now that you have assembled your car, the next step in our journey is learning how to flash programs onto FPGA boards. Doing so will cause the FPGA board to automatically load your program from flash memory as soon as you connect the board to a power source to the board. In order to accomplish this, we will have to make one more modification to the SoC.
Lab Instructions
Vivado:
We’re going to add the SPI Flash Memory to our design. The instructions below will walk you through the process.
- Open your project in Vivado. In the Flow Navigator, navigate to “Open Block Design”.
- Start by adding a port to the “microblaze_0_axi_mem” interconnect.
- Time to add the “AXI Quad SPI” flash memory controller:
- Navigate to the “Board” window.
- Right-click on the “Quad SPI Flash” and select “Auto Connect”. This should add a new IP block to your design.
- Next, connect the “AXI_LITE” port to the “microblaze_0_axi_mem” interconnect.
- Use the “Connection Automation” feature to make the following connections:
- ext_spi_clk:
/mig_7series_0/ui_clk (81 MHz)
- s_axi_aclk:
/mig_7series_0/ui_clk (81 MHz)
- M01_ACLK:
/mig_7series_0/ui_clk (81 MHz)
- ext_spi_clk:
- Finally, assign an address to the memory controller.
- Double-click on the “AXI Quad Flash” controller to open the “Re-customize IP” window:
- Under “IP Configuration”, change the “Slave Device” option to
Spansion
. - Select “OK” to save the changes and close the window.
- Under “IP Configuration”, change the “Slave Device” option to
- Validate your design, and generate a bitstream.
- Export your bitstream. Remember, to select to “include bitstream” option.
Spansion is the manufacturer of the SPI flash memory chip on the FPGA board.
SDK:
- Download this GitHub repo, and look at the example applications in the “embedded_systems_lab.sdk” directory. The examples demonstrate how to use the sensors and control the motors on your car.
- Download the Board Flashing Guide. The guide will show you how to flash how to flash any application onto your FPGA board. You can use any application from the “Fayetteville Bike Crossing” series to test the process.
- Design an application capable of following the line and driving your car around the track.
- Top 5 fastest cars get 5 points towards final grade.
Hints:
- The light sensors will pick up reflections from shiny objects. Use them to detect the reflective tape on track.
- The sonar sensors API function will return a distance value in inches. When you test them, point them towards a large open area. Spaces with many objects nearby will give you false readings.
- Test the functionality of your sensor on your desk first before moving to the track. This will save you a lot of time during development.
- If you get stuck, ask for help.
- While I recommend using FreeRTOS, you are free to design your application however you see fit. Remember, there are bonus points on the line. Take them by any means necessary!
Good luck!
Project Assignment
The PDF instructions have more details and illustration images.
- Turn your car into a line following robot. The line will be a (silver) duct tape track and your car should drive around the track with wheels on either side of the track. There will be an obstacle at the end of the track, use this to stop your car. To do this:
- Use the GPIO PMOD LS1 to detect when your car drives over the line and steer that car back onto the track
- Use the PMOD MAXSONAR to detect obstacles and stop the car before the obstacle.
- Program the Arty’s non-volatile 16 MB Quad-SPI flash memory with your SoC and application so that your application runs when you power on the Arty board. NB: the file names in this section may be different from what you have in your project. Just remember what you named your SoC in Vivado and project name in the SDK and the rest should look familiar. If you are unsure ask your TA for help. To program your Arty:
- Right-click your project folder, the project you want to flash onto the board, and select Generate Linker Script. On the right side, change all 3 dropdowns from
microblaze_0_local
… tomig_7series_0_memaddr
. If you are on Linux this might not work. You may need to open the lscript.ld file in your project’ssrc
directory and manually change all the entries tomig_7series_0_memaddr
. - Click the Program Flash button in the toolbar. Next to Image File, click Browse and navigate to your project folder, then into Debug. Select your_project_name.elf and click open. Next to Offset, enter
0x00C00000
. This is the address offset where your program will be stored in the flash memory. Next to ‘Flash Type,’ select S25FL128sxxxxxx0-spi-x1_x2_x4. IMPORTANT, make sure ‘Convert ELF to bootloadable SREC format and program’ is checked. Click Program. - To create a bootloader, in the toolbar select File > New > Application Project. Name the project something like ‘bootloader’ as shown in the image above. Click Next.
- Select SREC SPI Bootloader, and select Finish.
- We need to make a few changes to our bootloader before loading it onto the Arty board. First, we need to set the ‘address offset’ so the bootloader can find our application. In the ‘Bootloader’ project, open the blconfig.h file and change the FLASH_IMAGE_BASEADDR to
0x00C00000
. Note, this same address you used when you flashed your application onto the flash memory earlier. Optional, if you wish to improve your ArtyBot’s startup time. Edit the file bootloader.c and comment out the line
#define VERBOSE
. This will turn off console logging. NB: Console logs may be useful when you’re initially setting things up.- Click the Program FPGA button in the toolbar. In the right half of the Software Configuration section, there is a cell that says
bootloop
. Click the right side of this cell to reveal a drop-down menu. Select Bootloop.elf from the list, then click Program. This will generate a bit file with the MicroBlaze’s memory initialized with the program that you have written. The Arty is also programmed and if everything went well you should see your application running in your favorite console application (e.g. SDK Terminal, Putty or TeraTerm) - Almost there, click the Program Flash button in the toolbar. Next to Image File, click Browse and navigate to the SDK workspace, then into
base_soc_wrapper_hw_platform_0
. Selectdownload.bit
and click Open. Next of Offset, enter0x0
. Next to Flash Type, selectS25FL128sxxxxxx0-spi-x1_x2_x4
. Click Program. - Congratulations, you have flashed the bootloader and your application to the non-volatile SPI Qflash memory. Next time you power on the board, the bootloader will be copied from the flash memory and when it runs, it will execute your application.
Prelab Assignment
None this week. Lucky you!
References
- FreeRTOS Manual https://www.freertos.org/FreeRTOS-quick-start-guide.html (expand API Reference on the side for full documentation on function calls)
- Tang, A. ArtyBot - A two-wheel robotics platform built on the Arty development board. Hackster.io