View unanswered posts | View active topics It is currently Tue Oct 15, 2019 4:47 am






Reply to topic  [ 5 posts ] 
how to use task control 
Author Message
Rookie

Joined: Sun Nov 08, 2009 7:11 pm
Posts: 3
Post how to use task control
I'm fairly new and wanted to know how to combine two separate programs in one 'task main'. I read about task control and am confused about taskID how do i use the StartTask(taskID); stopTask(taskID; and can the ID be anything? (words, numbers)

Is the formatting something like
Code:
task main()
{
   starttask(????)
   ...// program one
   stopTask(????)

  starttask(???)
  ...// program two
  stoptask(???)

}

because i keep getting errors

also how do I undo a nSyncMotors if you want them to be independent again.


Thu Nov 12, 2009 12:12 am
Profile
Expert
User avatar

Joined: Tue Oct 14, 2008 7:16 pm
Posts: 171
Location: Investigating an unidentified ship sighted in Sector 31428
Post Re: how to use task control
taskID is simply the name of the task, which is declared like a function only using the task keyword. This name can be just about anything containing alpha-numeric characters, although if I recall, it can't start with a number. Also, you can't use the name of an existing function, it must be unique.

As for de-synching motors, set nSyncMotors to synchNone.

_________________
Captain, Head programmer, School of the Arts, Silverbots Robtics Team #2890
Code:
using namespace System;
using namespace Genius;
using namespace Personality;
public ref class Nerd : Geek, IAnserable
{
    Geek::Type brainMode = Geek::Type::Programmer;
}


Thu Nov 12, 2009 1:00 am
Profile
Rookie

Joined: Mon Nov 09, 2009 10:51 am
Posts: 23
Post Re: how to use task control
Can someone clarify the above answer? Maybe post an example? I'm finding this unclear, too.
For example, I try this way:
Code:
task main()
{
PlaySound(soundBlip);
PlayAnotherSound();
}
task PlayAnotherSound()
{
PlaySound(soundBeepBeep);
}

and it says the procedure 'PlayAnotherSound' is undefined.
So I try this way:
Code:
task main()
{
PlaySound(soundBlip);
StartTask(PlayAnotherSound);
}
task PlayAnotherSound()
{
PlaySound(soundBeepBeep);
}

And the error is Undefined variable 'PlayAnotherSound', along with other errors.
What am I leaving out?
Thanks!


Mon Nov 16, 2009 4:22 pm
Profile
Expert
User avatar

Joined: Tue Oct 14, 2008 7:16 pm
Posts: 171
Location: Investigating an unidentified ship sighted in Sector 31428
Post Re: how to use task control
The second way is correct as far as code goes, but the declaration for PlayAnotherSound() must go before it is called in main. That is to say,
Code:
task PlayAnotherSound()  //Declaration must appear before usage
{
    PlaySound(soundBeepBeep);
}

task main()
{
    PlaySound(soundBeep);
    StartTask(PlayAnotherSound);  //Usage
}


In the above code, the task is defined at the same time it is declared. You could also have done this
Code:
task PlayAnotherSound();   //Declaration

task main()
{
    PlaySound(soundBeep);
    StartTask(PlayAnotherSound); //Usage
}

task PlayAnotherSound()    //Definition
{
    PlaySound(soundBeepBeep);
}

The first line in this code is called a function (or in this case task) prototype. It simply declares the function name so that the compiler knows what it is and you can call it. The compiler then knows to look for a function (or task) body elsewhere in the code because there are no braces, only a semicolon. This method is useful because it allows you to write the bodies' of your functions later but still call them from the code you are working on now.

_________________
Captain, Head programmer, School of the Arts, Silverbots Robtics Team #2890
Code:
using namespace System;
using namespace Genius;
using namespace Personality;
public ref class Nerd : Geek, IAnserable
{
    Geek::Type brainMode = Geek::Type::Programmer;
}


Mon Nov 16, 2009 4:59 pm
Profile
Rookie

Joined: Mon Nov 09, 2009 10:51 am
Posts: 23
Post Re: how to use task control
That explains it perfectly! Thank you.


Tue Nov 17, 2009 12:57 pm
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.