View unanswered posts | View active topics It is currently Wed Dec 17, 2014 5:32 pm






Reply to topic  [ 4 posts ] 
Is it possible to create an "overlooking" function? 
Author Message
Rookie

Joined: Tue Mar 25, 2014 6:44 pm
Posts: 1
Post Is it possible to create an "overlooking" function?
Hey everyone,

My course requires us to build a robot that can detect an infrared pulse, travel to it, and neutralize it. On our last milestone, we had each function working fine independently. For this upcoming one, however, we also need to have bumpers that will always cause the robot to stop and back up if triggered. The issue is, I can't figure out a way to program this simply into our existing code. It may be possible to create some complicated loops and if statements, but this is a task I'd rather avoid if possible.

Here's my question. Is it possible to create a function in RobotC that is always "watching" to see if it needs to trigger? ie the robot can be doing any task at all, but if a bumper is activated, everything else is overridden and it backs up? Or, if not, is there a simple bit of code I can insert into each function to achieve this? Thank you for any replies.


Tue Mar 25, 2014 6:52 pm
Profile
Moderator
Moderator
User avatar

Joined: Wed Mar 05, 2008 8:14 am
Posts: 3297
Location: Rotterdam, The Netherlands
Post Re: Is it possible to create an "overlooking" function?
You can use multiple tasks for this purpose. You'd have a global variable that is set to a specific value in your watcher task and is constantly checked for in your other tasks:

Code:
bool bGlobalFlag = false;

task watcher()
{
  bool bSomeCondition = false;
 
  while (true)
  {
    // Check if the condition has changed here
    //
    if (bSomeCondition)
    {
      bGlobalFlag = true;
    }
    else
    {
      bGlobalFlag = false;
    }
  }
}

task main()
{
  StartTask(watcher);
  while (!bGlobalFlag)
  {
    // do something useful here
  }
}


Just keep in mind that using multiple tasks can cause more problems that you might think.

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


Wed Mar 26, 2014 2:43 am
Profile WWW
Guru
User avatar

Joined: Sun Nov 15, 2009 5:46 am
Posts: 1353
Post Re: Is it possible to create an "overlooking" function?
Or you can do multiple things in the same task.
Code:
task main()
{
    while (true)
    {
        if (bumper triggered)
        {
            //backing up.
        }
        else if (not reach target)
        {
            //go towards IR.
        }
        else
        {
            //neutralize target.
        }
        wait1Msec(50);
    }
}


Wed Mar 26, 2014 3:55 am
Profile
Moderator
Moderator

Joined: Thu Jan 03, 2013 5:10 pm
Posts: 198
Location: The plateau north of the Ohio River Valley, also known as Cave Country.
Post Re: Is it possible to create an "overlooking" function?
Or, instead of constantly checking the value in other tasks, Hog the CPU in the detecting task using hogCPU(), do the required actions, and then use releaseCPU(). Note that all other tasks are temporarily suspended and cannot function during this time. For more information, check out here.

-A

_________________
I'm not a robot! I'm british! ~ quote from an asparagus
I am not a robot! I am a unicorn! ~ quote from a robot


Fri Mar 28, 2014 10:44 am
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.