Senior project please help
UNFMech
Posts: 9
So here is the backround, I have a senior project due in a week and a half and I have been messing around with the Parallax BOE. I am constructing an autonomous waste sorter that must sort glass/plastic/tin-steel/ and aluminum. For sorting the tin-steel(soup can) we have a servo with a magnet attached to an arm that is sweeping under a conveyor belt continuously. For the aluminum we have a proximity inductive sensor wired to the bread board and to a servo arm, such that when the sensor is active the servo door swings open. I need both functions to work at once, aka, the sweeper servo for the tin-steel and the aluminum + sensor setup. Currently I have them both setup, the only problem is that when the sensor actives the door for the aluminum open BUT the sweeper servo stops. I know the problem I am just not very good at programming and PBASIC is still kinda new to me. Any help would be awesome. Below is the current code I am using with pictures.
' {$STAMP BS2}
' {$PBASIC 2.5}
'
[noparse][[/noparse] I/O Definitions ]
PIR PIN 0 'I/O Pin for PIR Sensor
LAR PIN 0
'
[noparse][[/noparse] Variables ]
Setup:
MinVal VAR Word
MaxVal VAR Word
x VAR Word
y VAR Word
z VAR Word
CheckForSensor VAR Word
counter VAR Word
Highest VAR Word
Lowest VAR Word
Lowest=205
Highest=1500
MinVal=205
MaxVal=1600
z=10
'
[noparse][[/noparse] Main Program ]
MAIN:
'Servo Sweeper, just moves from one position back and forth, looping
DO
FOR x=0 TO MaxVal STEP 20
PULSOUT 12, x
PAUSE 5
NEXT
FOR x=MaxVal TO 0 STEP -20
PULSOUT 12, x
PAUSE 5
NEXT
LOOP
Sensor:
DEBUG "Checking for Sensor!" 'checking for sensor
DO
PULSOUT 13, 1100 'returns sensor door to original position
IF PIR = 0 THEN DEBUG "Not Found" 'If sensor isnt sensing anything then servo sweep
'if sensor senses something then open servo door
IF PIR =1 THEN Open
GOSUB Sweep
LOOP
Sweep:
DO
FOR x=0 TO MaxVal STEP 20
PULSOUT 12, x
PAUSE 5
NEXT
FOR x=MaxVal TO 0 STEP -20
PULSOUT 12, x
PAUSE 5
NEXT
RETURN
LOOP
Open:
FOR counter = 1 TO 100
PULSOUT 13, 850
PAUSE 20
NEXT
GOSUB Close
Close:
FOR counter = 1 TO 100
PULSOUT 13, 1100
NEXT
GOSUB Sensor
' {$STAMP BS2}
' {$PBASIC 2.5}
'
[noparse][[/noparse] I/O Definitions ]
PIR PIN 0 'I/O Pin for PIR Sensor
LAR PIN 0
'
[noparse][[/noparse] Variables ]
Setup:
MinVal VAR Word
MaxVal VAR Word
x VAR Word
y VAR Word
z VAR Word
CheckForSensor VAR Word
counter VAR Word
Highest VAR Word
Lowest VAR Word
Lowest=205
Highest=1500
MinVal=205
MaxVal=1600
z=10
'
[noparse][[/noparse] Main Program ]
MAIN:
'Servo Sweeper, just moves from one position back and forth, looping
DO
FOR x=0 TO MaxVal STEP 20
PULSOUT 12, x
PAUSE 5
NEXT
FOR x=MaxVal TO 0 STEP -20
PULSOUT 12, x
PAUSE 5
NEXT
LOOP
Sensor:
DEBUG "Checking for Sensor!" 'checking for sensor
DO
PULSOUT 13, 1100 'returns sensor door to original position
IF PIR = 0 THEN DEBUG "Not Found" 'If sensor isnt sensing anything then servo sweep
'if sensor senses something then open servo door
IF PIR =1 THEN Open
GOSUB Sweep
LOOP
Sweep:
DO
FOR x=0 TO MaxVal STEP 20
PULSOUT 12, x
PAUSE 5
NEXT
FOR x=MaxVal TO 0 STEP -20
PULSOUT 12, x
PAUSE 5
NEXT
RETURN
LOOP
Open:
FOR counter = 1 TO 100
PULSOUT 13, 850
PAUSE 20
NEXT
GOSUB Close
Close:
FOR counter = 1 TO 100
PULSOUT 13, 1100
NEXT
GOSUB Sensor
Comments
Use two stamp boards?
I don't think you have to use a Servo to sweep the magnet under the conveyor belt to look for steel cans. You could have a continously moving DC motor and just have it oscillate when you turn power on. Otherwise I think you could use the ServoPal to control the servos while your Basic Stamp is doing other things.
Here's the data on the ServoPal http://www.parallax.com/Portals/0/Downloads/docs/prod//robo/ServoPAL_doc.pdf
By the way, your several "sweep" routines use a pause of 5ms. The servos are actually made to respond to a pause more like 20ms. You can't really move them faster or smoother by shortening the pause time.
You're going to have problems with your program. You're using GOSUB like a GOTO and there is no corresponding RETURN statement. The GOSUB and RETURN have to be matched up. Use a GOTO if that's really what you mean.
Your min and max values for servo pulses should be around 500 and 1000, certainly not zero and 1,600!
You would also need to trim your Senors subroutine down to the absolute minimum, the DEBUG statements will take a lot of time to execute and will cause the servos to be herky-jerky.
Rich H
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
The Simple Servo Tester, a kit from Gadget Gangster.
Post Edited (W9GFO) : 3/15/2010 6:58:45 PM GMT
This loop continuously sweeps the servo on pin 12. It also will maintain the position of the servo on pin 13. To open the gate, set gatePos to gateMax. To close the gate, set gatePos to gateMin. It will take a few cycles of the loop for the gate servo to move to the requested position. This can be handled by setting loopCnt to 15 when gatePos is set, then not reacting until loopCnt becomes zero.
Note change in sweepMax / sweepMin testing.
Post Edited (Mike Green) : 3/15/2010 11:36:37 PM GMT
'IF loopCnt > 0 THEN
'loopCnt = loopCnt - 1
'ENDIF
'IF PIR = 1 THEN
'gatePos=gateMax
' FOR counter = 1 TO 50
'gatePos=gaetMin
'ELSE
' gatePos=gateMin
'ENDIF
This code works for the aluminum door, the sweeper servo I am still having trouble with though, the sweeper servo will only stay at the end of the servo range in either direction, I have tried changing the values but am not quite sure what is wrong. The servo sweeper stays at max range then sweeps once and returns to max range and stays there.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
- Stephen
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
- Stephen
MaxVal VAR Word
x VAR Word
opening CON 0
closing CON 1
sweeper VAR Bit
sweepPos VAR Word
sweepMin CON 500
sweepMax CON 1600
gatePos VAR Word
gateMin CON 1100
gateMax CON 800
loopCnt VAR Nib
sweepPos = sweepMin
sweeper = opening
loopCnt = 0
MaxVal = 1600
counter VAR Word
DO
PULSOUT 12,sweepPos
IF sweeper = opening THEN
IF sweepPos + 20 > sweepMax THEN
sweeper = closing
ELSE
sweepPos = sweepPos + 20
ENDIF
ELSE
IF sweepPos - 20 < sweepMin THEN
sweeper = opening
ELSE
sweepPos = sweepPos - 20
ENDIF
ENDIF
PULSOUT 13,gatePos 'Aluminum door servo arm
IF loopCnt > 0 THEN
loopCnt = loopCnt - 1
ENDIF
IF PIR = 1 THEN
gatePos=gateMax
ELSE
gatePos=gateMin
ENDIF
Alright the sweeper is working and the aluminum door arm works but only like once or twice and then stops after the ferrous metal is introduced.
PULSOUT 13,gatePos 'Aluminum door servo arm
IF loopCnt > 0 THEN
loopCnt = loopCnt - 1
ENDIF
IF PIR = 1 THEN
gatePos=gateMax
ELSE
gatePos=gateMin
ENDIF
When introduced with the sweeper arm code its really up in the air if the sensor will activate or not. Sometimes when the sensor is placed right next to the material it will work, but sometimes the sensor just does not read it at all. Something to do with the sensor loop not activating? Individually each code block works perfectly, but when introduced with each other all heck breaks loose and the sensor gets a mind of its own. The base code that I am playing around with is the same as what is posted directly above. Thank You!
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
- Stephen
Post Edited (UNFMech) : 3/16/2010 11:15:27 PM GMT
Click on the post reply button and use the attachment manager to attach your code.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
- Stephen
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
- Stephen
Rich H
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
The Simple Servo Tester, a kit from Gadget Gangster.
Post Edited (W9GFO) : 3/18/2010 6:03:57 AM GMT
The PAUSE 15 is there to try to keep your loop running at 50 times a second. If the sweep servo is too slow the way to speed it up is to increase the amount that the sweep_value changes each time through the loop.
Put this at the top along with the other declarations:
Then replace -
With this;
Now when you want to alter the speed of the sweep servo just change the number assigned to sweep_change at the top of the program.
Put the PAUSE 15 back and only reduce it if the servo is stuttering.
Rich H
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
The Simple Servo Tester, a kit from Gadget Gangster.
Post Edited (W9GFO) : 3/19/2010 5:40:25 PM GMT
You could also create another CON for that value (just like we did for sweep_change above) so that you can adjust it from the top of your program rather than having to dig down through the code to find the value. Not really an issue in this short program but it is a good habit to get into.
Rich H
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
The Simple Servo Tester, a kit from Gadget Gangster.