Basic Stamp 2sx programming
Hello
Me and a friend are programming a robot with soms QTI sensors, 2 colorPAL's and a ping))) sensor, we need to follow a line and turn on a green mark.
We first used the Basic Stamp 2 but it was to slow. The robot wasn't riding smooth and stopped after a 2 seconds, so we bought a BS2SX, it is 2.5 times faster.
Now we changed our program to the specs of the BS2SX and uploaded it. The program still runs 2 seconds and 1 of the 2 colorPAL's doesn't work.
The BS2SX is also getting very hot, I don't think this is normal.
For programming we use subroutines for distance, colordetection and soms other functions, the main program is the linefollower. In the linefollower we call the subs.
Does somebody have any ideas what can be wrong of why it gets hot?
Thanks!
Me and a friend are programming a robot with soms QTI sensors, 2 colorPAL's and a ping))) sensor, we need to follow a line and turn on a green mark.
We first used the Basic Stamp 2 but it was to slow. The robot wasn't riding smooth and stopped after a 2 seconds, so we bought a BS2SX, it is 2.5 times faster.
Now we changed our program to the specs of the BS2SX and uploaded it. The program still runs 2 seconds and 1 of the 2 colorPAL's doesn't work.
The BS2SX is also getting very hot, I don't think this is normal.
For programming we use subroutines for distance, colordetection and soms other functions, the main program is the linefollower. In the linefollower we call the subs.
Does somebody have any ideas what can be wrong of why it gets hot?
Thanks!
Comments
This is something we tryed, this is also the first time we programmed, so the program can be a mess and the comments in the program are is dutch (sorry for this, we are from Belgium)
This is the program: programma.txt
I can see some of the code comes from the Ping and ColorPAL sample programs as well as the Learn QTI projects.
All of the servo commands are backwards because if you look at all the Boe-Bot programs you will see that the Servo on Pin 13 is always first.
None of the times were adjusted since the BS2SX is 2-1/2 times faster than the BS2.
There was a DO...LOOP inside of one of the subroutines.
Another subroutine had a GOTO inside it which can cause the BS2 to crash. You never want to use a subroutine and not return from it.
If you can explain what your program does or what it needs to do then we can help you with it.
[code]
' {$STAMP BS2}
' {$PBASIC 2.5}
'===== Variabelen & constanten ========================================================================================
' Variables & constants (Dutch)
constante CON 2260 ' Ping))) Constant (Echo time -> cm with **)
' Conversion constant for room temperature measurements.
' At sea level sound travels through air at 1130 feet per second.
' This equates to 1 inch in 73.746 uS, or 1 cm in 29.034 uS.
' 1 / 29.034 = 0.0344423779 (with **)
' 0.0344423779 * 65.536 = 2257.21567817 -> 2257
' The Ping))) returns a pulse width of 73.746 us per inch.
' The Ping))) returns a pulse width of 29.033 us per cm.
PingTrigger CON 5 * 2.5 ' Ping))) trigger pulse = 10 uS (Added - 12.5 for BS2SX)
ServoCW CON 650 * 2.5 ' Pulse Width for Full-Speed Clockwise (Added - 1625 for BS2SX)
ServoLeft CON 700 * 2.5 ' Pulse Width to Curve Left (Added - 1750 for BS2SX)
ServoStop CON 750 * 2.5 ' Pulse Width for Full-Stop (Added - 1875 for BS2SX)
ServoRight CON 800 * 2.5 ' Pulse Width to Curve Right (Added - 2000 for BS2SX)
ServoCCW CON 850 * 2.5 ' Pulse Width for Full-Speed Counter-Clockwise (Added - 2125 for BS2SX)
PulseDodge CON 16 ' Number of 20 ms Servo Pulses Needed to Dodge (Added)
PulseDetect CON 30 ' Number of 20 ms Servo Pulses Needed for Detecting (Added)
PulseSearch CON 100 ' Number of 20 ms Servo Pulses Needed for Searching (Added)
' 122 ~ 3 sec, 61 ~ 1.5 sec, 244 ~ 6 sec, 407 ~ 10 sec, 41 ~ 1 sec
Pulse90 CON 48 ' Number of 20 ms Servo Pulses Needed for a 90-degree Turn (Added - 24)
a VAR Bit 'variabele a voor linker kleurensensor (Variable a for left color sensor)
b VAR Bit 'variabele b voor rechter kleurensensor (Variable b for right color sensor)
afstand VAR Word 'De afstand tot een object (Distance - The distance to an object)
tijd VAR Word ' (time - Ping Pulse Time)
roodL VAR Word ' (redL - Left ColorPAL)
groenL VAR Word ' (greenL - Left ColorPAL)
blauwL VAR Word ' (blueL - Left ColorPAL)
kleurL VAR Word ' (colorL - Left ColorPAL)
roodR VAR Word ' (redR - Right ColorPAL)
groenR VAR Word ' (greenR - Right ColorPAL)
blauwR VAR Word ' (blueR - Right ColorPAL)
kleurR VAR Word ' (colorR - Right ColorPAL)
teller VAR Word ' (counter - Number of Servo Pulses)
' I/O Pin Declarations
Ping PIN 9 ' Ping))) Ultrasonic Sensor (Added)
ServoRight PIN 12 ' Right Servo (Added)
ServoLeft PIN 13 ' Left Servo (Added)
sio1 PIN 14 'Seri
We don't have shorts, we checked and double checked it! the BS2 isn't getting hot. The BS2SX draws +- 0.136 Amps, and yes we use the 5volts! The regulator is also getting hot! we use 9V batteries but they are in no time empty (10minutes)
Or worse, are you running your servos off of the board's regulated 5V? Ack!
Maybe this code does what you want to do;
(%nnnn notation does not display correctly, I used %%nnnn)
' {$STAMP BS2sx} ' {$PBASIC 2.5} ' ===== Variables & constants =============================================================== ' Variables & constants true CON 1 false CON 0 leftisgreen VAR Bit ' left color sensor Boolean rightisgreen VAR Bit ' right color sensor Boolean distance VAR Word ' the distance to an object time VAR Word ' time - ping pulse red VAR Word ' red - from ColorPAL green VAR Word ' green - from ColorPAL blue VAR Word ' blue - from ColorPAL counter VAR Word ' general counter ' I/O Pins pingpin PIN 9 ' Ping))) Ultrasonic Sensor ServoRpin PIN 12 ' Right Servo ServoLpin PIN 13 ' Left Servo sio1pin PIN 14 ' Serial in/output Left, ColorPAL #1 sio2pin PIN 15 ' Serial in/out Right, ColorPAL #2 baud CON 33095 ' Baud Rate for ColorPAL, 7200 Baud, 8-bit/no-parity, True, Open) ' 327 + 32768 = 33095, ColorPAL Baud Rate for BS2SX QTIs VAR Nib ' Black/white line data from QTIs ' ===== Main program ======================================================================= GOSUB init ' initialise everything that needs to be initialised once DO ' Main program loop GOSUB getcolors ' determine if left/right is green, then turn left or right or detect & turn towards bottle GOSUB followline ' otherwise follow black line LOOP ' forever END ' ===== Subroutines ========================================================= init: ' Reset colorpals: Sends a long break to reset ColorPALs and enter direct command mode. LOW sio1pin ' make serial I/O low so residual voltage fully disappears INPUT sio1pin ' Set serial I/O back to input DO UNTIL sio1pin : LOOP ' Wait until the Colorpal sets the pin high LOW sio1pin ' make I/O pin low PAUSE 80 ' Hold the pin low for 80 ms to switch to direct mode INPUT sio1pin ' Set I/O pin to input PAUSE 10 ' Wait another 10 ms LOW sio2pin ' same for colorpal 2 INPUT sio2pin DO UNTIL sio2pin : LOOP LOW sio2pin PAUSE 80 INPUT sio2pin PAUSE 10 OUTB =%%1111 ' initialise QTIs RETURN ' ------------------------------------------------------------------------------------------------------ getdistance: ' Range finder - ping), returns distance in cm in variable "distance" PULSOUT pingpin, 5 ' activate sensor (trigger pulse = 10 uS) PULSIN pingpin, 1, time ' measure echo pulse distance = pingconstant ** time RETURN ' ------------------------------------------------------------------------------------------ check_QTIs: ' 4 infrared emitter/receivers differentiate between a dark and a light surface ' 0 = white surface, 1 = black. ' P7 - Far Left, P6 - Mid Left, P5 - Mid Right, P4 - Far Right DIRB = %%1111 ' P7..P4 all output PAUSE 1 ' Delay = 1 msec (let the capacitors discharge) DIRB = %%0000 ' P7..P4 all input PAUSE 1 ' Delay = 1 msec QTIs = INB ' Save QTI outputs RETURN ' -------------------------- followline: GOSUB check_QTIs ' get black line data from QTIs SELECT QTIs CASE %%1000 ' Line is on the far left; turn left towards line PULSOUT servoRpin, 650 PULSOUT servoLpin, 650 CASE %%1100 ' Line is to the left, veer left PULSOUT servoRpin, 750 PULSOUT servoLpin, 650 CASE%%0100 ' Line is to the mid left PULSOUT servoRpin, 800 PULSOUT servoLpin, 650 CASE %%0110 ' Line is in the center, straight ahead PULSOUT servoRpin, 850 PULSOUT servoLpin, 650 CASE %%0010 ' Line is to the mid right PULSOUT servoRpin, 850 PULSOUT servoLpin, 700 CASE %%0011 ' Line is to the right PULSOUT servoRpin, 850 PULSOUT servoLpin, 750 CASE %%0001 ' line is to the far right, turn right towards line PULSOUT servoRpin, 850 PULSOUT servoLpin, 850 CASE ELSE ' No line, try to find it DO WHILE (Qtis = 0) ' No Line Detected PULSOUT servoRpin, 850 ' Veer right [Pivot Left Backwards] PULSOUT servoLpin, 750 ' Full-Stop PAUSE 20 GOSUB check_QTIs ' keep trying LOOP ENDSELECT GOSUB getdistance ' Measure the distance to an object (bottle) with PING)) range finder IF (distance <= 16) THEN ' object is too close, avoid it FOR counter = 1 TO 16 ' 90-degree Left Turn PULSOUT servoLpin, 650 PULSOUT servoRpin, 650 PAUSE 20 NEXT ENDIF RETURN ' ----------------------------------------------------------------------------------------------------------------------------------- getcolors: ' obtain RGB data from ColorPALs and determine if green 'left side ColorPAL leftisgreen = false ' reset color left side SEROUT sio1pin, baud, ["= (00 $ m) !"] SERIN sio1pin, baud, [WAIT("$"), HEX3 red, HEX3 green, HEX3 blue] ' Get the RGB data from the sensor IF ((red + green + blue) <= 300) THEN leftisgreen = true 'right side ColorPAL rightisgreen = false ' reset color right side SEROUT sio2pin, baud, ["= (00 $ m) !"] SERIN sio2pin, baud, [WAIT("$"), HEX3 red, HEX3 green, HEX3 blue] IF ((red + green + blue) <= 300) THEN rightisgreen = true IF (leftisgreen = true) AND (rightisgreen = false) THEN GOSUB turn90L ' if only left side detects green, turn 90 deg left IF (leftisgreen = false) AND (rightisgreen = true) THEN GOSUB turn90R ' if only right side detects green, turn 90 deg right IF leftisgreen AND rightisgreen THEN GOSUB object_detection ' if both sides detect green; look for bottle RETURN ' -------------------------------------------------------------------------------------------------------------------------- turn90L: 'Turn 90° to the left (reel off - Left) FOR counter = 1 TO 48 PULSOUT servoRpin, 700 PULSOUT servoLpin, 650 PAUSE 20 NEXT RETURN ' -------------------------------------------------------------------------------------------------------------------------- turn90R: ' Turn 90° to the right (reel off - Right) FOR counter = 1 TO 48 PULSOUT servoRpin, 650 PULSOUT servoLpin, 700 PAUSE 20 NEXT RETURN ' -------------------------------------------------------------------------------------------------------------------------- object_detection: FOR counter = 1 TO 30 ' 90-Degree Left Turn? PULSOUT servoRpin, 650 ' Turn to the Left ?-degrees PULSOUT servoLpin, 650 PAUSE 20 NEXT GOSUB getdistance ' get start value DO WHILE (distance > 45) ' Keep turning right until the object is <= 45 cm PULSOUT servoRpin, 850 PULSOUT servoLpin, 850 PAUSE 15 GOSUB getdistance LOOP FOR counter = 1 TO 2 ' Slight right turn PULSOUT servoRpin, 850 PULSOUT servoLpin, 850 PAUSE 15 NEXT FOR counter = 1 TO 100 ' Back-Up for a few seconds PULSOUT servoRpin, 850 PULSOUT servoLpin, 850 PAUSE 20 NEXT RETURN ' ===============================================================================
Nonetheless, you may have blown your regulator in those 30 minutes. Each servo can draw over an amp, and that regulator may be toast. If it worked then but it doesn't now, you may have answered your own question. Unplug your servos from the board entirely and run your Stamp alone for a while on the 9V. First see if it works, then see if the reg still overheats.
If you're a lucky fellow, both your Stamp & reg survived and all you have to do is add a separate battery for your servos. But if you killed your board's 5V regulator, you'll also have to add a separate 5V regulator, connection that to Vdd and not using Vin. Never feed anything but 5.000000V to Vin or you can kiss your $50 BS2 goodbye.
I think you mean Vdd, not Vin. Vdd can safely be between 4.5v and 5.5v.
Thank you, Sapphire, I maid another missteak.
Yes, you're correct, Vdd is what I meant. It's the sensitive one which dearly loves 5 volts.
Yes (and that's different from the Stamps' on-board 5V.) The two are kept separated on the BoE, that servo 5V comes from a regulator located on the BoE.