Shop OBEX P1 Docs P2 Docs Learn Events
Easy Basic Stamp Question... I HOPE.. — Parallax Forums

Easy Basic Stamp Question... I HOPE..

str4t3gystr4t3gy Posts: 2
edited 2010-04-30 17:34 in BASIC Stamp
Hey everyone.. i am doing a parallax project for school and i am using a bs2 to run a conveyer belt system and i have completed all of the programming except i need to find a way to use a timer in my program.· The idea is to have an infrared sensor to distinguish between a big block and a small block based on certain time that the sensor is broke from the block passing through.· If it is broke for a long time i want to signal a pump to push the block off the track as it goes down the track so far, and if the block is small and only breaks the signal for a short time i want it to continue down the conveyer.· any ideas would be extremely helpful?! Thank you ·

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2010-04-28 23:18
    The BS2 does not have an independent timer, but it does have an accurate PAUSE timer. Often what people will do is, rather than just waiting for the infrared sensor to see the end of the block, the program will have a PAUSE 1 in the wait loop and counts the number of times the loop executes. When the sensor sees the end of the block, the program looks at the count which approximates the time it takes the block to move past the sensor. The other statements in the loop take a little time to execute so the time isn't exact, but it's often exact enough to do the job. For other information on Stamp execution time, see www.emesystems.com. Click on the "app-notes" link on the bottom of the page.
  • metron9metron9 Posts: 1,100
    edited 2010-04-29 02:39
    Another idea for you would be to set up a second sensor to count the revolutions of the conveyer belts drive roller.

    You set up a simple reflective encoder wheel to count pulses per revolution. Say the encoder has 10 pulses per revolution and is 2 inched in diameter.
    2 * 3.14159 = 6.283 and divide by 10 you have a counter pulse for each .62 inches of travel.

    Waiting for the block ir sensor to change state, you would save the state of the conveyer sensor and then monitor the conveyer sensor and the block sensor.

    Counting the conveyer pulses you calculate the length when your block sensor changes state.

    Depending on the resolution you need (block size difference needed to be measured) you increase your encoder wheel to what you need.

    If for ecxample you set it up for 1/4 inch per pulse the minimum count would be 3 for a 1 inch block if both sensors were exactly lined up as you would have a pulse (state change) at 1/4 then 1/2 then 3/4.

    It could be a count of 4 if it was not lined up exactly and a box size of over 1.25 would be necessary to give a 5 count.

    Using 100 pulses per revolution you could measure much smaller differences in box sizes.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Think Inside the box first and if that doesn't work..
    Re-arrange what's inside the box then...
    Think outside the BOX!
  • str4t3gystr4t3gy Posts: 2
    edited 2010-04-29 18:18
    Thanks for your replies, but i still dont really feel comfortable on how to use this information you have given me..

    mike green- im not quite sure how u would use this pause 1 in a (??wait loop??) as a timer to trigger a pump to push over a block if it counts for too long, or to have it not activate the pump if it is a short block.. would u be able to show me just an example of a code that you would use to accomplish this task??

    metron9- im sorry i am not really any good with parallax yet, i have been reading and am going to keep on experimenting with different codes and try to get a good grasp with all that basic stamps can accomplish. But right now i am kind of puzzled on how you code in these pulses ect. to work properly. The diameter of this track wheel is 1 inch, so that would be 3.14/10 which would be .314 inches of travel, and the blocks that need to be distinguished are 1.5 inches for the long blocks that i want a pump to push off the track later on, and the small ones are 1 inch that i want the pump to ignore and let go through down further on the track.. if you could give some type of mock example code for this situation i would really appreciate it!!
  • metron9metron9 Posts: 1,100
    edited 2010-04-30 02:32
    Ok, assuming you can connect two IR sensors to give you a high and low signal on say pins 1 and 2
    Lets use pin 1 to monitor the block on the belt and pin 2 to monitor the pulse from the belt wheel
    1.5 inches / 0.314 = 4.77 signals per block maximum
    1.0 inch block / .314 = 3.18 signals per block maximum
    Since we can't measure the decimal part we end up with 4 signals for 1.5 inch and 3 signals for a 1 inch block.

    What is the minimum signals
    If the block sensor and the wheel sensor both changed states at the same time (leading edge of the block is in sync with the leading edge of the encoder wheel)
    We would read both pin 1 and pin 2 signals and count transitions on pin 2 (the wheel) while pin 1 was still high (assuming we set up the block sensor to read high when a block is sensed)
    Now the transitions counted would be at .314 - .628· - .942 - 1.256 and then pin 1 would change to low as the trailing edge of the 1.5 inch block went past the sensor.
    That would be 4 counts
    If the block entered a bit earlier we may have a count of 5 since the first transition on the encoder wheel would trigger
    So we know a count of 4 or 5 is a 1.5 inch block

    However we have a problem. If a 1 inch block entered just a bit before the encoder we might indeed get 4 counts as well
    So we need to double the encoder to 20. now we go through the same thing but using .157 steps per encoder.

    1.5 / .157 = 9.55
    1 / .157 = 6.3
    So we can deduce that if the count is greater then 7 it must be a 1.5 inch block
    Lets do the code

    ' {$STAMP BS2}
    ' {$PBASIC 2.5}
    ' {$PORT COM1}
    encoderstate VAR Bit
    ecount       VAR Byte
    
    INPUT 1 ' this pin is high when a block is in the IR field
    INPUT 2 ' this pin transitions from high to low when wheel turns
    main:
    'First we need to wait for a block but we want to make sure the area is first clear
    'So we wait for the pin to be LOW
    DEBUG "Waiting for initial clear area",CR
    blockwaitloop:
    IF IN1 = 1 THEN blockwaitloop
    'Now we wait for the pin to go high when it detects a block'
    DEBUG "Waiting for block",CR
    blockwaitloop1:
    IF IN1 = 0 THEN blockwaitloop1
    'Now the block has been detected'
    DEBUG "Block detected",CR
    'We save the state of pin 2 the wheel encoder'
    encoderstate = IN2
    'We need to monitor pin 1 and count transitions on pin 2'
    ecount=0 'Lets zero the counter variable'
    ' Now we monitor IN1 while counting transitions on pin 2
    countingloop:
    IF IN1 = 0 THEN Exitcountloop
    IF encoderstate = IN2 THEN countingloop
    ecount=ecount+1    'The state has changed so we add one to the variable
    encoderstate = IN2 'Since the encoderstate has changed we save the new state in the variable'
    GOTO countingloop     'We continue to monitor
    exitcountloop:     'Finished, block has passed IR sensor
    'Now we call a process loop and then jump back to the program start
    DEBUG "Processing data",CR
    GOSUB processdata
    GOTO main
    processdata:
    IF ecount > 7 THEN bigblock
    smallblock:
    DEBUG "block is small",CR,CR
    RETURN
    bigblock:
    DEBUG "Blockisbig",CR,CR
    'Code to enable arm to push block would go here'
    RETURN
     
     
     
     
    

    ·Remember, you may have to stop the conveyer belt depending on how close the blocks are to each other or you may miss a block.

    ·Not sure why code is not formatted with cut and paste so I have attached it as well.



    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Think Inside the box first and if that doesn't work..
    Re-arrange what's inside the box then...
    Think outside the BOX!
  • JaimeJaime Posts: 16
    edited 2010-04-30 16:55
    You can activate a counter each time the infrared sensor is obstructed, this counter contained as a subroutine which will start each time the sensor sends the signal, you can insert a PAUSE of 1000 which is equivalent to 1 sec and also you can register how many times the counter was incremented, once another signal is detected from the sensor the counter stops and you can fecth ( you have to assign a variable to log the times) the times the counter was incremented you multiply it by the PAUSE parameter. i.E 20 times X 1000= 20 secs and this was the time interval. This approach should work out fine.

    Have fun

    microwaveteach@hotmail.com

    Jaime Ibarra (Mexico)
  • metron9metron9 Posts: 1,100
    edited 2010-04-30 17:34
    I had another bright idea actually just before I fell asleep last night.



    Just use 2 sensors to read the block. Put the sensors 1.25 inches apart. When a 1.5 inch block blocks both sensors you know you have a larger than 1.25 inch block.

    Code something like this

    waitforblock:

    if in1 + in2·<> 2 then waitforblock

    process bigblock

    goto waitforblock





    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Think Inside the box first and if that doesn't work..
    Re-arrange what's inside the box then...
    Think outside the BOX!
Sign In or Register to comment.