Code Organization

From Officine Robotiche
Jump to: navigation, search

The µNav board is designed around a dsPIC33FJ128MC804 to both control the motors and perform navigation. The program is fully interrupt driven: after the initializations, the program enters in a "no-code" Main loop and every action is started via Interrupt Service Routines triggered by interrupts.

Folders Organization

Routines are grouped in 3 folders:

Communication
Control
System

Communication folder contains routines used for µNav communication with an external board used as Master board. Here are routines for UART and I2C communication.

Control folder contains PID, Odometry and Dead Reckoning routines

System folder contains Settings, Configuration word, Interrupt Service Routines.

Interrupt Service Routines

The dsPIC33F has 44 interrupt vectors used by the peripherals and 8 reserved to the system (traps). Some interrupts are managed directly by the hardware peripherals or through the DMA, other are used as "soft interrupts" triggered by the code. In this way it's possible to define the priority for each function, even dinamically, optimizing the resources at most. A slow procedure can be interrupted by time-critical one performing a true real-time behavior.

Peripheral interrupts

Input Capture 1 and 2 used to obtain the speed
Timer 1 overflow used as the time scheduler for all the timed procedures
Timer 2 overflow used, together with IC1 and IC2, to measure the encoder ticks
UART1 RX for incoming communication
DMA0 used by the ADC to measure the motor current
DMA1 used by UART TX

Soft interrupts

OC1 (Output Compare 1) triggers the speed measurement and PIDs control
OC2 (Output Compare 2) triggers the incoming communication packets parsing
RTC (Real Time Clock) triggers the dead-reckoning procedures