-

hey viewer, we're moving!

We are currently transitioning to a new web system, so we are not updating this wikisite anymore.

The public part of the new web system is available at http://www.ira.disco.unimib.it

Odometry Board

Project for Robotica performed by Lopez Josè Manuel, June 2009 - August 2009.

Contents

• Seal the amplifier.
• Fix the card.
• Interrupt Handler: calculates new state, reads from uart. OK
• Functions Calculating Odometry: angular and tangential velocity and position. OK
• Functions to set wheel distance, right and left wheel radius, encoder's resolution of right and left wheels and Position and reset Position. OK
• Functions to get Position, Velocity and right and left wheels enconders. OK
• Defining commands. OK

Introduction

When the project started there were the board, a part of code with the algorithm to calculate the odometry, and the configuration of the board for the interrupts, and the way to hand them. This parts were useful to understand how the pic works and how an interrupt should be handled.

I have been working in this project for a month each day but i didn't take a measurement of time spent in each task. I have spent the most of the time designing the interrupt handler, because of each one interfered in the other and caused some fails that i couldn't understand.

General

The program works waiting characters of the client and processing this as commands when a return arrives. Independently of this, the timer interrupt causes a call of a function that computes the current position and velocity.

Global Variables

There are three arrays: mCart, mOdometryData and mStatoCart.

mCart serves to access to the parameters of de cart, like radius of the wheels or the distance between the wheels.

mStatoCart is an array of three arguments, the position on the bidimensional plane (X,Y) and the direccion in degrees with respect to the position where the cart was when the program starts.

mOdometryData contents variables used when odometry is being calculed, like dataReady and cmdLen,which serve to manage the reading of commands'.

timeAttuale and timeVecchio serve to know the time between two timer interrupt and calculate the velocity.

Constants

There are so many constans to make the code easier to read and to know at which property are you accessing to each time.

Interrupt TIMER Handler

Each time the timer interrupt arrive, the handler starts a sequence of steps to calculate the present position and the average velocity between the previuos timer interrupt and this. First of this sequence we disable the timer interrupt, and we will enable it after making the steps.

```Disabiliting timer interrupt;
Computing New Position and Updating Velocity; see computePosition.
Timer interrupt flag;
Enabling timer interrupt;
```

Note: I calculated the timer between two interrupts calling the function time(NULL), that return the diffrecen between atcual time and 1/01/1970 in seconds. But the manage of the odometry can be made with a constant that will be the time between two timer interrupts. This time is aprox. 1,640 and we get it of the multiplication of 0,000000025 sec that is the time for an instruction of pic, and PR1=#FFFF=2^16-1 that is period register of timer 1.

computePosition()

We call computeOdometry and use it to calculate the actual position and save it. We take initial position, that will serve as the fix system reference, when the program starts, as (0,0,0 degrees) where the cart was (oriented above the axe 'x'). the turns are positive clockwise since 'x' to 'y'.

```Computing Odometry; see computeOdometry.
Compute updated position and saving it.
```

computeOdometry()

```Computing time;
Computing millimeters;
Computing real movement and rotation;
Computing and saving tangencial and rotacional speed.
```

Interrupt UART(Serial) Handler

Each character that arrives through the uart causes an uart interrupt, the handler starts a sequence of steps to save in a buffer the characters sent, analyses them and behaves on the analysis. If a return arrives means that we have to parse the buffer and if it's a command, we'll execute it. First of this sequence we disable timer and uart interrupts, and we will enable it after making the steps.

```Disabiliting timer interrupt;
Disabiliting uart interrupt;
Check if is a command and in this case Parsing the command; see Parse.
Enabling timer and uart interrupt.
Uart interrupt flag;
```

We read a character and we put it in the array 'inputBuffer'. We check if the character is 'return' and in this case, we put dataReady true and we reset the index 'inputBufferCounter'. This means that the program has recived a suposed command and is ready to parse it and to another command.

Parse()

This is the function that executes the command sent. The switch compares it with each of the posible commands, and the corresponding one is executed. First check the first character, and then checks if the number of characters of this command are right. The list of possible commands is the next:

```G     --->  	getPosition. The function sends through the uart three float, X, Y, and DEGREES, in this order.
D     --->  	getVelocity. The function sends through the uart two float, VELOCITY and ANGULAR VELOCITY.
gXYZ  --->	setPosition(X,Y,Z) where X, Y and Z are float. It changes the array globale 'mStatoCart'. The arguments X, Y  and DEGREES are equivalent to the floats that getPosition sends to uart.
r     --->  	reset. It's like a setPosition(0,0,0);
MX    --->	setWheelDistance(X) where x is float. It changes the distance between right and left wheels.
CX    ---> 	setRadius_dx(X) where x is float. It changes the radius of the right wheel.
EX    --->  	setRadius_sx(X) where x is float. It changes the radius of the left wheel.
KX    --->  	setEncoder_dx(X) where x is float. It changes the encoder of the right wheel.
HX    --->  	setEncoder_dx(X) where x is float. It changes the encoder of the right wheel.
```

Note: the program receives characters as they are being introduced and when 'return' is received, dataReady is actived. This is the signal to run Parse(); Then check if is a valid command and execute it.