Shop OBEX P1 Docs P2 Docs Learn Events
light tracking robot — Parallax Forums

light tracking robot

Technic-R-CTechnic-R-C Posts: 117
edited 2008-01-12 07:13 in BASIC Stamp
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

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

  • wellman.ronwellman.ron Posts: 16
    edited 2008-01-12 05:30
    the wheels do not turn when when pulsout is set to 750;
    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.
  • Technic-R-CTechnic-R-C Posts: 117
    edited 2008-01-12 05:38
    I have a BS2px, since it is much fasterm would it affect the HB-25 Pulse signals.· In the HB-25 manual it says that
    faster BS2 models or microcontrollers such as the SX will need to observe the minimum pause times

    more strictly. (pg. 4)

    What should I change the pause times to?

    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.·

    ' =========================================================================
    ' File...... HB-25 Motor Test.bs2
    ' Purpose... Tests One Or Two HB-25's Connected To P15
    ' Author.... Parallax, Inc.
    ' E-mail.... support@parallax.com
    ' Updated... 01-18-2006
    '
    ' {$STAMP BS2}
    ' {$PBASIC 2.5}
    ' -----[noparse][[/noparse] Program Description ]---------------------------------------------
    ' This program tests the HB-25 by waiting for it to power up, then pulsing
    ' the output to ramp the motors up in opposite directions, wait 3 seconds
    ' then ramp them back down to a stopped position. While the code is
    ' written for two HB-25/motors you can use it with just one by commenting
    ' out or removing the lines for the second motor, commented below. If you
    ' have two HB-25/motors connected, remember to remove the jumper block from
    ' the second HB-25.
    ' -----[noparse][[/noparse] I/O Definitions ]-------------------------------------------------
    HB25 PIN 15 ' I/O Pin For HB-25
    ' -----[noparse][[/noparse] Variables ]-------------------------------------------------------
    index VAR Word ' Counter For Ramping
    ' -----[noparse][[/noparse] Initialization ]--------------------------------------------------
    DO : LOOP UNTIL HB25 = 1 ' Wait For HB-25 Power Up
    LOW HB25 ' Make I/O Pin Output/Low
    PAUSE 5 ' Wait For HB-25 To Initialize
    PULSOUT HB25, 750 ' Stop Motor 1
    PAUSE 1 ' 1 mS Delay
    PULSOUT HB25, 750 ' Stop Motor 2 (If Connected)
    ' The Above 2 Lines May Be Removed
    ' If You Are Using Single Mode
    ' -----[noparse][[/noparse] Program Code ]----------------------------------------------------
    Main:
    PAUSE 20 ' Wait 20 mS Before Ramping
    FOR index = 0 TO 250 ' Ramp Up To Full Speed
    PULSOUT HB25, 750 + index ' Motor 1 Forward
    PAUSE 1 ' 1 mS Delay For Motor 2 Pulse
    PULSOUT HB25, 750 - index ' Motor 2 Reverse
    PAUSE 20 ' 20 mS Smoothing Delay
    NEXT
    PAUSE 3000 ' Wait 3 Seconds
    FOR index = 250 TO 0 ' Ramp Back Down
    PULSOUT HB25, 750 + index ' Motor 1 Forward Slowing
    PAUSE 1 ' 1 mS Delay For Motor 2
    PULSOUT HB25, 750 - index ' Motor 2 Reverse Slowing
    PAUSE 20 ' 20 mS Smoothing Delay
    NEXT
    
    STOP ' Use STOP To Prevent State Change
    
    
    

    All help appreciated

    Technic-R-C

    Post Edited (Technic-R-C) : 1/12/2008 6:25:39 AM GMT
  • Technic-R-CTechnic-R-C Posts: 117
    edited 2008-01-12 05:54
    What is the maximum number that you can input for an HB-25?

    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.

    IF (time <= 5000) THEN
      PULSOUT HB25, 1000
    ELSEIF (time > 5000) AND (time <= 15000) THEN
      PULSOUT HB25, 950
    ELSEIF (time > 15000) AND (time <= 25000) THEN
      PULSOUT HB25, 900
    ELSEIF (time > 25000) AND (time <= 35000) THEN
      PULSOUT HB25, 850
    ELSE
      PULSOUT HB25, 800
    ENDIF
    GOTO light:
    

    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
  • wellman.ronwellman.ron Posts: 16
    edited 2008-01-12 06:21
    ' {$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 '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:
  • wellman.ronwellman.ron Posts: 16
    edited 2008-01-12 06:26
    My last email is very difficult to read, Sorry. I inserted comments, PBasic does not seem to respect blank space. If your code works with numbers starting at 1000, by all means use those numbers. However I think the other comments are right. Hoping this helps! ron
  • Technic-R-CTechnic-R-C Posts: 117
    edited 2008-01-12 06:28
    It doesn't work.

    I have a BS2px which mught be affecting the program.

    Check out my second post, i edited it.

    Technic-R-C
  • Technic-R-CTechnic-R-C Posts: 117
    edited 2008-01-12 06:33
    Ok....

    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
  • wellman.ronwellman.ron Posts: 16
    edited 2008-01-12 06:35
    I notice that you have replaced the FOR...NEXT code in the Parallax program with with IF..ELSE..ENDIF. Do you think that might make a difference? Also seeing the Parallax code you posted, I guess my earlier comments are illformed. Sorry. ron
  • Bruce BatesBruce Bates Posts: 3,045
    edited 2008-01-12 06:43
    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

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
  • Technic-R-CTechnic-R-C Posts: 117
    edited 2008-01-12 06:45
    I found a post regarding the HB-25 motor controller with BS2px.

    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

    '   {$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, 2500
    ELSEIF (time > 5000) AND (time <= 15000) THEN
      PULSOUT HB25, 2350
    ELSEIF (time > 15000) AND (time <= 25000) THEN
      PULSOUT HB25, 2200
    ELSEIF (time > 25000) AND (time <= 35000) THEN
      PULSOUT HB25, 2050
    ELSE
      PULSOUT HB25, 1900
    ENDIF
    GOTO light:
    

    Thanks for all of the help wellman.ron

    Technic-R-C

    Post Edited (Technic-R-C) : 1/12/2008 6:52:53 AM GMT
  • wellman.ronwellman.ron Posts: 16
    edited 2008-01-12 06:48
    Just answer me when I ask for help in the next few days!
  • Technic-R-CTechnic-R-C Posts: 117
    edited 2008-01-12 06:49
    I'm not quite sure what you're looking to do, but does this grab the numbers you want?
    All I wanted to do was ramp up and down using the sample code and impliment the code in my own robot.· However, since the speed of the BS2 and BS2px are different, there HB-25 zero positions are also different.· THis solved the problem

    Technic-R-C
  • Technic-R-CTechnic-R-C Posts: 117
    edited 2008-01-12 06:53
    Just answer me when I ask for help in the next few days!
    Sure, no problem

    Thanks again

    Technic-R-C
  • Bruce BatesBruce Bates Posts: 3,045
    edited 2008-01-12 07:13
    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
Sign In or Register to comment.