To LUGNET HomepageTo LUGNET News HomepageTo LUGNET Guide Homepage
 Help on Searching
 
Post new message to lugnet.robotics.rcx.nqcOpen lugnet.robotics.rcx.nqc in your NNTP NewsreaderTo LUGNET News Traffic PageSign In (Members)
 Robotics / RCX / NQC / 1836
1835  |  1837
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: 
6136 times
  
In lugnet.robotics.rcx.nqc, Brian Davis wrote:
   In lugnet.robotics.rcx.nqc, Jordan Bradford wrote:

  
  
   I don’t 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, LEGO’s educational division does sell 3m LEGO wires.

Wow! That’s quite a long cable. Is this the right product? I only found it using Pitsco’s search box; it’s 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 there’s 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 setup’s 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 - it’s 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 I’m used to C#/Java applications where you set up event handlers and the environment is event-driven to begin with; you don’t 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 I’ll try a Java version next.



Message has 2 Replies:
  Re: Help me convert this train program to use events (NQC)
 
(...) I got to try my program tonight. It wouldn't compile, claiming EVENTTYPEHIGH and EVENTTYPEPRESSED were undefined. Eventually I figured out that I had to set the target flag -TRCX2. My compilation command is getting more and more complicated: (...) (19 years ago, 29-Nov-05, to lugnet.robotics.rcx.nqc, FTX)
  Re: Help me convert this train program to use events (NQC)
 
(...) We called LEGO and the Educational division has been shut down since the day after Thanksgiving for inventory. They won't be able to ship the cables to me in time for the Christmas party I was building this for. Grrrr. Bricklink shows some (...) (19 years ago, 30-Nov-05, to lugnet.robotics.rcx.nqc, FTX)

Message is in Reply To:
  Re: Help me convert this train program to use events (NQC)
 
(...) For future, LEGO's educational division does sell 3m LEGO wires. (...) 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 (...) (19 years ago, 28-Nov-05, to lugnet.robotics.rcx.nqc)

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
    

Custom Search

©2005 LUGNET. All rights reserved. - hosted by steinbruch.info GbR