Storing pulseCount Data
Hello ... How do I store the value of pulseCounts used to drive the servos at a certain period of time·then recall this value at another time. For example, the following code is used in my program:
·
FOR pulseCount = 0 TO 2310··· ' PulseCount to Drive·396 Inches forward········
····PULSOUT LeftServo, 850
··· PULSOUT RightServo, 650
··· PAUSE 20
NEXT
·
if an object is detected,·then my Bot will maneuver around it using the following simple code:
FOR pulseCount = 0 TO 20························ ' 90 Degrees Right Turn
··· PULSOUT LeftServo, 850
··· PULSOUT RightServo, 850
··· PAUSE 20
· NEXT
· FOR pulseCount = 0 TO 70······················ ' 12 inches
··· PULSOUT LeftServo, 850
··· PULSOUT RightServo, 650
··· PAUSE 20
· NEXT
· FOR pulseCount = 0 TO 20····················· ' 90 Degrees Left Turn
··· PULSOUT LeftServo, 650
··· PULSOUT RightServo, 650
··· PAUSE 20
· NEXT
· FOR pulseCount = 0 TO 140··················· ' Avoid Object
··· PULSOUT LeftServo, 850
··· PULSOUT RightServo, 650
··· PAUSE 20
· NEXT
· FOR pulseCount = 0 TO 20···················· ' 90 Degrees Left Turn
··· PULSOUT LeftServo, 650
··· PULSOUT RightServo, 650
··· PAUSE 20
· NEXT
· FOR pulseCount = 0 TO 70···················· ' 12 Inches
··· PULSOUT LeftServo, 850
··· PULSOUT RightServo, 650
··· PAUSE 20
· NEXT
· FOR pulseCount = 0 TO 15··················· ' 90 Degrees Right Turn
··· PULSOUT LeftServo, 850
··· PULSOUT rightServo, 850
··· PAUSE 20
· NEXT
The problem is how can i recall the pulseCount value·when an object is detected and use it after maneuvering to calculate for the remaining pulses needed to drive the servos for the remaining distance??
·
Let us say that an object is detected at 200 Inches, I must obtain the pulseCount at this time, and·after manuvering,·i must recall the value to use it in the following logic:
pulseCount·=pulseCount + 140·· ( This is the covered Distance)
reamining distance is 2310 - pulseCount
Thank you
·
FOR pulseCount = 0 TO 2310··· ' PulseCount to Drive·396 Inches forward········
····PULSOUT LeftServo, 850
··· PULSOUT RightServo, 650
··· PAUSE 20
NEXT
·
if an object is detected,·then my Bot will maneuver around it using the following simple code:
FOR pulseCount = 0 TO 20························ ' 90 Degrees Right Turn
··· PULSOUT LeftServo, 850
··· PULSOUT RightServo, 850
··· PAUSE 20
· NEXT
· FOR pulseCount = 0 TO 70······················ ' 12 inches
··· PULSOUT LeftServo, 850
··· PULSOUT RightServo, 650
··· PAUSE 20
· NEXT
· FOR pulseCount = 0 TO 20····················· ' 90 Degrees Left Turn
··· PULSOUT LeftServo, 650
··· PULSOUT RightServo, 650
··· PAUSE 20
· NEXT
· FOR pulseCount = 0 TO 140··················· ' Avoid Object
··· PULSOUT LeftServo, 850
··· PULSOUT RightServo, 650
··· PAUSE 20
· NEXT
· FOR pulseCount = 0 TO 20···················· ' 90 Degrees Left Turn
··· PULSOUT LeftServo, 650
··· PULSOUT RightServo, 650
··· PAUSE 20
· NEXT
· FOR pulseCount = 0 TO 70···················· ' 12 Inches
··· PULSOUT LeftServo, 850
··· PULSOUT RightServo, 650
··· PAUSE 20
· NEXT
· FOR pulseCount = 0 TO 15··················· ' 90 Degrees Right Turn
··· PULSOUT LeftServo, 850
··· PULSOUT rightServo, 850
··· PAUSE 20
· NEXT
The problem is how can i recall the pulseCount value·when an object is detected and use it after maneuvering to calculate for the remaining pulses needed to drive the servos for the remaining distance??
·
Let us say that an object is detected at 200 Inches, I must obtain the pulseCount at this time, and·after manuvering,·i must recall the value to use it in the following logic:
pulseCount·=pulseCount + 140·· ( This is the covered Distance)
reamining distance is 2310 - pulseCount
Thank you
Comments
FOR pulseCount = 0 TO 2310 ' PulseCount to Drive 396 Inches forward
IF Objectavoided then pulsecount=pulsecount+140
PULSOUT LeftServo, 850
PULSOUT RightServo, 650
PAUSE 20
NEXT
Post Edited (jmalaysia) : 4/6/2008 1:44:25 AM GMT
(pulseCount when object is detected + 140) = Distance Covered
Original value for pulseCount which is 2310 - Distnace covered = remaining pulses needed.
I am not sure hot to store the pulseCount value when the object is detected and recall it later after manuvering? I was trying to use the Read command but it did not work!!
Oops, see change above
Post Edited (Mike Green) : 4/6/2008 4:31:35 AM GMT
I need some explanation for what my Bot is doing; I am using the following simple code:
' {$STAMP BS2}
' {$PBASIC 2.5}
pulseCount VAR Byte ' Used For Measuring Turns
RightServo PIN 12 ' Right Servo is connected to pin 12
LeftServo PIN 13 ' Left Servo is connected to pin 13
task VAR Nib ' Current Task Being Performed
InitialValue VAR Nib ' Pulse value for task0,2,4
Piezo PIN 4 ' Piezo Speaker is connected to pin 4
GOSUB Drive
END
Drive:
InitialValue = 0
FOR pulseCount = InitialValue TO 272 *** This is where my problem is .... Please read below
PULSOUT LeftServo, 850
PULSOUT RightServo, 675
PAUSE 20
NEXT
RETURN
when i set my value to 68, my bot will go forward for 12 Inches ... But when i set my vlaue for 272 to have my Bot drive forward for 48 Inches, It just keep going forward for ever. I am not sure why it is doing that, can some one please help. Thank you
By the way, you have 3 identical messages. Please delete the extra ones (use the X in the upper right corner of the message window).
pulseCount VAR Word ' Used For Measuring Turns
RightServo PIN 12 ' Right Servo is connected to pin 12
LeftServo PIN 13 ' Left Servo is connected to pin 13
Task VAR Nib ' Current Task Being Performed
pulse VAR Byte ' Pulse value for task0,2,4
InitialValue VAR Word ' Pulse value for task0,2,4
Piezo PIN 4 ' Piezo Speaker is connected to pin 4
PAUSE 2000
FREQOUT Piezo, 100, 3000 ' Buzzer Initiate Indicating
ON Task GOSUB Task0, Task1, Task2, Task3, Task4
END
Task0:
InitialValue = 0
FOR pulseCount = InitialValue TO 2310
PULSOUT LeftServo, 850 ' Forward for 396 Inches
PULSOUT RightServo, 675
PAUSE 20
NEXT
RETURN
Task1:
FOR pulseCount = 0 TO 20 ' 90 Degrees Left Turn
PULSOUT LeftServo, 650
PULSOUT RightServo, 650
PAUSE 20
NEXT
RETURN
Task2:
InitialValue = 0
FOR pulseCount = InitialValue TO pulse
PULSOUT LeftServo, 850 ' Forward for 408 Inches
PULSOUT RightServo, 675
PAUSE 20
NEXT
RETURN
Task3:
FOR pulseCount = 0 TO 20 ' 90 Degrees Left Turn
PULSOUT LeftServo, 650
PULSOUT RightServo, 650
PAUSE 20
NEXT
RETURN
Task4:
InitialValue = 0
FOR pulseCount = InitialValue TO pulse
PULSOUT LeftServo, 850 ' Forward for 60 Inches
PULSOUT RightServo, 675
PAUSE 20
NEXT
RETURN
MAIN:
On Task Gosub ...
Task = Task + 1
·IF Task > 5 THEN
· Task = 0
·ENDIF
GOTO MAIN