I'm not sure what you are asking for here because I think I already have provided such an example. The program that my tutorial discusses is intended to demonstrate how use a mutex. Since the full NXC source is included, you can compile and run it. You can also experiment with modifications and see what effect they have. I will be happy to answer any further questions that arise from your experiments.mattallen37 wrote:Could you please provide an example program that shows what you mean? I would like to see the it in action, as well as the proper usage of the commands.
NXC Multitasking Tutorial
-
- Posts: 73
- Joined: 29 Sep 2010, 12:05
Re: NXC Multitasking Tutorial
Regards, Morton
-
- Posts: 1818
- Joined: 02 Oct 2010, 02:19
- Location: Michigan USA
- Contact:
Re: NXC Multitasking Tutorial
I know, but that program had a TON of extra "stuff", and I want a working code that is much smaller, but big enough to demonstrate. Often it helps me if I can see a command used in several ways (in different programs), so I better understand it, and am able to know more of what it can do.
Matt
http://mattallen37.wordpress.com/
I'm all for gun control... that's why I use both hands when shooting
http://mattallen37.wordpress.com/
I'm all for gun control... that's why I use both hands when shooting
Re: NXC Multitasking Tutorial
just erase all the LCD-like 7-segment display code and substitute it by a simple NumOut procedure. maybe that'll help already.
-
- Posts: 1818
- Joined: 02 Oct 2010, 02:19
- Location: Michigan USA
- Contact:
Re: NXC Multitasking Tutorial
Well, I did try modifying the code (not exactly how you said though), and I know what the values returned (displayed) are, and all that, but I want another example that uses a mutex. It would be nice if it also had nothing to do with the button interface.
Matt
http://mattallen37.wordpress.com/
I'm all for gun control... that's why I use both hands when shooting
http://mattallen37.wordpress.com/
I'm all for gun control... that's why I use both hands when shooting
Re: NXC Multitasking Tutorial
Here's an example from NXT Power Programming:
John Hansen
Code: Select all
#define BUMPER_PORT S1
#define BUMPER SENSOR_1
#define BAT_PORT S4
#define BAT_THRESHOLD 30
mutex motorMutex;
task Move() {
while(true) {
Acquire(motorMutex);
OnFwdSync(OUT_AC, 75, 0);
Release(motorMutex);
Wait(500);
}
}
task WatchUltra() {
while (true) {
if (SensorUS(BAT_PORT) < BAT_THRESHOLD) {
// too close so back up and turn
Acquire(motorMutex);
PlayTone(440, 500);
// backup and then spin
OnRevSync(OUT_AC, 40+Random(60), 0);
Wait(500+Random(500));
OnFwdSync(OUT_AC, 40+Random(60), 100);
Wait(500+Random(1000));
Release(motorMutex);
}
}
}
task WatchBumper() {
while (true) {
if (BUMPER) {
// sensor is pressed so back up and turn
Acquire(motorMutex);
PlayTone(880, 500);
OnRev(OUT_A, 40+Random(60));
OnRev(OUT_C, 60+Random(40));
Wait(500+Random(1000));
Release(motorMutex);
}
}
}
task main() {
SetSensorTouch(BUMPER_PORT);
SetSensorLowspeed(BAT_PORT);
Precedes(WatchBumper, WatchUltra, Move);
}
Multi-platform LEGO MINDSTORMS programming
http://bricxcc.sourceforge.net/
http://bricxcc.sourceforge.net/
-
- Posts: 1818
- Joined: 02 Oct 2010, 02:19
- Location: Michigan USA
- Contact:
Re: NXC Multitasking Tutorial
Oh, I see now why it is referred to as a "token". That makes sense now. Thanks for posting the code.
Matt
http://mattallen37.wordpress.com/
I'm all for gun control... that's why I use both hands when shooting
http://mattallen37.wordpress.com/
I'm all for gun control... that's why I use both hands when shooting
Who is online
Users browsing this forum: No registered users and 0 guests