Welcome to Hackster!
Hackster is a community dedicated to learning hardware, from beginner to pro. Join us, it's free!
Jozsef VasarhelyiDr. Afulay Ahmed Bouzid
Published © GPL3+

Autonomous robot control modelling with DNN IP generator

Have you ever try to accelerate your AI-based process? The tool we propose is able to generate a DNN IP to deploy on a dedicated hardware

AdvancedProtip1.75 hours238
Autonomous robot control modelling with DNN IP generator

Things used in this project

Hardware components

Kria KV260 Vision AI Starter Kit
AMD Kria KV260 Vision AI Starter Kit
×1

Software apps and online services

Vitis Unified Software Platform
AMD Vitis Unified Software Platform
Use Vitis 2021.1.1 with Apache Log4j Vulnerability patch
Vivado Design Suite
AMD Vivado Design Suite
Use Vivado 2021.1.1 with Apache Log4j Vulnerability patch
MATLAB
MATLAB
Use R2021a

Story

Read more

Schematics

The DNN IP simulation

The model of the Hardware in a Loop to test the Generated DNN IP (incorporated into the same model) for KV260 was not possible. The application is MPC control for autonomous steering. The outputs are AXI interfaced. The model can be directly deployed after generating the IP from the System Generator block. If the outputs are changed then the model can be depoloyed for non AXI interface. Both were implemented.

Initialization file, for Matlab mobile model

Before load the DNN IP Simulink model, in Matlab should be entered the initialization file content.

Results

Output results of the DNN-MPC simulation implemented on KV260

Code

DNN IP

MATLAB
Use for implement, import and test the IP in Vivado/Vitis. The file was created with the DNN generator tool.
No preview (download only).

DNN IP Generator Tool

MATLAB
A Matlab GUI to automatically generate a DNN IP to be deployed on FPGAs
No preview (download only).

DNNIP test on KC705 board

C/C++
The test program should be inserted in a Vitis project
#include <stdio.h>
#include <stdint.h>

#include "mb_interface.h"
#include "xparameters.h"
#include "xtmrctr.h"
#include "xuartlite.h"
#include "xintc.h"
#include "xgpio.h"

enum { nuof_data= 8 };
enum { DD_PERIOD= 100 };

uint32_t data[nuof_data];
int dptr= 0;
int bptr= 0;
volatile int timer_cyc= 0;

void timer_handler(void *CallBackRef, u8 TmrCtrNumber);
void uart_handler(void *CallBackRef, unsigned int ByteCount);

XIntc iintc;
XUartLite iuart;
XTmrCtr itimer;
XGpio igpio;

void
ddinit_intc()
{
	XIntc_Initialize(&iintc, 0);
	XIntc_Connect(&iintc, 0, (XInterruptHandler)&XTmrCtr_InterruptHandler, &itimer);
	XIntc_Connect(&iintc, 1, (XInterruptHandler)&XUartLite_InterruptHandler, &iuart);
	XIntc_Enable(&iintc, 0);
	XIntc_Enable(&iintc, 1);
	XIntc_Start(&iintc, XIN_REAL_MODE);
}

void
ddinit_uart()
{
	XUartLite_Initialize(&iuart, 0);
	XUartLite_SetSendHandler(&iuart, &uart_handler, NULL);
	XUartLite_EnableInterrupt(&iuart);
}

void
ddinit_gpio()
{
	XGpio_Initialize(&igpio, 0);
	XGpio_SetDataDirection(&igpio, 1, 0x00000000);
	XGpio_SetDataDirection(&igpio, 2, 0x00000000);
}

uint32_t rl;

void
ddinit_timer()
{
	//XPAR_AXI_TIMER_0_CLOCK_FREQ_HZ
	XTmrCtr_Initialize(&itimer, 0);
	XTmrCtr_Stop(&itimer, 0);
	XTmrCtr_Stop(&itimer, 1);
	rl= DD_PERIOD * (XPAR_AXI_TIMER_0_CLOCK_FREQ_HZ/1000);
	XTmrCtr_SetResetValue(&itimer, 0, rl);
	XTmrCtr_SetOptions(&itimer, 0,
			XTC_DOWN_COUNT_OPTION|
			XTC_INT_MODE_OPTION|
			XTC_AUTO_RELOAD_OPTION);
	XTmrCtr_SetHandler(&itimer, &timer_handler, NULL);
}

void
dd_init()
{
	ddinit_gpio();
	ddinit_intc();
	ddinit_uart();
	ddinit_timer();
	XTmrCtr_Start(&itimer, 0);
	microblaze_enable_interrupts();
}


void
uart_handler(void *CallBackRef, unsigned int ByteCount)
{
	// nothing
	XGpio_DiscreteWrite(&igpio, 2, timer_cyc&0xff);
}

void
start_send()
{
	XUartLite_Send(&iuart, (u8*)data, nuof_data*sizeof(uint32_t));
}

//! Byte swap unsigned int
uint32_t
swap_uint32(uint32_t val)
{
    val = ((val << 8) & 0xFF00FF00 ) | ((val >> 8) & 0xFF00FF );
    return (val << 16) | (val >> 16);
}

void
read_data()
{
	int i;
	data[0]= 0;
	data[1]= *((volatile uint32_t*)XPAR_DNNMPCAXI_0_DNNMPCAXI_KIMENETD_S_AXI_BASEADDR);
	data[2]= *((volatile uint32_t*)XPAR_DNNMPCAXI_0_DNNMPCAXI_KIMENETOMEGA_S_AXI_BASEADDR);
	data[3]= *((volatile uint32_t*)XPAR_DNNMPCAXI_0_DNNMPCAXI_KIMENETRHO_S_AXI_BASEADDR);
	data[4]= *((volatile uint32_t*)XPAR_DNNMPCAXI_0_DNNMPCAXI_KIMENETTHETA_S_AXI_BASEADDR);
	data[5]= *((volatile uint32_t*)XPAR_DNNMPCAXI_0_DNNMPCAXI_KIMENETU_S_AXI_BASEADDR);
	data[6]= *((volatile uint32_t*)XPAR_DNNMPCAXI_0_DNNMPCAXI_KIMENETVY_S_AXI_BASEADDR);
	data[7]= 0x55aa1122;
	for (i=0;i<8;i++)
		data[i]= swap_uint32(data[i]);
}


void
timer_handler(void *CallBackRef, u8 TmrCtrNumber)
{
	timer_cyc++;
	if (timer_cyc == 2)
	{
		XGpio_DiscreteWrite(&igpio, 1, 1);
		//return;
	}
	if (timer_cyc >= 2)
		read_data();
	dptr= 0;
	bptr= 0;
	start_send();
}


void
dd_loop()
{
	while (1)
	{
		mbar(16);
		__asm__ __volatile__ ( "nop" );
	}
}

void
dd()
{
	dd_init();
	dd_loop();
}

Credits

Jozsef Vasarhelyi
1 project • 1 follower
academia
Contact
Dr. Afulay Ahmed Bouzid
1 project • 2 followers
Adjunct Professor at University of Miskolc, Hungary PostDoc Researcher at ÉST, Canada
Contact
Thanks to Alhasan Zghaibe (University of Miskolc); -- Alhasan does not have hackster account, but is team member! and Ahmad Reda (University of Miskolc); -- Reda does not have hackster account, but is team member!.

Comments

Please log in or sign up to comment.