Subject:
|
Re: NXT Newbie "Is it possible" question
|
Newsgroups:
|
lugnet.robotics.nxt
|
Date:
|
Thu, 19 Aug 2010 14:19:52 GMT
|
Viewed:
|
49747 times
|
| |
| |
In lugnet.robotics.nxt, Chris Eyerly wrote:
> I am hoping to build a race timer mechanism using my NXT and 4 touch sensors.
> Essentially I need it to be similar to a pinewood derby timer. I am holding a
> LEGO car race for our homeschool group, and would love to be able to do all of
> the timing with the NXT. I don't even need it keep track of times, just to tell
> me which lane was first, second, third and fourth for each heat. Is this
> possible with NXT-G 1.1?
>
> thanks!
>
> Chris Eyerly
Chris,
Sure it is, as long as the NXT cables are long enough to place the sensors
where you want on the track.
As you already figured out, the tricky bits are in the software. Here is
pseudocode for what I would do were I to program it in G (no arrays here).
You want a variable for each lane indicating it finished. I picked variable
names lane1_finished, lane2_finished, lane3_finished and lane4_finished. You
start out with all those variables set to false (no one has finished before the
race even starts :). The moment a given lane's touch sensor is pressed, you
want to set that lane's finished variable to true. You want your program to
examine each of the sensors in parallel, so each sensor check should be on its
own sequence bar.... Here is some pseudo code
lane1_finished = false;
lane2_finished = false;
lane3_finished = false;
lane4_finished = false;
// as its own sequence bar
do {
if (sensor1.pressed) {
lane1_finished = true;
}
} while (lane1_finished == false);
// as its own sequence bar
do {
if (sensor2.pressed) {
lane2_finished = true;
}
} while (lane2_finished == false);
// as its own sequence bar
do {
if (sensor3.pressed) {
lane3_finished = true;
}
} while (lane3_finished == false);
// as its own sequence bar
do {
if (sensor4.pressed) {
lane4_finished = true;
}
} while (lane4_finished == false);
// We want the lane order (place order) to run in parallel with the
// touch sensor checking, so it should be on its own sequence bar...
// Now display the finish order, we'll display first place's
// lane number on the first line of the NXT display, second place's
// lane number on the second line, etc. We'll use a number variable to
// track how many have finished so far: place
place = 1
// Also we only allow a given finisher to show up once, so we need
// variables for each lane to indicate it is recorded.
lane1_recorded = false;
lane2_recorded = false;
lane3_recorded = false;
lane4_recorded = false;
do {
if (lane1_recorded is false and lane1_finished is true) {
display_on_line(place,"1");
place = place + 1;
lane1_recorded = true;
}
if (lane2_recorded is false and lane2_finished is true) {
display_on_line(place,"2");
place = place + 1;
lane2_recorded = true;
}
if (lane3_recorded is false and lane3_finished is true) {
display_on_line(place,"3");
place = place + 1;
lane3_recorded = true;
}
if (lane4_recorded is false and lane4_finished is true) {
display_on_line(place,"4");
place = place + 1;
lane4_recorded = true;
}
} while (1); // forever
You might be able to come up with a simpler algorithm, but this one should be
very reliable.
Have fun mapping this to G Chris!
Kevin
|
|
Message has 2 Replies: | | Re: NXT Newbie "Is it possible" question
|
| (...) Well, just for diversity here's a slightly different approach. Make the first block a "Reset Timer" block, then split the program into four sequences. Each is simply a "Wait for Touch Sensor", followed by "Read Timer" block with the result (...) (14 years ago, 24-Aug-10, to lugnet.robotics.nxt)
|
Message is in Reply To:
| | NXT Newbie "Is it possible" question
|
| I am hoping to build a race timer mechanism using my NXT and 4 touch sensors. Essentially I need it to be similar to a pinewood derby timer. I am holding a LEGO car race for our homeschool group, and would love to be able to do all of the timing (...) (14 years ago, 18-Aug-10, to lugnet.robotics.nxt)
|
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
|
|
|
|