Subject:
|
Re: Multitasker test script
|
Newsgroups:
|
lugnet.robotics.rcx.pbforth
|
Date:
|
Wed, 12 May 1999 14:06:41 GMT
|
Reply-To:
|
{robots@jpsc.co.uk}spamless{}
|
Viewed:
|
1603 times
|
| |
| |
Here it is, it is working, but is waiting for IR_MODE_HI,
STOP and a non-blocking EMIT.
There is a light sensor on the centre connector pad.
.dp displays proximity in the LCD as DEFCON.RawLight alternating
with the average ambient raw light sensor reading.
p20 starts the pinger and loops for 20 .dp
pl starts the pinger and loops until the power button is pressed
HEX
\ not all these are used...
4003 CONSTANT sndQueued
4004 CONSTANT sndUnqueued
0000 CONSTANT sndBlip
0001 CONSTANT sndBeepBeep
0002 CONSTANT sndDownwardTones
0003 CONSTANT sndUpwardTones
0004 CONSTANT sndLowBuzz
0005 CONSTANT sndFastUpwardTones
0006 CONSTANT sndLowBuzz2
0001 CONSTANT btnRun
0003 CONSTANT snsLight
0000 CONSTANT snsModeRaw
3003 CONSTANT lcd10sDecimalPoint
3001 CONSTANT lcdSignedNoLeadingZeros
0000 CONSTANT lcdSingleDigitNoPoint
3002 CONSTANT lcdNoDecimalPoint
3004 CONSTANT lcd100sDecimalPoint
3005 CONSTANT lcd1000sDecimalPoint
3017 CONSTANT lcdSingleDigitOnRight
301F CONSTANT lcdUnsignedLeadingZeros
0 CONSTANT FALSE
FFFF CONSTANT TRUE
: LIGHT? ( sensor -- value )
BEGIN
DUP SENSOR_READ
UNTIL
SENSOR_VALUE
;
DECIMAL
1 CONSTANT RawLight
30 CONSTANT SAMPLE_COUNT
77 417 * 1000 / CONSTANT FlashWidth \ ms
20 CONSTANT FlashDelay \ ms
FlashWidth FlashDelay - CONSTANT FlashRemain \ ms
VARIABLE DEFCON
VARIABLE AvgAmbient
VARIABLE MinRaw
VARIABLE RisingMins
VARIABLE LastRaw
VARIABLE DescendingRaw
: InitProximityDriver ( -- )
RCX_INIT
POWER_INIT
BUTTON_INIT
SENSOR_INIT
RawLight SENSOR_ACTIVE
snsLight RawLight SENSOR_TYPE
snsModeRaw RawLight SENSOR_MODE
." IRMode(IR_HI); !!!!!" CR
0
SAMPLE_COUNT 0 DO
RawLight LIGHT? +
LOOP
SAMPLE_COUNT /
AvgAmbient !
0 DEFCON !
AvgAmbient @ MinRaw !
FALSE RisingMins !
AvgAmbient @ LastRaw !
FALSE DescendingRaw !
;
: delay ( 10ms timer -- )
\ ." delay " SWAP DUP . SWAP DUP . CR
SWAP OVER timer_SET
BEGIN
PAUSE
DUP timer_GET 0=
UNTIL
DROP
;
: msWait ( ms -- )
[ DECIMAL ] 10 /
0 delay
;
: DEFCON! ( DiffRaw Raw -- DiffRaw )
AvgAmbient @ SWAP - ( dr aa-raw )
OVER / 0 MAX ( DEFCON )
DEFCON !
;
: ping
\ Algorithm due to Mark R. David markdavid@mediaone.net
RawLight SENSOR_READ
IF
RawLight SENSOR_VALUE
AvgAmbient @ 4 * + 5 /
DUP AvgAmbient !
[ DECIMAL ] 615 - 6 / 6 MAX ( DiffRaw )
[ HEX ] FF EMIT \ blocks unfortunatly - need SendMessage
FlashDelay msWait
RawLight LIGHT? SWAP ( tr dr )
OVER MinRaw @ < ( ThisRaw DiffRaw ThisRaw<MinRaw -- )
IF
OVER MinRaw !
FALSE RisingMins !
TRUE DescendingRaw !
OVER ( tr dr tr )
DEFCON! ( tr dr )
ELSE
OVER LastRaw @ > ( ThisRaw DiffRaw ThisRaw>LastRaw -- )
IF
DescendingRaw @
IF
RisingMins @
IF
LastRaw @ DUP MinRaw ! ( tr dr lr )
DEFCON! ( tr dr )
ELSE
TRUE RisingMins !
THEN
THEN
FALSE DescendingRaw !
ELSE
TRUE DescendingRaw !
THEN
THEN ( ThisRaw DiffRaw -- )
DROP LastRaw !
FlashRemain msWait
THEN
;
InitProximityDriver
DECIMAL 0 50 CELLS 50 CELLS HAT ProximityDriver
ProximityDriver BUILD
:NONAME ProximityDriver ACTIVATE
STOP
BEGIN
PAUSE
ping
\ [ HEX ] RCX_POWER 4000 POWER_GET RCX_POWER @ 0= IF STOP THEN \ this STOP is broke
AGAIN
; EXECUTE
MARKER ~TEST
: .V
BASE @ DECIMAL
RCX_POWER [ HEX ] 4001 POWER_GET
RCX_POWER @ [ DECIMAL ] 10997 390 */
0 <# [CHAR] V HOLD # # # [CHAR] . HOLD #S #> TYPE CR
BASE !
;
: .dp
[ DECIMAL ]
lcdSingleDigitNoPoint
AvgAmbient @
lcdSignedNoLeadingZeros
LCD_NUMBER LCD_REFRESH
40 1 delay
lcd1000sDecimalPoint
LastRaw @ DEFCON @ 1000 * +
lcdSignedNoLeadingZeros
LCD_NUMBER LCD_REFRESH
40 1 delay
;
: p20
ProximityDriver AWAKE
[ DECIMAL ] 20 0
DO
.dp
[ DECIMAL ] 100 2 delay
LOOP
ProximityDriver SLEEP
;
: pl
ProximityDriver AWAKE
BEGIN
.dp
[ DECIMAL ] 100 2 delay
[ HEX ] RCX_POWER 4000 POWER_GET RCX_POWER @ 0=
UNTIL
ProximityDriver SLEEP
;
.TASKS
.dp
.V
--
John Cooper, Wallington, UK
|
|
Message has 2 Replies: | | RE: Multitasker test script
|
| John, I tried to put this part of the code into my test script without the ping word and it worked fine. Yes, I uncommented the line that does not work for you. I'm going to have a closer look at ping...I wonder if it's running out of stack or doing (...) (26 years ago, 13-May-99, to lugnet.robotics.rcx.pbforth)
| | | RE: Multitasker test script
|
| John, I've been looking at your ping routine and note the following... Even if FF EMIT did not block, the wait makes things irrelevant. At 2400 baud, the FF is out the port within 4 msec. In fact, if EMIT did not block, you could probably wait jsut (...) (26 years ago, 13-May-99, to lugnet.robotics.rcx.pbforth)
|
Message is in Reply To:
| | RE: Multitasker test script
|
| (...) Post away! Two heads (too bad there only seem to be two of us :-( are usually better than one! Cheers, Ralph Hempel - P.Eng ---...--- Check out pbFORTH for LEGO Mindstorms at: (URL) ---...--- Reply to: rhempel at bmts dot com ---...--- (26 years ago, 12-May-99, to lugnet.robotics.rcx.pbforth)
|
9 Messages in This Thread:
- Entire Thread on One Page:
- Nested:
All | Brief | Compact | Dots
Linear:
All | Brief | Compact
This Message and its Replies on One Page:
- Nested:
All | Brief | Compact | Dots
Linear:
All | Brief | Compact
|
|
|
|