- Main Page
- Modules
- Data Structures
- Files
- Directories

# e_prox.c File Reference

Accessing proximity sensor of e-puck with timer 1. More...

`#include "e_ad_conv.h"`
`#include "./../motor_led/e_epuck_ports.h"`
`#include "e_prox.h"`

## Functions
void | init_tmr1 (void)
void | __attribute__ ((interrupt, auto_psv, shadow))
void | e_init_prox (void)
| Init the proxymity sensor A/D converter and the timer1.
void | e_stop_prox (void)
| Stop the acquisition (stop timer1).
int | e_get_prox (unsigned int sensor_number)
| To get the analogic proxy sensor value of a specific sensor.
int | e_get_ambient_light (unsigned int sensor_number)
| To get the analogic ambient light value of a specific sensor.
## Variables
static int | ambient_ir [8]
static int | ambient_and_reflected_ir [8]
static int | reflected_ir [8]

## Detailed Description

Accessing proximity sensor of e-puck with timer 1.

The functions of this file are made to deal with the proximity sensor data. You can know the value of the ambient light detected by the sensor. You can estimate the distance between the e-puck and an obstacle by using e_get_prox(unsigned int sensor_number) function.

A little exemple which turn the LED0 when an obstacle is detected by the proximity sensor number 0.

     #include <p30f6014A.h>
     #include <motor_led/e_epuck_ports.h>
     #include <motor_led/e_init_port.h>
     #include <a_d/e_prox.h>

     int main(void)
     {
            int value;
            e_init_port();
            e_init_prox();
            while(1)
            {
                    long i;
                    value = e_get_prox(0);
                    if(value > 1000)        //LED0 on if an obstacle is detected by proxy0
                            LED0 = 1;
                    else
                            LED0 = 0;
                    for(i=0; i<100000; i++) { asm("nop"); }
            }
     }

Warning:
  This module uses the timer1

Author:
  Code: Lucas Meier & Francesco Mondada, Michael Bonani
  Doc: Jonathan Besuchet

## Function Documentation

void __attribute__ | ( | (interrupt, auto_psv, shadow) |  | ) |

int e_get_ambient_light | ( | unsigned int | sensor_number | ) |

To get the analogic ambient light value of a specific sensor.

To get the analogic ambient light value of a specific ir sensor.

This function retur the analogic value of the ambient light measurement.

Parameters:

  | sensor_number | The proxy sensor's number that you want the value. Must be between 0 to 7.

Returns:
  The analogic value of the specified proxy sensor

int e_get_prox | ( | unsigned int | sensor_number | ) |

To get the analogic proxy sensor value of a specific sensor.

To get the analogic proxy sensor value of a specific ir sensor.

To estimate the proxymity of an obstacle, we do the following things:

- measure the ambient light
- turn on the IR led of the sensor
- measure the reflected light + ambient light
- calculate: reflected light = (reflected light + ambient light) - ambient light
- turn off the IR led of the sensor

The result value of this function is: reflected light. More this value is great, more the obsacle is near.

Parameters:

  | sensor_number | The proxy sensor's number that you want the value. Must be between 0 to 7.

Returns:
  The analogic value of the specified proxy sensor

void e_init_prox | ( | void |  | ) |

Init the proxymity sensor A/D converter and the timer1.

Warning:
  Must be called before starting using proximity sensor

void e_stop_prox | ( | void |  | ) |

Stop the acquisition (stop timer1).

void init_tmr1 | ( | void |  | ) |

## Variable Documentation

int ambient_and_reflected_ir[8]`[static]`

int ambient_ir[8]`[static]`

int reflected_ir[8]`[static]`