Subject:
|
Re: Help me convert this train program to use events (NQC)
|
Newsgroups:
|
lugnet.robotics.rcx.nqc
|
Date:
|
Tue, 29 Nov 2005 03:14:56 GMT
|
Viewed:
|
6643 times
|
| |
| |
In lugnet.robotics.rcx.nqc, Jordan Bradford wrote:
|
|
|
I was wondering about that monitor block and whether it would only execute
once. Should I put the monitor block inside a while(true) ?
|
Yes. I cobbled up an (untested!) version of your program using events
(before you decided to go over to touch sensors again). This assumes an
on-train RCX with an on-train light sensoer looking down:
#define eye SENSOR-1
#define train OUT-A
#define STATION-EVT 0
task main()
SetSensor(eye, SENSORLIGHT);
SetEvent(STATIONEVT, eye, EVENTTYPEHIGH);
SetPower(train, OUTHALF);
while(true)
monitor(EVENTMASK(STATIONEVT))
Wait(32767);
catch
Float(train);
Wait(100);
Toggle(train);
On(train);
Wait(500);
Note that the final Wait(500) is so that the train will have time after
reversing to clear the station again - otherwise, the monitor() command will
trip out again as the train reverses over the station.
Use events in this application - its a nice one to learn on, and if you
are using the standard firmware events are wonderful things to use - the
make coding easier and much faster. And for touch sensors there are
EVENTTYPEPRESSED or EVENTTYPERELEASED types that are defined as well.
|
Yep, I forgot that second wait(). My code was untested, remember. :)
The reason I asked about that monitor block is that Im used to C#/Java
applications where you set up event handlers and the environment is
event-driven to begin with; you dont need explicit idling loops that just
wait for something to happen. NQC seems similar to OpenGL/GLUT, then, since
you set up event callback functions and then enter an event loop using
glutMainLoop() or something like that.
Hmmm, maybe Ill try a Java version next.
|
I got to try my program tonight. It wouldnt compile, claiming EVENT_TYPE_HIGH
and EVENT_TYPE_PRESSED were undefined. Eventually I figured out that I had to
set the target flag -TRCX2. My compilation command is getting more and more
complicated:
nqc -SCOM2 -TRCX2 -d -pgm 5 trainshuttle2.nqc -run
Is there a way to tell NQC that this is an RCX 2.0 within the code, like with a
#define something ?
Also, if I put the latest firmware on an RCX 1.0 brick, can it still run 2.0
code like these events?
|
|
Message has 1 Reply:
Message is in Reply To:
16 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
|
|
|
|