Subject:
|
Re: Help me convert this train program to use events (NQC)
|
Newsgroups:
|
lugnet.robotics.rcx.nqc
|
Date:
|
Mon, 28 Nov 2005 18:59:11 GMT
|
Viewed:
|
6559 times
|
| |
| |
In lugnet.robotics.rcx.nqc, Brian Davis wrote:
|
In lugnet.robotics.rcx.nqc, Jordan Bradford wrote:
|
|
|
I dont have enough cords to reach the touch sensors...
|
Speaker wire and small alligator clips will make a dandy
solution for extending the basic wires...
|
I wanted the layout to be pure LEGO...
|
For future, LEGOs educational division does sell 3m LEGO wires.
|
Wow! Thats quite a long cable. Is this the right product? I only found it using
Pitscos search box; its not listed in any LEGO section as far as I could tell.
http://www.legoeducation.com/store/detail.aspx?ID=1060
|
|
I have seen the batteries run down very quickly.
|
A 1.0 RCX that allows you to power the setup from an outlet is ideal for
this. If it ends up being battery-based, you will have to adjust the power
level as the batteries drain (probably with finer control than just the 8
power levels the RCX usually allows - but theres ways around this). This to
could be automated, however - record the station-to-station time for the first
complete run, for instance, and if the station-to-station time interval is
ever too long, have the software readjust the output power.
|
My original setups RCX is a 1.0 with the AC adapter. The rails are powered by
the regulator; the RCX just changes their polarity.
|
|
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.
|
|
Message has 2 Replies:
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
|
|
|
|