View unanswered posts | View active topics It is currently Thu Jun 21, 2018 10:29 am






Reply to topic  [ 2 posts ] 
Help with concurrent programming with NXC ... 
Author Message
Rookie

Joined: Tue Feb 03, 2015 12:47 am
Posts: 1
Post Help with concurrent programming with NXC ...
Hi:

I was trying to code the Lego Mindstorms NXT 8527 to work on a small
program that uses concurrent programming. Basically, all it does is to
toggle between move forward and stop on pressing the touch sensor.

Code as below:

mutex catchMe, mutexStop, mutexRun;
bool running;

//
// runRobot: Start robot if stopped
//

task runRobot()
{
while (true)
{
if (!running)
{
Acquire (mutexRun);
Acquire(catchMe);

OnFwd (OUT_AC, 75);
running = true;
until (SENSOR_1 == 1);

Release (catchMe);
Release (mutexStop);
}

}
}

//
// stopRobot: Stop robot if running
//

task stopRobot()
{
while (true)
{
if (running)
{
Acquire (mutexStop);
Acquire (catchMe);

Off(OUT_AC);
running = false;
until (SENSOR_1 == 1);

Release (catchMe);
Release (mutexRun);
}

}
}

// Main task

task main ()
{
running = false;

Precedes (runRobot, stopRobot);
SetSensor(IN_1, SENSOR_TOUCH);
}

However, this doesn't quite work as required and there is some problem
related to concurrency. Would be glad to hear from others if there is a
better solution.

Thanks

Chandru


Tue Feb 03, 2015 1:04 am
Profile
Professor
User avatar

Joined: Sat Aug 31, 2013 9:15 am
Posts: 256
Post Re: Help with concurrent programming with NXC ...
An easier way to do this would be to combine the functionality of your two separate tasks into one big while (true) loop. So, it would be executing the one behavior, then on the touch sensor press go to the other one, and then on the next touch sensor press loop back around to the beginning and the first behavior.

_________________
FTC Team 6100 Chariots of Fire - Programmer (2012-2013)
FTC Team 7468 Blue Chariots of Fire - Programmer (2013-2014)
FTC Team 7468 Blue Chariots of Fire - Mentor (2014-2015)
Check out our team website at http://bluechariotsoffire.com/.


Tue Feb 03, 2015 10:46 pm
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 2 posts ] 

Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  



Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by ST Software for PTF.