Gripper and IR
CJW
Posts: 77
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
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
Comments
Can anyone help me. Please
Yours Sincerely,
James
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
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.
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
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'"
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
Thank you for guiding me. I go and try the error, if I don't understand I will ask you again.
Yours Sincerely,
James
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
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
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.
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.
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
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
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
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
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
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
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
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
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
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.
I felt that the counter = 0 or 1 should be the mistake. Please help me
Yours Sincerely
James
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
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