light tracking robot
Hi
I am currently building a robot that is programmed to go toward the brightest light source.· I am using two HB-25's, 2 DC motors, and 2 photoresistors.· I am currently trying to make the·right DC motor sync with the left·photoresistor.· This means that when the light is really bright·the·DC motor goes faster and when·the light is dimmer, the·DC motor slows down.··At the moment i am not able to do this because the DC motor only responds to the first part of my code
After the photoresistor gets a reading of more than 5,000 it stops completely.
I believe that there is something wrong with the IF.. ElseIf... Endif.. statement
·All help is much appreciated.· Thanks
Technic-R-C
Post Edited (Technic-R-C) : 1/12/2008 5:11:11 AM GMT
I am currently building a robot that is programmed to go toward the brightest light source.· I am using two HB-25's, 2 DC motors, and 2 photoresistors.· I am currently trying to make the·right DC motor sync with the left·photoresistor.· This means that when the light is really bright·the·DC motor goes faster and when·the light is dimmer, the·DC motor slows down.··At the moment i am not able to do this because the DC motor only responds to the first part of my code
IF (time <= 5000) THEN PULSOUT HB25, 750 + 250
After the photoresistor gets a reading of more than 5,000 it stops completely.
I believe that there is something wrong with the IF.. ElseIf... Endif.. statement
' {$STAMP BS2px} ' {$PBASIC 2.5} ' -----[noparse][[/noparse] I/O Definitions ]------------------------------------------------- HB25 PIN 15 ' I/O Pin For HB-25 HB252 PIN 14 ' I/O Pin For HB-25 ' -----[noparse][[/noparse] Variables ]------------------------------------------------------- index VAR Word ' Counter For Ramping time VAR Word ' left light sensor time1 VAR Word ' right light sensor ' -----[noparse][[/noparse] Initialization of both HB-25 ]------------------------------------ DO : LOOP UNTIL HB25 = 1 ' Wait For HB-25 Power Up LOW HB25 PAUSE 5 PULSOUT HB25, 750 LOW HB252 PAUSE 5 PULSOUT HB252, 750 PAUSE 1000 ' -----[noparse][[/noparse] Initialization of both photoresistors ]--------------------------- Light: HIGH 13 HIGH 12 RCTIME 13, 1, time ' 0-40,000 increments RCTIME 12, 1, time1 DEBUG HOME, "time = ", DEC5 time GOTO main: ' -----[noparse][[/noparse] Program Code ]---------------------------------------------------- Main: IF (time <= 5000) THEN PULSOUT HB25, 750 + 250 ELSEIF (time > 5000) AND (time <= 15000) THEN PULSOUT HB25, 750 + 200 ELSEIF (time > 15000) AND (time <= 25000) THEN PULSOUT HB25, 750 + 150 ELSEIF (time > 25000) AND (time <= 35000) THEN PULSOUT HB25, 750 + 100 ELSE PULSOUT HB25, 750 + 50 ENDIF GOTO light:
·All help is much appreciated.· Thanks
Technic-R-C
Post Edited (Technic-R-C) : 1/12/2008 5:11:11 AM GMT
Comments
if they turn you should use a tiny screwdriver to adjust them to no rotation
the maximum speed is attained at 750 +/- 100.
One tire will be going clockwise, the other counterclockwise.
I'd say pulsout 850, not 750 + 100
BTW, at maximum speed, the vehicle will drive jerkily. there is a way to
achieve smooth acceleration. Click on the purple book icon and look at
the command descriptions of the commands you are using.
BS2 original code from the manual doesnt work with the BS2px.· All the motor does is drive at the highest speed for 3 seconds and it does not ramp up or down at all.· I think this is because of the BS2px speed.·
All help appreciated
Technic-R-C
Post Edited (Technic-R-C) : 1/12/2008 6:25:39 AM GMT
I dont think its 750 +/- 100 because the DC motor does not respond to these values at all, it only responds to numbers 1000 and above.
The·HB-25 command only responds to numbers 1000 and over? Is this true?· What is the maimum number?· If this is true, than the speed of the motor is too fast.· DOes anyone know how to simplify my code above using mathematic relationshoips between the speed and the photoresistor number?
So many questions....
Thanks
Tehnic-R-C
Post Edited (Technic-R-C) : 1/12/2008 6:05:01 AM GMT
' {$PBASIC 2.5}
'
[noparse][[/noparse] I/O Definitions ]
HB25 PIN 15 ' I/O Pin For HB-25
HB252 PIN 14 ' I/O Pin For HB-25
'
[noparse][[/noparse] Variables ]
index VAR Word ' Counter For Ramping
time VAR Word ' left light sensor
time1 VAR Word ' right light sensor
'
[noparse][[/noparse] Initialization of both HB-25 ]
DO : LOOP UNTIL HB25 = 1 ' Wait For HB-25 Power Up 'DO LOOP syntax is wrong and probably in the wrong place.
LOW HB25 'If the syntax were correct your program would be continually
PAUSE 5 'initializing your 2 variables. An endless loop. Also pulsout and PULSOUT HB25, 750 'pause don't belong here.
LOW HB252
PAUSE 5
PULSOUT HB252, 750
PAUSE 1000
'
[noparse][[/noparse] Initialization of both photoresistors ]
Light:
HIGH 13
HIGH 12
RCTIME 13, 1, time ' 0-40,000 increments
RCTIME 12, 1, time1
DEBUG HOME, "time = ", DEC5 time
GOTO main:
'
[noparse][[/noparse] Program Code ]
Main:
IF (time <= 5000) THEN
PULSOUT HB25, 750 + 250 'PULSOUT HB25, 850
'PAUSE 5
ELSEIF (time > 5000) AND (time <= 15000) THEN
PULSOUT HB25, 750 + 200 'PULSOUT HB25, 830
'PAUSE 5
ELSEIF (time > 15000) AND (time <= 25000) THEN
PULSOUT HB25, 750 + 150 'PULSOUT HB25, 810
'PAUSE 5
ELSEIF (time > 25000) AND (time <= 35000) THEN
PULSOUT HB25, 750 + 100 'PULSOUT HB25, 790
'PAUSE 5
ELSE
PULSOUT HB25, 750 + 50 'PULSOUT HB25, 770
'PAUSE 5
ENDIF
'I think this is the code that should be in the loop.
'I'm encouraging you to go to Basic Stamp Online Help, then click on PBASIC REFERENCE icon and
' read about the commands you want to use.
GOTO light:
I have a BS2px which mught be affecting the program.
Check out my second post, i edited it.
Technic-R-C
lets start over.
The code that comes with the manual does not want to work correctly
The motors do not ramp up and down, however they do turn on during full power.· This might be a sign that i have to change pause times because i have a very fast Basic Stamp.· What would i change the pause time to for a BS2px?
Technic-R-C
I'm not quite sure what you're looking to do, but does this grab the numbers you want?
PW VAR WORD
PW = time / 20
PULSOUT HB25, PW
Regards,
Bruce Bates
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
http://forums.parallax.com/showthread.php?p=591681
http://forums.parallax.com/showthread.php?p=681320
It states that the zero position for a BS2px is 1875 instead of 750 for the BS2.· I tried that and it works for ramping up and down using the sample code.· I then inputed the new numbers into my light tracker code and it works PERFECTLY
Here is the final code
Thanks for all of the help wellman.ron
Technic-R-C
Post Edited (Technic-R-C) : 1/12/2008 6:52:53 AM GMT
Technic-R-C
Thanks again
Technic-R-C
Now I see what you're trying to do. Your "base numbers" will vary depending on which Stamp Model you are using. The base numbers for both the BS-2 and BS-2px are shown below, so you can see the difference. The reason for this is as follows.
PULSOUT (as with many time based commands) does NOT express duration directly in terms of time, but rather it is expressed in time units (TU's). The slower Stamps have higher (longer) TU's, and the faster Stamps have lower (shorter) TU's. The TU's for the BS-2 are 2.0 uS and for the BS-2px .08 uS. Therein the differences in these tables.
························ BS-2··BS-2px
DIRECT'N· TIME··· TU's····TU's
················ms
RIGHT······ 1.0···· 500···· 1250
CNTR······· 1.5···· 750···· 1875
LEFT········ 2.0··· 1000···· 2500
- - - -
I hope that helps to straighten things out.
Regards,
Bruce Bates