View unanswered posts | View active topics It is currently Sun Apr 20, 2014 7:28 am






Reply to topic  [ 4 posts ] 
Parallel Tasks problem 
Author Message
Rookie

Joined: Mon Sep 17, 2012 9:37 am
Posts: 1
Post Parallel Tasks problem
I've run into a problem with my code.
I know that normally, if you have a global variable, you can use it in a function, then use the return command to use it in other functions.
However, the return command does not work when used with parallel tasks. If I try to do so, I get the error "**Severe*:'void' function cannot return a value".

Is there a different command used to share variables in parallel tasks or is such an activity impossible?

An example of this situation would be:
Code:
int sharedvariable;
sharedvariable = 1;

task notmain()
 {
  while 1
   {
    sharedvariable = sharedvariable + 1;
    return sharedvariable;
    wait1Msec(100)
   }
 }

task main ()
 {
  motor[port1]  = sharedvariable;
 }


Mon Sep 17, 2012 9:48 am
Profile
Expert

Joined: Tue Feb 28, 2012 3:10 pm
Posts: 195
Post Re: Parallel Tasks problem
you wouldn't need to return it, simply set it.
Code:
int sharedvariable;

task notmain()
{
   while 1
   {
      sharedvariable = sharedvariable + 1;
      wait1Msec(100)
   }
}

task main ()
{
        sharedvariable = 1;
   StartTask(notmain);
   while 1 {
      motor[port1]  = sharedvariable;
      wait1Msec(500);
   }
}

that is why the tasks are parallel, if that is what you really want to do. In this case (as is usually the case) it is probably not what you really want to do.

_________________
Mike aka Spiked3
http://www.spiked3.com


Mon Sep 17, 2012 11:38 am
Profile
Moderator
Moderator
User avatar

Joined: Wed Mar 05, 2008 8:14 am
Posts: 3107
Location: Rotterdam, The Netherlands
Post Re: Parallel Tasks problem
Just look at my signature what I think about multitasking.

- 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]


Tue Sep 18, 2012 1:26 am
Profile WWW
Site Admin
Site Admin

Joined: Tue May 15, 2007 9:02 am
Posts: 403
Post Re: Parallel Tasks problem
There's a decent post at the top of the forum about multitasking: viewtopic.php?f=11&t=3341

_________________
Jesse Flot
CMU Robotics Academy
ROBOTC Support


Mon Oct 01, 2012 2:32 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.