Shop OBEX P1 Docs P2 Docs Learn Events
Teaching a robot to hear — Parallax Forums

Teaching a robot to hear

PromagicPromagic Posts: 17
edited 2008-11-24 07:55 in Robotics
Ill post Code and pics later...

Right now·I have two sound sensors with an analog output of·"0-5v", they are·connected to two separate ADC's, which gives me a volume reading from 0-255 "8-Bit"
MY CODE Functions! with no errors!!burger.gif

Now·I'm trying to teach it how to hear direction, My first attempt was:
if (adcBits < adcBits2) then

   debug "Turn Left"

Endif

[size=2][code]
if (adcBits > adcBits2) then

   debug "Turn Right"

Endif

[/code][/size]
Problems? No straight, wasn't very accurate

My second attempt was:
[size=2][code]
if (adcBits > adcBits2) then

   d = adcBits - adcBits2

Endif

If (d <= 5) then    'the tolerance is 5

   debug "Straight"

endif




[/code][/size]
··The idea is how would you make sound detection code from two values ranging from 0-255?
· How should·I write code to tell what mic hears sound first?

My exact code will be uploaded later, if you help me with my problem that would be awesome!

Im going to sleep on it.


▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
···· -Devin


"I can only ask every question once."

Comments

  • SRLMSRLM Posts: 5,045
    edited 2008-11-22 06:41
    How did you display all those lines in the code in your post?
  • HumanoidoHumanoido Posts: 5,770
    edited 2008-11-23 04:26
    You would write an ambiance level detector code and the first
    detector to exceed this white level would be the first to hear
    the sound. The ALD would set inside a fast loop, then jump
    out to math out the detection. Which sound sensors are you
    using?

    humanoido
  • Beau SchwabeBeau Schwabe Posts: 6,566
    edited 2008-11-23 05:05
    Promagic,

    humanoido is on the right track... Assuming that you aren't listening for a particular tone, then any kind of Phase detection is out. For ambient noise, the best approach would be to establish a peak detector with some level of decay. The peak detector will serve to filter and average any incoming signals. This averaging will make any differential comparing easier to manage in software.

    Here is a thread that is doing something very similar to what you want to do...
    http://forums.parallax.com/showthread.php?p=572182

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Beau Schwabe

    IC Layout Engineer
    Parallax, Inc.
  • PromagicPromagic Posts: 17
    edited 2008-11-24 03:13
    SRLM said...
    How did you display all those lines in the code in your post?
    I wrote it from memory?

    humanoido·and Beau Schwabe (Parallax):

    I checked out Botwire's website, it seemed like he was more into the circuitry then the software.

    The entire code is here: http://www.geocities.com/botwire/Vsoft.html
    However·I get lost in all his mathematics
    ' -----[noparse][[/noparse] Audio Sensor I/O Definitions ]-------------------------------------------------
    CS              PIN     15                      ' ADC0832.1
    Clk             PIN     14                      ' ADC0832.7
    Dio             PIN     13                      ' ADC0832.5 / ADC0832.6
     
    ' -----[noparse][[/noparse] Audio Sensor Constants ]-------------------------------------------------------
    Sgl             CON     %1                      ' single ended
    Dif             CON     %0                      ' differential
    Raw2mV          CON     $139B                   ' 19.6 mV per count
    
    ' -----[noparse][[/noparse] Audio Sensor Variables ]-------------------------------------------------------
    sglDif          VAR     Bit                     ' adc mode (1 = SE)
    oddSign         VAR     Bit                     ' chan (Sgl), sign (Dif)
    adc             VAR     Byte(2)                 ' channel values
    mVolts          VAR     Word(2)                 ' millivolts
    RightEar        VAR     Word
    LeftEar         VAR     Word
    ' -----[noparse][[/noparse] EEPROM Data ]-----------------------------------------------------
    
    ' -----[noparse][[/noparse] Audio Sensor Initialization ]--------------------------------------------------
    'Reset:
      HIGH CS                                       ' deselect ADC
      DEBUG CRSRXY, 0, 7, "Differential", CR, CR,
            "  Ch0:", CR,
            "  Ch1:"
    ' -----[noparse][[/noparse] Audio Sensor Main Program ]----------------------------------------------------
    Main:
        sglDif = dif
        FOR oddSign = 0 TO 1
          GOSUB Read_0832
          mVolts(oddSign) = adc(oddSign) */ Raw2mV
          DEBUG CRSRXY, 7, (9 + oddSign),
                DEC3 adc(oddSign), TAB,
                DEC mVolts(oddSign) DIG 3, ".", DEC3 mVolts(oddSign)
                LeftEar = adc(0)  'Get value from Channel 0
                RightEar = adc(1) 'Get value from channel 1
                DEBUG HOME, CR, DEC3 RightEar, "   <---RT MIC" 'Print value of CH1
                DEBUG CR, DEC3 LeftEar,        "   <---LT MIC" 'Print value of CH2
                IF RightEar > 15 THEN          'Threshold 5. If > than, then do something.
                   DEBUG HOME, "RT Ear"
                         ELSEIF (LeftEar) > 15 THEN  'Else this is greater than set threshold, do something.
                                DEBUG HOME, "LT Ear"
                                ELSE
                                      DEBUG HOME, "          "  'Else Clear labels.
     
                ENDIF
    
    


    My exact code and my sound sensor·is down below.·My code can pick out which side is louder but has a large margin of error, im also working on detecting a straight direction.

    "The ALD would set inside a fast loop, then jump out to math out the detection."

    Do·I have something like that?

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    ···· -Devin


    "I can only ask every question once."

    Post Edited (Promagic) : 11/24/2008 3:32:20 AM GMT
  • HumanoidoHumanoido Posts: 5,770
    edited 2008-11-24 07:55
    Thanks, it's a real neat sound sensor circuit. I followed the url from the document scan and they have a pdf file for download which may be much smaller in size. The manuals are downloaded here.

    www.inexglobal.com/downloads.php?type=manual

    They also have an English version web page, plus circuits for Parallax Stamps. To answer your question, no you don't have it in your code. Another thing you don't have in your code is any comments! 1) Establish a baseline filter. 2) get some sound reading data. 3) When you are satisfied with stability, write smallest programs to do each thing, i.e. detect each sound direction. 4) Experiment with sound direction, intensity and frequency, noting how they relate. 5) Write the code with comments and debug it.

    Note: surf the web for info about software filters. You can do many things with code filters, such as establish baselines, provide averages, vary numerical bandwidth, develop cutoffs, smooth and regulate quiescence, amplify, etc.

    humanoido
Sign In or Register to comment.