View unanswered posts | View active topics It is currently Fri Sep 19, 2014 5:55 pm






Reply to topic  [ 5 posts ] 
tasks 
Author Message
Rookie
User avatar

Joined: Wed Apr 30, 2008 7:05 am
Posts: 18
Location: Brisbane, QLD
Post tasks
Hey im just wondering if anyone knows if there is a way for the program to know when tasks are finished or still running (i.e. the motors have the runStateIdle). If the task gets started while it is already running it resets and starts again so i want to be able to avoid that if possible :o

_________________
experiencing slow death by thesis


Sun Oct 05, 2008 7:48 pm
Profile
Professor

Joined: Fri Sep 19, 2008 1:22 am
Posts: 200
Post Re: tasks
You could use a model like this:

Code:
// Globals
bool isTaskARunning;

task TaskA()
{
     isTaskARunning = true;
 
     // task does stuff here.

      isTaskARunning = false;
}

bool StartTaskA()
{
    if (isTaskARunning)
        return false;

    StartTask(TaskA);
    return true;
}

void StopTaskA()
{
    StopTask(TaskA);
    isTaskARunning = false;
}

task main()
{
    isTaskARunning = false;


    // stuff

    // Restart task A if it is done.
   StartTaskA();

   // more stuff
}

_________________
Jeff McBride
Benson Robotics Club


Sun Oct 05, 2008 8:06 pm
Profile
Moderator
Moderator
User avatar

Joined: Wed Mar 05, 2008 8:14 am
Posts: 3223
Location: Rotterdam, The Netherlands
Post Re: tasks
It *would* be nice to have some more task control. Jeff, your method is nice but is not fool proof by any means. It is not impossible for a thread to be pre-empted before the first command in it is executed, thus rendering your semaphore a little useless.

Dick, if you're reading this, we already have StartTask(), why not have that return a task id so it can be used subsequently in task control calls such as nTaskState[task_id]? which could have values like "taskStateStopped", "taskStateRunning", "taskStateInitialising", etc, etc. It would also be nice if threads could be suspended. SuspendTask(task_id), ResumeTask(task_id). I am sure these must exist inside the firmware, they are just not exposed to us.

Xander

_________________
| Professional Conduit of Reasonableness
| (Title bestowed upon on the 8th day of November, 2013)
| My Blog: I'd Rather Be Building Robots
| ROBOTC 3rd Party Driver Suite: [Project Page]


Mon Oct 06, 2008 2:45 am
Profile WWW
Rookie
User avatar

Joined: Wed Apr 30, 2008 7:05 am
Posts: 18
Location: Brisbane, QLD
Post Re: tasks
im with you mightor - it def would be nice to have a bit more user control over tasks :idea:

_________________
experiencing slow death by thesis


Mon Oct 06, 2008 3:55 am
Profile
Professor

Joined: Fri Sep 19, 2008 1:22 am
Posts: 200
Post Re: tasks
I would also like to see better to see task control but that is feature request. While we are waiting for that change it is possible, albeit tedious, to solve your problem with the existing feature set. The semiphore mechansim I proposed could be "hardened" in several ways including with careful use of HogCPU().

_________________
Jeff McBride
Benson Robotics Club


Mon Oct 06, 2008 10:20 am
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 5 posts ] 

Who is online

Users browsing this forum: No registered users and 2 guests


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.