Boe-Bot Exercise question: Roaming with Whiskers and ramping up
VeganRobot
Posts: 17
Hello,
First let me say what a blast electronics is, this coming from somebody who's really just getting into it. The Boe-Bot kit is amazing and I'm starting to get my head around programming but I have a question I was hoping somebody could shed some light on.
it's regarding the exercise Roaming With Whiskers and the BS2 code. I would like to add a servo-ramping up routine to the Forward, left, right, and back subroutines. After all Parallax recommends doing this to extend the life of the servos. I'm going to assume that you know which exercises I’m talking about as I haven't included any code in this post.
So i cut and paste the code from the ramping up BS2 exercise program and I put it into the forward_pulse subroutine. It works, but once it ramps up and the Pulse_Count variable hits 100, it starts all over again. so in other words it stops for about a half a second and ramps up again.
So i'm thinking what I need here is an IF...THEN statement that will determine that once the servos are at full speed forward (650,850) it keeps it at that speed until one of the whiskers is pressed and the respective subroutine is executed.
So I guess I'm asking: Is this the correct approach with a conditional IF...THEN, or am I over thinking it. I'd like to figure it out myself but if anyone has a few hints to move me a long that would be great.
Thanks.
First let me say what a blast electronics is, this coming from somebody who's really just getting into it. The Boe-Bot kit is amazing and I'm starting to get my head around programming but I have a question I was hoping somebody could shed some light on.
it's regarding the exercise Roaming With Whiskers and the BS2 code. I would like to add a servo-ramping up routine to the Forward, left, right, and back subroutines. After all Parallax recommends doing this to extend the life of the servos. I'm going to assume that you know which exercises I’m talking about as I haven't included any code in this post.
So i cut and paste the code from the ramping up BS2 exercise program and I put it into the forward_pulse subroutine. It works, but once it ramps up and the Pulse_Count variable hits 100, it starts all over again. so in other words it stops for about a half a second and ramps up again.
So i'm thinking what I need here is an IF...THEN statement that will determine that once the servos are at full speed forward (650,850) it keeps it at that speed until one of the whiskers is pressed and the respective subroutine is executed.
So I guess I'm asking: Is this the correct approach with a conditional IF...THEN, or am I over thinking it. I'd like to figure it out myself but if anyone has a few hints to move me a long that would be great.
Thanks.
Comments
It would be very helpful if you would post your code so we can see how you put it together. Without it is hard to help.
Use the upload manager to upload your code file. You can do this by editing the above post by pressing on the little pencil icon in the upper right coner.
I'm very glad you are discovering the joy of robotics and will do my best to help. The folks on the Parallax forum are a great group and more than willing to help.
Tony
[noparse][[/noparse]code]' Robotics with the Boe-Bot - RoamingWithWhiskers.bs2
' Boe-Bot uses whiskers to detect objects, and navigate around them.
' Ramp up routines are addded to ease servo load.
' {$STAMP BS2} ' Stamp Directive
' {$PBASIC 2.5} ' PBASIC Directive
DEBUG "Program Running"
'
[noparse][[/noparse] Variables ]
pulseCount VAR Byte ' FOR...NEXT loop counter.
'
[noparse][[/noparse] Initialization ]
FREQOUT 4, 2000, 3000
'
[noparse][[/noparse] Main Routine ]
DO
IF (IN5 = 0) AND (IN7 = 0) THEN ' Both whiskers detect obstacle
HIGH 10
HIGH 1
GOSUB Back_Up ' Back up & U-turn (left twice)
GOSUB Turn_Left
GOSUB Turn_Left
ELSEIF (IN5 = 0) THEN ' Left whisker contacts
HIGH 10
LOW 1
GOSUB Back_Up ' Back up & turn right
GOSUB Turn_Right
ELSEIF (IN7 = 0) THEN ' Right whisker contacts
HIGH 1
LOW 10
GOSUB Back_Up
GOSUB Turn_Left
ELSE
LOW 10
LOW 1 ' Both whiskers 1, no contact
GOSUB Forward_Pulse ' Apply a forward pulse
ENDIF ' And check again
LOOP
'
[noparse][[/noparse] Subroutines ]
Forward_Pulse: ' go forward and ramp up first
FOR pulseCount = 1 TO 100
PULSOUT 13, 752 + pulseCount
PULSOUT 12, 748 - pulseCount ' here is where i added the FOR...NEXT
PAUSE 20 ' command thinking it will check for the
NEXT ' Pulsouts to reach max and then go back to
IF pulseCount = 100 THEN ' the main program.
DO
PULSOUT 13, 850
PULSOUT 12, 710
PAUSE 20
LOOP
ELSE
RETURN
ENDIF
Turn_Left: ' Left turn, about 90-degrees
FOR pulseCount = 0 TO 20
PULSOUT 13, 800
PULSOUT 12, 650
PAUSE 20
NEXT
FOR pulseCount = 0 TO 20
PULSOUT 13, 650
PULSOUT 12, 650
PAUSE 20
NEXT
RETURN
Turn_Right:
FOR pulseCount = 0 TO 20 ' Right turn, about 90-degrees
PULSOUT 13, 850
PULSOUT 12, 850
PAUSE 20
NEXT
RETURN
Back_Up: ' Back up
FOR pulseCount = 0 TO 40
PULSOUT 13, 650
PULSOUT 12, 850
PAUSE 20
NEXT
RETURN
Post Edited (VeganRobot) : 5/10/2010 11:52:02 AM GMT
I like your ingenuity, and am so glad to hear that you are enjoying the Boe-Bot kit! You're on the right track here, but let me see if I can help you get that extra step further.
The original program, RoamingwithWiskers.bs2 executes subroutines based on the current states of the whiskers, as you already know. But if you take a look at the Forward_Pulse subroutine, you'll notice that only one pulse is sent to the servos. Now normally, sending one pulse to each servo will just make the Boe-Bot jerk a little bit, but in this instance, we're not sure how far the Boe-Bot will need to move forward until it hits something. And since the program executes so quickly, it looks like the Boe-Bot is steading moving forward when its really checking the whiskers, moving forward one pulse, checking the whiskers, moving forward one pulse, moving forward one pulse, checking the whiskers, and on and on until it detects that the whisker state has changed.
So this is what is happening in your current program. It ramps each time because your main program is checking the state of the whiskers, seeing it needs to move forward, and then executes the ramping subroutine each time.
But why then, isn't it catching on your IF...THEN statement? That's because after your FOR...NEXT loop finishes executing, counter is actually equal to 101. This is because the counter increments by one at the end of the loop each time even if it's reached it's limit, so your IF...THEN statement would need to check to see if counter is equal to 101. Try running this program to see for yourself:
However, once the program "sees" that counter is equal to 101, you currently have it set to go into a DO...LOOP, where it will never break out and check the sensors again. So it might be a bit easier to put your IF...THEN statement before the ramping code, so that you can go back to only executing one forward pulse, checking the whiskers, moving forward one pulse, checking the whiskers, etc. It could look a little something like this:
I hope this helps, and I apologize if the explanation is a little long winded. I just get excited when I see other people are excited! [noparse]:)[/noparse]
Let us know how it goes!
-- Jess
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Jessica Uelmen
Education Department
Parallax Inc.
Great information and help!! Thanks for helping.
VeganRobot,
As I was reviewing your code some other questions came up;
1. In the Forward_Pulse: sub why do you start with 752 and 748 and the more traditional 750 for both?
2. Do you intend to use ramping in all the movement subroutines?
3. Not that what you have is wrong, I was wondering why you didn't ramp up by 250, thus your Pulsout commands would be at full speed of 1000 and 500?
Like Jess, I would really like to know how the new code works out. Also, if you run into other problems don’t hesitate to post them here. As you can see both Parallax and forum members are more than willing to help solve problems you just can’t get past.
Tony
Why did I use 752 and 748? Good question. I'm not sure why either but I think you're correct that it should start at the centering pulse of 750 apiece and then ramp up from there.
I would like to use the ramping in all the movements as I can see how it will ease the wear and tear on the servos.
I'm going to finish the code with ramping on all movements plus a few extras like more sounds when the whiskers hit something and more of a light show with the LEDs.
I find these forums very useful, it can be somewhat intimidating getting into electronics for the first time but the help I get here coupled with the great products by Parallax makes it fun and encourages me to do more.
Thanks to all, you'll probably see more posts as I move forward (pulse
One more tip on posting code - other than the simple cut and paste that you did.·You can attach the code using the attach feature (bottom of post window - see below - people can just download the file) or cut and paste it in using the insert code feature (it is the "#" symbol on the post editor - stays in better shape - this is what Jessica did).
Three examples are shown:
1. Pasted in code (as you did)
' What's a· Microcontroller - FirstProgram.bs2
' BASIC Stamp sends a message to Debug Terminal.
' {$STAMP BS2}
' {$PBASIC 2.5}
DEBUG "Hello, it's me, your BASIC Stamp!"
END
2. Pasted in code (using the code paste feature - #)
3. Below is the attached file.
Hope this helps! Great to have you on the forums.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Whit+
"We keep moving forward, opening new doors, and doing new things, because we're curious and curiosity keeps leading us down new paths." - Walt Disney
Post Edited (Whit) : 5/11/2010 1:35:40 AM GMT