TripleMutexwithTouchandDistance

From ZENotes
Revision as of 20:49, 14 October 2011 by Admin (Talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search
mutex moveMutex; 

task move_square()
{
 while (true)
 {
   Acquire(moveMutex);
   OnFwd(OUT_AC, 55); Wait(1000);
   OnRev(OUT_C, 50); Wait(500);
   Release(moveMutex);
 }
}  

task check_sensors()
{
 while (true)
 {
   if (SENSOR_1 == 1)
   {
     Acquire(moveMutex);
     OnRev(OUT_AC, 15); Wait(3000);
     Release(moveMutex);
   }
 }
}

task closeup()
{
 while(true)
 {
  while(SensorUS(IN_4)>15);
  Acquire(moveMutex);
  Off(OUT_AC);
  OnRev(OUT_C,100);
  Wait(800);
  Release(moveMutex);
 }
}

task main()
{
 SetSensor(IN_1,SENSOR_TOUCH);
 SetSensorLowspeed(IN_4);
 Precedes(check_sensors, move_square, closeup);
}
Personal tools
Namespaces
Variants
Actions
Navigation
Toolbox