View unanswered posts | View active topics It is currently Sun Sep 21, 2014 10:12 pm






Reply to topic  [ 5 posts ] 
hogCPU() and releaseCPU() 
Author Message
Rookie

Joined: Sat Jun 08, 2013 11:58 am
Posts: 6
Post hogCPU() and releaseCPU()
I'm trying to use multitasking, but I have a bit problem with it. I've tried to use hogCPU() and releaseCPU() to stop a task and then start it again. I'd like that the task continues what it did before the stop, and I thought these can help. I wrote a short program to try them but it doesn't work good. I'd like the robot to start going and when it detects the heat it stops. It would be good if it could continue going until 1000 degrees. It doesn't good, though, because it doesn't stop. What did I write bad? Are hogCPU() and releaseCPU() suitable for this aim?

This is my program:

Code:
#pragma config(Sensor, S2,     left,           sensorI2CCustomFastSkipStates)
#pragma config(Sensor, S3,     right,          sensorI2CCustomFastSkipStates)

#include "drivers/dexterind-thermalir.h"

    float obr=0;
    float obl=0;


task go()
{
   while(true)
   {
   nMotorEncoder(motorC)=0;
   while (nMotorEncoder(motorC)>-1000)
     {
     motor(motorB)=-20;
     motor(motorC)=-20;
    }
    motor(motorB)=0;
    motor(motorC)=0;
  }
  return;
}

task heat()
{
   while (true)
   {
         obr=TIRreadObjectTemp(right);
        obl=TIRreadObjectTemp(left);

         if (obl>30 || obr>30)
        {
           hogCPU();
          motor(motorB)=0;
          motor(motorC)=0;
           motor(motorA)=30;
          wait1Msec(2000);
          motor(motorA)=0;
          releaseCPU();
        }
   }
    return;
}

task main()
{

  StartTask(go);
  StartTask(heat);

  while (true)
  {
     wait1Msec(300);
  }

}


Thu Jun 20, 2013 8:26 am
Profile
Professor
User avatar

Joined: Sat May 18, 2013 1:24 pm
Posts: 272
Location: Olympia, WA
Post Re: hogCPU() and releaseCPU()
I believe you should try `endTimeSlice();`, that might work better.

hogCPU() and releaseCPU() only make sure that a task doesn't get switched off during that time period; it doesn't guarantee that the task will switch after releasing.

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

and also quadrotors. Quadrotors!


Thu Jun 20, 2013 2:51 pm
Profile
Rookie

Joined: Sat Jun 08, 2013 11:58 am
Posts: 6
Post Re: hogCPU() and releaseCPU()
I'v tried, but it's not good. :-( The light is switched on, but the motors don't stop.


Fri Jun 21, 2013 2:26 am
Profile
Professor
User avatar

Joined: Sat May 18, 2013 1:24 pm
Posts: 272
Location: Olympia, WA
Post Re: hogCPU() and releaseCPU()
On a closer reading, you really don't need multitasking for this... All you need is to have an infinite while loop, which increments the motors and checks for a sensor reading. Then, when the sensor encounters heat, it can throw a flag and you can do whatever before resuming the loop.

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

and also quadrotors. Quadrotors!


Fri Jun 21, 2013 3:03 pm
Profile
Rookie

Joined: Sat Jun 08, 2013 11:58 am
Posts: 6
Post Re: hogCPU() and releaseCPU()
Ok. I managed to solve it. Thanks for your help. :)


Fri Jun 21, 2013 4:23 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.