Controling a servo with IR

bradfordbradford Posts: 4
edited 2004-11-29 - 02:27:24 in Robotics
I hope someone can help with this?
·
I have a board of education board with one (the right side) IR detector attached and one servo connected to socket twelve.
·
What I need to have happen is when the IR detector senses an object within 2 feet I need the servo to turn right about ten degrees from center and then pause for 10 seconds the rotate left 10 degrees from center again. Then after two seconds I need to have the servo go back to center and stay there until the IR detector senses an object again and then it repeats the above.
·
I am completely new at trying to write programs for the board so I would deeply appreciate any help.
·
Sincerely,
·
Steven Bradford

Comments

  • edited 2004-11-28 - 20:39:47
    There are a whole bunch of similar servo examples that you can experiment with in What's a Microcontroller, Chapter 4.· It's available for free download from www.parallax.com -> Downloads -> BASIC Stamp Tutorials.·
    ·
    I'm not sure what kind of IR detector you are using.· In the meantime, I would also recommend experimenting with the pushbutton examples in Chapter 3.· The pushbuttons can be used to iron out the servo behavior.· The IR object detection code can be ironed out separately.· Then, you can replace the pushbutton circuit and code with the IR circuit and code.·
    ·
    Also, take a quick look at Chapter 2 while you're in the book; it'll help complete the picture.·
    ·
    The Robotics with the Boe-Bot text is on the same downloads page as What's a Microcontroller.· There is an infrared object detection program in Chapter 7 that also exhibits behaviors similar to your project.· The Boe-Bot detects an object with infrared, then turns a few degrees, and keeps on moving forward, until it detects the object again.· The Boe-Bot does its navigation with a pair of continuous rotation servos, which are very similar to the standard servo you are using.· It would be possible to remove the code from the program so that it only works with a single servo and IR detector.·
    ·
    Still, I would doing the What's a Microcontroller chapters first.··Aside from the fact that it'll have most of the information you need, diving straight into Robotics with the Boe-Bot, chapter 7, will involve more backtracking to figure out what's going on.
  • bradfordbradford Posts: 4
    edited 2004-11-28 - 21:47:42
    Andy,

    Thanks, I have both the boe-bot and micro kit from an educators class. I am using the IR detectors that came with the kits. I can get the servos to move they way I want I can not figure out how to write in the program how to get the sensor to triger the sequence. In the books it is not clear what is doing what to cut and paste in the programs. If I wanted ServoTest.bs2 triggered by the infared sensor how would I do it.
  • edited 2004-11-28 - 22:27:22
    Here is a modified version of RoamingWithIr.bs2 from Robotics with the Boe-Bot v2.2.· It checks the left IR detector (IR LED connected to P8, IR detector connected to P9).· It then uses the detection information to make a standard servo turn left several degress off center·for a couple seconds, then go back to center.

    ' -----[noparse][[/noparse] Title ]--------------------------------------------------------------
    ' Robotics with the Boe-Bot - RoamingWithIrTest.bs2
    ' Adapt RoamingWithIr.bs2 as discussed in this thread.
     
    ' {$STAMP BS2}                               ' Stamp directive.
    ' {$PBASIC 2.5}                              ' PBASIC directive.
     
    DEBUG "Program Running!"
     
    ' -----[noparse][[/noparse] Variables ]----------------------------------------------------------
    
     
    irDetectLeft VAR Bit
    pulseCount VAR Byte
     
    ' -----[noparse][[/noparse] Initialization ]-----------------------------------------------------
     
    FREQOUT 4, 2000, 3000                        ' Signal program start/reset.
     
    ' -----[noparse][[/noparse] Main Routine ]-------------------------------------------------------
     
    DO
     
      FREQOUT 8, 1, 38500                       ' Store IR detection values in
      irDetectLeft = IN9                        ' bit variables.
     
      IF (irDetectLeft = 0) THEN                ' Left IR pair detects
        FOR pulseCount = 1 TO 80                ' Differnt position for about 2s.
          PULSOUT 13, 700
          PAUSE 20
        NEXT
      ELSE
        PULSOUT 13, 750                         ' Apply a center pulse
        PAUSE 18
      ENDIF                                     ' and check again
     
    LOOP
    



    Post Edited (Andy Lindsay) : 11/28/2004 10:29:30 PM GMT
  • bradfordbradford Posts: 4
    edited 2004-11-29 - 01:53:11
    Andy,



    Thanks again I am getting close now Here is what I came up with. But whenever I enter avalue above 250 in the pulseCount the servo freezes at that position. Is there a way to get it to hold a position for more than 250?

    Thanks,



    Steven Bradford





    ' {$STAMP BS2}······························ ' Stamp directive.
    ' {$PBASIC 2.5}····························· ' PBASIC directive.

    DEBUG "Program Running!"

    '
    [noparse][[/noparse] Variables ]


    irDetectLeft VAR Bit
    pulseCount VAR Byte

    '
    [noparse][[/noparse] Initialization ]

    FREQOUT 4, 2000, 3000······················· ' Signal program start/reset.

    '
    [noparse][[/noparse] Main Routine ]

    DO

    · FREQOUT 2, 1, 38500······················ ' Store IR detection values in
    · irDetectLeft = IN0······················· ' bit variables.

    · IF (irDetectLeft = 0) THEN··············· ' Left IR pair detects
    ··· FOR pulseCount = 1 TO 20··············· ' Differnt position for about 2s.
    ····· PULSOUT 13, 686
    ····· PAUSE 20
    ··· NEXT
    ··· FOR pulseCount = 1 TO 259
    ·· PULSOUT 13,600
    ·· PAUSE 20
    ··· NEXT
    ··· FOR pulseCount = 1 TO 10
    ·· PULSOUT 13,530
    ·· PAUSE 20
    · NEXT
    · ELSE
    ··· PULSOUT 13, 600························ ' Apply a center pulse
    ··· PAUSE 18
    · ENDIF···································· ' and check again

    LOOP
  • edited 2004-11-29 - 01:57:39
    Certianly. pulseCount is declared to be a Byte right now. As such, it can only store a number up to 255. In your program, pulseCount never makes it to 259.

    If you change the variable declaration in the program to make pulseCount a Word instead of a Byte, then you can deliver up to 65534 pulses.
  • bradfordbradford Posts: 4
    edited 2004-11-29 - 02:27:24
    Andy,



    Thanks so much I never expected such quick answers either. You have been a great help. Maybe Kris there mentioned our group from the sculpture program in New Paltz NY? Anyway this is one of the first uses of the stamps in peoples work. Pretty simple probably in your terms but we have been looking for ways to make work more interactive. In this case just to turn a cd player on when someone gets on a platform and then it had to play a track once reset and the go back to replay the same track from the begining when it was triggerd again.



    Thanks again!

    Steven Bradford
Sign In or Register to comment.