Help with Ramping Code for Boe-Bot
Hi, I'm new to the Parallaxe message boards and I've recently just gotten my Boe-Bot robot kit last month.· I've done most of the activities in the activity book that came with the kit.· Chapter 4 has a really short section on ramping up / down for the servos on the Boe-Bot...· I was wondering if there was a way to incorporate that code into the other example programs in the book.· One being the one for Roaming with Whiskers or Roaming with irDetection.· Here is the code that I'm tryin to modify..
' Robotics with the Boe-Bot - RoamingWithIrDetectionAndRamping.bs2
' Boe-Bot uses·irDetection to detect objects, and navigates around them.
' {$STAMP BS2}
' {$PBASIC 2.5}
DEBUG "Program running"
irDetectLeft·· VAR····· Bit
irDetectRight· VAR····· Bit
pulseCount···· VAR····· Byte
FREQOUT 4, 2000, 3000
DO
· FREQOUT 8, 1, 38500
· irDetectLeft = IN9
· FREQOUT 2, 1, 38500
· irDetectRight = IN0
· IF (irDetectLeft = 0) AND (irDetectRight = 0) THEN
··· HIGH 10
··· HIGH 1
··· GOSUB Ramp_down
··· GOSUB Back_Up
··· GOSUB Turn_Left
··· GOSUB Turn_Left
· ELSEIF (irDetectLeft = 0) THEN
··· HIGH 10
··· GOSUB Ramp_Down
··· GOSUB Back_Up
··· GOSUB Turn_Right
· ELSEIF (irDetectRight = 0) THEN
··· HIGH 1
··· GOSUB Ramp_down
··· GOSUB Back_Up
··· GOSUB Turn_Left
· ELSE
··· LOW 10
··· LOW 1
··· GOSUB Ramp_Up
··· GOSUB Forward_Pulse
· ENDIF
LOOP
Ramp_Up:
· FOR pulseCount = 0 TO 60
··· PULSOUT 13, 750 + pulseCount
··· PULSOUT 12, 750 - pulseCount
··· PAUSE 20
· next
· RETURN
Forward_Pulse:
· PULSOUT 13, 850
· PULSOUT 12, 650
· PAUSE 20
· RETURN
Turn_Left:
· FOR pulseCount = 0 TO 45
··· PULSOUT 13, 750 - pulseCount
··· PULSOUT 12, 750 - pulseCount
··· PAUSE 20
· NEXT
· RETURN
Turn_Right:
· FOR pulseCount = 0 TO 45
··· PULSOUT 13, 750 + pulseCount
··· PULSOUT 12, 750 + pulseCount
··· PAUSE 20
· NEXT
· RETURN
Ramp_Down:
····FOR pulseCount = 0 TO 60
····· PULSOUT 13, 750 - pulseCount
····· PULSOUT 12, 750 + pulseCount
····· PAUSE 20
··· NEXT
··· RETURN
Back_Up:
· FOR pulseCount = 0 TO 40
··· PULSOUT 13, 650
··· PULSOUT 12, 850
··· PAUSE 20
· NEXT
· RETURN
When I try to run this program - My Boe-Bot seems to get stuck on this bit of code ( Ramp_Up ), and it repeats that over and over.· Is there a way to program the servos to gradually accelerate without having to go in a set/determined programmed length of area?· I want my Boe-Bot to move more fluidly around instead of having the jerks whenever it changes into a new direction.·
Thanks.
' Robotics with the Boe-Bot - RoamingWithIrDetectionAndRamping.bs2
' Boe-Bot uses·irDetection to detect objects, and navigates around them.
' {$STAMP BS2}
' {$PBASIC 2.5}
DEBUG "Program running"
irDetectLeft·· VAR····· Bit
irDetectRight· VAR····· Bit
pulseCount···· VAR····· Byte
FREQOUT 4, 2000, 3000
DO
· FREQOUT 8, 1, 38500
· irDetectLeft = IN9
· FREQOUT 2, 1, 38500
· irDetectRight = IN0
· IF (irDetectLeft = 0) AND (irDetectRight = 0) THEN
··· HIGH 10
··· HIGH 1
··· GOSUB Ramp_down
··· GOSUB Back_Up
··· GOSUB Turn_Left
··· GOSUB Turn_Left
· ELSEIF (irDetectLeft = 0) THEN
··· HIGH 10
··· GOSUB Ramp_Down
··· GOSUB Back_Up
··· GOSUB Turn_Right
· ELSEIF (irDetectRight = 0) THEN
··· HIGH 1
··· GOSUB Ramp_down
··· GOSUB Back_Up
··· GOSUB Turn_Left
· ELSE
··· LOW 10
··· LOW 1
··· GOSUB Ramp_Up
··· GOSUB Forward_Pulse
· ENDIF
LOOP
Ramp_Up:
· FOR pulseCount = 0 TO 60
··· PULSOUT 13, 750 + pulseCount
··· PULSOUT 12, 750 - pulseCount
··· PAUSE 20
· next
· RETURN
Forward_Pulse:
· PULSOUT 13, 850
· PULSOUT 12, 650
· PAUSE 20
· RETURN
Turn_Left:
· FOR pulseCount = 0 TO 45
··· PULSOUT 13, 750 - pulseCount
··· PULSOUT 12, 750 - pulseCount
··· PAUSE 20
· NEXT
· RETURN
Turn_Right:
· FOR pulseCount = 0 TO 45
··· PULSOUT 13, 750 + pulseCount
··· PULSOUT 12, 750 + pulseCount
··· PAUSE 20
· NEXT
· RETURN
Ramp_Down:
····FOR pulseCount = 0 TO 60
····· PULSOUT 13, 750 - pulseCount
····· PULSOUT 12, 750 + pulseCount
····· PAUSE 20
··· NEXT
··· RETURN
Back_Up:
· FOR pulseCount = 0 TO 40
··· PULSOUT 13, 650
··· PULSOUT 12, 850
··· PAUSE 20
· NEXT
· RETURN
When I try to run this program - My Boe-Bot seems to get stuck on this bit of code ( Ramp_Up ), and it repeats that over and over.· Is there a way to program the servos to gradually accelerate without having to go in a set/determined programmed length of area?· I want my Boe-Bot to move more fluidly around instead of having the jerks whenever it changes into a new direction.·
Thanks.
Comments
IF irLeft = Detected THEN motorLeft = motorLeft + 5 MAX 255 ' in my case I map motor speeds of 0-128-255 to 650-750-850 pulsewidths; motoRight = motorRight MIN 5 - 5 ' it's a convenience that saves var space, but is technically unneccesary ELSEIF irRight = Detected THEN motorLeft = motorLeft MIN 5 - 5 motorRight = motorRight + 5 MAX 255 ELSE ' straighten out but do it more quicky motorLeft = motorLeft + 10 MAX 255 motorRight = motorRight + 10 MAX 255 ENDIF
The only trap here is if you are doing any kind of subsumption based program (like many of the examples for the Boe floating around the forum). Many of those routines effectively "destroy" the previously sent motor speed, so you need to either preserve the last "sent" speed, or you need to code your subsumption state machines so they do not destroy the previous motor speed if they are not actually subsuming.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
When the going gets weird, the weird turn pro. -- HST
1uffakind.com/robots/povBitMapBuilder.php
1uffakind.com/robots/resistorLadder.php
One other question.. Why is there not a Sticky Boe-Bot thread? Like for the ones Penguin robot and Squibbler Robot?
The basic idea is that you have a subroutine, or a single place in your code, where the motor speeds are actually "dumped" and output to the servos. That way you can have your main loop keep tweaking and changing the motor speeds, and when the loop is done, THEN the final "set" speeds are actually sent. This might show it better. I'm using Words for servo speeds for simplicity, but words are a real waste of var space for these speeds (if your servo speed range is 650-850 that's a range of only 200, far less than a byte):
servoLeft PIN 12 ' change if necessary servoRight PIN 13 ' change if necessary motorLeft VAR Word ' left servo speed motorRight VAR Word ' right servo speed Main: Obstacle_Check: IF irLeft = Detected THEN motorLeft = motorLeft + 5 MAX 850 ' turn right gradually motorRight = motorRight - 5 MIN 650 ELSEIF irRight = Detected THEN motorLeft = motorLeft - 5 MIN 650 ' turn left gradually motorRight = motorRight + 5 MAX 850 ELSE ' straighten out but do it more quicky motorLeft = motorLeft + 10 MAX 850 motorRight = motorRight + 10 MAX 850 ENDIF Output_Servos: PULSOUT ServoLeft, 1500 - motorLeft ' note that the motorspeed vars are "normal" -- 850 is forward for both; ' only during output is the "backwards" motor value switched around PULSOUT ServoRight, motorRight PAUSE 5 ' this pause may need to be adjusted up or down (or eliminated) depending on how long it takes to run through the whole loop ' -- the goal is for all the code + the pause to add up to about 20ms Main_Loop_Done: GOTO Main
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
When the going gets weird, the weird turn pro. -- HST
1uffakind.com/robots/povBitMapBuilder.php
1uffakind.com/robots/resistorLadder.php