Shop OBEX P1 Docs P2 Docs Learn Events
Gripper and IR — Parallax Forums

Gripper and IR

CJWCJW Posts: 77
edited 2010-05-17 01:41 in BASIC Stamp
Hi,

I would need help, when I start the thing my boe-bot wil turn round as boe bot need to detect the object then will go forward and grip the item. I would like to know where should I put the program when it grip on the object then can reverse or turn left or right. Do any of you have a program do reverse the bot. This is the link I record http://www.youtube.com/user/CJWSX and attachment is my programming.


Yours Sincerely
James
«1

Comments

  • CJWCJW Posts: 77
    edited 2010-05-02 15:14
    Hi,

    Can anyone help me. Please

    Yours Sincerely,
    James
  • Mike GreenMike Green Posts: 23,101
    edited 2010-05-02 15:50
    It sounds like you are trying to get your BoeBot to do things in sequence like: 1) circle and look for an object 2) object found, stop circling and move forward and close gripper 3) ??? (maybe move backwards)

    You need some kind of state machine to keep track of what state your BoeBot is in. There are two ways to do this. 1) Keep a state variable and test for it as you do things 2) Express the states as areas in your code where there are loops and labels and move from one loop to another depending on conditions

    state = 1
    DO
    if state = 1 then
        PULSOUT 13, 790       'Rotate slowly
        PULSOUT 12, 790
        PAUSE 15              '5ms for detectors
        GOSUB Check_IRs       'While looking for object
        if (irDetectLeft = 0) OR (irDetectRight = 0) then state = 2
    elseif state = 2
      'Object in both detectors -- go forward
        IF (irDetectLeft = 0) AND (irDetectRight = 0) THEN
          HIGH 10
          HIGH 1
          pulseLeft = 850     'Forward
          pulseRight = 650
          pulseGrip = 500
          state = 3
    
      'Object on Left - go left
        ELSEIF (irDetectLeft = 0) THEN
          pulseLeft = 850    'Left toward object
          pulseRight = 850
      'Object on right - go right
        ELSEIF (irDetectRight = 0) THEN
          pulseLeft = 650     'Right toward object
          pulseRight = 650
    'No object -- go forward anyway, because the detectors will
      ELSE                   'momentarily
        LOW 10
        LOW 1
        pulseLeft = 850      '"no object" as the
        pulseRight = 650     'Boe-Bot is adjusting
        pulseGrip = 1000
    ENDIF
    
      PULSOUT 13, pulseLeft
      PULSOUT 12, pulseRight
      PULSOUT 14, pulseGrip
      PAUSE 15
    
    'Check IRs again in case object is moving
      GOSUB Check_IRs
    elseif state = 3
    ' here you would continue to output servo pulses and perhaps reverse the wheel
    ' servos for a little while by counting down a counter representing 15ms or 20ms cycles
    ' then change to another state.  You'd reverse the BoeBot by using
    '      pulseLeft = 650     'Reverse
    '      pulseRight = 850
    endif
    LOOP
    
    
  • Mike GreenMike Green Posts: 23,101
    edited 2010-05-02 15:59
    The 2nd scheme I suggested is something you're already using. Your first state is handled by your first DO / LOOP that exits when something is detected by either detector. Your 2nd state continues forever after. Instead, have your 2nd DO / LOOP exit when the gripper is activated. You'll need something like:
    pulseGrip = 1000 ' initialize this to open gripper
    DO
    ' ...
    LOOP until pulseGrip = 1000
    


    Your 3rd state's code would follow this and might reverse the BoeBot for a while. A 4th state might turn the BoeBot right or left.
  • CJWCJW Posts: 77
    edited 2010-05-03 01:58
    Hi Mike,

    Do I need to declare variables for "state". Do I need to add anymore programming. As I been trying to solve the problem. Any hints for me. Thank You


    Yours Sincerely,
    James
  • Mike GreenMike Green Posts: 23,101
    edited 2010-05-03 04:18
    Of course you do. All variables have to be declared.

    I'm sure you will have to add more to your program. What I showed here were two different techniques that you can use to organize the steps of your program.

    What you have not communicated is what you want the BoeBot to do after it has grabbed the object. That's the next thing you have to do. It might be helpful for you to just make a list of the "rules" you want your BoeBot to follow and in what order. "if 'this' then do 'that'"
  • CJWCJW Posts: 77
    edited 2010-05-03 04:25
    Hi Mike,

    The "state" using wad to declare for variable. As I look through the book do not have the state example. Thank you

    Yours Sincerely,
    James
  • Mike GreenMike Green Posts: 23,101
    edited 2010-05-03 04:29
    "state" is just another variable like any other. In the example that I gave, it could have values of 1, 2, or 3. You could store it in a nib or a byte. You'll probably need more than 3 states. A nib could hold values from 0 to 15.
  • CJWCJW Posts: 77
    edited 2010-05-03 14:53
    Hi Mike,

    Thank you for guiding me. I go and try the error, if I don't understand I will ask you again.

    Yours Sincerely,
    James
  • CJWCJW Posts: 77
    edited 2010-05-05 04:06
    Hi Mike,

    I try putting the information inside but the boe-bot will not able to grip on it and eventually it stop. I do not know whether my programming got any mistake. Can you please assist me. Below is my programming that I add in. Thank you

    Yours Sincerely
    James

    'Robotics with the Boe-Bot - latestSumoBoeBot.bs2
    'Search for object, lock onto it and push it

    '{$STAMP BS2}
    ' {$PBASIC 2.5}



    irDetectLeft VAR Bit 'Left IR reading
    irDetectRight VAR Bit 'Right IR reading
    pulseLeft VAR Word 'pulse values for servos
    pulseRight VAR Word
    pulseGrip VAR Word
    pulseCount VAR Byte
    state VAR Nib
    '[noparse][[/noparse]Initialization]

    DEBUG "Program Running!"
    FREQOUT 4, 2000, 3000

    DEBUG CLS,
    "IR DETECTORS", CR,
    "LEFT RIGHT", CR
    '[noparse][[/noparse]Main Routine]

    Main:

    state = 1
    DO
    IF state = 1 THEN
    PULSOUT 13, 790 'Rotate slowly
    PULSOUT 12, 790
    PAUSE 15 '5ms for detectors
    GOSUB Check_IRs 'While looking for object
    IF (irDetectLeft = 0) OR (irDetectRight = 0) THEN state = 2
    ELSEIF state = 2 THEN
    'Object in both detectors -- go forward
    IF (irDetectLeft = 0) AND (irDetectRight = 0) THEN
    HIGH 10
    HIGH 1
    pulseLeft = 850 'Forward
    pulseRight = 650
    pulseGrip = 500

    state = 3

    'Object on Left - go left
    ELSEIF (irDetectLeft = 0) THEN
    pulseLeft = 850 'Left toward object
    pulseRight = 850
    'Object on right - go right
    ELSEIF (irDetectRight = 0) THEN
    pulseLeft = 650 'Right toward object
    pulseRight = 650
    'No object -- go forward anyway, because the detectors will
    ELSE 'momentarily
    LOW 10
    LOW 1
    pulseLeft = 850 '"no object" as the
    pulseRight = 650 'Boe-Bot is adjusting
    pulseGrip = 1000
    ENDIF

    PULSOUT 13, pulseLeft
    PULSOUT 12, pulseRight
    PULSOUT 14, pulseGrip
    PAUSE 15

    'Check IRs again in case object is moving
    GOSUB Check_IRs
    ELSEIF state = 3 THEN

    Check_IRs:
    FREQOUT 8, 1, 38500
    irDetectLeft = IN0
    FREQOUT 2, 1, 38500
    IrDetectRight = IN9
    RETURN

    Forward_Pulse:
    PULSOUT 13,850
    PULSOUT 12,650
    PAUSE 20
    RETURN

    Turn_Left:
    FOR pulseCount = 0 TO 20
    PULSOUT 13, 650
    PULSOUT 12, 650
    PAUSE 15
    NEXT
    RETURN

    Turn_Right:
    FOR pulseCount = 0 TO 20
    PULSOUT 13, 850
    PULSOUT 12, 850

    PAUSE 15
    NEXT
    RETURN

    Back_Up:
    FOR pulseCount = 0 TO 40
    PULSOUT 13, 650
    PULSOUT 12, 850
    PAUSE 15
    NEXT
    RETURN



    ' here you would continue to output servo pulses and perhaps reverse the wheel
    ' servos for a little while by counting down a counter representing 15ms or 20ms cycles
    ' then change to another state. You'd reverse the BoeBot by using
    ' pulseLeft = 650 'Reverse
    ' pulseRight = 850
    ENDIF
    LOOP
  • Mike GreenMike Green Posts: 23,101
    edited 2010-05-05 04:31
    Here I've added a state that will complete the movement of the BoeBot moving forward and closing the gripper. You can add more states to do other movements. I've also moved the subroutines to the end of the program for clarity.
  • CJWCJW Posts: 77
    edited 2010-05-05 06:01
    Hi Mike,

    Thank you for assisting me. I wanted to try the error to see how the count work in order to continue but when i press run button it gave me "Symbol is already defined". So what do i need to change?Is it I need to change Count into Counter. The attachment above is what i have print screen. What do you mean doing something similar to what's in state 3, can u give me more example.


    Yours Sincerely
    James

    Post Edited (CJW) : 5/5/2010 11:14:51 AM GMT
    1302 x 800 - 155K
  • Mike GreenMike Green Posts: 23,101
    edited 2010-05-05 15:10
    I'm sorry I made the mistake with "count". I'm glad you thought to change it to "counter". That should work.

    Here's the corrected program and another version that doesn't use a "state" variable, but uses individual loops for the different actions. Maybe you'll find that easier to understand. It's mostly your own code with minor changes.
  • Mike GreenMike Green Posts: 23,101
    edited 2010-05-05 17:20
    Unfortunately, it sounds like you need to first understand how your current program works. Your program (even your original one) goes through a cycle of actions (a series of steps) that eventually repeat. In both the examples I gave you, I just added on to the series of steps. A "GOTO Main" would just start everything over again since "Main" is a label at the beginning of the code for the first step.

    If you haven't gone through them, you need to work through the "What's a Microcontroller?" and the "Stamp Basic Syntax and Reference Manual". Both are included in the help files for the Stamp Editor and there are translations of both into a variety of languages that you can get from Parallax's Downloads page. Use the "BASIC Stamp Documentation" and "Stamps in Class Downloads" links.
  • CJWCJW Posts: 77
    edited 2010-05-07 05:17
    Hi Mike,

    Thank you for the information. I will troubleshoot the bot again. If I have any that i don't know, I will ask you again.

    Yours Sincerely
    James
  • CJWCJW Posts: 77
    edited 2010-05-08 10:13
    Hi Mike,

    I have use the program but i do not know why cannot grip on it in the first round. This is the link hat I record
    Is it I need bring the IR to put on top of the gripper. Below is my program. Thank you

    Yours Sincerely
    James

    '{$STAMP BS2}
    '{$PBASIC 2.5}

    irDetectLeft VAR Bit 'Left IR reading
    irDetectRight VAR Bit 'Right IR reading
    pulseLeft VAR Word 'pulse values for servos
    pulseRight VAR Word
    pulseGrip VAR Word
    pulseCount VAR Byte
    counter VAR Byte '***** Added MG *****
    '[noparse][[/noparse]Initialization]

    DEBUG "Program Running!"
    FREQOUT 4, 2000, 3000

    DEBUG CLS,
    "IR DETECTORS", CR,
    "LEFT RIGHT", CR
    '[noparse][[/noparse]Main Routine]

    Main:

    DO 'This is the same as state = 1
    PULSOUT 13, 790 'Rotate slowly
    PULSOUT 12, 790
    PAUSE 15 '5ms for detectors
    GOSUB Check_IRs 'While looking for object
    LOOP UNTIL (irDetectLeft = 0) OR (irDetectRight = 0)

    DO 'This is the same as state = 2
    'Object in both detectors -- go forward

    IF (irDetectLeft = 0) AND (irDetectRight = 0) THEN
    HIGH 10
    HIGH 1
    pulseLeft = 850 'Forward
    pulseRight = 650
    pulseGrip = 500
    counter = 100 '***** Added MG *****
    EXIT '***** Added MG *****
    ELSEIF (irDetectLeft = 0) THEN
    'Object on Left - go left
    pulseLeft = 850 'Left toward object
    pulseRight = 850
    ELSEIF (irDetectRight = 0) THEN
    'Object on right - go right
    pulseLeft = 650 'Right toward object
    pulseRight = 650
    ELSE 'momentarily
    'No object -- go forward anyway, because the detectors will
    LOW 10
    LOW 1
    pulseLeft = 850 '"no object" as the
    pulseRight = 650 'Boe-Bot is adjusting
    pulseGrip = 1000
    ENDIF
    PULSOUT 13, pulseLeft
    PULSOUT 12, pulseRight
    PULSOUT 14, pulseGrip
    PAUSE 20
    'Check IRs again in case object is moving
    GOSUB Check_IRs
    LOOP

    DO 'This is the same as state = 3
    'This loop is entered with counter = 100. pulseLeft and pulseRight are set
    'to cause the robot to move forward and pulseGrip is set to cause the gripper
    'to close. The idea here is that these pulses need to continue to be produced
    'for a few seconds (roughly 2 in this case), then these values need to be
    'changed for the next action of the robot to occur. Once these values are
    'changed, this should drop through to the next loop (state # 4) where the
    'next action will be managed.

    ' here you would continue to output servo pulses and perhaps reverse the wheel
    ' servos for a little while by counting down a counter representing 15ms or 20ms cycles
    ' then change to another state. You'd reverse the BoeBot by using
    ' pulseLeft = 650 'Reverse
    ' pulseRight = 850
    IF counter = 1 THEN '***** Added MG *****
    pulseLeft = 650
    pulseRight = 850 'Reverse the BoeBot after 100 * 20ms = 2 seconds
    counter = 100
    EXIT
    ENDIF ' ***** Added MG *****
    PULSOUT 13, pulseLeft '***** Added MG *****
    PULSOUT 12, pulseRight 'Continue outputting pulses
    PULSOUT 14, pulseGrip
    PAUSE 20
    counter = counter - 1 '***** Added MG *****
    LOOP

    DO 'This is the same as state = 4
    'here you'd do something similar to what's in state 3. You will need to
    'add additional states for each different movement needed. At some point,
    'you'll do a GOTO Main to begin the whole cycle over again.
    IF counter = 1 THEN '***** Added MG *****
    pulseLeft = 650
    pulseRight = 850 'Reverse the BoeBot after 100 * 20ms = 2 seconds
    counter = 100
    EXIT
    ENDIF
    PULSOUT 13, pulseLeft '***** Added MG *****
    PULSOUT 12, pulseRight 'Continue outputting pulses
    PULSOUT 14, pulseGrip
    PAUSE 20
    counter = counter - 1 '***** Added MG *****

    LOOP

    DO
    IF counter = 1 THEN '***** Added MG *****
    pulseLeft = 850
    pulseRight = 650 'Reverse the BoeBot after 100 * 20ms = 2 seconds
    counter = 100
    EXIT
    ENDIF
    PULSOUT 13, pulseLeft '***** Added MG *****
    PULSOUT 12, pulseRight 'Continue outputting pulses
    PULSOUT 14, pulseGrip
    PAUSE 20
    counter = counter - 1
    LOOP

    DO
    IF counter = 0 THEN '***** Added MG *****
    pulseLeft = 850
    pulseRight = 850 'Reverse the BoeBot after 100 * 20ms = 2 seconds
    counter = 100
    EXIT
    ENDIF
    PULSOUT 13, pulseLeft '***** Added MG *****
    PULSOUT 12, pulseRight 'Continue outputting pulses
    PULSOUT 14, pulseGrip
    PAUSE 20
    counter = counter - 1
    GOTO Main
    LOOP


    'I've moved the subroutines here. They would work where you had them, but
    'moving them to the end of the program keeps the main part of the program
    'uncluttered.

    Check_IRs:
    FREQOUT 8, 1, 38500
    irDetectLeft = IN0
    FREQOUT 2, 1, 38500
    IrDetectRight = IN9
    RETURN

    Forward_Pulse:
    PULSOUT 13,850
    PULSOUT 12,650
    PAUSE 20
    RETURN

    Turn_Left:
    FOR pulseCount = 0 TO 20
    PULSOUT 13, 650
    PULSOUT 12, 650
    PAUSE 15
    NEXT
    RETURN

    Turn_Right:
    FOR pulseCount = 0 TO 20
    PULSOUT 13, 850
    PULSOUT 12, 850
    PAUSE 15
    NEXT
    RETURN

    Back_Up:
    FOR pulseCount = 0 TO 40
    PULSOUT 13, 650
    PULSOUT 12, 850
    PAUSE 15
    NEXT
    RETURN
  • CJWCJW Posts: 77
    edited 2010-05-09 09:19
    Hi,

    I have troubleshoot but it didn't turn well. I really need help to guide me until the end. This is the link that i recorded , I also have attachment for the programming.Please help me I only left 1 more week to go or else I will fail this module as I still got another want to troubleshoot. Thank you.

    Yours Sincerely
    James
  • Mike GreenMike Green Posts: 23,101
    edited 2010-05-09 15:28
    At this point, your program is a bit complicated and is hard to follow. It's not clear to me what you want your robot to do. It will save you a lot of time and grief to write down the steps of what you want like:
    1) rotate slowly checking IR sensors constantly, gripper is open
    2) if either sensor detects something, start moving forward slowly and close gripper
    3) after 2 seconds, stop with gripper closed
    ... and so on

    Once you've defined these steps, you can go back and make your program reflect the steps you've written
  • CJWCJW Posts: 77
    edited 2010-05-09 15:35
    Hi Mike,

    What do you suggest as I want the bot to
    1) turn round as when the bot detect the item, the bot will go forward and grip the item.
    2) When the bot grip on it he will reverse back and either turn right or left to drop the item
    3) repeat the same thing again.

    As I posted the video and attach the program is not able to do that. Please help me,

    Yours Sincerely
    James
  • CJWCJW Posts: 77
    edited 2010-05-09 15:44
    Can Help me pls
  • Mike GreenMike Green Posts: 23,101
    edited 2010-05-09 15:46
    Your step #1 and step #2 are each made up of several separate steps and you need to break those down into individual steps including timing. For example, how long should it take for the gripper to close? How long should the bot move forward in step #1? How does the bot know which way to turn in step #2? When the bot opens the gripper in step #2, should it move backwards for a short time so the object comes out from between the grippers? All these and more are questions you have to think about and answer.
  • CJWCJW Posts: 77
    edited 2010-05-09 15:50
    Hi Mike,

    But how to program all this part? Do you have the example for the bot as i don't wan to fail my module. Thank you

    Yours sincerely
    James
  • CJWCJW Posts: 77
    edited 2010-05-09 16:19
    Hi Mike,

    I have try to use the program 2 that you given to me. I don't know is it my code got error. Can you help me check, is the want that I have post earlier. Thank you.
    Please assist me.

    Yours Sincerely
    James
  • Mike GreenMike Green Posts: 23,101
    edited 2010-05-09 16:48
    I have already given you some examples. You first have to define exactly what you want your bot to do. I can't help you there except to suggest what you need to do. Once you have defined in detail what you want your bot to do, then it's pretty straightforward to make those steps into program loops.

    Again, you need to define a series of steps, each consisting of one or more actions (servo movements) and a time duration or some kind of sensor condition that marks the end of the step. These steps we call "states". Normally one step follows another. Sometimes one step can go to one of several possible "successors" based on some condition. For example, if the left IR sensor detects something, then the next step might be #10. If the right IR sensor detects something, then the next step might be #12. If neither sensor detects anything, then the next step would be #11.

    Post Edited (Mike Green) : 5/9/2010 4:56:41 PM GMT
  • CJWCJW Posts: 77
    edited 2010-05-10 04:36
    Hi Mike,

    I try some error but when I on the bot. It will automatic close the gripper, when it sense something the led will high and the gripper will open.

    Yours Sincerely,
    James
  • Mike GreenMike Green Posts: 23,101
    edited 2010-05-10 13:50
    You have to define what you want your robot to do, step by step!

    Go through your existing program and figure out what it is doing in each loop. Print the program on paper, cut out each loop, and paste it on a separate piece of paper. Make notes on each piece of paper about what that loop is doing in terms of robot actions. Put the pieces of paper on the floor or taped to a wall so you can look at the overall steps involved, then see if you can figure out what steps need to be changed.
  • CJWCJW Posts: 77
    edited 2010-05-10 14:22
    Thank you.. I will try the error again..
  • CJWCJW Posts: 77
    edited 2010-05-10 15:07
    Hi Mike,

    I felt that the counter = 0 or 1 should be the mistake. Please help me

    Yours Sincerely
    James
  • CJWCJW Posts: 77
    edited 2010-05-10 16:12
    Hi Mike,

    I have try some error until i got this but i don't know where to change the bot stop turning when it grip on it. Can i i use this to do following a stripe line. Above is my attachment and this is the link i have recorded

    Sorry for all the trouble, but I would to say thank you for helping me. I hope I have improve a lot.

    Yours Sincerely
    James

    Post Edited (CJW) : 5/10/2010 4:40:21 PM GMT
  • Mike GreenMike Green Posts: 23,101
    edited 2010-05-10 17:45
    Your bot is doing exactly what the program tells it to do. You have to spend the time to examine your program and figure out what it does. I could tell you, but it's your job to do this and the task is not too hard.
  • CJWCJW Posts: 77
    edited 2010-05-12 12:28
    Hi,

    I still trying to troubleshoot but i still get the same thing that I have post up. I still cannot find the mistake. Can I know counter = 100, is for usage? Can anyone assist me, please. Thank you


    Yours Sincerely
    James

    Post Edited (CJW) : 5/12/2010 12:41:18 PM GMT
Sign In or Register to comment.