View unanswered posts | View active topics It is currently Fri Dec 19, 2014 6:29 am






Reply to topic  [ 4 posts ] 
Variable arguments to `StartTask()` 
Author Message
Professor
User avatar

Joined: Sat May 18, 2013 1:24 pm
Posts: 272
Location: Olympia, WA
Post Variable arguments to `StartTask()`
As the title suggests, I want to have the user select from different tasks, and then start said task. But what should I pass to `StartTask()`? Or is this not possible? What about this `nCurrentTask` I keep seeing?

Edit: It seems like `nCurrentTask` returns a number corresponding to the "index" of that task, as can be viewed in the debugger window.

_________________
FTC Team 6424, the 'Oly Cow - Chief programmer.
FRC Team 4450, Olympia Robotics Federation (ORF).

and also quadrotors. Quadrotors!


Sun Aug 04, 2013 11:44 pm
Profile
Professor
User avatar

Joined: Sat May 18, 2013 1:24 pm
Posts: 272
Location: Olympia, WA
Post Re: Variable arguments to `StartTask()`
I'm just posting this for future reference, in case some poor soul stumbles upon this post and wants to know what happened.

The argument to `StartTask()` is not a function pointer. In fact, I haven't found a way to declare function pointers in RobotC yet, and it doesn't seem like they're supported as of RobotC 3.60. `StartTask()` will take parameters that happen to be the task name, as well as the index number of a task (determined at runtime). This index number is viewable through the debugger window, as well as by accessing the intrinsic variable `nCurrentTask`. By default, I think `main()` is always 0 (pretty sure of this).

It seems like only 20 tasks (0~19) are able to run at one time, and all defined tasks are instantiated at the beginning of the program. Therefore, you cannot define more than 20 tasks in a single program. I don't know what happens if you do (RobotC crashes?). Also, for FTC teams out there, there are two tasks that always run whenever you use "JoystickDriver.c": `ReadMsgFromPC()` and `displayDiagnostics()`. While `displayDiagnostics()` can be disabled, it is still defined, and always listed in the index. Therefore, the number of additional tasks you can define (other than `main()`) is effectively 17.

So what if you want to pass variable arguments to `StartTask()` (and by extension, `StopTask()`)? Simply make a global struct with 2 elements: a string and an int. Then, make an array of 20 of these structs. At the beginning of each task, use `nCurrentTask` to get the index of the current task, and assign one of the elements of the array to that task, along with a string. Or something with enums? Anyway, you get the idea. Hope this helps somebody. Probably me-in-the-future.

_________________
FTC Team 6424, the 'Oly Cow - Chief programmer.
FRC Team 4450, Olympia Robotics Federation (ORF).

and also quadrotors. Quadrotors!


Mon Aug 05, 2013 2:58 pm
Profile
Guru
User avatar

Joined: Sun Nov 15, 2009 5:46 am
Posts: 1362
Post Re: Variable arguments to `StartTask()`
I am not too much an expert in RobotC but my understanding is that RobotC does not support function pointers although the internal implementation does use function pointers. RobotC has a built-in task table apparently has about 20 slots in it. The pointer to each task is stored in this table along side with the name of the task. StartTask is a special function that the compiler will look up its argument in the task table to find the task index in the task table. This lookup is happening only in compile time, so you cannot do this in run-time. To do this in run-time, you have to implement your own lookup table. So just like what Ernest3.14 said, you need to declare a structure that contains the information for translating whatever name you give to your task to the task index.

Having said that, I do not recommend using task. In fact, I haven't found a single scenario where I must use RobotC task. You can simulate multiple tasks using just the task main. That is called cooperative multi-tasking. I have a few posts on the subject if you are interested.


Mon Aug 05, 2013 6:56 pm
Profile
Professor
User avatar

Joined: Sat May 18, 2013 1:24 pm
Posts: 272
Location: Olympia, WA
Post Re: Variable arguments to `StartTask()`
Sure! Any links?

Edit: Never mind. I found the link under my other topic.

_________________
FTC Team 6424, the 'Oly Cow - Chief programmer.
FRC Team 4450, Olympia Robotics Federation (ORF).

and also quadrotors. Quadrotors!


Mon Aug 05, 2013 7:15 pm
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 4 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.