Motors do not work on BS2PX
ptruini
Posts: 9
in BASIC Stamp
Hi,
Hoping someone can help me with an issue I'm having. I have been using a BS2 as my microcontroller on a BOE for a long time and all my programs work as designed on it. However, I just recently received a BS2PX and now that I'm using that microcontroller instead; now the issue I'm having is in any of my programs or any example programs that I've tried, the motors do not run on the BS2PX; everything else works fine though, sensors, LEDs, speech, etc. Everything including the motors work perfectly on the BS2.
Same program, just changed the the Stamp module in the code from ' {$STAMP BS2} to ' {$STAMP BS2px}. My robot is running two DC motors powered by a 12 volt lead acid battery and controlled by two HB25 motor controllers. Are there any commands/initialization for this type of module that need to be specified first in order for the motors to run? I've been researching the "CONFIGPIN" command, thinking maybe I need to set the motors/controllers as an output pin, but nothing yet. Below is an example of of one of my programs:
Any help would be greatly appreciated!
' Robot will speak a warning, then using a PIR motion sensor, Robot will detect If movement is detected or not. If movement
' is detected then robot will ramp up backwards and speak. If no movement is detected then robot will ramp up CCW and then start over
' in a infinit loop.
' {$STAMP BS2px}
' {$PBASIC 2.5}
'
[ I/O Definitions ]
EMIC_TX PIN 0 ' Serial output (connects to Emic 2 SIN)
EMIC_RX PIN 1 ' Serial input (connects to Emic 2 SOUT)
FrontLED PIN 4
RLED PIN 6
BLED PIN 8
GLED PIN 9
PIR PIN 10 ' PIR motion detector
HB25 PIN 12 ' I/O Pin For HB-25
'
[ Variables ]
i VAR Byte
pulseCount VAR Word
pulseLeft VAR Word
pulseRight VAR Word
time VAR Word
'
[ Constants ]
#SELECT $STAMP ' Select Baud constants
#CASE BS2, BS2E, BS2PE
T1200 CON 813
T2400 CON 396
T4800 CON 188
T9600 CON 84
T19K2 CON 32
#CASE BS2SX, BS2P
T1200 CON 2063
T2400 CON 1021
T4800 CON 500
T9600 CON 240
T19K2 CON 110
#CASE BS2PX
T1200 CON 3313
T2400 CON 1646
T4800 CON 813
T9600 CON 396
T19K2 CON 188
#ENDSELECT
EmicBaud CON T9600
'
[ Initialization ]
DEBUG "HB25 Controller Initializing..."
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
DEBUG "Completed!", CR
'
Emic 2
' When the Emic 2 powers on, it takes about 3 seconds for it to successfully
' intialize. it then sends a ":" character to indicate it's ready to accept
' commands. if the Emic 2 is already initialized, a CR will also cause it
' to send a ":"
DEBUG "Waiting for Emic 2..."
SEROUT EMIC_TX, EmicBaud, [CR]
SERIN EMIC_RX, EmicBaud, [WAIT(":")]
DEBUG "Ready!", CR
'
[ Program Code ]
LEDs:
HIGH FrontLED
HIGH RLED
PAUSE 500
LOW RLED
HIGH GLED
PAUSE 500
LOW GLED
HIGH BLED
PAUSE 500
LOW BLED
SEROUT EMIC_TX, EmicBaud, ["V18", CR] 'Set volume to to maximum.
SERIN EMIC_RX, EmicBaud, [WAIT(":")]
DEBUG "Speaking some text..."
SEROUT EMIC_TX, EmicBaud, ["S", ":-)4Hello. I am Sentry bot. Please state your business", CR] ' Send the string to convert to speech
SERIN EMIC_RX, EmicBaud, [WAIT(":")] ' Wait here until the Emic 2 responds with a ":"
'indicating it's ready to accept the next command
DEBUG "Done!", CR
DO
MOTION:
INPUT PIR
DO
i = i - 10
DEBUG HOME, "WAIT 10 seconds FOR PIR Sensor warm up",CR,
DEC i, " seconds left ",CR
LOOP UNTIL i = 0
NAP 6 ' Nap for 1152 ms (1.152 Seconds).
MAIN:
IF (PIR = 1) THEN ' If PIR sensor detects motion, then speak and drive motors.
HIGH RLED
HIGH BLED
DEBUG CRSRXY, 0,4, "PIR Sensor State = ", BIN1 IN10
SEROUT EMIC_TX, EmicBaud, ["S", ":-)4 Please state the passcode", CR] ' Send the string to convert to speech
SERIN EMIC_RX, EmicBaud, [WAIT(":")] ' Wait here until the Emic 2 responds with a ":"
PAUSE 20 ' Wait 20 mS Before Ramping
FOR pulseCount = 0 TO 100 ' Ramp Up To Full Speed
PULSOUT HB25, 750 - pulseCount ' Motor 1 Reverse
PAUSE 1 ' 1 mS Delay For Motor 2 Pulse
PULSOUT HB25, 750 + pulseCount ' Motor 2 Forward
PAUSE 20 ' 20 mS Smoothing Delay
NEXT
PAUSE 3000 ' Wait 3 Seconds
FOR pulseCount = 100 TO 0 ' Ramp Back Down
PULSOUT HB25, 750 - pulseCount ' Motor 1 Reverse Slowing
PAUSE 1 ' 1 mS Delay For Motor 2
PULSOUT HB25, 750 + pulseCount ' Motor 2 Forward Slowing
PAUSE 20 ' 20 mS Smoothing Delay
NEXT
ELSE
DEBUG CRSRXY, 0,6, "PIR Sensor State = ", BIN1 IN10
LOW RLED
LOW BLED
HIGH GLED
PAUSE 3000 ' Wait 3 Seconds
PAUSE 20 ' Wait 20 mS Before Ramping
FOR pulseCount = 0 TO 100 ' Ramp Up To Full Speed
PULSOUT HB25, 750 + pulseCount ' Motor 1 Forward
PAUSE 1 ' 1 mS Delay For Motor 2 Pulse
PULSOUT HB25, 750 + pulseCount ' Motor 2 Forward
PAUSE 20 ' 20 mS Smoothing Delay
NEXT
PAUSE 3000 ' Wait 3 Seconds
FOR pulseCount = 100 TO 0 ' Ramp Back Down
PULSOUT HB25, 750 + pulseCount ' Motor 1 Forward Slowing
PAUSE 1 ' 1 mS Delay For Motor 2
PULSOUT HB25, 750 + pulseCount ' Motor 2 Forward Slowing
PAUSE 20 ' 20 mS Smoothing Delay
NEXT
ENDIF
LOOP
Thank you,
Paul
Hoping someone can help me with an issue I'm having. I have been using a BS2 as my microcontroller on a BOE for a long time and all my programs work as designed on it. However, I just recently received a BS2PX and now that I'm using that microcontroller instead; now the issue I'm having is in any of my programs or any example programs that I've tried, the motors do not run on the BS2PX; everything else works fine though, sensors, LEDs, speech, etc. Everything including the motors work perfectly on the BS2.
Same program, just changed the the Stamp module in the code from ' {$STAMP BS2} to ' {$STAMP BS2px}. My robot is running two DC motors powered by a 12 volt lead acid battery and controlled by two HB25 motor controllers. Are there any commands/initialization for this type of module that need to be specified first in order for the motors to run? I've been researching the "CONFIGPIN" command, thinking maybe I need to set the motors/controllers as an output pin, but nothing yet. Below is an example of of one of my programs:
Any help would be greatly appreciated!
' Robot will speak a warning, then using a PIR motion sensor, Robot will detect If movement is detected or not. If movement
' is detected then robot will ramp up backwards and speak. If no movement is detected then robot will ramp up CCW and then start over
' in a infinit loop.
' {$STAMP BS2px}
' {$PBASIC 2.5}
'
[ I/O Definitions ]
EMIC_TX PIN 0 ' Serial output (connects to Emic 2 SIN)
EMIC_RX PIN 1 ' Serial input (connects to Emic 2 SOUT)
FrontLED PIN 4
RLED PIN 6
BLED PIN 8
GLED PIN 9
PIR PIN 10 ' PIR motion detector
HB25 PIN 12 ' I/O Pin For HB-25
'
[ Variables ]
i VAR Byte
pulseCount VAR Word
pulseLeft VAR Word
pulseRight VAR Word
time VAR Word
'
[ Constants ]
#SELECT $STAMP ' Select Baud constants
#CASE BS2, BS2E, BS2PE
T1200 CON 813
T2400 CON 396
T4800 CON 188
T9600 CON 84
T19K2 CON 32
#CASE BS2SX, BS2P
T1200 CON 2063
T2400 CON 1021
T4800 CON 500
T9600 CON 240
T19K2 CON 110
#CASE BS2PX
T1200 CON 3313
T2400 CON 1646
T4800 CON 813
T9600 CON 396
T19K2 CON 188
#ENDSELECT
EmicBaud CON T9600
'
[ Initialization ]
DEBUG "HB25 Controller Initializing..."
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
DEBUG "Completed!", CR
'
Emic 2
' When the Emic 2 powers on, it takes about 3 seconds for it to successfully
' intialize. it then sends a ":" character to indicate it's ready to accept
' commands. if the Emic 2 is already initialized, a CR will also cause it
' to send a ":"
DEBUG "Waiting for Emic 2..."
SEROUT EMIC_TX, EmicBaud, [CR]
SERIN EMIC_RX, EmicBaud, [WAIT(":")]
DEBUG "Ready!", CR
'
[ Program Code ]
LEDs:
HIGH FrontLED
HIGH RLED
PAUSE 500
LOW RLED
HIGH GLED
PAUSE 500
LOW GLED
HIGH BLED
PAUSE 500
LOW BLED
SEROUT EMIC_TX, EmicBaud, ["V18", CR] 'Set volume to to maximum.
SERIN EMIC_RX, EmicBaud, [WAIT(":")]
DEBUG "Speaking some text..."
SEROUT EMIC_TX, EmicBaud, ["S", ":-)4Hello. I am Sentry bot. Please state your business", CR] ' Send the string to convert to speech
SERIN EMIC_RX, EmicBaud, [WAIT(":")] ' Wait here until the Emic 2 responds with a ":"
'indicating it's ready to accept the next command
DEBUG "Done!", CR
DO
MOTION:
INPUT PIR
DO
i = i - 10
DEBUG HOME, "WAIT 10 seconds FOR PIR Sensor warm up",CR,
DEC i, " seconds left ",CR
LOOP UNTIL i = 0
NAP 6 ' Nap for 1152 ms (1.152 Seconds).
MAIN:
IF (PIR = 1) THEN ' If PIR sensor detects motion, then speak and drive motors.
HIGH RLED
HIGH BLED
DEBUG CRSRXY, 0,4, "PIR Sensor State = ", BIN1 IN10
SEROUT EMIC_TX, EmicBaud, ["S", ":-)4 Please state the passcode", CR] ' Send the string to convert to speech
SERIN EMIC_RX, EmicBaud, [WAIT(":")] ' Wait here until the Emic 2 responds with a ":"
PAUSE 20 ' Wait 20 mS Before Ramping
FOR pulseCount = 0 TO 100 ' Ramp Up To Full Speed
PULSOUT HB25, 750 - pulseCount ' Motor 1 Reverse
PAUSE 1 ' 1 mS Delay For Motor 2 Pulse
PULSOUT HB25, 750 + pulseCount ' Motor 2 Forward
PAUSE 20 ' 20 mS Smoothing Delay
NEXT
PAUSE 3000 ' Wait 3 Seconds
FOR pulseCount = 100 TO 0 ' Ramp Back Down
PULSOUT HB25, 750 - pulseCount ' Motor 1 Reverse Slowing
PAUSE 1 ' 1 mS Delay For Motor 2
PULSOUT HB25, 750 + pulseCount ' Motor 2 Forward Slowing
PAUSE 20 ' 20 mS Smoothing Delay
NEXT
ELSE
DEBUG CRSRXY, 0,6, "PIR Sensor State = ", BIN1 IN10
LOW RLED
LOW BLED
HIGH GLED
PAUSE 3000 ' Wait 3 Seconds
PAUSE 20 ' Wait 20 mS Before Ramping
FOR pulseCount = 0 TO 100 ' Ramp Up To Full Speed
PULSOUT HB25, 750 + pulseCount ' Motor 1 Forward
PAUSE 1 ' 1 mS Delay For Motor 2 Pulse
PULSOUT HB25, 750 + pulseCount ' Motor 2 Forward
PAUSE 20 ' 20 mS Smoothing Delay
NEXT
PAUSE 3000 ' Wait 3 Seconds
FOR pulseCount = 100 TO 0 ' Ramp Back Down
PULSOUT HB25, 750 + pulseCount ' Motor 1 Forward Slowing
PAUSE 1 ' 1 mS Delay For Motor 2
PULSOUT HB25, 750 + pulseCount ' Motor 2 Forward Slowing
PAUSE 20 ' 20 mS Smoothing Delay
NEXT
ENDIF
LOOP
Thank you,
Paul
Comments
Thank you and have a blessed day!
Paul
I've been looking over your program and I noticed a few things:
Twice in your program you switch to Voice 4, using ":-)4", so why not just change to Voice 4 after you set the volume to maximum.
The PIR documentation initializes with only this instead of the strange DO...LOOP you use and I/O pins starts as Inputs.
I am guessing you have your LEDs wired to be Active-High or on when the output is high. According to the BASIC Stamp Manual the NAP will momentarily turn off the current to all I/O pins as it wakes up.
Use PAUSE instead and if you need more time then use a FOR...NEXT loop or several PAUSES in a row.
You have 2 lines in each part your IF...THEN...ELSE that display the status of the PIR sensor using IN10. You are using PIR for pin 10 so change the IN10 to PIR.
The only variable your program uses in pulseCount.
You also need to change the 100 in your FOR...NEXT loops for pulseCount to 250 since the BS2px PULSOUT command uses a smaller time interval than the BS2.
I don't know what motors you are using but the HB-25 documentation says that pulses of 1 and 2 milliseconds will more the motor at full speed in each direction.
Remember that the pulse value starts at 1875, which results in a pulse of 1875 x 0.8 = 1.5 ms or motor neutral (off).
To get the full speed values, remember that 1000 us are in 1 ms since PULSOUT is in us or micro-seconds. Those are the PULSOUT full speed values but you need to ramp up to them, so you need to know difference between stop and full. Changing the FOR...NEXT value from 100 to 625 should make your motors run at full speed but you might want to try 300 or 400 first and then increase it until your happy.
Paul and Dylbot
Your program already has conditional compilation code for serial baud values so you could add PULSOUT values to the list also.
Unlike the baud rate, the BS2px uses the same PULSOUT duration as the BS2sx and BS2p. Then just change the PULSOUT values in the program to these constants.
Some of the code in your program repeats so you might want to consider using subroutines instead.
For example, you first blink each of the colored LEDs.
A variable now controls which LED will be blinked and the blink time can be easily changed.