Hi,

I'm trying to get started with the microphone function of the e-puck. My
problem is getting any one of the microphones to listen for any level of
sound. I then want to check that level, if it's beyond a certain integer I
turn on an LED. I know to get a better reading I set the robot to listen
for as period of time, then I take the absolute of these samples. This way
it shouldn't miss a noise too. But my code doesn't seem to function
properly and I'm unable to figure out why. I think it has something to do
with the  e_get_micro, but this function isn't very well documented.

Any help would be greatly appreciated.

The following is my code so far, ignore the proximity handling:


#include <motor_led/e_init_port.h>
#include <motor_led/e_epuck_ports.h>
#include <motor_led/advance_one_timer/e_agenda.h>
#include <motor_led/advance_one_timer/e_motors.h>
#include <motor_led/advance_one_timer/e_led.h>
#include <codec/e_sound.h>
#include <p30f6014A.h>
#include <a_d/advance_ad_scan/e_prox.h>
#include <a_d/advance_ad_scan/e_ad_conv.h>
#include <dsp.h>
#include <fft/e_fft.h>
#include <fft/e_fft_utilities.h>
#include <a_d/e_ad_conv.h>
#include <a_d/e_ad_conv.c>
#include <a_d/e_micro.c>

#define _MOTORS



  int proxy0;
  int proxy1;
  int proxy2;
  int proxy3;
  int proxy4;
  int proxy5;
  int proxy6;
  int proxy7;
  int m0;
  int m1;
  int m2;



void blink_body(void)
{
        BODY_LED = BODY_LED^1;

}

//----------Methods to alternate on and off for led's creating blinking
effect---

void blink_led0(void)
{
        if (LED0 == 1)
                LED0 = 0;
        else
                LED0 = 1;
}

void blink_led1(void)
{
        if (LED1 == 1)
                LED1 = 0;
        else
                LED1 = 1;
}

void blink_led2(void)
{
        if (LED2 == 1)
                LED2 = 0;
        else
                LED2 = 1;
}

void blink_led3(void)
{
        if (LED3 == 1)
                LED3 = 0;
        else
                LED3 = 1;
}

void blink_led4(void)
{
        if (LED4 == 1)
                LED4 = 0;
        else
                LED4 = 1;
}

void blink_led5(void)
{
        if (LED5 == 1)
                LED5 = 0;
        else
                LED5 = 1;
}

void blink_led6(void)
{
        if (LED6 == 1)
                LED6 = 0;
        else
                LED6 = 1;
}

void blink_led7(void)
{
        if (LED7 == 1)
                LED7 = 0;
        else
                LED7 = 1;
}



void forward(){
e_set_speed_left(500);
e_set_speed_right(500);
}

void stop(){
e_set_speed_left(0);
e_set_speed_right(0);
}

void backward(){
e_set_speed_left(-500);
e_set_speed_right(-500);
}

// Left turning methods

void left_turn1(){
e_set_speed_right(500);
e_set_speed_left(-600);
}

void left_turn2(){
e_set_speed_right(500);
e_set_speed_left(-500);
}

void left_turn3(){
e_set_speed_right(500);
e_set_speed_left(-200);
}

// Right turning methods

void right_turn1(){
e_set_speed_left(500);
e_set_speed_right(-600);
}

void right_turn2(){
e_set_speed_left(500);
e_set_speed_right(-500);
}

void right_turn3(){
e_set_speed_left(500);
e_set_speed_right(-200);



// Pointers made to each microphone
/*
void e_get_micro(int *m0, int *m1,int *m2)
{
        T1CONbits.TON = 0;//cut of proximity timer
        *m0=e_read_ad(0);
        *m1=e_read_ad(1);
        *m2=e_read_ad(2);
        T1CONbits.TON = 1;
}
*/


int main()
{
e_init_port();          // initialize e-puck ports
e_init_micro();         // initialize e-puck microphones
e_start_agendas_processing();// start Timer 2 processing tasks
e_init_motors();        // setup the motors to use Agenda


 while(1){

 int I;
 long x;
 long y;
 long z;


    x = 0;
    y = 0;
    z = 0;

    for(I=0; I<100; I++){

    e_get_micro(&m0, &m1, &m2);

    x +=abs(m0);
    y +=abs(m1);
    z +=abs(m2);

    }

    if (x < 200) LED1 = 1 ; else LED1 = 0 ;
    if (x < 2000) LED2 = 1 ; else LED2 = 0 ;
    if (x < 20000) LED3 = 1 ; else LED3 = 0 ;
    if (x < 200000) LED4 = 1 ; else LED4 = 0 ;
    if (x < 2000000) LED5 = 1 ; else LED5 = 0 ;

    //~ if(x < 20000) LED2 = 0;   else LED2 = 1;
    //~
    //~ if(y < 2000) LED4 = 0;    else LED4 = 1;
    //~
    //~ if(z < 2000) LED6 = 0;   else LED6 = 1;



 //---Proximity Sensor handling for collision detection----

 proxy0 = e_get_prox(0);
 proxy1 = e_get_prox(1);
 proxy2 = e_get_prox(2);
 proxy3 = e_get_prox(3);
 proxy4 = e_get_prox(4);
 proxy5 = e_get_prox(5);
 proxy6 = e_get_prox(6);
 proxy7 = e_get_prox(7);

//---IR sensor 0---//
if(proxy0 <1000){
LED0 = 0;

}
else{
LED0 = 1;
//e_set_speed_left(-600);
left_turn1();
}

//---IR sensor 1---//
if(proxy1 < 1000){
LED1 = 0;

}
else{
LED1 = 1;
//e_set_speed_left(-500);
left_turn2();
}

//---IR sensor 2---//
if(proxy2 < 1000){
LED2 = 0;

}
else{
LED2 = 1;
//e_set_speed_left(-200);
left_turn3();
}

//---IR sensor 3---//
if(proxy3 < 1000){
//LED3 = 0;
LED4 = 0;

}
else{
//LED3 = 1;
LED4 = 1;
//e_set_speed_left(500);
//e_set_speed_right(500);
forward();
}

//---IR sensor 4---//
if(proxy4 < 1000){
//LED3 = 0;
LED4 = 0;

}
else{
//LED3 = 1;
LED4 = 1;
//e_set_speed_left(500);
//e_set_speed_right(500);
forward();
}

//---IR sensor 5---//
if(proxy5 < 1000){
LED6 = 0;

}
else{
LED6 = 1;
//e_set_speed_right(-200);
right_turn3();
}

//---IR sensor 6---//
if(proxy6 < 1000){
LED7 = 0;

}
else{
LED7 = 1;
//e_set_speed_right(-500);
right_turn2();
}

//---IR sensor 7---//
if(proxy7 < 1000){
LED0 = 0;

}
else{
LED0 = 1;
//e_set_speed_right(-600);
right_turn1();
}
}
}


-- 
The Sunday Times Scottish University of the Year 2009/2010
The University of Stirling is a charity registered in Scotland, 
 number SC 011159.


_______________________________________________
E-puck-user mailing list
[email protected]
https://mail.gna.org/listinfo/e-puck-user

Reply via email to