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 / 1839
1838  |  1840
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: 
6216 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 - 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.

I got to try my program tonight. It wouldn’t 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:
  Re: Help me convert this train program to use events (NQC)
 
(...) Not to my knowledge. (...) Yes. The internal hardware between the 1.0, 1.5, and 2.0 bricks is identical with regards to the firmware, so any firmware will work on any RCX. (19 years ago, 29-Nov-05, to lugnet.robotics.rcx.nqc, FTX)

Message is in Reply To:
  Re: Help me convert this train program to use events (NQC)
 
(...) 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. (URL) (...) My original setup's RCX is a 1.0 with the AC adapter. The rails are (...) (19 years ago, 28-Nov-05, to lugnet.robotics.rcx.nqc, FTX)

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