Elisa3
sensors.h File Reference

Sensors module. More...

#include <stdlib.h>
#include <math.h>
#include "variables.h"
#include <avr\io.h>
#include "leds.h"
#include "twimaster.h"

Go to the source code of this file.

Functions

void calibrateSensors ()
 Calibrate all the sensors (proximity, ground and accelerometer). Pay attention for the robot to be positionated in a flat surface and that no objects obstruct the sensors. Peripherals need to be already initialized before calling this function.
void initAccelerometer ()
 Test which device is mounted on the robot and configure it.
unsigned char initADXL345 ()
 Configure the ADXL345 accelerometer (2g sensitivity, 10 bits resolution).
unsigned char initMMA7455L ()
 Configure the MMA74565L accelerometer (2g sensitivity, 10 bits resolution).
void readAccelXY ()
 Request the X and Y values (10 bit data, 2's complement) and save them in their respective global variables accX and accY.
void readAccelXYZ ()
 Request the X, Y and Z values (10 bit data, 2's complement) and save them in their respective global variables accX, accY and accZ.
void readAccelXYZ_1 ()
void readAccelXYZ_2 ()
void computeAngle ()
 Compute the angle of the robot using the X and Y axes; the resulting angle is saved in the global variable "currentAngle". The angle refers to a classical reference system where the 0 points to the right, 90 to the top, 180 to the left and 270 to the bottom in a vertical wall. In order for the angle to be computed correctly, the robot has to be calibrated leaving it flat on the ground. Moreover this function update the robot motion plane (horizontal or vertical) based on the Z axis; this information is then used to switch between horizontal and vertical speed controller.

Detailed Description

Sensors module.

Author:
Stefano Morgani <stefano@gctronic.com>
Version:
1.0
Date:
01.02.12

General module that contains functions to interact with the sensors mounted on the robot (proximity, ground, accelerometer). The I2C communication is initialized to work with the accelerometer. There are functions to work with both the Freescale MMA7455 and the Analog Device ADXL345 accelerometers.


Function Documentation

void calibrateSensors ( )

Calibrate all the sensors (proximity, ground and accelerometer). Pay attention for the robot to be positionated in a flat surface and that no objects obstruct the sensors. Peripherals need to be already initialized before calling this function.

Returns:
none
void computeAngle ( )

Compute the angle of the robot using the X and Y axes; the resulting angle is saved in the global variable "currentAngle". The angle refers to a classical reference system where the 0 points to the right, 90 to the top, 180 to the left and 270 to the bottom in a vertical wall. In order for the angle to be computed correctly, the robot has to be calibrated leaving it flat on the ground. Moreover this function update the robot motion plane (horizontal or vertical) based on the Z axis; this information is then used to switch between horizontal and vertical speed controller.

Returns:
none

Test which device is mounted on the robot and configure it.

Returns:
none
unsigned char initADXL345 ( )

Configure the ADXL345 accelerometer (2g sensitivity, 10 bits resolution).

Return values:
0configuration ok
1communication error
unsigned char initMMA7455L ( )

Configure the MMA74565L accelerometer (2g sensitivity, 10 bits resolution).

Return values:
0configuration ok
1communication error
void readAccelXY ( )

Request the X and Y values (10 bit data, 2's complement) and save them in their respective global variables accX and accY.

Returns:
none
void readAccelXYZ ( )

Request the X, Y and Z values (10 bit data, 2's complement) and save them in their respective global variables accX, accY and accZ.

Returns:
none
void readAccelXYZ_1 ( )
void readAccelXYZ_2 ( )
 All Files Functions Variables Defines